Wednesday, 11 May 2022

Azure Blob storage trigger for Azure Functions - Messag from Azure Blob Storage to Azure-Service-Bus using azure blob trigger funtion

Azure Function

Azure Functions is a serverless computing service and is hosted on the Microsoft Azure public cloud. It is designed to accelerate and simplify application development. 

Azure Functions are the individual functions created in a Function App. Every Function can be invoked using the configured trigger.


 Blob Storage working scenario.

The Blob storage trigger starts a function when a new or updated blob is detected. The blob contents are provided as input to the function.

When Azure Function runs, it needs to know how to connect to the blob container. In local.settings.json from the Storage Account copy the connection string from Access keys and add the connection string in local.settings.json 

 Blob Trigger function having parameter myBlob which gives the details of the uploaded blob,

These details will send to Service Bus Queue for further process.

  


Azure Function Will be Triggered once the file is uploaded to Azure Storage Account





Prerequisites

  • Microsoft Azure Account.
  • Visual Studio with the Azure Development workload enabled. you can also create Azure Function directly in the portal, but the visual studio is preferred when you want easy source control integration.


Code Snippet for Azure Blob Trigger Function

Function Name: Triggerwhenfileuploads
Return Type: JSON
Blob Container Name: Your-container-Name
Service bus Queue Name: Your-Queue-Name
 

BlobTrigger

name - holds the name of the file found in the blob container.

myBlob - holds the content of the file.

containerName - actual container name created in blob storage.

connection - blob storage connection string.

Service Bus

Service-Bus-demo: Service bus Queue Name

Connection - Service bus connection string.







Class File For Message     






OutPut






The connection string from the storage account to local.setting.json

This config file will not be going to deploy to Azure, so will need to specify the information in the portal as well.








 

Azure BLOB Storage

 The Azure Storage platform offers various services that cater to different scenarios:

·        Azure Blobs: Azure Blob Storage offers massively scalable object stores for storing text and binary data. It also includes support for big data analytics through Data Lake Storage Gen2.

·        Azure Queues: Microsoft offers Azure Queue Storage as a service for storing large numbers of messages. They can enable reliable messaging between applications and components.

·        Azure Tables: Azure Table storage is an excellent choice if we want to store structured NoSQL data in the cloud. It can store key and attribute values without defining a schema. 

·        Azure Disks: Azure Disks offer managed block-level storage volumes. We can easily attach them to Azure Virtual Machines.

·        Azure Files: Microsoft offers Azure File Storage as a fully managed cloud file share. We can access them from both cloud and on-premises services.

 

A Deeper Look at Azure BLOB Storage

Now let’s take a deeper look at the Azure BLOB storage. Microsoft offers Azure Blob storage for storing large object blobs in the cloud. This is optimized for storing large amounts of text or binary data.

Blob storage is ideal for many scenarios like:

·        Serving images or documents directly through the browser.

·        Storing files for access from multiple locations and services.

·        Streaming video and audio files.

·        Storing data for backup and restore operations, disaster recovery, and archiving, etc.

·        Storage for data analysis by both on-premises and Azure-hosted services.

We can access objects stored in BLOB storage from anywhere in the world via HTTP or HTTPS. Users or client applications can access files stored in BLOB storage via URLs,

the Azure Storage REST API, Azure PowerShell, Azure CLI, or Azure Storage client libraries (SDKs) that are available in various languages. In this example, we’ll see how to access Azure BLOB storage using Angular.

 

Structure of an Azure BLOB Storage

Blob storage has three types of resources:

·        Storage Accounts: A storage account provides a unique namespace in Azure for our data. Every object that we store in Azure Storage has an address that includes the unique account name. The combination of the account name and the Azure Storage BLOB endpoint forms the base address for the objects in the storage account.

·        Containers: Just like how a directory organizes files in a file system, containers organize a set of blobs. A storage account can include any number of containers, and a container can store an unlimited number of blobs.

·        Blobs: BLOB can store text and binary data. Blob storage offers three types of blobs – Block blobsAppend blobs, and Page blobs. We can specify the blob type while creating the blob. It is not possible to change its type afterward and we can only update a blob file using the operations appropriate for that particular blob type, for instance, we can only write a block or list of blocks to a block blob, append blocks to an append blob, and write pages to a page blob.

 

We can represent the structure of BLOB storage this way:

 






Types of blobs



Key concepts

Blob storage is designed for:

  • Serving images or documents directly to a browser.
  • Storing files for distributed access.
  • Streaming video and audio.
  • Writing to log files.
  • Storing data for backup and restore, disaster recovery, and archiving.
  • Storing data for analysis by an on-premises or Azure-hosted service.

Saturday, 19 June 2021

Difference between WCF, Web API, WCF REST   and Web Service?



The Dot Net framework has a number of technologies that allow you to create HTTP services such as Web Service, WCF and now Web API. There are a lot of articles over the internet which may describe to whom you should use.

Web Service

  • It is based on SOAP and return data in XML form.
  • It support only HTTP protocol.
  • It is not open source but can be consumed by any client that understands xml.
  • It can be hosted only on IIS.

WCF

  • It is also based on SOAP and return data in XML form.
  • It is the evolution of the web service(ASMX) and support various protocols like TCP, HTTP, HTTPS, Named Pipes, MSMQ.
  • The main issue with WCF is, its tedious and extensive configuration.
  • It is not open source but can be consumed by any client that understands xml.
  • It can be hosted with in the application or on IIS or using window service.

WCF Rest

  • To use WCF as WCF Rest service you have to enable webHttpBindings.
  • It support HTTP GET and POST verbs by [WebGet] and [WebInvoke] attributes respectively.
  • To enable other HTTP verbs you have to do some configuration in IIS to accept request of that particular verb on .svc files
  • Passing data through parameters using a WebGet needs configuration. The UriTemplate must be specified.
  • It support XML, JSON and ATOM data format.

Web API

  • This is the new framework for building HTTP services with easy and simple way.
  • Web API is open source an ideal platform for building REST-Full services over the .NET Framework.
  • Unlike WCF Rest service, it use the full feature of HTTP (like URIs, request/response headers, caching, versioning, various content formats)
  • It also supports the MVC features such as routing, controllers, action results, filter, model binders, IOC container or dependency injection, unit testing that makes it more simple and robust.
  • It can be hosted with in the application or on IIS.
  • It is light weight architecture and good for devices which have limited bandwidth like smart phones.
  • Responses are formatted by Web API’s MediaTypeFormatter into JSON, XML or whatever format you want to add as a MediaTypeFormatter.

To whom choose between WCF or WEB API

  • Choose WCF when you want to create a service that should support special scenarios such as one way messaging, message queues, duplex communication etc.
  • Choose WCF when you want to create a service that can use fast transport channels when available, such as TCP, Named Pipes, or maybe even UDP (in WCF 4.5), and you also want to support HTTP when all other transport channels are unavailable.
  • Choose Web API when you want to create a resource-oriented services over HTTP that can use the full features of HTTP (like URIs, request/response headers, caching, versioning, various content formats).
  • Choose Web API when you want to expose your service to a broad range of clients including browsers, mobiles, iPhone and tablets.

Wednesday, 15 November 2017

What Is AngularJS?


AngularJS is a structural framework for dynamic web apps. It lets you use HTML as your template language and lets you extend HTML's syntax to express your application's components clearly and succinctly. AngularJS's data binding and dependency injection eliminate much of the code you would otherwise have to write. And it all happens within the browser, making it an ideal partner with any server technology.
AngularJS is what HTML would have been, had it been designed for applications. HTML is a great declarative language for static documents. It does not contain much in the way of creating applications, and as a result building web applications is an exercise in what do I have to do to trick the browser into doing what I want?
The impedance mismatch between dynamic applications and static documents is often solved with:
  • a library - a collection of functions which are useful when writing web apps. Your code is in charge and it calls into the library when it sees fit. E.g., jQuery.
  • frameworks - a particular implementation of a web application, where your code fills in the details. The framework is in charge and it calls into your code when it needs something app specific. E.g., durandalember, etc.
AngularJS takes another approach. It attempts to minimize the impedance mismatch between document centric HTML and what an application needs by creating new HTML constructs. AngularJS teaches the browser new syntax through a construct we call directives. Examples include:
  • Data binding, as in {{}}.
  • DOM control structures for repeating, showing and hiding DOM fragments.
  • Support for forms and form validation.
  • Attaching new behavior to DOM elements, such as DOM event handling.
  • Grouping of HTML into reusable components.

Wednesday, 8 November 2017

Generate QR code in asp.net



               Follow Me To get Health tip and bodybuilding
instagram:sayyedtanveer1410




To generate QR Code in asp.net VB lang.

On Default.aspx page just put IMG tag.

 <img  id="img" alt="Alternate Text" />


On Default.aspx.vb 

Just Import MessagingToolkit.QRCode.Codec in namespace

 Dim data As String = "codens.blogspot.com"


  •              Dim qrCodeEncoder As New QRCodeEncoder()
  •             qrCodeEncoder.QRCodeBackgroundColor = Color.White
  •             qrCodeEncoder.QRCodeForegroundColor = Color.Black
  •             qrCodeEncoder.QRCodeEncodeMode = qrCodeEncoder.ENCODE_MODE.[BYTE]

  •             Dim scale As Integer = Convert.ToInt16(1) 'Here we need to give size of Qr
  •             qrCodeEncoder.QRCodeScale = scale
  •             Dim version As Integer = Convert.ToInt16(0)

  •             qrCodeEncoder.QRCodeVersion = version
  •             qrCodeEncoder.QRCodeErrorCorrect = qrCodeEncoder.ERROR_CORRECTION.H

  •             QRImageName = "Qr_IMG.Gif"
  •  qrImagePath = System.Web.HttpContext.Current.Server.MapPath("~\" & ConfigurationManager.AppSettings("ImageFolder").ToString & "\ImagesNew\")


  •             Try
  •                 If File.Exists(qrImagePath) Then
  •                     File.Delete(qrImagePath)
  •                 End If
  •             Catch generatedExceptionName As Exception
  •                 Throw
  •             End Try
  •             
  •             Dim bimg As Bitmap = qrCodeEncoder.Encode(data)
  •             bimg.Save(qrImagePath, System.Drawing.Imaging.ImageFormat.Gif)




Tuesday, 7 November 2017

How to convert linq query result in datatable


                         Follow Me To get Health and bodybuilding tip's
instagram:sayyedtanveer1410



LINQ stands for Language Integrated Query is a set of features introduced in Visual Studio 2008, using LINQ you can manipulate the data as similar SQL queries .Let us learn it practically how to convert LINQ query result to Datatable by creating one simple function.


Create function to named LINQResultQueryToDataTable which convert LINQ Result To DataTable as

public DataTable LINQResultQueryToDataTable<T>(IEnumerable<T> Linqlist) 
       { 
          
  1. DataTable dt = new DataTable();  
  2.   
  3.              
  4.             PropertyInfo[] columns = null;  
  5.   
  6.             if (Linqlist == nullreturn dt;  
  7.   
  8.             foreach (T Record in Linqlist)  
  9.             {  
  10.                   
  11.                 if (columns == null)  
  12.                 {  
  13.                     columns = ((Type)Record.GetType()).GetProperties();  
  14.                     foreach (PropertyInfo GetProperty in columns)  
  15.                     {  
  16.                         Type colType = GetProperty.PropertyType;  
  17.                              if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition()  
  18.                         == typeof(Nullable<>)))  
  19.                         {  
  20.                             colType = colType.GetGenericArguments()[0];  
  21.                         }  
  22.   
  23.                         dt.Columns.Add(new DataColumn(GetProperty.Name, colType));  
  24.                     }  
  25.                 }  
  26.   
  27.                 DataRow dr = dt.NewRow();  
  28.   
  29.                 foreach (PropertyInfo pinfo in columns)  
  30.                 {  
  31.                     dr[pinfo.Name] = pinfo.GetValue(Record, null) == null ? DBNull.Value : pinfo.GetValue  
  32.                     (Record, null);  
  33.                 }  
  34.   
  35.                 dt.Rows.Add(dr);  
  36.             }  
  37.             return dt;  
  38.         }  
  39.   
       }  
The above function takes the LINQ query result and convert it into the Data Table

Friday, 22 August 2014

C# Enumeration

                         Follow Me To get Health tip and bodybuilding
instagram:sayyedtanveer1410



Enumeration provides efficient way to assign multiple constant integral values to a single variable. Enumeration improves code clarity and makes program easier to maintain. Enumeration in C# also provides more security by better error-checking technology and compiler warnings.
An enumeration can be defined using enum keyword. In enumeration, you can define special set of value that can be assigned with enumeration. For Example, you are creating an attendance log application in which a variable can contains value only Monday to Friday. The other value will not be applicable with variables. In order to fulfill this requirement you need to use enumeration that will hold only assigned values and will returns numeric position of values starting with zero.

using System;

namespace Enumeration
{
  // creating enumeration for storing day.
  public enum attandance
   {
     Monday,
     Tuesday,
     Wednesday,
     Thursday,
     Friday
   }

  class Program
   {
     static void Main(string[] args)
      {
        attandance present = attandance.Monday;//Valid
        Console.WriteLine(present);
           
        //attandance absent = attandance.Sunday;//Invalid
        Console.ReadLine();
      }
   }
}

output
Monday