Thursday, December 29, 2011

Create Nuget Package with powershell script

0 comments


There are so many blogs available to creating nuget package but i would like to go in more details with powershell script option in that.

Use GUI tool

Using commnad lines (http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package ) you can create whole package however better way is to use GUI (Nuget Package Explorer)

Please look below link & follow step

Know about Directory structure

Directory structure of Nuget Package as per docs.nuget.org

  • tools – contains Powershell scripts
  • lib – contains assemblies (dlls)
  • content – contains files to be added on root path

Alter web.config or app.config and Source

If you want to add some settings in configuration file then it is also possible using .tranform
Just add web.config or app.config in \content folder with .tranform extension e.g.
web.config.transform
app.config.tranform


Using Powershell Script

Now if you want some manipulation with files in project then you have to add Powershell Script
under \tool folder , following 3 types files you can add for that , read about in more details at here

    • Init.ps1 runs the first time a package is installed in a solution.
  • Install.ps1 runs when a package is installed in a project.
  • Uninstall.ps1 runs every time a package is uninstalled.


Example to change property value of Project's Item & dispaly popup Message

Here i am going to create install.ps1 and add powsershell script to change property of Test.exe file
Copy To Output Directory = Copy Always

using
$project.ProjectItems.Item("Test.exe").Properties.Item("CopyToOutputDirectory").Value = 1

also add script to open popup at last as per shown in below figs.






Monday, December 26, 2011

Handle chart rendering on multiple instance of Azure webrole application

0 comments
If you would like to know how chart rendering occurs with different ways in asp.net then this link is great one.

Generally when we add graph , at that time in web.config handlers will be added automatically as per below

  
<handlers>
<remove name="ChartImageHandler"/>
<add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</handlers>

<httpHandlers>
<add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>

and to store graph images in folder we need to put app-setting as per below
<add key="ChartImageHandler" value="deleteAfterServicing=false;Storage=file;Timeout=20;URL=~/TempCharts/; />"<validation validateIntegratedModeConfiguration="false"/>

in this case graph data point will be plotted and image will generated and store that in temp folder (as per appsetting)
and on request that image will be displayed on page .

Now this will work well in window azure up to 1 instance but when you will make more then 1 instance at that time sometimes graph will be empy. why?

because if one request store that image in first server of stack then another request want that graph from different server of stack and it can not able to find there!

So how we can handle this issue on multiple instance

simple solution is instead of temp location we need to use blob storage  provided by Azure.

generally chart control will use custom charthanlder for handling to store images of chart so we need to make custom chart handler that will store chart images in blob storage and from there it will be serve in all instances.

Just code your custom handler as per below


public class ChartImageHandler : IChartStorageHandler
{
CloudStorageAccount account;
CloudBlobClient client;
CloudBlobContainer ImageContainer;

public ChartImageHandler()
{
//Here you get the container to the CloudStorageAccount object
//The proper way to do this is with:
//account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
//this is the Dirty way...

account = CloudStorageAccount.Parse("DefaultEndpointsProtocol=http;AccountName=<youraccountstorage>;AccountKey=<yourkey>");
client = account.CreateCloudBlobClient();


//The name of the image container is totatally up to you
ImageContainer = client.GetContainerReference("images");
//if it may not exist, you can use this call to create it....
ImageContainer.CreateIfNotExist();
}
#region IChartStorageHandler Members

public void Delete(string key)
{
CloudBlob image = ImageContainer.GetBlobReference(key);
image.Delete();
}

public bool Exists(string key)
{
CloudBlob image = ImageContainer.GetBlobReference(key);
try
{
image.FetchAttributes();
return true;
}
catch (StorageClientException e)
{
if (e.ErrorCode == StorageErrorCode.ResourceNotFound)
{
return false;
}
else
{
throw;
}
}
}

public byte[] Load(string key)
{
//sometimes load gets called before save is done

CloudBlob image = ImageContainer.GetBlobReference(key);
byte[] imageArray;
try
{
imageArray = image.DownloadByteArray();
}
catch (Exception e)
{
System.Threading.Thread.Sleep(1000);
imageArray = image.DownloadByteArray();

}
return imageArray;
}

public void Save(string key, byte[] data)
{
CloudBlob image = ImageContainer.GetBlobReference(key);
image.UploadByteArray(data);
}
#endregion
}


