Which of the Following File Types Can Be Uploaded to Azure to Run as a Webjob?

Microsoft is probably the near renowned and rewarding visitor that builds tools and techniques for businesses to optimize their processes and gain profitable concern results. One of its less common methods is Microsoft Azure Webjobs. For businesses who aren't aware of Microsoft Azure webjobs, so let me bring it to the limelight.

What is Microsoft Azure WebJobs?

WebJobs is an Azure App Service feature that provides an easy way for SharePoint developers to ru n code or script as a background procedure in the aforementioned context equally an app service web app, API app or mobile app. WebJobs back up C#, PowerShell, JavaScript, PHP, TypeScript, Bash, Python, Bash, .bat, .cmd and more which means that a WebJob can run any lawmaking or script that can execute in the App Service sandbox. Information technology supports NPM and NuGet. There is no extra cost to use WebJobs.

Note: WebJobs is not yet supported for App Service on Linux.

SharePoint developers tin utilize Azure WebJobs to develop timer job functionality or Windows Chore Scheduler to carry out tasks in SharePoint Online for overall Sharepoint development .

For instance, y'all may require a schedule timer task to call back information that is added to the database of the SharePoint listing. It is of import to annotation that SharePoint Online does not provide luxury to deploy farm solutions and timer jobs to iteratively perform scheduled tasks. To schedule a similar timer job in SharePoint Online, yous are required to implement a panel application as an Azure WebJob . The panel application uses the client-side object model (CSOM) to access SharePoint Online resource.

If a SharePoint evolution Company requires to fill the need for a custom background process, Azure WebJobs is what you crave.

Types of WebJobs

There are two types of Azure WebJobs: Continuous and Triggered . Refer to the below tabular array for the differences betwixt them.

Continuous Triggered
It starts as before long as the WebJob is configured.
The chore keeps on running in an endless loop to avoid itself from ending.
In case, if the job ends, you lot can restart it.
Starts on a manual trigger or a schedule.
Runs on all the instances that a web app runs on. Runs on a single instance that Azure chooses for load balancing.
Provides back up for remote debugging. Doesn't provide support for remote debugging.

File Types Supported for scripts or lawmaking

  • .ps1 (PowerShell)
  • .js (Node.js)
  • .cmd, .bat, .exe (Windows cmd)
  • .php (PHP)
  • .sh (Fustigate)
  • .jar (Java)
  • .py (Python)

What is Microsoft Flow?

Microsoft Flow is the meridian choic e for SharePoint development companies to practice any automat ed task in Function 365. It is an online workflow service that automates activities over the most widely recognized apps and services. It is regularly used to automate work processes betwixt your preferred applications and services, synchronize records, get notifications, gather data, and significantly more than.

When you sign upwardly, you can interface with, more 220 services and can manage data either in the on-premises or in cloud sources like SharePoint and Microsoft SQL Server. The list of applications you tin can use with Microsoft Catamenia grows constantly.

For case, SharePoint developers can autom ate the beneath type of tasks:

  1. Instantly react to loftier-need warnings or messages.
  2. Capture, track, and grab up with new sales customers.
  3. Copy all e-mail attachments to your OneDrive for Business organization business relationship.
  4. Collect information about your business organization, and share that information with your group.
  5. Automate approval work processes.

For reference Delight follow this blog to know more about MS Menstruation.

Let's call a Triggered Azure WebJob (manual/scheduled WebJob) through MS Period. But before that one must have active Azure and Office 365 subscriptions .

Azure WebJobs for Office 365 sites

Here, the basic concepts for building a custom task for Role 365 sites and Azure WebJob human activity similar a scheduled task for Function 365 SharePoint sites.

All SharePoint developers requir e is to build a new WebJob is to create a console application.

Setup and run console awarding as Azure WebJob

To configure a console application to run equally an Azure WebJob, perform the below steps:

  • Select New Project > Visual C# > Console Application > Name: WebJobSample > OK in Visual Studio. Also, make certain to select the .Net Framework four.5 or later on.
    New Project

