Sunday 14 April 2013

How Compilation in .NET works.?

Compilation in .Net

What is Common Language Runtime (CLR).?

  • CLR works like a virtual machine in executing all languages. 
  • All .NET languages must obey the rules and standards imposed by CLR. Examples: 
    • Object declaration, creation and use
    • Data types,language libraries
    • Error and exception handling
    • Interactive Development Environment (IDE)
  • Development
  • Deployment
  • CLS is a set of specifications that language and library designers need to follow 
    • This will ensure interoperability between languages

Friday 12 April 2013

C# Evolution

I summarized all the key features into a C# Evolution Matrix for your reference as below diagram shows:

Tuesday 9 April 2013

Getting a User’s Time from Twitter API in C#

<?xml version="1.0" encoding="UTF-8"?>
<statuses type="array">
  <status>
    <created_at>Tue Apr 09 10:08:15 +0000 2013</created_at>
    <id>1016846548</id>
    <text>Hi &quot;everybody&quot; #greetings</text>
    <source>web</source>
    <truncated>true</truncated>
    <in_reply_to_status_id></in_reply_to_status_id>
    <in_reply_to_user_id></in_reply_to_user_id>
    <favorited>false</favorited>
    <user>
      <id>2566935</id>
      <name>Abc Xyz</name>
      <screen_name>Abc</screen_name>
      <location></location>
      <description></description>
      <profile_image_url>http://.../normal.jpg</profile_image_url>
      <url>https://www.blogger.com/blogger</url>
      <protected>false</protected>
      <followers_count>42</followers_count>
    </user>
  </status>
  <status>
    ...
  </status>
</statuses>

Extracting the Data

XDocument document = XDocument.Parse(response, LoadOptions.None);

var query = from e in document.Root.Descendants("status")

            select new UserStatus
            {
                UserName = e.Element("user").Element("name").Value,
                ProfileImage = e.Element("user").Element("profile_image_url").Value,
                Status = HttpUtility.HtmlDecode(e.Element("text").Value),
                StatusDate = (e.Element("created_at").Value.ParseDateTime())
            };

Few things to note about the above code:

1. HttpUtility.HtmlDecode is being used in order to get a readable text. The response contained text like “Testing "posts" #devacademy3” and this method (in System.Web) converts it to “Testing “posts” #devacademy3”.

2. The ParseDateTime() method on the element’s value is an extension method I created in order to parse a DateTime from the special string representation of the time the status was posted: Sat Nov 15 10:08:15 +0000 2008 This method looks like:

public static class StringExtensions
{
    public static DateTime ParseDateTime(this string date)
    {
        string dayOfWeek = date.Substring(0, 3).Trim();
        string month = date.Substring(4, 3).Trim();
        string dayInMonth = date.Substring(8, 2).Trim();
        string time = date.Substring(11, 9).Trim();
        string offset = date.Substring(20, 5).Trim();
        string year = date.Substring(25, 5).Trim();
        string dateTime = string.Format("{0}-{1}-{2} {3}", dayInMonth, month, year, time);
        DateTime ret = DateTime.Parse(dateTime);
        return ret;
    }
}

Wednesday 3 April 2013

How to Execute Large Database script in SQL Server?

In case the generated scripts files are too large to open in SQL Server Management Studio, you can utilize the SQLCMD Utility to execute the scripts.
SQLCMD -S LOCALHOST -d AdventureWorks -i C:\script.sql -E 



You will be able to see the below snippet once the schema and data is successfully loaded to the destination database.


How to Execute Large Database script in SQL Server?

In case the generated scripts files are too large to open in SQL Server Management Studio, you can utilize the SQLCMD Utility to execute the scripts.
SQLCMD -S LOCALHOST -d AdventureWorks -i C:\script.sql -E 



You will be able to see the below snippet once the schema and data is successfully loaded to the destination database.


Tuesday 2 April 2013

Difference Between Razor View Engine and ASPX View Engine

View Engine is responsible for rendering the view into html form to the browser.
By default, Asp.net MVC support Web Form(ASPX) and Razor View Engine.

Razor uses @ symbol to make the code like as:

 @Html.ActionLink("Login", "Login")

Webform uses <% and %> delimiters to make the code like as:

 <%: Html.ActionLink("Login", "Login") %> 

 One of the advantages of using Razor is that you can have a Razor parser run against any string, where aspx needs an httpcontext and other heavyweight elements