Monday, February 14, 2022

Azure Storage Account Types


Defferent Types of Blobs

  1. Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually. Block blobs can store up to about 190.7 TiB.
  2. Append blobs are made up of blocks like block blobs, but are optimized for append operations. Append blobs are ideal for scenarios such as logging data from virtual machines.
  3. Page blobs store random access files up to 8 TiB in size. Page blobs store virtual hard drive (VHD) files and serve as disks for Azure virtual machines.

Different Storage Type in Azure

Storage V1 (Storage):

General purpose storage prior to Azure virtual hard disks. Allows to store un-managed data

Replication: LRS, ZRS4, GRS, RA-GRS

If your applications require the Azure classic deployment model, then these accounts are best suited for you

These accounts deliver the lowest per-gigabyte capacity prices for Azure Storage

Storage V2:

Upgraded version of Storage, with tiering. 

Replication: LRS, ZRS4, GRS, RA-GRS

These accounts deliver the lowest per-gigabyte capacity prices for Azure Storage

Tiering

Hot: Lowest access rates, most expensive per GB capacity.

Cold: Still low latency, but cheap per GB capacity at higher access rate.

Archive: The cheapest per GB capacity (~$2.05 per TB per month!), but it

Tiering means that we can move a blob between 3 tiers within the same storage account (not automatic tiering today):

Reference:

BlobStorage:

Blob storage account is specialized storage account for storing unstructed object data as block and append appended blobs, but not page blobs.

Reference:

What is Azure Blob Storage used for?

Azure Blob Storage was designed to serve specific needs. If your business use case needs to store unstructured data like audio, video, images, etc then you should probably go with this option. The objects which are being stored in Blob does not necessarily have an extension.

The following points describe the use case scenarios:

  1. Serving images or documents directly to a browser
  2. Storing Files for distributed access
  3. Streaming video and audio
  4. Writing to log Files
  5. Storing data for backup, restore, disaster recovery and archiving
  6. Storing data for analysis by an on-premises or Azure-hosted service

FileStorage:

Azure Files enables you to set up highly available network file shares that can be accessed by using the standard Server Message Block (SMB) protocol. That means that multiple VMs can share the same files with both read and write access. You can also read the files using the REST interface or the storage client libraries.

File Storage can be used if your business use case needs to deal mostly with standard File extensions like *.docx, *.png and *.bak then you should probably go with this storage option.

The following points describe the use case scenarios: 

Replace or supplement on-premises File servers

“Lift and shift” applications

Simplify cloud development

Reference 1:

Reference 2:

BlockBlobStorage:

https://www.ais.com/how-to-choose-the-right-kind-of-azure-storage-account/





Friday, February 11, 2022

Metadata Generation Failed - Error - Azure Fuctions

Today I encountered with the error, Metadata Generation Failed just after try to add .NET standard project to existing .NET 4.6.2 fleet of projects in solution. 

I was trying to add few features to my existing Azure Function V1, in .NET framework

My function SDK is: 
  • Microsoft.NET.Sdk.Functions version 1.0.24
  • Microsoft.Azure.WebJobs.ServiceBus 2.2.0
Managed to resolve this by deleting the below folder

C:\Users\CharithGunasekara\.nuget\packages\microsoft.net.sdk.functions\1.0.24\build\netstandard1.0


Saturday, December 26, 2020

Implicit Conversion of .NET Objects and Json Converstion from String to .NET Object

Implicit Conversion of .NET Objects and Json Converstion from String to .NET Object

Using this method you can assign object to a string value which is the default value depending on environment vairable, and you can converrt string to a object using JSON serialization.

This instrumention is ideal for JSON configuration where it automatically resolve the DEV/UAT/PROD values so that you do not have to worry about configuration changes over multiple files while deployment

Config Value Class


using Newtonsoft.Json;using System;
using System.Collections.Generic;
namespace ImplicitConversion
{
    [JsonConverter(typeof(ConfigValueConverter))]
    class ConfigValue : Dictionary<string, string>
    {
        readonly string devKey = "DEV", uatKey = "UAT", prodKey = "PROD";
        public string DEV
        {
            get
            {
                if (ContainsKey(devKey)) return this[devKey];
                return default;
            }
            set
            {
                if (ContainsKey(devKey)) this[devKey] = value;
                else Add(devKey, value);
            }
        }
        public string UAT
        {
            get
            {
                if (ContainsKey(uatKey)) return this[uatKey];
                return default;
            }
            set
            {
                if (ContainsKey(uatKey)) this[uatKey] = value;
                else Add(uatKey, value);
            }
        }
        public string PROD
        {
            get
            {
                if (ContainsKey(prodKey)) return this[prodKey];
                return default;
            }
            set
            {
                if (ContainsKey(prodKey)) this[prodKey] = value;
                else Add(prodKey, value);
            }
        }
        public string Value
        {
            get
            {
                if (Environment.UserName.StartsWith("prod"))
                    return PROD;
                if (Environment.UserName.StartsWith("uat"))
                    return UAT;
                return DEV;
            }
            set
            {
                DEV = UAT = PROD = value;
            }
        }
        public static implicit operator string(ConfigValue value)
        {
            return value.Value;
        }
    }
}

