Sample code and instructions for Azure Workshop 2017 done at IIT
You need the following prerequisite in order to perform the hands-on activities during the workshop.
- Azure Subscription (Trial Subscription is enough)
- Visual Studio Community 2017
- GitHub Account (With this sample project code pushed to a repository of your own)
You can create a Trial Azure Subscription to follow the hands-on demos during the workshop. Follow the instructions below to create the subscription. You will need a Microsoft Account to proceed.
- Click the link and Create a Microsoft Account with any of your emails
- Click the link to create the Azure Trial Subscription.
- Click on the Start Free button
- Follow the instructions and complete the details to create the Azure Subscription.
Note: You will need a Credit/Debit Card to complete the subscription creation process. You will not be charged. It's for identity verification.
You need to download the Visual Studio Community 2017 edition and install on your development machine to work on hands-on demo. You can sign in to Visual Studio Community 2017 instance using the Microsoft Account you created in the earlier step.
Create a GitHub account and create a repository. Then push this sample code project to the new repository you just created in your own GitHub account. We will be using it to host a web application on Azure
The sample application is a ASP.Net MVC Application created using the default template come with Visual Studio 2017. The solution contains 2 projects.
- IITAzureWorkshop.Web - ASP.Net MVC Application
- IITAzureWorkshop.Functions - Azure Functions application
In addition to the default pages of the application. An additional Order page is added. This contains the UI to create a simple order that will send an email to the buyer using Azure Functions application. There are 2 *AppSettings you need to configure to use this app.
- AppTitle - Title of the application that shows up in the home page
- StorageConnection - Connection string for the Azure Storage Account. (Using this for putting the order in to the Azure Storage Queue)
Azure Functions project with the pre-compiled function SendOrderConfirmation which is a Queue Triggered function with a SendGrid output binding for sending emails using SendGrid email service.
During the demo we will create an Azure Function using the Azure Portal. The sample code for that function is given bellow.
#r "SendGrid"
using System;
using SendGrid.Helpers.Mail;
public static void Run(Order order, TraceWriter log, out Mail email)
{
log.Info($"C# Queue trigger function processed: {order.Id}");
var personalization = new Personalization();
personalization.AddTo(new Email(order.Email));
var messageContent = new Content("text/html", string.Format("Dear {0}, The {1} x {2}(s) you ordered is processing. Thank You for Ordering", order.CustomerName, order.Quantity, order.Product));
email = new Mail();
email.AddPersonalization(personalization);
email.AddContent(messageContent);
email.Subject = "Order Processing";
email.From = new Email("[email protected]");
}
public class Order
{
public Guid Id { get; set; }
public string Email { get; set; }
public string CustomerName { get; set; }
public string Product { get; set; }
public int Quantity { get; set; }
}