Monthly Archives: May 2017

Use Azure IaaS As A Starting Point On Your Cloud Journey

In this article , we will discuss how to leverage business with Azure IaaS (Infrastructure as a Service). We will take a comparative look between Traditional Model vs. Cloud Model.

If you have quesitons about the clous Cloud , please look over the following:

I am sure by the end of this article, we will have a sound rationale for using Cloud Services

Azure

As shown above , in the Traditional on-premise Service Model we have to take care of the Application, Data, Runtime, Server, Storage etc.

But we could use either IaaS, PaaS or SaaS based on individual and business usage

Pay per use

Azure

For Platform as a Service (PaaS), we can benefit from one or all of the Security & Management, Platform Services or Infrastructure Services.

Worldwide Azure Regions Availability

Azure

As of today, there are a total of 34 Azure regions to give support 24/7 to customers in almost every continent.

Geo Redundancy

Azure

Highly promising Geo replications options are available across the globe for Disaster Recovery.

Security

It would not be wrong to say that the data is highly secure in the Cloud, owing to the Security mechanisms at the levels of:

  1. Physical
  2. Infra
  3. Network and
  4. VM

It is shown below.

Azure

Azure Security Center

For details, please refer to this related article:

Azure Security – Solution To Digital Transformation

Azure security center is available to keep an eye out every time for Cloud Resources, as shown below.

Azure

Now, let’s dive deep down into IaaS Core Services.

It’s a combination of the following

  1. Compute
  2. Storage
  3. Networking and
  4. ManagementAzure

Options for the Compute Families

Azure

Azure Storage,

For more details, please refer to my Azure Storage series from 1 to 7,

Azure NoSQL DocumentDB

Azure DocumentDB is a NoSQL document database-as-a-Service from Microsoft Azure is designed for saving, retrieving and managing each record in an internal structure of fields (semi-structured data, documents or keys). DocumentDB is a schema free JSON document database and also support JavaScript. DocumentDB includes built-in high availability, offers predictable performance and supports elastic scale-out. DocumentDB has some exciting features.

  • Tunable, high performance.
  • Multi document transactions.
  • Query over schema free JSON.
  • Automatic Indexing.
  • Easy to learn query grammar.
  • Low-latency access around the globe.
  • Rich SQL queries over schema-free JSON storage.
  • Server side execution of the Application defined JavaScript as stored procedures and triggers.
  • JavaScript language integration for multi-document transactions.
  • Tunable consistency levels for optimal Application performance.
  • Standard JSON storage with RESTful HTTP interfaces.

    Azure

Let’s understand it by performing something practical on the portal. Enter your credentials and login to Azure portal. Go to New, select Storage and click See All because it seems there is no DocumentDB in Featured Apps.

Azure

Select NoSQL and click it. Here, I need to create Document Account.

Azure

Give a name to your account and select API for it. There are two options for selecting API DocumentDB and MongoDB. I’ll discuss MongoDB in my further articles. All steps are same and are related to the previous articles. Click to create DocumentDB Account.

Azure

Under DocumentDB account, I have to create a Collection. It is a logical container for the physical partitions. A collection is like a container for JSON documents and JavaScript Application logic. Click Add Collection to add a new one.

Azure

For a collection, give a name to your collection and its storage capacity to handle collection is up to 10 TB and set a storage capacity for it. Now, there is a Partition key, which is a JSON property within your documents. Partition key is an element within your document. Give a database name to it and click OK button to create a Collection.

Azure

Thus, my collection is ready now.

Azure

Go to Document Explorer, where we can create and upload our documents under our Collection.

Azure

Click Create and you will see a JSON format script with ID and People (partion). You can upload JSON script as well. I’ve given an Id and some data in People Partition. Click Save to save this script.

Azure

Now, go to Query Explorer and run a query.

Azure

The query will be executed successfully and produces the expected result.

Azure

Creating And Using Azure SQL Server And Azure SQL Database

I am going to explain SQL Server and SQL database in Microsoft Azure portal. You can create a database and Server from Azure portal and access it in Visual Studio. Afterwards, you can use it as Entity Framework Designer from the database in any Application.

Let’s login to Azure new portal and create a SQL database.

SQL Server

For creating a database on Azure portal, you have to fill in some details of it. Give a name to your database, subscription name, resource group whatever you want to use, blank database and a Server.

Click Servers, if you want to use an existing SQL Server from the list of the available Servers into your Azure, then you can select it (you must know name and password of the Server). Here, I am going to create a new one.

SQL Server

To create a new Server, follow the steps given below.

  • Server Name – Give a name to your Server.
  • Server Admin Login – Enter user name but make sure that your login name meets the requirements, given below – it’s a SQL identifier and not a typical system name such as an admin, administrator, sa, root, dbmanager, loginmanager etc.
  • Password- Create a password for your Server, which would be used when you connect with it from MS SQL Server Management.
  • Confirm Password – The password should match with the password.
  • Location- Your Server location.