you need to add reference of this dll found in window azure SdK at C:\Program Files\Windows Azure SDK\v1.3\ref

Microsoft.WindowsAzure.StorageClient.dll

and in web.config just assign that handler in appsetting as per below


<add key="ChartImageHandler" value="deleteAfterServicing=false;Storage=file;Timeout=20;URL=~/TempCharts/;handler=MyApp.MyChartHandler.ChartImageHandler, MyApp;" />


Friday, December 23, 2011

Session state in Window Azure using caching

0 comments
In my previous post , I have talked about different ways to maintain session state in window azure.
From there the best way to maintain session state in window azure is by using appfabric caching, so i am going to discuss it here in details.

1) Create a Cache in Windows Azure

Open management portal , click on servicebus & caching option as per shown in fig-1.




Expand services and click caching , create new namespace as per shown in below fig.



Select service (here cache) add namesapce, location and subscription as per shown in fig



click to view client configuration file.





http://msdn.microsoft.com/en-us/library/gg618004.aspx


2) Prepare Visual Studio to Use Caching for Windows Azure

Verify that the target framework version is .NET Framework 2.0 or higher (non-client profile).

open web.config copy portion of configsection , datacacheclient in web.config,

copy Sessionstate section under system.web


http://msdn.microsoft.com/en-us/library/gg278344.aspx


Related Links

http://www.windowsazure.com/en-us/develop/net/how-to-guides/cache/

http://weblogs.asp.net/shijuvarghese/archive/2011/05/04/usi

ng-windows-azure-appfabric-caching.aspx

http://www.codeproject.com/KB/azure/WA-AppFabric-cache.aspx



Wednesday, December 21, 2011

How to maintain session state in Window Azure

0 comments
In ASP.NET there is concept of a session which is maintained from the user’s first request to their last request for visit of the web site. By default, ASP.NET session is maintained in the RAM of the running web server.

However Window Azure is statless!, web role haven't any local storage.

If only one instance in webrole then usaul session will work but when you make more then one instance then sesion will not work because at any time trafic will be moved to different instance the data center.

generally in web.config session state defined as below

<sessionState timeout="20" mode="InProc"></sessionState>

that is InProc session state maintain in process and will remove after 20 minutes

In Window azure you can maitain session state by following ways

1) By SQL Azure

you can use sql azure database to store session values.

web.config Change

<sessionState mode="SQLServer"
sqlConnectionString="connectionstring"
cookieless="false"
timeout="20"
allowCustomSqlDatabase="true"
/>

Example


2) By Table Storage

you can use storage (table storage) availbale on window azure 

web.config Change

<sessionState mode="Custom" customProvider="TableStorageSessionStateProvider">
<providers>
<clear/>
<add name="TableStorageSessionStateProvider"
type ="Microsoft.Samples.ServiceHosting.AspProviders.TableStorageSessionStateProvider"/>
</providers>
</sessionState>

Example


Download aspprovider from here

3) By AppFabric Caching

You can use appfbric  caching to store session values

web.config Change

<sessionState mode="Custom" customProvider="AppFabricCacheSessionStoreProvider">
<providers>
<!-- specify the named cache for session data -->
<add
name="AppFabricCacheSessionStoreProvider"
type="Microsoft.ApplicationServer.Caching.DataCacheSessionStoreProvider"
cacheName="NamedCache1"
sharedId="SharedApp"/>
</providers>
</sessionState>

Example


Thursday, December 15, 2011

Explore ASP.NET - AutoEventWireUp

0 comments


If you are asp.net developer then may be you know this term -"AutoEventWireUp"

I would like to write about this because many developers don't know about it as it will be added automatically when you create any page in asp.net.

But it is basic fundamental thing every developer should know about it!

If you ask question yourself why all page_event will be call automatically?

then "AutoEventWireUp" can give you answer about that.

As per msdn link

"If the AutoEventWireup attribute of the @ Page directive is set to true, page events are automatically bound to methods that use the naming convention of Page_event, such as Page_Load and Page_Init."