Note: Before the SharePoint developer starts to i mplement a console application, make sure to add required assemblies in the Visual Studio.

  • Install SharePoint specific assemblies from NuGet. Navigate to Tools > NuGet Package Director > Manage NuGet Packages for Solution
    NuGet Package Manager
  • Scan for App for SharePoint > Select package called AppForSharePointWebToolkit > Click Install .
    Install App For SharePoint WebToolkit
  • Open up App.config file and store your Role 365 business relationship credentials by calculation appSettings element equally shown below to fetch them easily inside your code. Add together SPOAccount and SPOPassword keys within the appSettings chemical element to store the username and countersign of your tenant account.
    App.config                  <?xml version=                  "ane.0"                  encoding=                  "utf-eight"                  ?>                  <configuration>                  <startup>                  <supportedRuntime version=                  "v4.0"                  sku=                  ".NETFramework,Version=v4.five.2"                  />                  </startup>                  <appSettings>                  <add cardinal=                  "SPOAccount"                  value=                  "  "                  />                  <add key=                  "SPOPassword"                  value=                  "  "                  />                  </appSettings>                  </configuration>                

    App.config
    <?xml version="1.0″ encoding="utf-8″ ?>
    <configuration>
    <startup>
    <supportedRuntime version="v4.0″ sku=".NETFramework,Version=v4.v.2″ />
    </startup>
    <appSettings>
    <add together cardinal="SPOAccount" value=" "/>
    <add fundamental="SPOPassword" value=" "/>
    </appSettings>
    </configuration>