Click to select button to create a new Server.

SQL Server

Just click to create button to create a Server and database.

SQL Server

I want to add it with Microsoft SQL Server. To generate a client IP, click Add Client IP in Firewall Setting.

SQL Server

Here, I am using Visual Studio 2015. My Azure subscription is already connected with Visual Studio Server Explorer. Open SQL Databases under your Azure subscription. You’ll get your database, which you created on Azure portal. I want to open it in Microsoft SQL Server Explorer where we can create the scripts.

SQL Server

In next popup, give a Server name into Server name section, which you created in Azure portal along with the user name and password.

SQL Server

After clicking Connect button, you connect with Explorer. Now, you can create tables.

SQL Server

Add a new table.

SQL Server

After writing table script in to design section, click Update button.

SQL Server

Click Update database to update whole database.

SQL Server

Refresh the table and you will get the expected result.

SQL Server

If you want to connect with it again, then you have to enter only Server password.

SQL Server

Now, you can connect with ADO.NET Entity Data model. Also, you can use an Entity Framework approach.

Fundamentals Of Microsoft Azure Mobile Service

Fundamentals Of Microsoft Azure Mobile Service

Azure

Microsoft Azure Mobile Service gives us the authority to create a Cloud Service Mobile Application. This will leverage us with more flexibility and make an Application more portable.

This is a short introduction of Azure Mobile Service. Now, let’s create and integrate new mobile Service with new or an existing Application. Thus, let’s understand Azure Mobile Service and I am sure, it would mesmerize the users.

Let’s create a new mobile Service

First go to your Azure portal and select the Mobile Service option. Click plus new icon in the bottom of the page.

Azure

Create a new Mobile Service.

After creating Mobile Service, open the Mobile Service and select the dropdown option “CONNECT AN EXISTING WINDOWS OR WINDOWS PHONE APP” below the Get Started option.

Azure

Now, copy the code and paste it in the App.xaml.cs file of your Application. Please focus on the additional instruction, which is right above the code.

Now, create a new class named MyItems, which will make all the necessary tables of your Mobile Service.

  1. class MyItems
  2. {
  3.     [JsonProperty(PropertyName = “id”)]
  4.     public string Id { get; set; }
  5.     [JsonProperty(PropertyName = “message”)]
  6.     public string Message { get; set; }
  7.     [JsonProperty(PropertyName = “location”)]
  8.     public string Location { get; set; }
  9.     [JsonProperty(PropertyName = “Date”)]
  10.     public DateTime Date { get; set; }
  11. }

I have created four attributes namely fieldsID, Message, Location and Date. Please remember for JsonProperty attribute, which we have to install ‘Newtonsoft.JsonNuGet package manager’.

Now, to perform any CRUD operation like insert, update and delete the data in your SQL table, let’s write the code in .cs files.

To begin with, let’s create MainPage.xaml. We need a ListBox to display the data from out Mobile Service table. As there are multiple attributes and columns, here we re showing only Message, Location and Date values.

  1. <ScrollViewer>
  2.     <StackPanel Margin=“10,10,0,0”>
  3.         <ListBox x:Name=“listBox”
  4.                         Margin=“10,10”
  5.                         RequestedTheme=“Dark”
  6.                         FontSize=“20”
  7.                         Background=“White”
  8.                         Foreground=“Black” BorderThickness=“1”
  9.                         BorderBrush=“Transparent” >
  10.             <ListBox.ItemContainerStyle>
  11.                 <Style TargetType=“ListBoxItem”>
  12.                     <Setter Property=“HorizontalContentAlignment” Value=“Stretch”></Setter>
  13.                 </Style>
  14.             </ListBox.ItemContainerStyle>
  15.             <ListBox.ItemTemplate>
  16.                 <DataTemplate>
  17.                     <Border BorderThickness=“0,0,0,1” BorderBrush=“#c0c0c0”>
  18.                         <StackPanel>
  19.                             <TextBlock Foreground=“Black” Text=“{Binding Message}” />
  20.                             <TextBlock Foreground=“Black” Text=“{Binding Location}” />
  21.                             <TextBlock Foreground=“Black” Text=“{Binding Date}” />
  22.                         </StackPanel>
  23.                     </Border>
  24.                 </DataTemplate>
  25.             </ListBox.ItemTemplate>
  26.         </ListBox>
  27.     </StackPanel>
  28. </ScrollViewer>

Listing: 2

Put the code given below in MainPage.cs, which is above the constructor.

  1. /// <summary>
  2. /// Mobile Service
  3. /// </summary>
  4. private MobileServiceCollection<Item, Item> Myitems;
  5. private IMobileServiceTable<Item> itemTable = App.MobileService.GetTable<Item>();