1) By default It is true
2) If you make It false then page_event will not call automatically
for that you need handled that event explicitly
        protected override void OnInit(EventArgs e)
        {
            this.Load += Page_Load;
        }

To know more about it look ASP.NET Web Server Control Event Model

An another product by google - google currents

0 comments
Finally Google launched it's another product in competition with flip board & amazon kindle

This is attempt of Google to give you content in magazine format.

Google Currents is integrated with Google+ so users can share articles or videos they’ve enjoyed with their circles.

Download Google currents for android and apple devices from here.

See the introduction video on You Tube
 

If you would like to publish your content then get start from here

Related Links

http://www.labnol.org/internet/google-currents-magazine/20546/

http://googlemobile.blogspot.com/2011/12/google-currents-is-hot-off-press.html

Saturday, December 10, 2011

Why Mark Zuckerberg is a great IT Leader?

0 comments
Fist question raised in some people mind who is Mark Zuckerberg ? but when you ask about Facebook then every people says that I am on Facebook !
So Mark Zukerberg is founder of Facebook and  youngest billionaire of the world and person of the year 2010 by Times magazine. Many people also watched movie "The Social Network" on this geek guy.


You should have look details of this young guy on Wikipedia here

Why I believe that he is Great IT leader , there are many reason behind this....

A great leader has big and great vision - You can see in Mark and Facebook 
A great leader make prosperous life of his followers - You like to follow it
A great leader can never stop learning and continue on their path without looking past and create history for futureA True Entrepreneur
A great leader encourage people to make change in this world and to reach new heights.
A great leader remain always motivated and motivate people around him.
A great leader never worry about giant competitors when he start their business. (Mark had started development of Facebook when he was studying and goggle and Microsoft were giant IT company at that time)
A great leader always make great smile.   :)

The most amazing thing is that he has make $80 billions on just one site!!

Great quotes by Mark Zukerberg
"I started the site when I was 19. I didn't know much about business back then."

"I think a simple rule of business is, if you do the things that are easier first, then you can actually make a lot of progress."


Read more @ here

And in the last see him with  The Most powerful man of the world US president Obama as Mark also stand at 9th position.

Sunday, December 4, 2011

World is changing let’s look at Future of work

0 comments

Population is increasing at tremendously and everyone is busy in study to make their career, to get good job, to make money... on the other hand economist says that 2nd crisis will be soon..

Non-technical people say that because of technology unemployment is increasing but no one can stop this growth you have to change with world that is only option :)

This will never end if technology is changing every day then it will create new opportunity in work , to earn money just you need to find ways and implement it and you will be winner !

Just look at below video , Future of Work - it's Awesome!



Just try to change you as world is changing now

cheers!


Monday, November 28, 2011

RazorSQL - Very useful client to manage SQL Azure database

0 comments

If you are working with SQL Azure database then you know that how tough it is to manage database with Azure portal!

If you are using it after connecting Sql Azure database with SQL server R2 then also there are some limitations to manage it..

You are not able to
  • Create table
  • Edit data
  • Manage relationship

When i goggled it to find useful tool i found one and that was RazorSQL - very awesome tool!

You can manage 30 type of databases using it including cloud database like SQL Azure and you can overcome all that limitations of Sql Azure to manage from client like SSMS

Look out the features of it form here

Look out the features providing for SQL Azure from here

Look out the screenshot from here

This is paid tool but you can use as trial version for 30 days and after using it you will like to buy it :)

Look out price from here

cheers!

Thursday, November 10, 2011

Enable intellisense with HTML & css in Visual Studio using Web Essentials Extension

1 comments
If you are using visual studio 2010 then this is good to know that now it is possible to use intellisense with css & html file by adding "web essential" extension.  So by using it you can increase your productivity in Visual Studio , it's awesome!

This extension developed by Mads Kristensen .
you can download from here.

Alternate way you can add it in visual studio by Extension Manager













































Now when you open any css file then as per above you will able to add property value through  intellisense and that's great feather for designer.

Cheers!

Related Links

http://visualstudiogallery.msdn.microsoft.com/6ed4c78f-a23e-49ad-b5fd-369af0c2107f

http://www.hanselman.com/blog/UsefulVisualStudioExtensionWebEssentialsFromMadsKristensen.aspx