Tuesday, December 13, 2011

Science for kids

Today I have decided to share my knowledge of science experiments with you. The experiments that I am going to demonstrate are very basic and most suitable for kids in age range 7 to 16.
In these experiments I will tell few concepts, the reasoning behind behavior of matters and of course few images demonstrating the experiments.

It was fantastic experience for me to conduct those experiments on my own. I hope you will also gain some knowledge from these experiments which will help you in your career and will definitely shape your learning curve. I will make sure that you enjoy a wide range of information and science facts that are sure to surprise and amaze you.

Here is the list of topics. Click on the links to visit the particular experiment –

Ice on a String – Wow, Pick Ice cube using thread…

Refraction of light - Breaking sppon in glass of water...

Stay tuned for more…

Monday, December 12, 2011

Uploading large file to Azure blob storage and httpRuntime maxRequestLength

Recently I was told to write a code for uploading large size files to Azure Blob storage from an aspx page. I asked for specifications of size of files. I was told that file to be uploaded will vary from 1MB to anything.
When I had actually implemented a code for file upload, things were working smoothly for the file up to 4MB. For all other files having size more than 4MB, I was receiving many errors.
Those errors included, time out errors, maxRequestLength exceeded, operation could not be completed, and my favorite error – “Internet explorer cannot display the web page”.
I had used normal asp.net file upload control in my web role and a very standard code to upload file to Azure Blob storage. After tweaking some code segments it finally worked. Following is the code segment used for uploading big files on a button click to Azure Blob storage from web role or web site page.
First read all the configuration values from project. I am here using web role project therefore my code to read configuration values will be as follows. If you are using simple asp.net web site project then your code to read configuration values will be different.
protected void btnUpload_Click(object sender, EventArgs e)
{
//using some local variables
string packageFilePath = string.Empty;
string packageFileName = string.Empty;
string referenceFileName = string.Empty;
string packageFileURL = string.Empty;
#region read required configuration values
            Container = RoleEnvironment.GetConfigurationSettingValue("ContainerName");
            AccountName = RoleEnvironment.GetConfigurationSettingValue("AccountName");
            SharedKey = RoleEnvironment.GetConfigurationSettingValue("SharedKey");
            blobEndPoint = RoleEnvironment.GetConfigurationSettingValue("BlobStorageEndpoint");
            tableEndpint = RoleEnvironment.GetConfigurationSettingValue("TableStorageEndpoint");
            #endregion

//create cloud blob client
CloudBlobClient blobClient = new CloudBlobClient(blobEndPoint, new StorageCredentialsAccountAndKey(AccountName, SharedKey));

// For large file copies you need to set up a custom timeout period and using parallel settings appears to spread the copy across multiple threads
// if you have big bandwidth you can increase the thread number below because Azure accepts blobs broken into blocks in any order of arrival.
blobClient.Timeout = new System.TimeSpan(1, 0, 0);
blobClient.ParallelOperationThreadCount = 2;

//get container reference           
CloudBlobContainer container = blobClient.GetContainerReference(Container);

//setup permission on container to be public
var permissions = new BlobContainerPermissions();
permissions.PublicAccess = BlobContainerPublicAccessType.Container;
container.SetPermissions(permissions);

//retrieving file details. uploadCSPKG is the name of my file upload control              
if (uploadCSPKG.HasFile)
{
try
{
                  packageFileName = Path.GetFileName(uploadCSPKG.FileName);

//attaching application name before file name so as to create hierarchy in blob. txtApplicationName is my text box where in user provides sname for logical folder in blob under which file will be uploaded.
referenceFileName = txtApplicationName.Text + "/" + packageFileName;

                  uploadCSPKG.SaveAs(Server.MapPath("~/") + packageFileName);
                  packageFilePath = Server.MapPath("~/") + packageFileName;
            }
            catch (Exception ex)
            {
                throw ex;
            }
      }

//open the stream and upload package file to blob
using (FileStream fs = File.OpenRead(packageFilePath))
{
CloudBlob blob = container.GetBlobReference(referenceFileName);
      blob.UploadFromStream(fs);
      packageFileURL = blob.Uri.AbsoluteUri;
}
}

The above is the complete code required to perform a file upload to Azure blob. Apart from this, you will need to do one more configuration related to ASP.NET runtime setting using httpRuntime tag in web.config of your application.
Add following line in web.config under <system.web> -
<httpRuntime maxRequestLength="51200" enable ="true" executionTimeout="45"/>

Here I assume that, my file size will never exceed the value provided in maxRequestLength attribute. If you feel the size of file to be uploaded can exceed above value then you can change the value as per your need. So with the above setting of maxRequestLength, you should be able to upload file upto sizes of 50MB. If you wish to upload file of size more than 50MB then increase the value under maxRequestLength attribute.
maxRequestLength  - Indicates the maximum file upload size supported by ASP.NET. The size specified is in kilobytes. The default is 4096 KB (4 MB).
Therefore I was able to add 4MB file previously without any difficulty whereas file sizes more than 4MB was failing with various errors. The above code segment resolved the issue.
Hope this helps.
Cheers…
Happy Programming!!!

Sunday, December 11, 2011

Multi Tenancy and Windows Azure. Overview of Multi tenant Application and Single tenant Application Architectural considerations.

Multitenancy is referred as important characteristics of all cloud application. There are many reasons why cloud applications today are being designed to support multi tenancy. Today I am going to discuss multi tenancy in cloud application (of course related to Windows Azure) based on the articles and posts I have gone through.
Wikipedia – Multi tenancy refers to a principle in software architecture where a single instance of the software runs on a server, serving multiple clients (or in other words “tenants”).
Dictionary meaning of “Tenant” say, people who take resources on lease. In Azure, we acting as a customer take cloud resources on lease therefore; customers or clients of application are referred as “Tenants”.
Single-Tenant vs Multi-Tenant applications –
Single Tenant Applications – Has a separate, logical instance of the application for each customer or client. For example, if there are 5 customers that require using the application then, we will have 5 different OS, 5 copies of database and 5 copies of the application. This is illustrated in following diagram –

Thursday, December 8, 2011

Azure Diagnostics – Creating Windows Azure Diagnostics and Performance Counters Table

In Azure application development you may need to perform Windows Azure Logging. The best way to debug windows Azure application is to write diagnostics information in Azure Table Storage.
Also, System Center Operation Manager (SCOM) can monitor performance of Azure Application. A management pack has been already released for Azure Application monitoring using SCOM. In such scenario for monitoring Azure Performance counter, SCOM reads information from Azure Table Storage. For monitoring health information of Azure deployment from SCOM, diagnostics information is read from Azure Table Storage only.
But before using these tools for visualizing data one needs to capture diagnostics data; for which you will need to write some code in role “onstart” method.

Here I am presenting code which can be used for collecting Azure Role Instance event log information and transferring it to diagnostics table – WADWindowsEventLogsTable and performance counter information in WADPerformanceCountersTable.
Add reference to required Azure DLL’s and then use following code -