Listing: 3

Now, in constructor; initialize MainPage_Loaded method and implement, as shown below.

  1. public MainPage()
  2. {
  3.     this.InitializeComponent();
  4.     this.Loaded += MainPage_Loaded;
  5. }
  6. async void MainPage_Loaded(object sender, RoutedEventArgs e)
  7. {
  8.     Myitems = await itemTable.ToCollectionAsync();
  9.     this.listBox.ItemsSource = Myitems;
  10. }

Listing: 4

Here, listbox is the name of out ListBox control. Thus, we set an item source as Myitems, which sets Mobile Service table’s values.

If you run the Application, it will show all the data in the ListBox control.

Conclusion

I hope, you understood the basics of Microsoft Windows Azure Mobile Service. Till next time, keep learning.

Azure App Service – API Apps

Microsoft Azure app Service API apps offers secure and flexible development, easy deployment including continous delivery, accessing On-Permises data, Web jobs for background processing, high availability and scaling options for any sized RESTful API Applications. Use frameworks and templates to create RESTful APIs in seconds. Azure API apps are well known for automatic OS patching. You can use any tool or an opearting system to develop your RESTful API with .NET, Java, Node.js, PHP or Python.

  • Fastest and easy way to build productivity developement.
  • Provision and deploy fast and consume API.
  • Simple develop, host access control and authentication.
  • Secure platform, which scales automatically with hybrid connectivity.
  • New Developement experience with API features.
  • API definition for the Website host.
  • Swagger metadata, which is integrated with API app.
  • Easy connectivity with all apps.

    Azure

Source – https://docs.microsoft.com/en-us/azure/app-service-api/app-service-api-apps-why-best-platform

Create a Azure API app Service from Azure portal,;login to your credentials and go to New and select Web+Mobile. In featured apps , you may get API app. If it is not there, then click See all options.

Azure

Type API app and select it from the given list.

Azure

Click Create button to create a new API app.

Azure

Give a name to your API app, your default subscription will be selected by default and I have selected an existing resource group for my app.

App Service Plan/Location is your physical resource, where you host your apps. API app associates with one app Service Plan/Location. You can create a new plan for your app by clicking it.

Azure

You have to choose one pricing tier P1 Premium or S1 Standard or B1 basic for your app.

Azure

Application insights contain tools, which can be used to manage your app behavior. After filling all the necessary details, click Create button to create an API app.

Azure

When your app will create under your selected resource group, a notification appears.

Azure

Whenever your app is created, then you can manage your app such as Deployment settings, Settings, app Service plan, deployment tools, API, Monitoring and some common setting related to the app.

Azure

You can manage and see your app by clicking Overview, where would all the details be, which are available for your app.

Azure

Host your app Service to the existing app on Azure

I’m going to create an Azure API app from Visual Studio 2015 and I will publish it to our existing API app. Thus, let’s create a new solution and give it a name.

Azure

Select Azure API app template from the templates.

Azure

Create a model class by right clicking on Models folder in the solution.

Azure

In the class, I have created three properties.

  1. namespace AzureApiApp.Models
  2. {
  3.     public class Cricketer
  4.     {
  5.         public int Rank { get; set; }
  6.         public string Name { get; set; }
  7.         public string BatingStyle { get; set; }
  8.     }
  9. }}

Let’s add a Web API2 Controller class by right clicking on Controllers folder.

Azure

Give a name to your Controller class.

Azure

Write the code given below into your Controller class, where I’ve returned a list of cricketers.

  1. using AzureApiApp.Models;
  2. using System.Collections.Generic;
  3. using System.Web.Http;
  4. namespace AzureApiApp.Controllers
  5. {
  6.     public class CricketersController : ApiController
  7.     {
  8.         [HttpGet]
  9.         public IEnumerable<Cricketer> Get()
  10.         {
  11.             return new List<Cricketer>()
  12.             {
  13.                 new Cricketer() {
  14.                         Rank = 1, Name = “A.B r DeVilliers “, BatingStyle=“Right Hand Batsman”
  15.                     },
  16.                     new Cricketer() {
  17.                         Rank = 2, Name = “Virat Kohali”, BatingStyle=“Right Hand Batsman”
  18.                     },
  19.                     new Cricketer() {
  20.                         Rank = 3, Name = “David Warner”, BatingStyle=“Left Hand Batsman”
  21.                     },
  22.                     new Cricketer() {
  23.                         Rank = 4, Name = “Martin Gupti”, BatingStyle=“Right Hand Batsman”
  24.                     }
  25.             };
  26.         }
  27.     }
  28. }

Now, it’s time to publish our app to Azure. Right click on the solution and select Publish option.

Azure

Select a target to publish your app and click ext.

Azure

Enter your credentials and you’ll get your Azure Subscription along with the list of Resource Group. If you remember, where I have created an API app in the Default-Web-EastAsia. Expand and select app.

Azure

After clicking OK button, a connection will be created. Click Next button.

Azure

I don’t have any database for this app. Continue clicking on to next.

Azure

Finally, click Publish to publish your app on Azure.

Azure

It can take some time to publish it.

Azure

After a successful attempt, your app Service will be created.

Azure

Your app has been published now you can check your Service data by calling your controller in the Browser.

Azure

In this article, we learned about how can we create an Azure API app and publish it on Azure.

Azure Security – Solution To Digital Transformation

Nowadays, we are moving more and more towards digital transformation, like banking, automobiles, and  other sensitive information. Digital transformation has changed the business world totally and digital transformation is not just about end users in a particular organization or region. The technologies and processes driving digital transformation can help transform IT and also drive business rapidly.

Azure

Why security is important?

For most of us, the recent Zero Day vulnerabilities in iOS are probably still fresh.

Let’s think about what could happen. By clicking a link, we would get a text/message, our device could be jailbroken, and then it would ne completely owned by an attacker with access to literally everything stored and accessed with that device.

This is an incredible reminder of the importance of securing and protecting our people and data.

Given are the examples of most recent security breaches.

Azure

So, we could say that Cyber Security is the number one priority.

Azure

So, not coincidentally, this escalating threat comes at the same time when the surface area you have to protect is also rapidly expanding. This expansion is driven by the always growing number of mobile devices in your network, and these devices are constantly taking your data well beyond the confines of your data center. There is also the growing number of SaaS applications your organization needs or that your employees are already using.

Your operations are most likely run from a different set of datacenters, public and private. For decades, we all have relied on the perimeters of our organizations to act as one of the primary lines of defense from attacks but as our data regularly moves outside of these perimeters to the cloud and cloud-based apps, these boundaries are no longer effective deterrents.

Azure

Azure

  • Do you know which user accounts have been compromised and are being used to access your company or customer information?
  • Can you guarantee that only your employees are accessing corporate resources?
  • Do you know what SaaS apps your employees are using and protect the company data in those apps?
  • Are you confident that corporate data being accessed and stored on mobile devices is secure?
  • Do you know what sensitive/confidential data is being shared with partners?
  • Do you want to know if sensitive/confidential data is assessable without requiring authentication and validation?

So, we could say that after any security threat, these are action items needed to be performed.

  1. Protect
  2. Detect
  3. Respond

    Azure

Azure Active Directory is a comprehensive identity and Access Management cloud solution that provides a robust set of capabilities to manage users and groups. It helps secure access to on-premises and cloud applications, including Microsoft Online services like Office 365 and many non-Microsoft SaaS applications.

How reliable is Azure AD?

The multi-tenant, geo-distributed, high availability design of Azure AD means that you can rely on it for your most critical business needs. Running out of 28 data centers around the world with automated failover, you’ll have the comfort of knowing that Azure AD is highly reliable and that even if a data center goes down, copies of your directory data are live in at least two more regionally dispersed data centers and available for instant access.

Azure

Control and help secure email, documents, and sensitive data that you share outside your company walls. From easy classification to embedded labels and permissions, enhance data protection at all times with Azure Information Protection—no matter where it’s stored or who it’s shared with.

Azure

What is Azure Security Center?

Security Center helps you prevent, detect, and respond to threats with increased visibility into and control over the security of your Azure resources. It provides integrated security monitoring and policy management across your Azure subscriptions, helps detect threats that might otherwise go unnoticed, and works with a broad ecosystem of security solutions.

Key capabilities

Security Center delivers easy-to-use and effective threat prevention, detection, and response capabilities that are built in to Azure. Key capabilities are:

Stage Capability
Prevent Monitors the security state of your Azure resources
Prevent Defines policies for your Azure subscriptions and resource groups based on your company’s security requirements, the types of applications that you use, and the sensitivity of your data
Prevent Uses policy-driven security recommendations to guide service owners through the process of implementing needed controls
Prevent Rapidly deploys security services and appliances from Microsoft and partners
Detect Automatically collects and analyzes security data from your Azure resources, the network, and partner solutions like antimalware programs and firewalls
Detect Leverages global threat intelligence from Microsoft products and services, the Microsoft Digital Crimes Unit (DCU), the Microsoft Security Response Center (MSRC), and external feeds
Detect Applies advanced analytics, including machine learning and behavioral analysis
Respond Provides prioritized security incidents/alerts
Respond Offers insights into the source of the attack and impacted resources
Respond Suggests ways to stop the current attack and help prevent future attacks

I hope this article has increased your understanding about digital transformation. Until next time, keep learning!!

Overview Of Microsoft Azure Storage – Part Seven

This article is based on the Storage tool of Microsoft Azure. In previous articles of the series, we learned all about storage in Microsoft Azure. The Azure Storage tool is one kind of place where you can manage all your Microsoft Azure Storage in a new fashion. You can manage all your storage, even blobs, or files, or tables, or queues in a very fast and easily manner as such as your files. You can directly copy, paste and delete files within the Azure Storage Explorer.

You can download Azure Explorer from this Link or this Link.

Azure

Open the setup of Azure Explorer, and accept the agreement before installation of it.

Azure

The setup will take a default folder in to your system.

Azure

Click on to Next to finish the setup.

Azure

The Azure Storage Explorer has successfully installed, open it and you’ll find that you are connected with your default subscription. You need one storage account on Azure Portal to connect with it. So just go to Azure Portal and create a storage account.

Azure

Now right click on to storage account to add an account from portal.

Azure

A Storage Account has its name and primary and secondary key which is used for accessing a storage account from outside the portal. I’m going to use a storage account name and key to connect with Storage account.

Azure

Here you need to copy your Storage Account name and Account Key from the Azure portal.

Azure

You can get your name and key from the Azure Portal by clicking on to Access keys.

Azure

The keys really help in to connect with outside of the portal where you want to access storage account.

Azure

Copy your Storage Account name and Keys from here and paste it on Azure Storage Explorer.

Azure

After clicking on the next button, you’ll be connected with your Storage Account, now you can perform all operations in one place.

Azure

In fthe ollowing screenshot you can see your storage account is connected with Azure Explorer.

Azure

Under Blob Container, I have a Container which is a set of blobs. Under Container I have three files. Right click on to any file where you can see the properties of any file.

Azure

Notice

If you want to access blobs to the browser or you want to download, you have to change permission of the container  make either the blob or container not private.

Azure

If you’re going to download any file then the file will be saved in Temp folder.

Azure

Copy the path of any file and paste it on directly browser’s url. You will get your expected result on the browser.

Azure

You can access other storages by the Azure Storage Explorer as well.

I hope you enjoyed this series. Thank you

Overview Of Microsoft Azure Storage – Part Six