Config Value Converter Class

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;

namespace ImplicitConversion
{
    class ConfigValueConverter : JsonConverter
    {
        public override bool CanConvert(Type objectType)
        {
            throw new NotImplementedException();
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            ConfigValue value = new ConfigValue();
            try
            {
                JObject jObject = JObject.Load(reader);
                serializer.Populate(jObject.CreateReader(), value);
                return value;
            }
            catch
            {
                value.Value = reader.Value?.ToString();
                return value;
            }
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            throw new NotImplementedException();
        }
    }
}

Simpile Refernece Class for JSON Serialization

namespace ImplicitConversion
{
    class Configuration
    {
        public ConfigValue Email { get; set; }
    }
}

Program Class to Test

using Newtonsoft.Json;
using System;

namespace ImplicitConversion
{
    class Program
    {
        static void Main(string[] args)
        {
            string json = @"{ 
                ""Email"": ""no-reply@company.com"" 
            }";
            Configuration configuration = JsonConvert.DeserializeObject(json);
            Console.WriteLine($"DEV value : { configuration.Email.DEV }");
            Console.WriteLine($"UAT value : { configuration.Email.UAT }");
            Console.WriteLine($"PROD value : { configuration.Email.PROD }");

            json = @"{ 
                ""Email"": {
                    ""DEV"":""no-reply-DEV@company.com"",
                    ""UAT"":""no-reply-UAT@company.com"",
                    ""PROD"":""no-reply-PROD@company.com""
                }
            }";
            configuration = JsonConvert.DeserializeObject(json);
            Console.WriteLine($"DEV value : { configuration.Email.DEV }");
            Console.WriteLine($"UAT value : { configuration.Email.UAT }");
            Console.WriteLine($"PROD value : { configuration.Email.PROD }");

            string email = configuration.Email;
            Console.WriteLine($"DEV value : { email }");

            Console.ReadLine();
        }
    }
}

Friday, April 24, 2015

iPhone Launch Screen Sizes

iPhone Portrait iOS 8

Retina HT 5.5 = 1242 X 2208
Retna HD 4.7 = 750 X 1134

iPhone Landscape iOS 8

Retina HD 5.5  2208 X 1242

iPhone Portrait iOS 7,8

2X 640 X 960
Retina 4 640 x 1136

iPad Portrate iOS 7,8

1x 768 X 1024
2x 1536 X 2048

iPad Landscape iOS 7,8

1x 1024 X 768
2X 2048 X 1536

iPhone Portrait iOS 5,6

1x 320 X 480
2x 640 X 960
Retina 4 640 X 1136

iPad POrtrait (Without Status Bar) iOS 5,6

1x 768 X 1004
2X 1536 X 2008

iPad Portrait iOS 5,6

1X 768 X 1024
2x 1536 X 2048

iPad Landscape (Without Status Bar) iOS 5,6

1X 1024 X 748
2X 2048 X 1496

iPad Landscapd iOS 5,6

1x 1024 X 768
2X 2048 X 1536

Wednesday, September 19, 2012

How to crop and compress an bitmap file and load it as a Meta File

    Bitmap croppedImage = bitmap.Clone(new Rectangle(0, top, bitmap.Width, limit - top), bitmap.PixelFormat);
    System.Drawing.Image cha = image;
    Graphics g = null;                                    
    ImageCodecInfo imageCodecInfo = null;
    System.Drawing.Imaging.Encoder encoder;
    EncoderParameter encoderParameter;
    EncoderParameters encoderParameters;
    ImageCodecInfo[] encoders;
    encoders = ImageCodecInfo.GetImageEncoders();
    for (int j = 0; j < encoders.Length; ++j)
        if (encoders[j].MimeType == "image/tiff")
            imageCodecInfo = encoders[j];
    encoder = System.Drawing.Imaging.Encoder.Compression;
    encoderParameters = new EncoderParameters(1);
    encoderParameter = new EncoderParameter(encoder, (long)EncoderValue.CompressionLZW);
    encoderParameters.Param[0] = encoderParameter;
    string path = this.TempFileName("tif");
    croppedImage.Save(path, imageCodecInfo, encoderParameters);
    System.Drawing.Image m = Metafile.FromFile(path);

Saturday, December 17, 2011

How to validate a number between 0-24 with Java Scripts

<%@ Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <script language="javascript" type="text/javascript">
        function checkIt(obj, evt) {
            evt = (evt) ? evt : window.event
            var charCode = (evt.which) ? evt.which : evt.keyCode
            if ((charCode < 45 || charCode > 57) && charCode != 8 && charCode != 37 && charCode != 39) {
                alert("This field accepts numbers only")
                return false
            }
            var t = (charCode / 1) - 48;
            var v = obj.value + t;
            var value = v / 1;
            if(value > 24){ 
                alert("Number should be less than 24");
                return false;
            }
            return true
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox runat="server" ID="txtNumber" onKeyPress='javascript:return checkIt(this, event)' />
    </div>
    </form>
</body>
</html>

Wednesday, December 14, 2011

How to retain the password in a postback

<%@ Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Test Page</title>
    <script runat="server">
        public string Password
        {
            get { return ViewState["Password"as string; }
            set { this.ViewState["Password"] = value; }
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (this.IsPostBack)
            {
                if (!string.IsNullOrEmpty(this.txtPassword.Text))
                    this.Password = this.txtPassword.Text;
                this.txtPassword.Attributes.Add("value"this.Password ?? string.Empty);
            }
        }
    </script>
</head>
<body>
    <form  id="aspNetForm" runat="server">
        UserName: <asp:TextBox runat="server" ID="txtName" />
        Password: <asp:TextBox runat="server" ID="txtPassword" TextMode="Password" />
        <hr />
        <asp:Button runat="server" ID="btnSave" Text="Save" />
    </form>
</body>
</html>

Tuesday, December 13, 2011

Html Header Tag Sizes

  • H1 - 24pt / 32px
  • H2 - 18pt / 24px
  • H3 - 14pt / 18px
  • H4 - 12pt / 15px
  • H5 - 10pt / 13px
  • H6 - 8pt   / 11px
Above are the default font sizes in points and their approximate sizes in pixels

Friday, August 19, 2011

How to upload a external image link url and save on the disk

 We can get the use of HttpWebRequest and HttpWebResponse to send the request and get the response. Then response.GetResponseStream() will give us a stream of the image where we can use that stream to create a Image object like Image image = Image.FromStream(stream)

Markup:
<%@ Page Language="C#" CodeBehind="Test.aspx.cs" Inherits="ActiveTest.Test" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox runat="server" ID="txtUpload" 
            Text="http://www.web-sphere.co.uk/web/websphere/blog/bloggerheader.jpg" />
        <asp:Button runat="server" ID="btnUpload" OnClick="Upload" Text="Upload" />
    </div> 
    </form>
</body>
</html>
Code:
namespace ActiveTest
{
    public partial class Test : Page
    {
        protected void Upload(object sender, EventArgs e)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(this.txtUpload.Text);
            HttpWebResponse response = request.GetResponse() as HttpWebResponse;
            Stream stream = response.GetResponseStream();         
            ///
            /// use response content type to findout the image type, 
            /// here I just use jpg to simplify the story.
            /// 
            System.Drawing.Image image = System.Drawing.Image.FromStream(stream);
            image.Save(this.Server.MapPath(string.Format("~/Uploads/{0}.jpg",Guid.NewGuid())));
        }
    }
}

Tuesday, November 16, 2010

How to output web page as MS word document

public partial class Test : Page
{
    protected override void Render(HtmlTextWriter writer)
    {
        Response.Clear();
        Response.Buffer = true;
        Response.ContentType = "application/msword";
        StringBuilder sb = new StringBuilder();
        StringWriter stringWriter = new StringWriter(sb);
        HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
        base.Render(htmlTextWriter);
        Response.Write(sb.ToString());
        Response.End();            
    }
}

Friday, November 12, 2010

How to keep track of selected file during a postback.

When you select a file and then do a postback, you will lose your selected file. This is because there is no ViewState for posted file in asp.net FileUpload control. This example is to demonstrate an idea of how to save the file in any-postback and if there is a selected file, then we save the file and show the fileName in a hyperlink to download or view,
Example:
<%@ Page Language="C#" %>
<html>
<head id="Head1" runat="server">
    <script runat="server">
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (this.fuFile.HasFile)
            {                
                string filePath = Server.MapPath(string.Format("~/Uploads/{0}"this.fuFile.FileName));
                if (!System.IO.File.Exists(filePath))
                {
                    this.fuFile.SaveAs(filePath);
                    this.linkSelectedFile.NavigateUrl 
                        this.ResolveUrl(string.Format("~/Uploads/{0}", this.fuFile.FileName));
                    this.linkSelectedFile.Text = this.fuFile.FileName;
                }
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        Select a File: <asp:FileUpload runat="server" ID="fuFile" />
        <asp:HyperLink runat="server" ID="linkSelectedFile" />
        <hr />
        <asp:DropDownList runat="server" ID="ddlItems" AutoPostBack="true">
            <asp:ListItem>Item One</asp:ListItem>
            <asp:ListItem>Item Two</asp:ListItem>
        </asp:DropDownList>
    </form>
</body>
</html>

Azure Storage Account Types

Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...