Note: Here, the config file stores the organisation's username and password in clear text. It depends upon your project requirements for where and how to store hallmark details and encrypting the passwords for product deployments.

  • Add below code inside the Program.cs file of the created console application.
  • Import using statements
    Program.cs                  using Microsoft.SharePoint.Client                  ;                  using System.Security                  ;                  using System.Configuration                  ;                  using System;                

    Program.cs
    using Microsoft.SharePoint.Customer;
    using System.Security;
    using System.Configuration;
    using System;

  • Configure the post-obit methods inside your class:
  • Main: This method is used to cosign your SharePoint site and execute CSOM requests to carry out tasks within your site. SharePoint consultants volition get a SharePoint library using CSOM and then become the total number of documents inside that library as an output.
    Programme.cs                  static                  void                  Master(string[                  ]                  args)                  {                  using                  (ClientContext context                  =                  new                  ClientContext(                  " "                  )                  )                  {                  // Use default authentication way.                  context.AuthenticationMode                  =                  ClientAuthenticationMode.Default                  ;                  context.Credentials                  =                  new                  SharePointOnlineCredentials(GetSPOAccountName(                  )                  ,                  GetSPOSecureStringPassword(                  )                  )                  ;                  // Add your CSOM code to perform tasks on your sites and content.                  try                  {                  List objList                  =                  context.Web.Lists.GetByTitle                  (                  "Docs"                  )                  ;                  context.Load                  (objList)                  ;                  context.ExecuteQuery                  (                  )                  ;                  if                  (objList                  !=                  null                  &&                  objList.ItemCount                  >                  0                  )                  {                  Console.WriteLine                  (objList.Title.ToString                  (                  )                  +                  " has "                  +                  objList.ItemCount                  +                  " items."                  )                  ;                  }                  }                  take hold of                  (Exception ex)                  {                  Panel.WriteLine                  (                  "ERROR: "                  +                  ex.Bulletin                  )                  ;                  Panel.WriteLine                  (                  "Fault: "                  +                  ex.Source                  )                  ;                  Console.WriteLine                  (                  "ERROR: "                  +                  ex.StackTrace                  )                  ;                  Console.WriteLine                  (                  "ERROR: "                  +                  ex.InnerException                  )                  ;                  }                  }                  }                

    Programme.cs
    static void Main(string[] args)
    {
    using (ClientContext context = new ClientContext(" "))
    {
    // Apply default hallmark style.
    context.AuthenticationMode = ClientAuthenticationMode.Default;
    context.Credentials = new SharePointOnlineCredentials(GetSPOAccountName(), GetSPOSecureStringPassword());

    // Add your CSOM code to perform tasks on your sites and content.
    try
    {
    List objList = context.Web.Lists.GetByTitle("Docs");
    context.Load(objList);
    context.ExecuteQuery();

    if (objList != cipher && objList.ItemCount > 0)
    {
    Panel.WriteLine(objList.Title.ToString() + " has " + objList.ItemCount + " items.");
    }

    }
    catch (Exception ex)
    {
    Console.WriteLine("ERROR: " + ex.Message);
    Panel.WriteLine("Fault: " + ex.Source);
    Panel.WriteLine("ERROR: " + ex.StackTrace);
    Console.WriteLine("Error: " + ex.InnerException);

    }
    }
    }

  • GetSPOAccountName: Create this method to read a username from the config file.
    Programme.cs                  private                  static                  string GetSPOAccountName(                  )                  {                  endeavour                  {                  Console.WriteLine                  (                  "Entered GetSPOAccountName."                  )                  ;                  return                  ConfigurationManager.AppSettings                  [                  "SPOAccount"                  ]                  ;                  }                  catch                  {                  throw                  ;                  }                  }                

    Program.cs
    private static string GetSPOAccountName()
    {
    try
    {
    Console.WriteLine("Entered GetSPOAccountName.");
    render ConfigurationManager.AppSettings["SPOAccount"];
    }
    catch
    {
    throw;
    }
    }

  • GetSPOSecureStringPassword: Create this method to read a countersign from the config file.
    Program.cs                  private                  static                  SecureString GetSPOSecureStringPassword(                  )                  {                  try                  {                  Console.WriteLine                  (                  "Entered GetSPOSecureStringPassword."                  )                  ;                  var                  secureString                  =                  new                  SecureString(                  )                  ;                  foreach                  (                  char                  c                  in                  ConfigurationManager.AppSettings                  [                  "SPOPassword"                  ]                  )                  {                  secureString.AppendChar                  (c)                  ;                  }                  Panel.WriteLine                  (                  "Constructed the secure password."                  )                  ;                  return                  secureString;                  }                  take hold of                  {                  throw                  ;                  }                  }                

    Program.cs
    private static SecureString GetSPOSecureStringPassword()
    {
    endeavour
    {
    Console.WriteLine("Entered GetSPOSecureStringPassword.");
    var secureString = new SecureString();
    foreach (char c in ConfigurationManager.AppSettings["SPOPassword"])
    {
    secureString.AppendChar(c);
    }
    Console.WriteLine("Constructed the secure password.");

    return secureString;
    }
    catch
    {
    throw;
    }
    }

Publish your console application past running it as Azure WebJob

If the user has once completed implementing a console awarding, SharePoint consultants need to publish their panel application equally an Azure WebJob.

To publish your console application every bit an Azure WebJob, you can configure on-demand or triggered Azure WebJob.

Create WebJob binaries cipher file to upload every bit Azure WebJob

You tin upload a zip file containing output files from Visual Studio build (files in bin/Debug or bin/Release binder). This is a simple way of compiling and shipping your code.

Create WebJob binaries

Shrink all the output files that are resulted from the building of the process to create a zip file for your WebJob.

WebJob samples

Create an on-need or manually triggered WebJob

  • Select App Services from left blade content and navigate to the App Service page of your App Service web app in the Azure portal .
    App Services Note: You can utilize any sample app service to schedule your WebJob.
  • Click WebJobs.
    Click WebJobs
  • On the WebJobs page, click Add.
    WebJobs page
  • Provide Add WebJob settings as needed and click OK .
    • Name: A unique name, say "triggeredWebJob", within the App service app. Make sure that the name must showtime with a letter or a number and should not comprise special characters except "-" and "_".
    • File Upload: Hither upload the .zip file created earlier that contains the executable output files.
    • Type: Triggered
    • Triggers: TransmissionAdd WebJob
  • After a few seconds, the newly created WebJob appears on the WebJobs folio of the App service.
    Newly created WebJob

Trigger Azure WebJob through Microsoft Flow

We have a WebJob that counts the number of items within a library. Such a chore works perfectly for a scheduled task. Though, it can be ideal to trigger the web chore automatically when a new document item is added instead of waiting for the scheduled job to run. You can behave out the procedure past triggering Azure WebJob through Microsoft Catamenia.

Users are required to fetch hallmark tokens of the app service containing WebJob.

  • Retrieve hallmark token for the app service where WebJob is running. Select Get publish profile from the ribbon on the app service overview folio.Get publish profile

Information technology volition download a file that has the PublishSettings extension. Browse for the publishProfile element with publishMethod =" MSDeploy ". Note the userName "$spWebJob" and password i.e userPWD in the file that will exist used later while configuring a flow.

Publish Data

  • Fetch the Web Claw url by selecting your WebJob Properties.Web Hook
  • Visit the MS Menstruum via https://flow.microsoft.com, select My flows and click New > Instant-from blank.Visit the MS Flow
  • Add when a file is created (properties only) SharePoint trigger. Select Site Address and required Library Name every bit "Docs".SharePoint trigger
  • Add HTTP-HTTP activeness step. Rename the action to Trigger Azure WebJob. Change Method to "Postal service" for URI https://spwebjob.scm.azurewebsites.net/api/triggeredwebjobs/triggeredWebJob/run, which is the spider web hook URL retrieved earlier. No need to set Header and Body.
  • To view the advanced settings options, click on Show avant-garde options. Set Authentication to "Basic", enter your Username and Password copied before.
  • Provide a flow proper noun equally Phone call Azure WebJob and click Salvage . The final flow would look like the i below.
    Provide flow name
  • In improver to a document within the library, your catamenia will start running.
    Flow will start running
  • Cheque the Period run.
    Check the Flow run

View the WebJob history

Once MS Flow runs successfully, y'all demand to verify whether WebJob has been triggered successfully or not.

  • In the Azure Portal , navigate to the WebJobs page for your app service.
    Azure Portal
  • Select triggeredWebJob WebJob under your app service for which you want to view chore history and click the Logs push in the height ribbon.WebJobs
  • It will open the WebJob Details page in a new browser tab. Choose the time for your task run to bank check details. Note the status of the chore run to verify a successful run.Webjob Details

You can besides view output details in a split window past clicking the download link. SharePoint consultant tin can likewise download the output text itself by right-clicking the download link and using browser options to save the output text of the job run.

Download Details

  • You can navigate back to the list of WebJobs by clicking WebJobs breadcrumb link at the top.
    List of WebJobs

Microsoft Azure WebJobs

Determination

If a WebJob has the Web Hook endpoint, try not to hold on to information technology at a unmarried attempt. SharePoint consultants can provoke a tri ggered Azure WebJob automatically without hanging tight for its manual input/scheduled commencement fourth dimension through MS Menstruum. MS Flow provisions the states with different triggering actions similar "When an item is created or modified", "Item is deleted", "When a record is selected", etc. and furthermore provide other services like Dynamics 365, Salesforce, OneDrive, Dropbox, etc. to piece of work around them alongside Azure WebJob.

Alludes to our next blog showcasing the utilise of an Azure Part through the remarkable MS Menses.

whitesensill.blogspot.com

Source: https://www.tatvasoft.com/blog/securely-trigger-an-azure-webjob-using-microsoft-flow/

0 Response to "Which of the Following File Types Can Be Uploaded to Azure to Run as a Webjob?"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel