Posts

Showing posts from 2016

Covert Image URL in to base64 string

Suppose you have your images hosted in azure blob storage. And you access the images using the URL. Else you have some images from another online location where you have only the URL. I got a requirement recently on a project to generate a Vcard. For that I need the base64 string of the image, as all the data will be saved in to a text file. So I used the following code to first download the image them convert it to base64 string. public String GetImageData(String url) { StringBuilder _sb = new StringBuilder(); Byte[] _byte = GetImage(url); //convert byte array in to base 64 string _sb.Append(Convert.ToBase64String(_byte, 0, _byte.Length)); return _sb.ToString(); } // Download image in to byte array private byte[] GetImage(string url) { Stream stream = null; byte[] buf; try { WebProxy myProxy = new WebProxy(); HttpWebRequest req = (HttpWebRe...

Azure Push Notification with Web API

Image
Before explaining how to to push notification to hub using Web API, let us see what is azure push notifications hub provides. Azure Notification Hubs provide an easy-to-use, multiplatform, scaled-out push infrastructure that enables you to send mobile push notifications from any backend (in the cloud or on-premises) to any mobile platform. With Notification Hubs you can easily send cross-platform, personalized push notifications, abstracting the details of the different platform notification systems (PNS). With a single API call, you can target individual users or entire audience segments containing millions of users, across all their devices. Step 1 : Create Push Notification Hub Log on to the Azure Portal , and then click +NEW at the top left of the screen. Click on New , then Web + Mobile . Scroll down if necessary and click Notification Hub . Add All the details and create the hub Step 2 : Add Keys After creating the hub next you need to add keys...

Azure Search #1

Image
  I will be writing a series of post on azure search step by step. Each post I will be explaining different areas in azure search. As this is the first post I will be explaining what azure search is and what are the applications of azure search. What is Azure Search ? A search-as-a-service solution allowing developers to incorporate great search experiences into applications without managing infrastructure or needing to become search experts. If I elaborate the definition bit more,Azure search provides lot of services, which allows developer to add high search experience to their end users, without been a search expert. In other words developer has to call some API calls to azure search all the search algorithms will be executed by azure search service and result will be returned. this makes developer life easier and giving end user a high search experience. Why we need search? Search box in an application has been the main entry point of most of the applications. If we una...

Saving Base64 String as image to Azure Blob Storage

  Recently I started working on a API which supports mobile backend. I got the following requirement 1. When user uploads a image to their profile API will get the base64 string of the image 2. When viewing the User profile to increase the performance of service calls have to send an image URL rather base64 string   Solution : Save the base 64 string in the azure storage & save it in DB public class AzureBlogService { private static string _connectionString = "DefaultEndpointsProtocol=https;AccountName=****;AccountKey=****"; public static string UploadImage(string imageData, ImageType imageType, int cardId) { string filename = GetFileName(imageType, cardId); CloudBlobContainer container = GetContainer("userimages"); byte[] imageBytes = Convert.FromBase64String(imageData); CloudBlockBlob blob = container.GetBlockBlobReference(filename); blob.Properties.Cont...

Group By First Letter of word with Linq

  This is sample code which you can used to group some list of objects based on first letter of the object name or any string property. In the following example I get list of contacts in an application and after getting those from DB , I group them with the First letter of the Contact name and order them in alphabetical order. Following is my Contact Class. public class CardContactModel { public int CardId { get; set; } public string CardName { get; set; } public int? ContactId { get; set; } public JObject Information { get; set; } public string ProfileImage { get; set; } public string SharedTo { get; set; } public string RecievedFrom { get; set; } } Then I group it and add it to a dictionary with the following line of code. Dictionary > Contacts = contacts.GroupBy(x => x.CardName.Substring(0, 1).ToUpper(), (Letter, Contacts) => new { Alphabet = Letter, SubList = Contacts.OrderBy(...

RSS reader in c#

  What is RSS? RSS (Rich Site Summary) is a format for delivering regularly changing web content . Many news-related sites, weblogs and other online publishers syndicate their content as an RSS Feed to whoever wants it. Recently I got a requirement of reading rss feeds of blogger and other few sites and load posts in to db. I followed the following steps. 1. Create Domain Classes public class Post:Entity   {       public Post()       {       }       public Post(long id)       {           Id = id;       }       public DateTime DatePublished { get; set; }       public Blogger Blogger { get; set; }       public string PostGUID { get; set; }       public string Title { get; set; } ...