In this article I’m going to explain File Storage Service in Azure which offers to the users fully managed file sharing on the cloud. File Storage provides reliable and security based file sharing on the cloud. The file can be share with a very fast speed as much as possible. One of the best advantages of file storage is that it provides Ease-of-Use access of the files. File storage supports REST and SMB Protocol (Server Message Block Protocol). Many VMs (Virtual Machines can attach to file systems concurrently, allowing you to share persistent data easily between various and roles. Advantages of File Storage in Cloud

  • Mount the File Share from on-premises.
  • Built on Standard SMB 3.0 and REST.
  • SMB offers high-performance connectivity to highly available file shares.
  • Managing File server and share without any hardware.
  • Highly available and geo-replicated.

The following figure illustrates how we can manage file storage on Azure Portal. First login to Azure new Portal and create a Storage Account. After creating Storage Account you’ll found that Storage Account supports four types of storage that I already discussed in my previous articles. Follow the upcoming steps to use File Share in Azure based on the following figure.

Azure

Create a Storage Account under a Resource Group.

Azure

Select Files from the given storage to create a storage share.

Azure

Probably, you have didn’t use this storage ever, that’s why there is no any file service. Go ahead and click on to File Share to create a FileShare, where you can store your files in a hierarchy directory.

Azure

Give a name and size to your file share, the maximum size can be up to 5120GB (in Quota) of it.

Click on to Create button to create file share.

Azure

File Service is created and ready to use. Click to open it.

Azure

Now you can perform various operations such as if you want to upload a file then just click on to upload, if you want to make directory (hierarchy) then you have to click on Add directory. Connect is used to connect your file share from a window computer as well as Linux computer.

Azure

I want to use add directories facility. Click on to Add directory to add new.

Azure

Give a name to your new directory and click on create.

Azure

The directory is ready now. Click to open it, where under it you can add a new directory in a hierarchy way. You can also upload a file under this directory.

Azure

Click on to Upload button to upload a file.

Azure

A new slider will be open for uploading files, select a file that you want to upload (image, docs, txt etc.)

Azure

After selecting a file click on Upload button.

Azure

The file has uploaded, you can select and use it.

Azure

Here are the some properties of this particular file, where you can delete, download to the local system, and copy url of the file.

Azure

You can upload files in to File Storage by using PowerShell ISE, and with Visual Studio code.

Overview Of Microsoft Azure Storage – Part Five

Azure queue storage

Queues are serially accessed messages of requests, which allow Web roles and worker roles to interact. It means whenever a new message will be added in a queue, the roles interact with that queue and pull the messages from in that queue one by one and ones the message has deliver to the roles that message will delete from the Queue.

Basically queue is the list of messages, which flows from the bottom from the queue to the top of the queue. They were added to the queue. Azure queues are located in Microsoft Cloud, which you can use for exchanging messages between the components either in the Cloud or in Premise.

Queues can store a large number of messages and a single queue can be up to 64 kb in size. Azure queue is used for passing the messages to an Azure worker role from an Azure Web role.

Out of the some advantages, queue has some limitations also such as the sent message should be in either text or binary format. Along with this, the individual message size can’t be more than 8kb in size.

I have a storage account. In the storage account, I have a queue and in this queue, we have multiple messages. We can have more than one message in a queue.

Azure

Let’s understand storage accounts practically. You have to be ready with the setup procedure given below.

  • Visual Studio 2015.
  • Microsoft Azure account.

With Azure storage account, you need to create a queue, which is a set of messages. Thus, let’s follow the steps given below.

Step 1

Create ASP.NET Web Project and a give a name to your project.

Step 2

Select MVC template.

Step 3

Right click on Project and add on Connected Services to connect with your Azure Storage account.

Let’s create an Empty Controller class in to your solution by right clicking Controllers folder.

Azure

Create a Method under your Controller and parse the connection string to retrieve your account detail from the key, which is in Web.Config file.

Create a client for your queue by passing the reference of storage account. As you have retrieved the reference of your queue by passing a queue name, createIfNotExists method will create your queue, if it does not exist and hold it in ViewBag.

  1. public class QueueStorageController : Controller
  2.     {
  3.         // GET: QueueStorage
  4.         public ActionResult CreateQueue()
  5.         {
  6.             CloudStorageAccount yourStorageAccount = CloudStorageAccount.Parse(
  7.         CloudConfigurationManager.GetSetting(“mystoragecontainer002_AzureStorageConnectionString”));
  8.             CloudQueueClient myQueueClient = yourStorageAccount.CreateCloudQueueClient();
  9.             CloudQueue myQueue = myQueueClient.GetQueueReference(“storagequeue”);
  10.             ViewBag.CreateSucess = myQueue.CreateIfNotExists();
  11.             ViewBag.YourQueueName = myQueue.Name;
  12.             return View();
  13.         }

Add namespaces given below into your Controller.

  1. using Microsoft.Azure;
  2. using Microsoft.WindowsAzure.Storage;
  3. using Microsoft.WindowsAzure.Storage.Table;

Add a View for this Method.

Azure

Give a name to it and click Add.

Azure

Write the script given below to show a message on the Browser.

  1. @{
  2.     ViewBag.Title = “CreateQueue”;
  3.     Layout = “~/Views/Shared/_Layout.cshtml”;
  4. }
  5. <h2>Creating Queue</h2>
  6. <h3>
  7.     Hey Your Queue <b style=“color:red”“@ViewBag.YourQueueName” </b>
  8.     @(ViewBag.CreateSuccess == true ? “Has Been Successfully Created.”“Already Exist Into Your Storage Account.☻”)
  9. </h3><br />

Afterwards, go to _Layout.cshtml and create a list item with Action Link to create queue.

Azure

Click Queues on Azure portal.

Azure

When you open it, there will not be any queue.

Azure

Click Action link to create a queue on Azure storage, which you have retrieved in your code.

Azure

The screenshot given below shows that the queue has been created into the storage account.

Azure

Check in Visual Studio, if it is created or not. Refresh Queue folder under storage account and you’ll get queue.

Azure

There is no message in the queue.

Azure

If you try to create once again with the same name, then it shows a message that queue already exists.

Azure

You can check your queue in Azure portal.

Azure

Insert a message into a queue

After creating queue, I want to insert a message into it. To insert a message into queue, create a method and write all the code of CreateQueue method because in the current method, I need the reference of the queue.

Now, create a message and add this message into your queue. AddMessage method will insert your message, which you write.

  1. public ActionResult insertMessageinToQueue()
  2.         {
  3.             CloudStorageAccount yourStorageAccount = CloudStorageAccount.Parse(
  4.         CloudConfigurationManager.GetSetting(“mystoragecontainer002_AzureStorageConnectionString”));
  5.             CloudQueueClient myQueueClient = yourStorageAccount.CreateCloudQueueClient();
  6.             CloudQueue myQueue = myQueueClient.GetQueueReference(“storagequeue”);
  7.             ViewBag.CreateSuccess = myQueue.CreateIfNotExists();
  8.             ViewBag.YourQueueName = myQueue.Name;
  9.             CloudQueueMessage insertMessage = new CloudQueueMessage(“Hello, Azure Storage Queue”);
  10.             myQueue.AddMessage(insertMessage);
  11.             return View();
  12.         }

Add View for this method and write the script given below to show the users that the message is inserted.

  1. @{
  2.     ViewBag.Title = “insertMessageinToQueue”;
  3.     Layout = “~/Views/Shared/_Layout.cshtml”;
  4. }
  5. <h2>Insert Your Message Into Queue</h2>
  6. <h3>The Message has Successfully Inserted into <b style=“color:red”>“@ViewBag.YourQueueName”</b> Table </h3>

Create an action link in CreateQueue.Chtml.

Azure

Run your Application and when you click Create Queue, the queue will not create because it is already inserted. Click on the link.

Azure

The message has successfully inserted into your queue.

Azure
Check it into your queue in Visual Studio. A message will be inserted and by default, it is an Id.

Azure

You can delete your queue by calling a myQueue.Delete().

Overview Of Microsoft Azure Storage – Part Four

In my previous articles about Microsoft Azure Storage, I’ve discussed about Blob Storage in detail. As I explained, in first article of the series that Azure Storage has 4 types of Storage Blob, Table, Queue, and File Storage.

In this article, I’m going to explain about Table Storage in Azure. Table is simply structured data which can be accessed by ADO.NET Data Services. Azure Table Storage is non-relational, key value pair, storage system suitable for storing massive amounts of structured data. So Table can be useful for applications that must store large amounts of relational data and need additional structure for that data.

So the Table Storage stores structured data without schemas, it does not provide any way to represent relationship between the data.

So for the table, you must have a Storage Account. In Storage Account we have got the two separate tables and in those table we have got Entity and in Entities we have columns property. I’m going to develop same table storage structure through the Visual Studio 2015.

Azure

Let’s see how we can create Table Storage programmatically and how to save the data into that Table storage. I’m using Visual Studio 2015 and Azure Storage Account like previous article. Follow the same steps of previous article unless ready of Controller.

Step 1

Create Asp.net Web Project and a give a name to your project.

Step 2

Select MVC Template

Step 3

Right click on to Project and add on “Connected Services” to connect with your Azure Storage Account. (Follow Part-Three of the series article)

I hope your project is ready now. Right click on to controller’s folder to add a controller. Create a Method under your controller and parse the connection string to retrieve your account detail from key is in Web.Config file as it is previous article where we created a client of the table, here we returned client for table. Next create a CloudTable object that represents your table name. Create the table if it doesn’t exist and take it into ViewBag for showing it in View result and table name as well as.

  1. public class TableStorageController : Controller
  2.     {
  3.         public ActionResult MyTableCreation()
  4.         {
  5.             CloudStorageAccount userstorageAccount = CloudStorageAccount.Parse
  6.                 (CloudConfigurationManager.GetSetting(“mystoragecontainer002_AzureStorageConnectionString”));
  7.             CloudTableClient myTableClient = userstorageAccount.CreateCloudTableClient();
  8.                         CloudTable cricketTable = myTableClient.GetTableReference(“cricketers”);
  9.             ViewBag.CreateSuccess= cricketTable.CreateIfNotExists();
  10.             ViewBag.YourTableName = cricketTable.Name;
  11.             return View();
  12.         }
  13.     }

Add following namespaces into your Controller

  1. using Microsoft.Azure;
  2. using Microsoft.WindowsAzure.Storage;
  3. using Microsoft.WindowsAzure.Storage.Table;

If you face any problem then you can refer to this screenshot.

Azure

Table should definitely be created but I want to show the result of adding a View. Right click on your ActionResult method and add a View. Add the following snippet into view

  1. @{
  2.     ViewBag.Title = “MyTableCreation”;
  3.     Layout = “~/Views/Shared/_Layout.cshtml”;
  4. }
  5. <h2>Table Created</h2>
  6. <h3>
  7.     Hey This Table <b style=“color:red”“@ViewBag.YourTableName” </b>
  8.     @(ViewBag.CreateSuccess == true ? “Has Been Successfully Created.” : “Already Exist Into Your Storage Account.☻”)
  9. </h3><br />

Azure

Open _Layout.chtml and add another Action Link as shown below.

Azure

Run your application now. You’ll see there is a “Create Table” link to create a table. Click on it.

Azure

The result is on your screen. The table has been created.

Azure

You can check it in Azure Portal.

Azure

When you try to upload again with same name. It will produce the following result.

Azure

Add an Entity to a Table

In this article, we will see how we can add an Entity and Batch of Entities in a Table. Create a Model class and define properties of entity.

Right click on Models folder and add a class CricketerEntity.cs.

Azure

I’ve a Cricketer Entity class that uses TableEntity which represents the base object type for a table entity in the Table Service. The class uses the cricketer’s first name and last name with row key and partition key respectively, with some other property.

  1. public class CricketerEntity: TableEntity
  2.     {
  3.         public CricketerEntity(string lastName, string firstName)
  4.         {
  5.             this.PartitionKey = lastName;
  6.             this.RowKey = firstName;
  7.         }
  8.         public CricketerEntity() { }
  9.         public string BatingStyle { get; set; }
  10.         public string Rank { get; set; }
  11.         public string Runs { get; set; }
  12.     }

Create a new ActionResult method for creating New Entity. Here, I need to retrieve my storage account for accessing cloud table. Create a new Cricketer entity with its respective properties.

After creating entity, you need to create the TableOperation object that would be inserted to your entity. Next, execute the insertOperation to insert an entity. At the end of the code, I’m getting the table name from MyTableCreation Method string of session, into ViewBag.

  1. public ActionResult CreateEntity()
  2.         {
  3.             CloudStorageAccount userstorageAccount = CloudStorageAccount.Parse
  4.                 (CloudConfigurationManager.GetSetting(“mystoragecontainer002_AzureStorageConnectionString”));
  5.             CloudTableClient myTableClient = userstorageAccount.CreateCloudTableClient();
  6.             CloudTable cricketTable = myTableClient.GetTableReference(“cricketers”);
  7.             CricketerEntity cricketer1 = new CricketerEntity(“A.B”“Divillers”);
  8.             cricketer1.BatingStyle = “Right Hand Batsman”;
  9.             cricketer1.Rank = “1”;
  10.             cricketer1.Runs = “5000”;
  11.             TableOperation insertOperation = TableOperation.Insert(cricketer1);
  12.             cricketTable.Execute(insertOperation);
  13.             string getTable = Session[“getTable”].ToString();
  14.             ViewBag.YourTableName = getTable;
  15.             return View();
  16.         }

Take table name into session in the MyTableCreation method.

  1. Session[“getTable”] = cricketTable.Name;

Right click on CreateEntity method to add a view and write following script on to it.

  1. @{
  2.     ViewBag.Title = “CreateEntity”;
  3.     Layout = “~/Views/Shared/_Layout.cshtml”;
  4. }
  5. <h2>Table Entity</h2>
  6. <h3>The Entity is Successfully creating into <b style=“color:red”>“@ViewBag.YourTableName”</b> Table </h3>

Now, go to MyTableCreation.chtml view to make a ActionLink for creating Entity.

Azure

Now, run your application and check the output.

Azure

Click on the created Entity.

Azure

Check your created Entity in Azure Table Storage. Click on the Server Explorer in your Visual Studio Project, click on Storage, and refresh your table.

Azure

Table has been created under selected container.

Azure

Click to view your table entity.

Azure

How can you Create Batch Entity into Table?

By performing Batch Operation, you can insert up to 100 entities in table. Create a new method for Batch Entity and create two cricketer entities. Then, add both in batch insert operation. After that, execute the batch operation method.

  1. public ActionResult CreateBatchEntity()
  2.         {
  3.                         CloudStorageAccount userstorageAccount = CloudStorageAccount.Parse
  4.                 (CloudConfigurationManager.GetSetting(“mystoragecontainer002_AzureStorageConnectionString”));
  5.             CloudTableClient myTableClient = userstorageAccount.CreateCloudTableClient();
  6.             CloudTable cricketTable = myTableClient.GetTableReference(“cricketers”);
  7.             TableBatchOperation batchOperation = new TableBatchOperation();
  8.             CricketerEntity cricketer1 = new CricketerEntity(“Mike”“Hussy”);
  9.             cricketer1.BatingStyle = “Left Hand Batsman”;
  10.             cricketer1.Rank = “2”;
  11.             cricketer1.Runs=“4500”;
  12.             CricketerEntity cricketer2 = new CricketerEntity(“Mike”“Henry”);
  13.             cricketer2.BatingStyle = “Right Hand batsman”;
  14.             cricketer2.Rank = “3”;
  15.             cricketer2.Runs = “6500”;
  16.             batchOperation.Insert(cricketer1);
  17.             batchOperation.Insert(cricketer2);
  18.             // Execute the batch operation for both entities.
  19.             cricketTable.ExecuteBatch(batchOperation);
  20.             string getTable = Session[“getTable”].ToString();
  21.             ViewBag.YourTableName = getTable;
  22.             return View();
  23.         }

Add a view and right following script.

  1. @{
  2.     ViewBag.Title = “UploadYourBlob”;
  3.     Layout = “~/Views/Shared/_Layout.cshtml”;
  4. }
  5.     <h3>Uploaded…..☺</h3><br />
  6.     <h2>This Blob <b style=“color:purple”“@ViewBag.BlobName” </b>@ViewBag.Message in <b style=“color:red”“@ViewBag.YourBlobContainerName” </b> </h2>

To show an Action Link on MyTableCreation.cshtml page, update this by the following code.

Azure

Run your application and select the second Action Link.

Azure
After clicking on the link, your entities have been created to the tables.

Azure
Refresh your table and you’ll get the expected result.

Azure

In my next article, I’ll discuss other storage methods in Azure.