<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-22141639</atom:id><lastBuildDate>Mon, 28 May 2012 14:50:25 +0000</lastBuildDate><category>Me</category><category>Back To Basics</category><category>Cartoon</category><category>xaml</category><category>Neural Network</category><category>MVC</category><category>MVVM</category><category>CSharp5</category><category>winrt</category><category>Philosophy</category><category>Parallel Programming</category><category>Robotics</category><category>JQuery</category><category>node</category><category>Community</category><category>.NET Rx</category><category>DSL</category><category>cqrs</category><category>Surface</category><category>Mono</category><category>Tech Trends</category><category>VS SDK</category><category>India</category><category>HTML5</category><category>Non-Tech</category><category>Blend</category><category>linq</category><category>Google Wave</category><category>Kinect</category><category>Javascript</category><category>TFS</category><category>Software Development</category><category>Screencast</category><category>XML</category><category>Tips</category><category>windows8</category><category>Fun</category><category>K-MUG</category><category>VS2008</category><category>Windows Phone 7</category><category>Weekend Hacks</category><category>WCF</category><category>Functional Programming</category><category>.NET 4.0</category><category>Dynamic</category><category>VS2010</category><category>Tools</category><category>Programming-Tips</category><category>asp.net</category><category>CSharp</category><category>WPF</category><category>.NET</category><category>Silverlight</category><category>Design And Architecture</category><category>Books</category><title>amazedsaint's #tech journal</title><description>anoop&amp;#39;s observations on tech, web, design &amp;amp; architecture, .net and more..</description><link>http://www.amazedsaint.com/</link><managingEditor>noreply@blogger.com (Anoop Madhusudanan)</managingEditor><generator>Blogger</generator><openSearch:totalResults>159</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/amazedsaint/articles" /><feedburner:info uri="amazedsaint/articles" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><guid isPermaLink="false">tag:blogger.com,1999:blog-22141639.post-3686630697188780642</guid><pubDate>Wed, 16 May 2012 07:33:00 +0000</pubDate><atom:updated>2012-05-16T13:17:04.293+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Javascript</category><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">asp.net</category><category domain="http://www.blogger.com/atom/ns#">CSharp</category><title>Self Hosting ASP.NET Web API and Understanding the Routing Conventions</title><description>&lt;p&gt;&lt;a href="http://lh6.ggpht.com/-oVKTMRwHlqk/T7NYRVhl-yI/AAAAAAAABaU/m262rCLi6CM/s1600-h/image%25255B9%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" align="right" src="http://lh4.ggpht.com/-ivb5LHxHlE4/T7NYSi-2xnI/AAAAAAAABac/50iVxNYc5GU/image_thumb%25255B6%25255D.png?imgmax=800" width="424" height="315" /&gt;&lt;/a&gt;In this post, we’ll have a quick look at ASP.NET Web API Self Hosting and Routing Conventions. ASP.NET Web APIs allow you to easily build RESTful applications on top of the .NET framework. ASP.NET Web API is bundled with ASP.NET MVC 4, but you can also self host Web APIs in your custom .NET application (like a console application or a Windows Forms application or in ASP.NET Web Forms applications).&lt;/p&gt;  &lt;p&gt;Let us quickly build a Pet Store API to query pets using ASP.NET Web API, and we’ll be self hosting the same. &lt;/p&gt;  &lt;h2&gt;Self Hosting&lt;/h2&gt;  &lt;p&gt;Fire up Visual Studio in Admin mode, and create a new Console application. Then, install the Nuget package AspNetWebApi.SelfHost&lt;/p&gt;  &lt;pre&gt;Install-Package AspNetWebApi.SelfHost&lt;/pre&gt;

&lt;p&gt;This will add the required dependencies to your Self host application.&lt;/p&gt;

&lt;pre class="cs" name="code"&gt;class Program
    {
        static void Main(string[] args)
        {

            //Create a host configuration
            var selfHostConfiguraiton = new HttpSelfHostConfiguration(&amp;quot;http://localhost:8080&amp;quot;);

            //Setup the routes
            selfHostConfiguraiton.Routes.MapHttpRoute(
                name: &amp;quot;DefaultApiRoute&amp;quot;,
                routeTemplate: &amp;quot;api/{controller}/{id}&amp;quot;,
                defaults:new { controller = &amp;quot;Pet&amp;quot;, id = RouteParameter.Optional }
                );
           
            //Create Server &amp;amp; Wait for new connections
            using (var server = new HttpSelfHostServer(selfHostConfiguraiton))
            {
                server.OpenAsync().Wait();
                Console.WriteLine(&amp;quot;Now Hosting at http://localhost:8080/api/{controller}&amp;quot;);
                Console.ReadLine();
            }

        }
    }&lt;/pre&gt;

&lt;h2&gt;Adding Controllers&lt;/h2&gt;

&lt;p&gt;Now, you can add your controllers by inheriting them from the ApiController base class, and the requests will be dispatched to the correct controller based on the routing information we added. So, let us have a PetController class, where you expose few pets. &lt;/p&gt;

&lt;pre class="cs" name="code"&gt;  

    //-- Actual controller 

    public class PetController : ApiController
    {
        //GET All Pets /api/pet
        public IEnumerable&amp;lt;Pet&amp;gt; Get()
        {
            var rep = new PetRepository();
            return rep.GetAllPets();
        }

        //GET One Pet /api/pet/2
        public Pet Get(int id)
        {
            var rep = new PetRepository();
            return rep.GetAllPets().First(p =&amp;gt; p.Id == id);
        }
       
    }

   //-- View Model

   public class Pet
    {
        public string Name { get; set; }
        public string Type { get; set; }
        public int Id { get; set; }
    }


    //-- Simple repository elsewhere for some mock data

    public class PetRepository
    {
        public IEnumerable&amp;lt;Pet&amp;gt; GetAllPets()
        {
            //Ideally get the data from a source
            return new List&amp;lt;Pet&amp;gt;
                    {
                        new Pet(){Name=&amp;quot;Jim&amp;quot;, Type=&amp;quot;Dog&amp;quot;, Id=1},
                        new Pet(){Name=&amp;quot;Meow&amp;quot;, Type=&amp;quot;Cat&amp;quot;,Id=2},
                        new Pet(){Name=&amp;quot;Jam&amp;quot;, Type=&amp;quot;Dog&amp;quot;,Id=3},
                        new Pet(){Name=&amp;quot;Tommy&amp;quot;, Type=&amp;quot;Dog&amp;quot;,Id=4},
                        new Pet(){Name=&amp;quot;Bigpaw&amp;quot;, Type=&amp;quot;Cat&amp;quot;,Id=5}
                    };
        }

    }&lt;/pre&gt;

&lt;p&gt;At this point, if you go to the target URL, you’ll find the XML response. Here is a formatted view. Have a look at the URL. &lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh3.ggpht.com/-kP3QySSP3ZE/T7NYTjMpZaI/AAAAAAAABak/sedWfWqtg88/s1600-h/image7.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-YbdrSjV-C74/T7NYVL9zPtI/AAAAAAAABas/Gvs0ZGbacjQ/image_thumb3.png?imgmax=800" width="520" height="380" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And for accessing one pet, you can provide the Id, which gets mapped to the Get method in controller that accepts Id parameter.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh4.ggpht.com/-_RMIzQhBFLI/T7NYYS5PE9I/AAAAAAAABa0/SPjAtAmxsvA/s1600-h/image3.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-8-FLIgfBLUw/T7NYZWXZECI/AAAAAAAABa8/W-hZQtkAM8o/image_thumb1.png?imgmax=800" width="520" height="380" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Default Routing Conventions&lt;/h2&gt;

&lt;p&gt;ASP.NET Web API will try to match the URL with the mapped HTTP routes. Based on the above example you can see that URLs like &lt;em&gt;&lt;strong&gt;/api/pet&lt;/strong&gt;&lt;/em&gt; or &lt;em&gt;&lt;strong&gt;/api/pet/2&lt;/strong&gt;&lt;/em&gt; etc&amp;#160; are matching the route template we provided – &lt;em&gt;&lt;strong&gt;/api/{controller}/{id}&lt;/strong&gt;&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;Now, let us see how the Web API resolves the Controller and the correct action. The controller class will be picked by using the value of the {controller} variable in the URL that corresponds to the routing template.&amp;#160; To choose the action, the Http Action bill be used.&amp;#160; For example, if this is a HTTP GET request, according to the convention, that will be mapped to a method with the name starting with ‘Get’ in the controller. &lt;/p&gt;

&lt;p&gt;As an exercise, change the first Get method’s name to a different one to GetAll, and change the name of our second Get method to GetById – and notice that above URLs are still correctly getting mapped. This convention works out of the box for the GET, POST, PUT and Delete HTTP Methods .&amp;#160; Instead of following the Naming conventions, you can use the attributes HttpGet, HttpPut, HttpPost and HttpDelete. For example, instead of starting the method names with ‘Get’ as in the above example, you could use the HttpGet attribute as below.&lt;/p&gt;

&lt;pre class="cs" name="code"&gt; public class PetController : ApiController
    {
        //GET All Pets /api/pet
        [HttpGet]
        public IEnumerable&amp;lt;Pet&amp;gt; FindAll()
        {
            var rep = new PetRepository();
            return rep.GetAllPets();
        }

        //GET One Pet /api/pet/2
        [HttpGet]
        public Pet FindById(int id)
        {
            var rep = new PetRepository();
            return rep.GetAllPets().First(p =&amp;gt; p.Id == id);
        }
       
    }&lt;/pre&gt;

&lt;p&gt;You might be wondering why the default mapping scheme is limited to the GET, POST, PUT and DELETE actions, but this mapping scheme fits well for RESTful services. Because in REST, all URIs should identify a resource and not actions. Note that this is different than the ASP.NET MVC mapping scheme, where you can specify actions directly. How ever, you can enforce MVC style route selection by specifying the action in the route template, like &lt;/p&gt;

&lt;pre class="cs" name="code"&gt;routes.MapHttpRoute(
    name: &amp;quot;default&amp;quot;,
    routeTemplate: &amp;quot;api/{controller}/{action}/{id}&amp;quot;,
    defaults: new { id = RouteParameter.Optional }
);&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;And this will enable you to choose actions by name in the URL. For example, now you can access the actions in our PetController using the URLs &lt;strong&gt;&lt;em&gt;/api/pet/findall&lt;/em&gt;&lt;/strong&gt; and&lt;strong&gt; &lt;em&gt;/api/pet/findbyid/2&lt;/em&gt;&lt;/strong&gt;&amp;#160;&amp;#160; - Note that we are using the action name in the URL scheme, much like in MVC. This may be useful if you want to build RPC/HTTP APIs.&lt;/p&gt;

&lt;p&gt;While this is a quick introduction, you may refer more detailed tutorials on these topics at &lt;a href="http://www.asp.net/web-api/overview"&gt;http://www.asp.net/web-api/overview&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22141639-3686630697188780642?l=www.amazedsaint.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/O_LG_4INeYBVPMh6cMACK87Dy4Y/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/O_LG_4INeYBVPMh6cMACK87Dy4Y/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/O_LG_4INeYBVPMh6cMACK87Dy4Y/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/O_LG_4INeYBVPMh6cMACK87Dy4Y/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=jDhVf0yach8:0I0GbwTHMH8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=jDhVf0yach8:0I0GbwTHMH8:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=jDhVf0yach8:0I0GbwTHMH8:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=jDhVf0yach8:0I0GbwTHMH8:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=jDhVf0yach8:0I0GbwTHMH8:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=jDhVf0yach8:0I0GbwTHMH8:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=jDhVf0yach8:0I0GbwTHMH8:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=jDhVf0yach8:0I0GbwTHMH8:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=jDhVf0yach8:0I0GbwTHMH8:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/amazedsaint/articles/~4/jDhVf0yach8" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/amazedsaint/articles/~3/jDhVf0yach8/self-hosting-aspnet-web-api-and.html</link><author>noreply@blogger.com (Anoop Madhusudanan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/-ivb5LHxHlE4/T7NYSi-2xnI/AAAAAAAABac/50iVxNYc5GU/s72-c/image_thumb%25255B6%25255D.png?imgmax=800" height="72" width="72" /><feedburner:origLink>http://www.amazedsaint.com/2012/05/self-hosting-aspnet-web-api-and.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-22141639.post-4453432705873038787</guid><pubDate>Tue, 13 Mar 2012 17:32:00 +0000</pubDate><atom:updated>2012-03-14T05:51:02.582+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Software Development</category><category domain="http://www.blogger.com/atom/ns#">Design And Architecture</category><category domain="http://www.blogger.com/atom/ns#">Non-Tech</category><title>The Patent System is so Broken, Be careful if you are a developer!!</title><description>&lt;p&gt;I was reading &lt;a href="http://www.avc.com/a_vc/2012/03/yahoo-crosses-the-line.html"&gt;Fred’s rants&lt;/a&gt; about Yahoo crossing the line by suing Facebook, and got kind of Shocked when I went through the patents &lt;a href="http://paidcontent.org/article/419-meet-the-10-patents-yahoo-is-using-to-sue-facebook/"&gt;Yahoo is using to Sue Facebook&lt;/a&gt;. The point is, most of these patents are so generic that you can get sued if you run a web site. Why patents do exist for all trivial common tasks and architecture patterns in the world? A common sense design decision I’m going to take for my next website or my next customer project is already patented!! This is ridiculous.&lt;/p&gt;  &lt;h2&gt;“Dynamic Page Generator”&lt;/h2&gt;  &lt;p&gt;For example, have a look at this &lt;a href="http://www.google.com/patents?id=H8QWAAAAEBAJ&amp;amp;printsec=abstract&amp;amp;zoom=4#v=onepage&amp;amp;q&amp;amp;f=false"&gt;“Dynamic Page Generator” patent&lt;/a&gt; – It can be used to sue any CGI/Server side stack.&amp;#160; The patent states&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;An custom page server is provided with user preferences organized into templates stored in compact data structures and the live data used to fill the templates stored local to the page server which is handing user requests for custom pages. One process is executed on the page server for every request. The process is provided a user template for the user making the request, where the user template is either generated from user preferences or retrieved from a cache of recently used user templates. Each user process is provided access to a large region of shared memory which contains all of the live data needed to fill any user template&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;So, your website has an architecture similar to this? I’m sure most new age web sites are dynamic – but hey, you can get sued for this (Or correct me if I’m missing anything). &lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-qzzCUAwatjY/T1-Ej18NKKI/AAAAAAAABVQ/1U1xMEZVTdg/s1600-h/image%25255B5%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-sKoSkgtF3FU/T1-EkcKN-wI/AAAAAAAABVY/ZWSBeXeVNGM/image_thumb%25255B3%25255D.png?imgmax=800" width="565" height="423" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;h2&gt;“Personalized Information Retrieval Using Profiles”&lt;/h2&gt;  &lt;p&gt;Such trivial tasks has got a patent too, for example&amp;#160; &lt;a href="http://www.google.com/patents/US5761662"&gt;see this&lt;/a&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;An automatic method and system for retrieving information based on a user-defined profile (e.g. a personalized newspaper). A user-controlled client establishes communication with a stateless server, the server presenting a list of options to the client between the server and the client. The client provides an identification of the user-defined profile. The server engages a first application program, the first application program retrieving the user-defined profile wherein the user-defined profile identifies information which is of interest to the user.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-SRfU9QD8sgg/T1-EmJ1BLFI/AAAAAAAABVg/Ry-5Wn5jEhc/s1600-h/image%25255B9%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-O9i9UwUzb3k/T1-EmkG3nRI/AAAAAAAABVo/PjntURa6pUY/image_thumb%25255B5%25255D.png?imgmax=800" width="511" height="283" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;So, is it that if I implement a Profile based customization for my website, I can be sued by Sun Microsystems (Oops, now by Oracle, may be?)&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h2&gt;The larger perspective&lt;/h2&gt;  &lt;p&gt;To be honest, I think this entire Patent system is a time bomb that’ll explode pretty soon – large companies will use this to bomb small companies. And some one please fix it. Not sure why all these patents are getting approved, who are reviewing them and why these generic concepts are patented to this extent?&lt;/p&gt;  &lt;p&gt;Or may be I’m so naïve that I’m missing something here!!&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: Found that The Verge has &lt;a href="http://www.theverge.com/2011/08/11/broken-patent-system/"&gt;another great article&lt;/a&gt; on the same topic, read that too.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22141639-4453432705873038787?l=www.amazedsaint.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/p51_1IQVhfwhgxff9EVIz8_g5vA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/p51_1IQVhfwhgxff9EVIz8_g5vA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/p51_1IQVhfwhgxff9EVIz8_g5vA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/p51_1IQVhfwhgxff9EVIz8_g5vA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=mmuUUDqpxpc:ULNrLbBnRRg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=mmuUUDqpxpc:ULNrLbBnRRg:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=mmuUUDqpxpc:ULNrLbBnRRg:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=mmuUUDqpxpc:ULNrLbBnRRg:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=mmuUUDqpxpc:ULNrLbBnRRg:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=mmuUUDqpxpc:ULNrLbBnRRg:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=mmuUUDqpxpc:ULNrLbBnRRg:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=mmuUUDqpxpc:ULNrLbBnRRg:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=mmuUUDqpxpc:ULNrLbBnRRg:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/amazedsaint/articles/~4/mmuUUDqpxpc" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/amazedsaint/articles/~3/mmuUUDqpxpc/patent-system-is-so-broken-you-can-get.html</link><author>noreply@blogger.com (Anoop Madhusudanan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh6.ggpht.com/-sKoSkgtF3FU/T1-EkcKN-wI/AAAAAAAABVY/ZWSBeXeVNGM/s72-c/image_thumb%25255B3%25255D.png?imgmax=800" height="72" width="72" /><feedburner:origLink>http://www.amazedsaint.com/2012/03/patent-system-is-so-broken-you-can-get.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-22141639.post-5546040368937433816</guid><pubDate>Sat, 18 Feb 2012 10:11:00 +0000</pubDate><atom:updated>2012-02-18T15:43:20.990+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Javascript</category><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">HTML5</category><category domain="http://www.blogger.com/atom/ns#">.NET 4.0</category><category domain="http://www.blogger.com/atom/ns#">CSharp</category><title>CanML– Creating simple Markup language using XML + T4 for drawing shapes in HTML5 Canvas in your ASP.NET/C# applications</title><description>&lt;p&gt;In this post, we’ll explore how to create a simple Xml based markup language for defining shapes for HTML5 Canvas. We’ll achieve this by generating JavaScript code from the Xml definition, and this post is intended to be a pointer towards how you can leverage scaffolding and meta programming to simplify a lot of scenarios.&amp;#160; If you &lt;a href="http://www.codinghorror.com/blog/2012/02/farewell-stack-exchange.html"&gt;don’t have a lot of kids to look after&lt;/a&gt;, modify this to create your own version of full fledged CanML (take that name) and let me know &lt;/p&gt;  &lt;p&gt;Coming back - We’ll be using my Elastic Object Nuget package and T4 templates for code generation as I explained in my last post [&lt;a href="http://www.amazedsaint.com/2012/02/xml-driven-ct4-code-generation-with.html"&gt;Using AmazedSaint.ElasticObject Nuget Package for code generation&lt;/a&gt;], so reading that post will help for sure. I also suggest you to read quickly this &lt;a href="https://developer.mozilla.org/en/Canvas_tutorial/Basic_usage"&gt;Basic Canvas tutorial in MDN&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;[+] Source code -&lt;/strong&gt;&amp;#160; &lt;a href="https://skydrive.live.com/redir.aspx?cid=583493a69dfcdddb&amp;amp;resid=583493A69DFCDDDB!182&amp;amp;parid=583493A69DFCDDDB!147"&gt;Download ASP.NET MVC zipped example From Skydrive&lt;/a&gt; and keep it handy&lt;/p&gt;  &lt;h2&gt;What we are going to achieve?&lt;/h2&gt;  &lt;p&gt;You’ll be able to declare your canvas shapes using XML, for example see how I’m declaring a Heart shape and a Triangle slice. In the heart shape, I’m using absolute co-ordinates, and I’m using variables for triangle slice so that you can draw it anywhere.&lt;/p&gt;  &lt;pre class="xml" name="code"&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot; ?&amp;gt;

&amp;lt;shapes&amp;gt;

  &amp;lt;!--Normal Heart Shape, Fixed Coords--&amp;gt;
  &amp;lt;shape name=&amp;quot;shapeHeart&amp;quot; type=&amp;quot;fill&amp;quot; params=&amp;quot;fillColor&amp;quot;&amp;gt;
    &amp;lt;fillStyle value=&amp;quot;fillColor&amp;quot;/&amp;gt;
    &amp;lt;to params=&amp;quot;75,40&amp;quot;/&amp;gt;
    &amp;lt;bcurve params=&amp;quot;75,37,70,25,50,25&amp;quot;/&amp;gt;
    &amp;lt;bcurve params=&amp;quot;20,25,20,62.5,20,62.5&amp;quot;/&amp;gt;
    &amp;lt;bcurve params=&amp;quot;20,80,40,102,75,120&amp;quot;/&amp;gt;
    &amp;lt;bcurve params=&amp;quot;110,102,130,80,130,62.5&amp;quot;/&amp;gt;
    &amp;lt;bcurve params=&amp;quot;130,62.5,130,25,100,25&amp;quot;/&amp;gt;
    &amp;lt;bcurve params=&amp;quot;85,25,75,37,75,40&amp;quot;/&amp;gt;
  &amp;lt;/shape&amp;gt;

  &amp;lt;!--Triangle Slice with variables--&amp;gt;
  &amp;lt;shape name=&amp;quot;shapeTriangleSlice&amp;quot; type=&amp;quot;fill&amp;quot; params=&amp;quot;fillColor,firstX,firstY,delta&amp;quot;&amp;gt;
    &amp;lt;fillStyle value=&amp;quot;fillColor&amp;quot;/&amp;gt;
    &amp;lt;to params=&amp;quot;firstX,firstY&amp;quot;/&amp;gt;
    &amp;lt;line params=&amp;quot;firstX,firstY+delta&amp;quot;/&amp;gt;
    &amp;lt;line params=&amp;quot;firstX+delta,firstY&amp;quot;/&amp;gt;
  &amp;lt;/shape&amp;gt;


  &amp;lt;!--Draw both--&amp;gt;
  &amp;lt;shape name=&amp;quot;allShapes&amp;quot;&amp;gt;
    &amp;lt;shape name=&amp;quot;shapeHeart&amp;quot; params=&amp;quot;'yellow'&amp;quot;/&amp;gt;
    &amp;lt;shape name=&amp;quot;shapeTriangleSlice&amp;quot; params=&amp;quot;'red',200,200,100&amp;quot;/&amp;gt;
    &amp;lt;shape name=&amp;quot;shapeTriangleSlice&amp;quot; params=&amp;quot;'red',200,200,-100&amp;quot;/&amp;gt;
  &amp;lt;/shape&amp;gt;
  
&amp;lt;/shapes&amp;gt;&lt;/pre&gt;

&lt;p&gt;And this will be rendered to an HTML5 Canvas as below. This trick is, we are generating the required JavaScript code from the above markup, using the technique I explained in my earlier post – &lt;a href="http://www.amazedsaint.com/2012/02/xml-driven-ct4-code-generation-with.html"&gt;Generating code from simple XML models&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh3.ggpht.com/-_5OlZhB3KcY/Tz95WYdaDAI/AAAAAAAABU8/hZ5-RKG7x8I/s1600-h/image%25255B13%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-xedPGOEbQao/Tz95XmLV1oI/AAAAAAAABVE/w86w78aG0HM/image_thumb%25255B9%25255D.png?imgmax=800" width="644" height="445" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h2&gt;What about the Generated JavaScript?&lt;/h2&gt;

&lt;p&gt;If you are interested to see the JavaScript getting generated from the above Markup, see that below. If you examine the generated code closely along with the xml model we’ve above, you can see that we are following a couple of simple conventions to generate the code from the above markup.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Each &amp;lt;shape/&amp;gt; definition is wrapped as a method, with a canvas parameter (along with other parameters if param element is present) &lt;/li&gt;

  &lt;li&gt;The type attribute of the Shape &lt;/li&gt;

  &lt;li&gt;We are having some short cut notations (like to –&amp;gt; moveTo and bcurve-&amp;gt; bezierCurveTo) &lt;/li&gt;

  &lt;li&gt;If an element has a param attribute, it’ll be rendered as a method (example is moveTo) &lt;/li&gt;

  &lt;li&gt;If an element has a value attribute, it’ll be rendered as a property (example is &lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="javascript" name="code"&gt;//Method generated 
var shapeHeart = function (canvas, fillColor) 
{
if (canvas.getContext){  
    var ctx = canvas.getContext('2d');  
	ctx.beginPath();
	ctx.fillStyle=fillColor;
	ctx.moveTo(75,40);
	ctx.bezierCurveTo(75,37,70,25,50,25);
	ctx.bezierCurveTo(20,25,20,62.5,20,62.5);
	ctx.bezierCurveTo(20,80,40,102,75,120);
	ctx.bezierCurveTo(110,102,130,80,130,62.5);
	ctx.bezierCurveTo(130,62.5,130,25,100,25);
	ctx.bezierCurveTo(85,25,75,37,75,40);
	ctx.fill();			
}
}
//Method generated 
var shapeTriangleSlice = function (canvas, fillColor,firstX,firstY,delta) 
{
if (canvas.getContext){  
    var ctx = canvas.getContext('2d');  
	ctx.beginPath();
	ctx.fillStyle=fillColor;
	ctx.moveTo(firstX,firstY);
	ctx.lineTo(firstX,firstY+delta);
	ctx.lineTo(firstX+delta,firstY);
	ctx.fill();
			
}
}
//Method generated 
var allShapes = function (canvas) 
{
if (canvas.getContext){  
    var ctx = canvas.getContext('2d');  
	ctx.beginPath();
	shapeHeart(canvas,'yellow');
	shapeTriangleSlice(canvas,'red',200,200,100);
	shapeTriangleSlice(canvas,'red',200,200,-100);			
}
}&lt;/pre&gt;
Note that all methods are generated with a canvas input parameter. And now, you may call these methods by linking to the generated CanvasShapes.js script file in your html page – See my index.cshtml ASP.NET MVC razor view where I invoke the allShapes method.&amp;#160; Just get your actual canvas element, and pass it to draw, as shown below.

&lt;pre class="html" name="code"&gt;@{
    ViewBag.Title = &amp;quot;Home Page&amp;quot;;
}

@section headerSection{
    &amp;lt;script src=&amp;quot;@Url.Content(&amp;quot;~/CanvasShapes/CanvasShapes.js&amp;quot;)&amp;quot; type=&amp;quot;text/javascript&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;
     &amp;lt;style type=&amp;quot;text/css&amp;quot;&amp;gt;  
      canvas { border: 1px solid black; margin-left:auto; margin-right:auto;}  
    &amp;lt;/style&amp;gt;  
}

&amp;lt;canvas id=&amp;quot;myCanvas&amp;quot; width=800 height=480&amp;gt;&amp;lt;/canvas&amp;gt;

&amp;lt;script&amp;gt;
    var canvas = document.getElementById(&amp;quot;myCanvas&amp;quot;);
    allShapes(canvas);
&amp;lt;/script&amp;gt;&lt;/pre&gt;

&lt;h2&gt;Tell me about the Actual Generation of JS from XML?&lt;/h2&gt;

&lt;p&gt;The actual generation is super simple – In fact this was just intended to be an sample use case for using the &lt;a href="http://www.amazedsaint.com/2012/02/xml-driven-ct4-code-generation-with.html"&gt;Elastic Object Nuget package&lt;/a&gt; for code generation.&lt;/p&gt;

&lt;p&gt;To try this out manually, &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Create a new ASP.NET MVC Project in Visual Studio. &lt;/li&gt;

  &lt;li&gt;Install the AmazedSaint.ElasticObject package as explained in my previous post – This will also add an Xml file and a TT (Text template file) to your project &lt;/li&gt;

  &lt;li&gt;Rename the Xml file to CanvasModel.xml – and copy the above XML code to the same &lt;/li&gt;

  &lt;li&gt;Rename the TT file CanvasShapes.tt, and add&amp;#160; the below T4 code to the TT File &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is the simple T4 code we are using for generating the JS Code. Oops, the actual conversion code is not even 25 lines, but this is enough to convey the idea, right? You can beef this up further, by adding some support for gradiants, transitions etc to make this full fledged. Keep the &lt;a href="https://developer.mozilla.org/en/Canvas_tutorial"&gt;MDN Canvas documentation handy.&lt;/a&gt;&lt;/p&gt;

&lt;pre class="c#" name="code"&gt;&amp;lt;#@ template debug=&amp;quot;true&amp;quot; hostspecific=&amp;quot;true&amp;quot; language=&amp;quot;C#&amp;quot; #&amp;gt;
&amp;lt;#@ Assembly Name=&amp;quot;System.Xml.dll&amp;quot; #&amp;gt;
&amp;lt;#@ Assembly Name=&amp;quot;System.Xml.Linq.dll&amp;quot; #&amp;gt;
&amp;lt;#@ Assembly Name=&amp;quot;System.Core.dll&amp;quot; #&amp;gt;
&amp;lt;#@ Assembly Name=&amp;quot;Microsoft.CSharp.dll&amp;quot; #&amp;gt;
&amp;lt;#@ Assembly name=&amp;quot;$(SolutionDir)packages\AmazedSaint.ElasticObject.1.2.0\lib\net40\AmazedSaint.Elastic.dll&amp;quot; #&amp;gt;
&amp;lt;#@ Import Namespace=&amp;quot;System.Xml&amp;quot; #&amp;gt;
&amp;lt;#@ Import Namespace=&amp;quot;System.Xml.Linq&amp;quot; #&amp;gt;
&amp;lt;#@ Import Namespace=&amp;quot;AmazedSaint.Elastic&amp;quot; #&amp;gt;
&amp;lt;#@ Import Namespace=&amp;quot;System.Collections.Generic&amp;quot; #&amp;gt;
&amp;lt;#@ Import Namespace=&amp;quot;System.Collections&amp;quot; #&amp;gt;
&amp;lt;#@ Import Namespace=&amp;quot;AmazedSaint.Elastic.Lib&amp;quot; #&amp;gt;
&amp;lt;#@ output extension=&amp;quot;.js&amp;quot; #&amp;gt;

&amp;lt;#
var model=FromFile(&amp;quot;CanvasModel.xml&amp;quot;);
foreach(var c in model[&amp;quot;shape&amp;quot;])  //get all classes
	WriteShapeMethod(c);

#&amp;gt;

&amp;lt;#+ 
//Create an elastic object
private dynamic FromFile(string file)
{
   var path= Host.ResolvePath(file);
   return XDocument.Load(path).Root.ToElastic();
}

//Write a shape method
private void WriteShapeMethod(dynamic c)
{ 
#&amp;gt;
//Method generated 
var &amp;lt;#= c.name #&amp;gt; = function (&amp;lt;#=c.HasAttribute(&amp;quot;params&amp;quot;)
                         ?&amp;quot;canvas, &amp;quot; + c.@params :&amp;quot;canvas&amp;quot;  #&amp;gt;) 
{
if (canvas.getContext){  
    var ctx = canvas.getContext('2d');  
	ctx.beginPath();
&amp;lt;#+	
var tokens = new System.Collections.Generic.Dictionary&amp;lt;string, string&amp;gt;()
			{
				{&amp;quot;bcurve&amp;quot;,&amp;quot;bezierCurveTo&amp;quot;},
                {&amp;quot;qcurve&amp;quot;,&amp;quot;quadraticCurveTo&amp;quot;},
                {&amp;quot;line&amp;quot;,&amp;quot;lineTo&amp;quot;},
                {&amp;quot;to&amp;quot;,&amp;quot;moveTo&amp;quot;},
                {&amp;quot;arcTo&amp;quot;,&amp;quot;arcTo&amp;quot;}
			};
	foreach (var member in c[null])
    {
	    string mname = tokens.ContainsKey(member.InternalName) 
               ? tokens[member.InternalName] : member.InternalName;
        if (member.HasAttribute(&amp;quot;params&amp;quot;))
        {
           if (member.InternalName==&amp;quot;shape&amp;quot;)
		WriteLine(&amp;quot;\t&amp;quot; + member.name + &amp;quot;(canvas,&amp;quot; + member.@params + &amp;quot;);&amp;quot;);
           else
	       WriteLine(&amp;quot;\tctx.&amp;quot; + mname + &amp;quot;(&amp;quot; + member.@params + &amp;quot;);&amp;quot;);
   }
        else if (member.HasAttribute(&amp;quot;value&amp;quot;))
	        WriteLine(&amp;quot;\tctx.&amp;quot; + mname + &amp;quot;=&amp;quot; + member.@value + &amp;quot;;&amp;quot;);
        else
	        WriteLine(&amp;quot;\tctx.&amp;quot; + mname + &amp;quot;();&amp;quot;); 
	}

    if (c.HasAttribute(&amp;quot;type&amp;quot;))
	    WriteLine(&amp;quot;\tctx.&amp;quot; + c.type + &amp;quot;();&amp;quot;);
        
#&amp;gt;			
}
}
&amp;lt;#+
}

#&amp;gt;&lt;/pre&gt;

&lt;p&gt;All right, Happy coding as usual. Enjoy some simple meta coding cookies.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22141639-5546040368937433816?l=www.amazedsaint.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/G5hZBzYRZzZN5BOkdUzXmCAuuz4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/G5hZBzYRZzZN5BOkdUzXmCAuuz4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/G5hZBzYRZzZN5BOkdUzXmCAuuz4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/G5hZBzYRZzZN5BOkdUzXmCAuuz4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=_jJiWhCnr8c:x-G7XwGxlk4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=_jJiWhCnr8c:x-G7XwGxlk4:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=_jJiWhCnr8c:x-G7XwGxlk4:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=_jJiWhCnr8c:x-G7XwGxlk4:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=_jJiWhCnr8c:x-G7XwGxlk4:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=_jJiWhCnr8c:x-G7XwGxlk4:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=_jJiWhCnr8c:x-G7XwGxlk4:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=_jJiWhCnr8c:x-G7XwGxlk4:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=_jJiWhCnr8c:x-G7XwGxlk4:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/amazedsaint/articles/~4/_jJiWhCnr8c" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/amazedsaint/articles/~3/_jJiWhCnr8c/canml-creating-simple-markup-language.html</link><author>noreply@blogger.com (Anoop Madhusudanan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh3.ggpht.com/-xedPGOEbQao/Tz95XmLV1oI/AAAAAAAABVE/w86w78aG0HM/s72-c/image_thumb%25255B9%25255D.png?imgmax=800" height="72" width="72" /><feedburner:origLink>http://www.amazedsaint.com/2012/02/canml-creating-simple-markup-language.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-22141639.post-8997119221403700752</guid><pubDate>Thu, 16 Feb 2012 07:01:00 +0000</pubDate><atom:updated>2012-02-18T15:56:01.195+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Dynamic</category><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">.NET 4.0</category><category domain="http://www.blogger.com/atom/ns#">CSharp</category><title>XML Driven C#/T4 Code Generation with ElasticObject Nuget Package For Minimalists ;)</title><description>&lt;p&gt;&lt;a href="http://lh3.ggpht.com/-fuIyMRN-pUw/TzypooCo1jI/AAAAAAAABUE/YJOo78-dUOA/s1600-h/image%25255B18%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" align="right" src="http://lh4.ggpht.com/-Ru5wRLys5qg/Tzyppm7RciI/AAAAAAAABUM/b9-zwl5XRzQ/image_thumb%25255B8%25255D.png?imgmax=800" width="173" height="167" /&gt;&lt;/a&gt;Code generation should be simple, and I wanted to do it by using a simple XML file as my model from with in Visual Studio. So, here is a quick wrapper I’ve created for Xml driven code generation for minimalists/minimal scenarios.&lt;/p&gt;  &lt;h2&gt;Starting Super Simple XML driven code generation – Now with Nuget&lt;/h2&gt;  &lt;p&gt;Here we go – this is based on my &lt;a href="http://www.amazedsaint.com/2010/02/introducing-elasticobject-for-net-40.html"&gt;ElasticObject&lt;/a&gt; implementation to generate code using Text Templates (TT/T4), by using simple XML files as a model. It is so simple that it won’t support the entire XML schema &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="http://lh6.ggpht.com/-7nlvpRW0FjE/TzypqioLqdI/AAAAAAAABUU/tNgZOitTZzc/wlEmoticon-winkingsmile%25255B2%25255D.png?imgmax=800" /&gt; -&amp;#160; But I’ll live with that for now. So, the steps are simple.&lt;/p&gt;  &lt;h3&gt;&lt;a href="http://lh4.ggpht.com/-4Ou-OTrWKaA/Tzyprvs5Z5I/AAAAAAAABUs/-zjRrv04ntU/s1600-h/image%25255B25%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" align="right" src="http://lh6.ggpht.com/-V678Ne97SLU/TzypspoPIsI/AAAAAAAABUw/w3FkvG5nAIQ/image_thumb%25255B15%25255D.png?imgmax=800" width="296" height="274" /&gt;&lt;/a&gt;Step 1 - Get the ElasticObject Nuget Package&lt;/h3&gt;  &lt;p&gt;Install AmazedSaint.ElasticObject, run the following command in the &lt;a href="http://docs.nuget.org/docs/start-here/using-the-package-manager-console"&gt;Package Manager Console&lt;/a&gt;&lt;/p&gt;  &lt;pre&gt;PM&amp;gt; Install-Package AmazedSaint.ElasticObject&lt;/pre&gt;

&lt;p&gt;Or you can install this via the Nuget Package manager, it is your choice.&lt;/p&gt;

&lt;h3&gt;Step 2 – Enjoy&lt;/h3&gt;

&lt;p&gt;This should add the reference to ElasticObject library, and will add an Xml model file and a T4 template in the Solution Explorer (See the image). The xml file can be your model, and the TT file has a bit of code that wraps the model for generating what ever you need (source code, views, scaffolding etc). You can modify the xml and the TT file. Also, there is a &lt;em&gt;ReadMe-ElasticObject.cs.txt&lt;/em&gt; which you can re-name to&amp;#160; a CS file and view/run the tests to see the usage of ElasticObject.&lt;/p&gt;

&lt;h2&gt;What is in the Xml model file and TT generator?&lt;/h2&gt;

&lt;p&gt;The example model file contains some sample xml, it can be anything (infact, a reasonable subset of xml ;)) &lt;/p&gt;

&lt;pre class="xml" name="code"&gt;&amp;lt;model&amp;gt;
&amp;lt;class name=&amp;quot;MyClass1&amp;quot;&amp;gt;
  &amp;lt;property name=&amp;quot;MyProperty1&amp;quot; type=&amp;quot;string&amp;quot;/&amp;gt;
  &amp;lt;property name=&amp;quot;MyProperty2&amp;quot; type=&amp;quot;string&amp;quot;/&amp;gt;
&amp;lt;/class&amp;gt;
  &amp;lt;class name=&amp;quot;MyClass2&amp;quot;&amp;gt;
    &amp;lt;property name=&amp;quot;MyProperty1&amp;quot; type=&amp;quot;string&amp;quot;/&amp;gt;
    &amp;lt;property name=&amp;quot;MyProperty2&amp;quot; type=&amp;quot;string&amp;quot;/&amp;gt;
  &amp;lt;/class&amp;gt;
&amp;lt;/model&amp;gt;&lt;/pre&gt;

&lt;p&gt;So, as you can see, the model can be anything, with in a valid root element. The example just mimics few classes and properties in that. Now, let us have a quick look at the example TT file added by the Nuget package. Don't get afraid, it is some simple T4 syntax - &lt;a href="http://www.olegsych.com/tag/t4/"&gt;Refresh your T4 Skills from here&lt;/a&gt;, Oleg has everything for you to start with the T4 syntax (and much more). &lt;/p&gt;

&lt;p&gt;Did I tell you you can use Visual T4 Editor Free edition to reduce the pain when you work with T4 Templates? &lt;a href="http://visualstudiogallery.msdn.microsoft.com/40a887aa-f3be-40ec-a85d-37044b239591"&gt;Get it today from the VS Extensions gallery&lt;/a&gt;, otherwise you’ll end up sending hate mails to the guys who created the Visual Studio T4 editor.&lt;/p&gt;

&lt;p&gt;In the below code, you could see that we are creating an elastic object from the xml, and then iterating the elements for generating the code – In case you are not familiar with ElasticObject, &lt;a href="http://www.amazedsaint.com/2010/02/10-minute-twitter-search-app-using-duck.html"&gt;see my post here&lt;/a&gt; – It is just a wrapper dynamic object I created for loosely wrapping stuff like xml. Also, you could see this LIDNUG presentation where &lt;a href="http://www.amazedsaint.com/2011/11/this-is-cool-just-found-that-ironshay.html"&gt;Shey is demoing the ElasticObject&lt;/a&gt; in between his dynamic talk.&lt;/p&gt;

&lt;p&gt;Anyway, here is the T4 code you’ll find in the tt file added by our Nuget package.&lt;/p&gt;

&lt;pre class="c#" name="code"&gt;&amp;lt;#@ template debug=&amp;quot;false&amp;quot; hostspecific=&amp;quot;true&amp;quot; language=&amp;quot;C#&amp;quot; #&amp;gt;
&amp;lt;#@ Assembly Name=&amp;quot;System.Xml.dll&amp;quot; #&amp;gt;
&amp;lt;#@ Assembly Name=&amp;quot;System.Xml.Linq.dll&amp;quot; #&amp;gt;
&amp;lt;#@ Assembly Name=&amp;quot;System.Core.dll&amp;quot; #&amp;gt;
&amp;lt;#@ Assembly Name=&amp;quot;Microsoft.CSharp.dll&amp;quot; #&amp;gt;
&amp;lt;#@ Assembly name=&amp;quot;$(SolutionDir)packages\AmazedSaint.ElasticObject.1.0.0\lib\net40\AmazedSaint.Elastic.dll&amp;quot; #&amp;gt;
&amp;lt;#@ Import Namespace=&amp;quot;System.Xml&amp;quot; #&amp;gt;
&amp;lt;#@ Import Namespace=&amp;quot;System.Xml.Linq&amp;quot; #&amp;gt;
&amp;lt;#@ Import Namespace=&amp;quot;AmazedSaint.Elastic&amp;quot; #&amp;gt;
&amp;lt;#@ Import Namespace=&amp;quot;AmazedSaint.Elastic.Lib&amp;quot; #&amp;gt;
&amp;lt;#@ output extension=&amp;quot;.cs&amp;quot; #&amp;gt;

&amp;lt;#
var model=FromFile(&amp;quot;ElasticDemoModel.xml&amp;quot;);

foreach(var c in model[&amp;quot;class&amp;quot;])  //get all classes
	WriteClass(c);

#&amp;gt;

&amp;lt;#+ 
//Create an elastic object
private dynamic FromFile(string file)
{
   var path= Host.ResolvePath(file);
   return XDocument.Load(path).Root.ToElastic();
}

//Write a class
private void WriteClass(dynamic c)
{ 
#&amp;gt;
//Class generated 
class &amp;lt;#= c.name #&amp;gt; 
{
&amp;lt;#+
	foreach(var p in c[&amp;quot;property&amp;quot;])
	   WriteProperty(p);  
#&amp;gt;			
}
&amp;lt;#+
}


//Write a Property
private void WriteProperty(dynamic p)
{
#&amp;gt;
public &amp;lt;#= p.type #&amp;gt; &amp;lt;#= p.name #&amp;gt;  {get;set;}
&amp;lt;#+   
}
#&amp;gt;&lt;/pre&gt;

&lt;p&gt;And you guessed it, the generated file is here. &lt;/p&gt;

&lt;pre class="c#" name="code"&gt;//Class generated 
class MyClass1 
{
public string MyProperty1  {get;set;}
public string MyProperty2  {get;set;}			
}
//Class generated 
class MyClass2 
{
public string MyProperty1  {get;set;}
public string MyProperty2  {get;set;}			
}&lt;/pre&gt;

&lt;p&gt;Note that this requires C# dynamic support, and hence targets the .NET 4.0 runtime – So if you want to have code generation in other platforms with out dynamic support, add a .NET 4.0 project, keep your models and TT/T4s there, and add/link the generated files to other projects. This example just shows C# code generation from the model, but you can imagine what all things you can do &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="http://lh6.ggpht.com/-7nlvpRW0FjE/TzypqioLqdI/AAAAAAAABUU/tNgZOitTZzc/wlEmoticon-winkingsmile%25255B2%25255D.png?imgmax=800" /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update: &lt;/strong&gt;See an example implementation – &lt;a href="http://www.amazedsaint.com/2012/02/canml-creating-simple-markup-language.html"&gt;CanML – Creating a simple markup language for drawing shapes to HTML5 Canvas&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Few more of my previous posts, if you’ve more interest.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://www.amazedsaint.com/2010/03/c-40-dynamic-keyword-for-dummies-under.html"&gt;Dynamic for dummies&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://www.amazedsaint.com/2009/09/systemdynamicexpandoobject-similar.html"&gt;C# Expando Object Inside look&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://www.google.co.in/url?sa=t&amp;amp;rct=j&amp;amp;q=c%23%20dynamic%20elasticobject&amp;amp;source=web&amp;amp;cd=1&amp;amp;ved=0CCUQFjAA&amp;amp;url=http%3A%2F%2Fwww.codeproject.com%2FArticles%2F62839%2FAdventures-with-C-4-0-dynamic-ExpandoObject-Elasti&amp;amp;ei=LKM8T6mpEY6zrAeJvpTNBw&amp;amp;usg=AFQjCNEW67t4D50XMHaUr_0dFM-aeLM7ow&amp;amp;sig2=Ehr5iTK2KB3Zx1xmFD4Oag"&gt;Adventures with C# dynamic&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22141639-8997119221403700752?l=www.amazedsaint.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/iVHugeo_PIafhsfitJWbemklqFA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/iVHugeo_PIafhsfitJWbemklqFA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/iVHugeo_PIafhsfitJWbemklqFA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/iVHugeo_PIafhsfitJWbemklqFA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=JNBu7y6Llxg:_xZqnuZu4qg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=JNBu7y6Llxg:_xZqnuZu4qg:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=JNBu7y6Llxg:_xZqnuZu4qg:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=JNBu7y6Llxg:_xZqnuZu4qg:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=JNBu7y6Llxg:_xZqnuZu4qg:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=JNBu7y6Llxg:_xZqnuZu4qg:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=JNBu7y6Llxg:_xZqnuZu4qg:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=JNBu7y6Llxg:_xZqnuZu4qg:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=JNBu7y6Llxg:_xZqnuZu4qg:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/amazedsaint/articles/~4/JNBu7y6Llxg" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/amazedsaint/articles/~3/JNBu7y6Llxg/xml-driven-ct4-code-generation-with.html</link><author>noreply@blogger.com (Anoop Madhusudanan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/-Ru5wRLys5qg/Tzyppm7RciI/AAAAAAAABUM/b9-zwl5XRzQ/s72-c/image_thumb%25255B8%25255D.png?imgmax=800" height="72" width="72" /><feedburner:origLink>http://www.amazedsaint.com/2012/02/xml-driven-ct4-code-generation-with.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-22141639.post-4792492990416816736</guid><pubDate>Sun, 29 Jan 2012 17:26:00 +0000</pubDate><atom:updated>2012-02-04T19:10:14.435+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Weekend Hacks</category><category domain="http://www.blogger.com/atom/ns#">Software Development</category><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">Kinect</category><title>Kibloc – Real time, distance based object tracking and counting using Kinect</title><description>&lt;p&gt;This weekend hack is a small Kinect application - Kibloc is a physical object counter/tracker using Kinect.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Update As Of Feb 1 2012:&lt;/strong&gt; This article is explaining Version 1.0 Beta 2 APIs. How ever, now the Official 1.0 Kinect SDK For Windows is available, and there are changes from the Beta 2 API.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-qbFVYIL93fc/TyWBBlpOghI/AAAAAAAABS8/vu4CqYT7P80/s1600-h/image%25255B12%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" align="right" src="http://lh6.ggpht.com/-ClbkugAjJ08/TyWBCo8iVhI/AAAAAAAABTE/i4V8CsgB1VM/image_thumb%25255B6%25255D.png?imgmax=800" width="299" height="168" /&gt;&lt;/a&gt;Kinect for Windows SDK (&lt;a href="http://www.microsoft.com/en-us/kinectforwindows/download/"&gt;Download&lt;/a&gt;) is pretty intuitive (I’m using&lt;em&gt; Version 1.0 Beta 2&lt;/em&gt; for this, so if you want to test this you should use Beta 2 APIs which is still available as a separate download and NOT the Version 1.0 APIs), and you may use the same to develop pretty cool applications using &lt;a href="http://www.microsoft.com/en-us/kinectforwindows/"&gt;Microsoft Kinect&lt;/a&gt;. In this post, we’ll be focusing on implementing a quick real time blob counter using Kinect depth data, for counting and tracking objects in front of the sensor. This is a basic demo, but as you can imagine, this has got a couple of pretty hot real life use cases.&amp;#160; As a heads up, the source code is at &lt;a href="http://kibloc.codeplex.com/"&gt;http://kibloc.codeplex.com/&lt;/a&gt; and keep it handy when you read along. Ensure you’ve the NuGet Packages in &lt;em&gt;packages.config&lt;/em&gt; &lt;/p&gt;  &lt;p&gt;Here is the video that demonstrates real time, distance based blob tracking.&lt;/p&gt;  &lt;p&gt;&lt;iframe height="315" src="http://www.youtube.com/embed/b3fh7kGgzng" frameborder="0" width="560" allowfullscreen="allowfullscreen"&gt;&lt;/iframe&gt;&lt;/p&gt;  &lt;p&gt;In the video, the image drawing for the blob highlight is a bit slow, this is because I’m drawing it on top of the color image as discussed below. For actual games/calculations, you don’t need the drawing on top of the color image/bitmap.&lt;/p&gt;  &lt;p&gt;So, let us develop this. The steps involved are pretty simple.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Initializing Kinect &lt;/li&gt;    &lt;li&gt;Get the depth image, and slice the depth frame to draw pixels with in the range to form a gray scale image &lt;/li&gt;    &lt;li&gt;Pass this image to the blob detection algorithm &lt;/li&gt;    &lt;li&gt;Find the convex hull/edges/quadrilateral&amp;#160; &lt;/li&gt;    &lt;li&gt;Draw the same on the color image from the video frame &lt;!--EndFragment--&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;h2&gt;Introduction to Kinect API&lt;/h2&gt;  &lt;p&gt;Kinect API allows you to work with the Kinect camera’s image/video stream, almost similar to a web cam.&amp;#160; Apart from the RGB Video camera, Kinect has got a depth sensor as well., which gives you information about the distance of an object in front of the device - and you can leverage the Video data and Depth data together to detect objects using Kinect. Kinect also exposes built in support for Skeletal tracking. The classes for working with Video, Depth and Skeletal Tracking resides in the namespace &lt;em&gt;Microsoft.Research.Kinect.Nui&lt;/em&gt;. You can access the Kinects connected to the device via the &lt;em&gt;Runtime.Kinects&lt;/em&gt; enumeration, and can access the Depth, Video and Skeletal tracking data by handling the &lt;em&gt;DepthFrameReady&lt;/em&gt;, &lt;em&gt;VideoFrameReady&lt;/em&gt; and &lt;em&gt;SkeletalFrameReady&lt;/em&gt; events of a connected Kinect object. In the below example you could see that we are accessing the Depth data from Kinect. &lt;/p&gt;  &lt;p&gt;Additionally, you can also use the Audio features of Kinect, leveraging classes available under the namespace &lt;em&gt;Microsoft.Research.Kinect.Audio&lt;/em&gt;.&lt;/p&gt;  &lt;p&gt;That is it for an interesting, and I suggest you should go through the &lt;a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts"&gt;SDK Quick starts and samples here at Coding 4 Fun&lt;/a&gt; if you need to learn more about how to work with the SDK in detail. The API is intuitive and super easy, but I suggest you may go through these videos to kick start.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Understanding-Kinect-Hardware"&gt;Installing and using the Kinect Sensor&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Camera-Fundamentals"&gt;Camera Fundamentals&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Working-with-Depth-Data"&gt;Depth Data Fundamentals&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h2&gt;Initializing Kinect&lt;/h2&gt;  &lt;p&gt;The first step is to initialize Kinect, so here is the self explanatory code.&lt;/p&gt;  &lt;pre class="csharp" name="code"&gt;           
// If you don't make sure the Kinect is plugged in and working before trying to use it, the app will crash
if (Runtime.Kinects.Count &amp;gt; 0)
{
    runtime = Runtime.Kinects[0];
    runtime.Initialize(RuntimeOptions.UseColor | RuntimeOptions.UseDepth);
    runtime.DepthFrameReady += (s, e) =&amp;gt;
        {
           // Use depth data
        };

    runtime.VideoFrameReady += (s, e) =&amp;gt;
        {
            //Use video data
        };

    runtime.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240, ImageType.Depth);
    runtime.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480, ImageType.Color);
}
else
    MessageBox.Show(&amp;quot;Oops, please check if your Kinect is connected?&amp;quot;);&lt;/pre&gt;

&lt;p&gt;Basically, you may see that we are initializing the Kinect run time by passing the flags UseColor and UseDepth, so that we can consume the DepthStream and VideoStream later. The event handlers are attached to DepthFrameReady and VideoFrameReady events as shown above.&lt;/p&gt;

&lt;h2&gt;Get the depth image for a range&lt;/h2&gt;

&lt;p&gt;Kinect depth data is just an array of bytes, where each pixel is represented with two bytes (16 bits). Each pixel in the depth data provides distance of a pixel from the sensor, instead of color information as in a normal bitmap pixel. You can either specify Kinect to provide you the raw depth data (&lt;em&gt;ImageType.Depth&lt;/em&gt;) or to provide you depth data along with player index (&lt;em&gt;ImageType.DepthAndPlayerIndex&lt;/em&gt;) when you initialize the DepthStream (see the above code). You can read this &lt;a href="http://www.i-programmer.info/programming/hardware/2714-getting-started-with-microsoft-kinect-sdk-depth.html"&gt;iProgrammer article&lt;/a&gt; if you are interested to learn more about the Depth data, in detail.&lt;/p&gt;

&lt;p&gt;Basically, what we do in the below method is to walk through the PlanarImage (raw byte array) for Depth data, and create a bitmap with 4 bytes per pixel (Red, Blue, Green and Alpha)&amp;#160; – where Red, Blue and Green values will be the same value to form a gray scale image. The value is any number between 0 to 255, based on the distance of a pixel. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh4.ggpht.com/-afFNwjRWCCI/TyWBDvjkNXI/AAAAAAAABT0/ZsiuHlDz8cM/s1600-h/image%25255B18%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-0blNfqSRcDo/TyWBEtzN_qI/AAAAAAAABT4/makHXxgwYOQ/image_thumb%25255B10%25255D.png?imgmax=800" width="644" height="367" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;pre class="csharp" name="code"&gt;    /// &amp;lt;summary&amp;gt;
    /// Credits due: 
    /// Portions of code below from
    /// (1) http://www.codeproject.com/Articles/317974/KinectDepthSmoothing though I'm not really smoothing here :)
    /// (2) http://stackoverflow.com/questions/94456/load-a-wpf-bitmapimage-from-a-system-drawing-bitmap
    /// 
    /// -- Anoop
    /// &amp;lt;/summary&amp;gt;

   public static BitmapSource SliceDepthImage(this ImageFrame image, int min=20, int max=1000)
        {
            int width = image.Image.Width;
            int height = image.Image.Height;

            var depthFrame = image.Image.Bits;
            // We multiply the product of width and height by 4 because each byte
            // will represent a different color channel per pixel in the final iamge.
            var colorFrame = new byte[height * width * 4];

            // Process each row in parallel
            Parallel.For(0, 240, depthRowIndex =&amp;gt;
            {
                //  Within each row, we then iterate over each 2 indexs to be combined into a single depth value
                for (int depthColumnIndex = 0; depthColumnIndex &amp;lt; 640; depthColumnIndex += 2)
                {
                    var depthIndex = depthColumnIndex + (depthRowIndex * 640);

                    // Because the colorFrame we are creating has twice as many bytes representing
                    // a pixel in the final image, we set the index to be twice of the depth index.
                    var index = depthIndex * 2;

                    // Calculate the distance represented by the two depth bytes
                    var distance = CalculateDistanceFromDepth(depthFrame[depthIndex], depthFrame[depthIndex + 1]);

                    // Map the distance to an intesity that can be represented in RGB
                    var intensity = CalculateIntensityFromDistance(distance);

                    if (distance &amp;gt; min &amp;amp;&amp;amp; distance &amp;lt; max)
                    {
                        // Apply the intensity to the color channels
                        colorFrame[index + 0] = intensity; //blue
                        colorFrame[index + 1] = intensity; //green
                        colorFrame[index + 2] = intensity; //red
                        colorFrame[index + 3] = 255; //alpha
                    }
                }
            });&lt;/pre&gt;

&lt;p&gt;Once the depth image is created, we pass it over to the Blob detector to detect the blobs and high light the same.&lt;/p&gt;

&lt;h2&gt;Blob Detection and Highlighting &lt;/h2&gt;

&lt;p&gt;For blob detection, I’m using the Excellent &lt;a href="http://www.aforgenet.com/framework/docs/html/d7d5c028-7a23-e27d-ffd0-5df57cbd31a6.htm"&gt;AForge library&lt;/a&gt;. The BlobCounter class takes the above image, and calculate the edges/rectangles of the blobs in the image. Here is an expansion of our earlier DepthFrameReady and ImageFrameReady events, you can see that we are creating a sliced depth image based on the slider values, and creating a depth frame image bitmap and a color frame image bitmap, and passes both of them to the blob detector. We are also specifying what type of high lighting to be used by the detector, based on the combo box the user has selected.&lt;/p&gt;

&lt;pre class="c#" name="code"&gt; runtime.DepthFrameReady += (s, e) =&amp;gt;
        {
            if (colorFrame == null) return;

            if (sliderMin.Value &amp;gt; sliderMax.Value)
                sliderMin.Value = sliderMax.Value;

            detector.Highlighting = (HighlightType) cmbHighlight.SelectedIndex;
                        
            txtInfo.Text = detector.BlobCount + &amp;quot; items detected..&amp;quot;;
            txtDistance.Text = &amp;quot;Detecting objects in the range &amp;quot; + sliderMin.Value + &amp;quot; and &amp;quot; + sliderMax.Value + &amp;quot; mm&amp;quot;;

            //Depth frame bitmap
            var depthFrame=e.ImageFrame.SliceDepthImage((int)sliderMin.Value,(int)sliderMax.Value);
            var depthBmp =depthFrame.ToBitmap();

            //Color frame bitmap
            var colorBmp = colorFrame.ToBitmapSource().ToBitmap();

            //Detect blobs using depthBmp, draw high lights to colorBmp
            var outBmp=detector.ProcessImage(depthBmp,colorBmp);

            //Draw the output high lighted color image
            this.ImageColor.Source = outBmp.ToBitmapSource();

            depthBmp.Dispose();
            colorBmp.Dispose();
            outBmp.Dispose();
                        
        };

    runtime.VideoFrameReady += (s, e) =&amp;gt;
        {
            //colorFrame is a global variable 
            colorFrame = e.ImageFrame;
        };&lt;/pre&gt;

&lt;p&gt;The following &lt;em&gt;ProcessImage&lt;/em&gt; method in our BlobDetector class basically uses the AForge library to do the detection based on depth image. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh3.ggpht.com/-cu8o4UpatcM/TyWBHJp5FTI/AAAAAAAABT8/dYBQRRz_DZY/s1600-h/image%25255B19%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-KUIY2F240Kk/TyWBJwGcRPI/AAAAAAAABUA/eLGLoW8zo_Q/image_thumb%25255B11%25255D.png?imgmax=800" width="640" height="371" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After detection, we are drawing the high lights back to the color image which results in the image above. This code is mostly based on the AForge blob detection sample.&lt;/p&gt;

&lt;pre class="c#" name="code"&gt;        // Set image to display by the control
        public Bitmap ProcessImage(Bitmap depthImage, Bitmap colorImage)
        {
            leftEdges.Clear();
            rightEdges.Clear();
            topEdges.Clear();
            bottomEdges.Clear();
            hulls.Clear();
            quadrilaterals.Clear();

            this.image = AForge.Imaging.Image.Clone(depthImage, PixelFormat.Format24bppRgb);
            imageWidth = this.image.Width;
            imageHeight = this.image.Height;

            blobCounter.ProcessImage(this.image);
            blobs = blobCounter.GetObjectsInformation();

            //Let us resize the color image to the size of depth image
            ResizeNearestNeighbor filter = new ResizeNearestNeighbor(depthImage.Width, depthImage.Height);
            var outImage = filter.Apply(colorImage);

            //Let use flip the color image to match the depth image
            outImage.RotateFlip(RotateFlipType.RotateNoneFlipX);


            BlobCount = blobs.Count();

            GrahamConvexHull grahamScan = new GrahamConvexHull();

            foreach (Blob blob in blobs)
            {
                List&amp;lt;IntPoint&amp;gt; leftEdge = new List&amp;lt;IntPoint&amp;gt;();
                List&amp;lt;IntPoint&amp;gt; rightEdge = new List&amp;lt;IntPoint&amp;gt;();
                List&amp;lt;IntPoint&amp;gt; topEdge = new List&amp;lt;IntPoint&amp;gt;();
                List&amp;lt;IntPoint&amp;gt; bottomEdge = new List&amp;lt;IntPoint&amp;gt;();

                // collect edge points
                blobCounter.GetBlobsLeftAndRightEdges(blob, out leftEdge, out rightEdge);
                blobCounter.GetBlobsTopAndBottomEdges(blob, out topEdge, out bottomEdge);

                leftEdges.Add(blob.ID, leftEdge);
                rightEdges.Add(blob.ID, rightEdge);
                topEdges.Add(blob.ID, topEdge);
                bottomEdges.Add(blob.ID, bottomEdge);

                // find convex hull
                List&amp;lt;IntPoint&amp;gt; edgePoints = new List&amp;lt;IntPoint&amp;gt;();
                edgePoints.AddRange(leftEdge);
                edgePoints.AddRange(rightEdge);

                List&amp;lt;IntPoint&amp;gt; hull = grahamScan.FindHull(edgePoints);
                hulls.Add(blob.ID, hull);

                List&amp;lt;IntPoint&amp;gt; quadrilateral = null;

                // find quadrilateral
                if (hull.Count &amp;lt; 4)
                {
                    quadrilateral = new List&amp;lt;IntPoint&amp;gt;(hull);
                }
                else
                {
                    quadrilateral = PointsCloud.FindQuadrilateralCorners(hull);
                }
                quadrilaterals.Add(blob.ID, quadrilateral);

                // shift all points for vizualization
                IntPoint shift = new IntPoint(1, 1);

                PointsCloud.Shift(leftEdge, shift);
                PointsCloud.Shift(rightEdge, shift);
                PointsCloud.Shift(topEdge, shift);
                PointsCloud.Shift(bottomEdge, shift);
                PointsCloud.Shift(hull, shift);
                PointsCloud.Shift(quadrilateral, shift);
            }

            //Method to draw the high lights, just see the full source code
            DrawHighLights(outImage);

            return outImage;


        }&lt;/pre&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;In this post, we explored how to create a blob detector and object counter using Kinect. As of now, Kinect’s built in tracking feature is limited just to Skeletal tracking, but you can use libraries like AForge.net and openCV to leverage Kinect for more out of the box scenarios. Thanks to my kiddo for lending me her dolls for the demo &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="http://lh5.ggpht.com/-U9rPu0y37O8/TyWBKhTVRhI/AAAAAAAABTs/KryMY1H58ow/wlEmoticon-winkingsmile%25255B2%25255D.png?imgmax=800" /&gt;. Also, &lt;a href="http://twitter.com/amazedsaint"&gt;follow me in twitter&lt;/a&gt;. And here are few more posts on a similar taste. &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://www.amazedsaint.com/2012/01/5-awesome-learning-resources-for.html"&gt;5 Awesome Learning Resources For Programmers (To help you and your kids to grow the geek neurons)&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://www.amazedsaint.com/2011/11/introduction-ksigdo-knockout-signalr-to.html"&gt;KsigDo Task Pad – Real-Time UI View Model syncing across users with ASP.NET, SignalR, Knockout MVVM and EF&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://www.amazedsaint.com/2010/11/top-6-coding-standards-guideline.html"&gt;Top 7 Coding Standards &amp;amp; Guideline Documents For C#/.NET Developers&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://www.amazedsaint.com/2010/09/7-freely-available-e-booksguides-i.html"&gt;7 Freely available E-Books/Guides I found essential for .NET Programmers and Architects&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22141639-4792492990416816736?l=www.amazedsaint.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/1_70P2SwinPhHymDeBTz8BnnzBo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1_70P2SwinPhHymDeBTz8BnnzBo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/1_70P2SwinPhHymDeBTz8BnnzBo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1_70P2SwinPhHymDeBTz8BnnzBo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=jgFEd-fiXzE:0USvK8kAO9c:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=jgFEd-fiXzE:0USvK8kAO9c:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=jgFEd-fiXzE:0USvK8kAO9c:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=jgFEd-fiXzE:0USvK8kAO9c:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=jgFEd-fiXzE:0USvK8kAO9c:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=jgFEd-fiXzE:0USvK8kAO9c:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=jgFEd-fiXzE:0USvK8kAO9c:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=jgFEd-fiXzE:0USvK8kAO9c:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=jgFEd-fiXzE:0USvK8kAO9c:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/amazedsaint/articles/~4/jgFEd-fiXzE" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/amazedsaint/articles/~3/jgFEd-fiXzE/kibloc-kinect-based-real-time-distance.html</link><author>noreply@blogger.com (Anoop Madhusudanan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh6.ggpht.com/-ClbkugAjJ08/TyWBCo8iVhI/AAAAAAAABTE/i4V8CsgB1VM/s72-c/image_thumb%25255B6%25255D.png?imgmax=800" height="72" width="72" /><feedburner:origLink>http://www.amazedsaint.com/2012/01/kibloc-kinect-based-real-time-distance.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-22141639.post-471694008624937065</guid><pubDate>Tue, 03 Jan 2012 17:35:00 +0000</pubDate><atom:updated>2012-01-03T23:06:56.827+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Software Development</category><category domain="http://www.blogger.com/atom/ns#">Me</category><category domain="http://www.blogger.com/atom/ns#">Books</category><category domain="http://www.blogger.com/atom/ns#">Back To Basics</category><category domain="http://www.blogger.com/atom/ns#">Programming-Tips</category><category domain="http://www.blogger.com/atom/ns#">Community</category><title>5 Awesome Learning Resources For Programmers (To help you and your kids to grow the geek neurons)</title><description>&lt;p&gt;Happy New Year, this is my first post in 2012. I’ll be sharing few awesome learning resources I’ve bookmarked, and will be pointing out some specific computer/programming related courses I've found interesting from these resources.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-rnUXo_nznzc/TwM8Q5EZdjI/AAAAAAAABSg/8I2SlaVn5rw/s1600-h/image%25255B4%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-lJEa1q6BHIk/TwM8W2N6CtI/AAAAAAAABSo/hdtnq2sX3Mo/image_thumb%25255B2%25255D.png?imgmax=800" width="640" height="226" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Also, thought about saving this blog post for my kids as well - instead of investing in these Child education schemes (though they are too small as of today, 2 years and 60 days respectively &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="http://lh3.ggpht.com/-3WTB2r_6YT8/TwM8YDqXZSI/AAAAAAAABSw/cEGLGcSyqGs/wlEmoticon-winkingsmile%25255B2%25255D.png?imgmax=800" /&gt;). Anyway, personally my new year resolution is to see as much videos from this course collections (assuming I can find some free time in between my regular job &amp;amp;&amp;amp; changing my babies diapers).&lt;/p&gt;  &lt;h3&gt;1 – Khan Academy&lt;/h3&gt;  &lt;p&gt;As I &lt;a href="https://twitter.com/#!/amazedsaint/status/154233704401739776"&gt;mentioned some time back&lt;/a&gt;, you and your kids are missing some thing huge if you havn’t heard about Khan Academy.&amp;#160; It is an awesome learning resource, especially if you want to re-visit your basics in Math, Science etc.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;With a library of over &lt;a href="http://www.khanacademy.org/#browse"&gt;2,600 videos&lt;/a&gt; covering everything from arithmetic to physics, finance, and history and &lt;a href="http://www.khanacademy.org/exercisedashboard"&gt;268 practice exercises&lt;/a&gt;, &lt;a href="http://www.khanacademy.org/about"&gt;they're on a mission&lt;/a&gt; to help you learn what you want, when you want, at your own pace&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Not just Math and Science, I assume you’ll be interested to know more about &lt;a href="http://www.khanacademy.org/video/black-holes?playlist=Cosmology+and+Astronomy"&gt;Black Holes&lt;/a&gt;,&amp;#160; &lt;a href="http://www.khanacademy.org/video/why-cepheids-pulsate?playlist=Cosmology+and+Astronomy"&gt;Why Cepheids Pulsate&lt;/a&gt;, and how to find &lt;a href="http://www.khanacademy.org/video/detectable-civilizations-in-our-galaxy-1?playlist=Cosmology+and+Astronomy"&gt;Detectable Civilizations in our Galaxy 1&lt;/a&gt;. So, bookmark &lt;a href="http://www.khanacademy.org/"&gt;http://www.khanacademy.org/&lt;/a&gt;. Respect to &lt;a href="http://www.khanacademy.org/video/salman-khan-talk-at-ted-2011--from-ted-com?playlist=Khan+Academy-Related+Talks+and+Interviews"&gt;Salman Khan&lt;/a&gt;, consider donating them a bit if you find these materials useful.&lt;/p&gt;  &lt;h3&gt;2 – MIT Open Courseware and Videos&lt;/h3&gt;  &lt;p&gt;Just in case you are not aware, MIT has a huge collection of open courses, bookmark &lt;a href="http://ocw.mit.edu/index.htm"&gt;http://ocw.mit.edu/index.htm&lt;/a&gt;. Specifically, take a look at the &lt;a href="http://ocw.mit.edu/courses/audio-video-courses/"&gt;Audio/Video Courses section&lt;/a&gt; and&amp;#160; &lt;a href="http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/"&gt;Electrical Engineering and Computer Science course&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;And go through this &lt;a href="http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/video-lectures/"&gt;Introduction to computer science course&lt;/a&gt; to get the feel. Few more interesting courses (if you are a programmer) include&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-046j-introduction-to-algorithms-sma-5503-fall-2005/video-lectures/"&gt;Introduction to algorithms&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-035-computer-language-engineering-sma-5502-fall-2005/lecture-notes/"&gt;Introduction to Computer Language Engineering&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-189-multicore-programming-primer-january-iap-2007/lecture-notes-and-video/"&gt;Multi Core Programming Primer&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Obviously, there are other subject specific courses too, like this &lt;a href="http://ocw.mit.edu/courses/mathematics/"&gt;Mathematics (Calculus, Algebra, Probability etc) related videos&lt;/a&gt;.&lt;/p&gt;  &lt;h3&gt;3 – Stanford Engineering Courses&lt;/h3&gt;  &lt;p&gt;Stanford Engineering everywhere has also got some &lt;a href="http://itunes.apple.com/itunes-u/iphone-application-development/id384233225#ls=1"&gt;cool courses.&lt;/a&gt; For example, this &lt;a href="http://itunes.apple.com/itunes-u/iphone-application-development/id384233225#ls=1"&gt;Free course on iPhone Application development is available via iTunes&lt;/a&gt;&lt;/p&gt;  &lt;p&gt; From the computer science perspective, checkout these introduction to Computer Science. Click the Lectures tab, and most lectures are available via Youtube, iTunes and even as WMV.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://see.stanford.edu/see/courseinfo.aspx?coll=824a47e1-135f-4508-a5aa-866adcae1111"&gt;Programming Methodology &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://see.stanford.edu/see/courseinfo.aspx?coll=11f4f422-5670-4b4c-889c-008262e09e4e"&gt;Programming Abstractions&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://see.stanford.edu/see/courseinfo.aspx?coll=2d712634-2bf1-4b55-9a3a-ca9d470755ee"&gt;Programming Paradigms&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;And don’t miss these Artificial Intelligence courses&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://see.stanford.edu/see/courseinfo.aspx?coll=86cc8662-f6e4-43c3-a1be-b30d1d179743"&gt;Introduction to Robotics &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://see.stanford.edu/see/courseinfo.aspx?coll=63480b48-8819-4efd-8412-263f1a472f5a"&gt;Natural Language Processing&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://see.stanford.edu/see/courseinfo.aspx?coll=348ca38a-3a6d-4052-937d-cb017338d7b1"&gt;Machine Learning&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;4 – Stanford Free Online Courses&lt;/h3&gt;  &lt;p&gt;Xavier recently shared a bunch of new free online courses that Stanford will be starting soon. These courses are starting by this February 2012, why not sign up.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Computer Science&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;Game Theory &lt;a href="http://www.game-theory-class.org/"&gt;http://www.game-theory-class.org/&lt;/a&gt;&lt;/li&gt;      &lt;li&gt;Design and Analysis of Algorithms I &lt;a href="http://www.algo-class.org/"&gt;http://www.algo-class.org/&lt;/a&gt;&lt;/li&gt;      &lt;li&gt;Cryptography &lt;a href="http://www.crypto-class.org/"&gt;http://www.crypto-class.org/&lt;/a&gt;&lt;/li&gt;      &lt;li&gt;Software Engineering for Software as a Service &lt;a href="http://www.saas-class.org/"&gt;http://www.saas-class.org/&lt;/a&gt;&lt;/li&gt;      &lt;li&gt;Natural Language Processing &lt;a href="http://www.nlp-class.org/"&gt;http://www.nlp-class.org/&lt;/a&gt;&lt;/li&gt;      &lt;li&gt;Computer Science 101 &lt;a href="http://www.cs101-class.org/"&gt;http://www.cs101-class.org/&lt;/a&gt;&lt;/li&gt;      &lt;li&gt;Human-Computer Interaction &lt;a href="http://www.hci-class.org/"&gt;http://www.hci-class.org/&lt;/a&gt;&lt;/li&gt;      &lt;li&gt;Probabilistic Graphical Models &lt;a href="http://www.pgm-class.org/"&gt;http://www.pgm-class.org/&lt;/a&gt;&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;Entrepreneurship&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;Lean Launchpad &lt;a href="http://www.launchpad-class.org/"&gt;http://www.launchpad-class.org/&lt;/a&gt;&lt;/li&gt;      &lt;li&gt;Technology Entrepreneurship &lt;a href="http://www.venture-class.org/"&gt;http://www.venture-class.org/&lt;/a&gt;&lt;/li&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;h3&gt;5 – University of California&lt;/h3&gt;  &lt;p&gt;Berkeley, University of California (&lt;a href="http://berkeley.edu/about/"&gt;http://berkeley.edu/about/&lt;/a&gt;) has got a webcast zone where a number of courses are featured. &lt;/p&gt;  &lt;p&gt;Here are few play lists (I havn’t gone through all of them, but still).&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://webcast.berkeley.edu/series.html#c,d,Computer_Science"&gt;Computer Science&lt;/a&gt; related play lists&lt;/li&gt;    &lt;li&gt;&lt;a href="http://webcast.berkeley.edu/series.html#c,d,Mathematics"&gt;Mathematics&lt;/a&gt; related play lists&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;And most of them are available via Youtube, iTunes etc.&lt;/p&gt;  &lt;p&gt;These are few resources I explored and book marked for future reference, and I’m pretty sure there are lot more out there that I’ve skipped/missed. For instance, &lt;a href="http://jeffhuang.com/best_paper_awards.html"&gt;this awesome list of Computer Science papers&lt;/a&gt; that I came across the other day. Please share, and enjoy.&amp;#160; Happy Coding!!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22141639-471694008624937065?l=www.amazedsaint.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Tmf2Y3PfvCOuBYD05IMEvhl20rA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Tmf2Y3PfvCOuBYD05IMEvhl20rA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Tmf2Y3PfvCOuBYD05IMEvhl20rA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Tmf2Y3PfvCOuBYD05IMEvhl20rA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=SBtw9nwYbwQ:2dMDg6ud38Q:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=SBtw9nwYbwQ:2dMDg6ud38Q:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=SBtw9nwYbwQ:2dMDg6ud38Q:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=SBtw9nwYbwQ:2dMDg6ud38Q:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=SBtw9nwYbwQ:2dMDg6ud38Q:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=SBtw9nwYbwQ:2dMDg6ud38Q:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=SBtw9nwYbwQ:2dMDg6ud38Q:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=SBtw9nwYbwQ:2dMDg6ud38Q:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=SBtw9nwYbwQ:2dMDg6ud38Q:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/amazedsaint/articles/~4/SBtw9nwYbwQ" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/amazedsaint/articles/~3/SBtw9nwYbwQ/5-awesome-learning-resources-for.html</link><author>noreply@blogger.com (Anoop Madhusudanan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/-lJEa1q6BHIk/TwM8W2N6CtI/AAAAAAAABSo/hdtnq2sX3Mo/s72-c/image_thumb%25255B2%25255D.png?imgmax=800" height="72" width="72" /><feedburner:origLink>http://www.amazedsaint.com/2012/01/5-awesome-learning-resources-for.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-22141639.post-6903982444968160345</guid><pubDate>Tue, 22 Nov 2011 13:20:00 +0000</pubDate><atom:updated>2011-11-22T19:03:04.020+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Dynamic</category><category domain="http://www.blogger.com/atom/ns#">.NET 4.0</category><category domain="http://www.blogger.com/atom/ns#">CSharp</category><title>What! C# could do that!!  @ironshay demoing my ElasticObject implementation in @LIDNUG presentation</title><description>&lt;p&gt;&lt;a href="http://lh4.ggpht.com/-qbRiUdQOHdk/TsuiE62NaBI/AAAAAAAABR4/Exg2e3q2TxE/s1600-h/image%25255B3%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" align="right" src="http://lh5.ggpht.com/-wJNS5yn4P3E/TsuiFvwjlXI/AAAAAAAABSA/wabKL2npLfk/image_thumb%25255B1%25255D.png?imgmax=800" width="225" height="225" /&gt;&lt;/a&gt;This is cool, Just found that &lt;a href="http://twitter.com/ironshay"&gt;@ironshay&lt;/a&gt; has featured my &lt;a href="http://www.amazedsaint.com/2010/02/introducing-elasticobject-for-net-40.html"&gt;ElasticObject&lt;/a&gt; in his &lt;a href="http://twitter.com/LIDNUG"&gt;@LIDNUG&lt;/a&gt; web cast, to show C# dynamic features.&lt;/p&gt;  &lt;p&gt;Elastic Object is a C# dynamic object implementation I’ve done some time back, which is&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;An easier, fluid way to work with data formats – like XML and JSON. Presently, we’ve some support for XML. &lt;/li&gt;    &lt;li&gt;Cleaner code though it is duck typed &lt;/li&gt;    &lt;li&gt;A hierarchical way to maintain loosely typed data.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="http://www.amazedsaint.com/2010/02/introducing-elasticobject-for-net-40.html"&gt;ElasticObject&lt;/a&gt; post and source code here, and pretty cool presentation from Ironshay (embedded below).&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;iframe height="480" src="http://www.youtube.com/embed/zqyVONGlrdM" frameborder="0" width="640" allowfullscreen="allowfullscreen"&gt;&lt;/iframe&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22141639-6903982444968160345?l=www.amazedsaint.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/IDTtVNxbUOGlRg6vzWaI4LNWTNw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/IDTtVNxbUOGlRg6vzWaI4LNWTNw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/IDTtVNxbUOGlRg6vzWaI4LNWTNw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/IDTtVNxbUOGlRg6vzWaI4LNWTNw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=-99L9Uwo-9E:rKNSbJGRP-c:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=-99L9Uwo-9E:rKNSbJGRP-c:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=-99L9Uwo-9E:rKNSbJGRP-c:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=-99L9Uwo-9E:rKNSbJGRP-c:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=-99L9Uwo-9E:rKNSbJGRP-c:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=-99L9Uwo-9E:rKNSbJGRP-c:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=-99L9Uwo-9E:rKNSbJGRP-c:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=-99L9Uwo-9E:rKNSbJGRP-c:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=-99L9Uwo-9E:rKNSbJGRP-c:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/amazedsaint/articles/~4/-99L9Uwo-9E" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/amazedsaint/articles/~3/-99L9Uwo-9E/this-is-cool-just-found-that-ironshay.html</link><author>noreply@blogger.com (Anoop Madhusudanan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/-wJNS5yn4P3E/TsuiFvwjlXI/AAAAAAAABSA/wabKL2npLfk/s72-c/image_thumb%25255B1%25255D.png?imgmax=800" height="72" width="72" /><feedburner:origLink>http://www.amazedsaint.com/2011/11/this-is-cool-just-found-that-ironshay.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-22141639.post-1575581218717303245</guid><pubDate>Mon, 21 Nov 2011 11:33:00 +0000</pubDate><atom:updated>2011-11-22T19:18:02.278+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Javascript</category><category domain="http://www.blogger.com/atom/ns#">Design And Architecture</category><category domain="http://www.blogger.com/atom/ns#">HTML5</category><category domain="http://www.blogger.com/atom/ns#">asp.net</category><category domain="http://www.blogger.com/atom/ns#">CSharp</category><title>KsigDo Task Pad – Real-Time UI View Model syncing across users with ASP.NET, SignalR, Knockout MVVM and EF</title><description>&lt;h2&gt;Introduction&lt;/h2&gt;  &lt;p&gt;KsigDo = Knockout + SignalR To-do app. &lt;a href="http://ksigdo.codeplex.com"&gt;Source code is here in Codeplex&lt;/a&gt;, keep it handy.&lt;a href="http://lh4.ggpht.com/-OlLvkacKz1E/TsuoDBRUTHI/AAAAAAAABSI/NkiaVxcdg0Y/s1600-h/image4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" align="right" src="http://lh5.ggpht.com/-9N_iDA2FERg/TsuoEO05YJI/AAAAAAAABSQ/7ruEpjwSaqk/image_thumb1.png?imgmax=800" width="240" height="227" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Real time data syncing across user views *was* hard, especially in web applications. Most of the time, the second user needs to refresh the screen, to see the changes made by first user, or we need to implement some long polling that fetches the data and does the update manually. &lt;/p&gt;  &lt;p&gt;Now, with SignalR and Knockout, ASP.NET developers can take advantage of view model syncing across users, that’ll simplify these scenarios in a big way, with minimal code. This post discusses how to implement a real time to-do pad, which will sync data across users accessing the application. This means, users can make changes to their tasks (add/remove/update etc), and other users will see the changes instantly. The focus is on the technique, I’m not trying to build a fabulous user experience here.&lt;/p&gt;  &lt;p&gt;I know we are tired with To-do examples, but now let us build a To-do application that can sync tasks between you and your wife (or your team mates) in real time, with full CRUD support, and persistence. And yes, we’ll keep the code minimal, and maintainable using a proper View Model (Oh, is that possible in JavaScript?). &lt;/p&gt;  &lt;p&gt;So, see this video, and here you can see the changes you apply to the tasks in one screen (adding, deleting, updating etc) you can see that the data is getting synced across multiple users.&lt;/p&gt; &lt;iframe height="360" src="http://www.youtube.com/embed/1wh33W-09bk" frameborder="0" width="640" allowfullscreen="allowfullscreen"&gt;&lt;/iframe&gt;  &lt;p&gt;We’ll be using KnockoutJs for maintaining a View Model, and will be syncing the View Model across users using SignalR. If you are not familiar with Knockout and SignalR, we’ll have a quick look at both of them on the way.&lt;/p&gt;  &lt;h2&gt;First Things First&lt;/h2&gt;  &lt;p&gt;To start with, let us create a new ASP.NET MVC 3.0 application. Create an empty project, I’ve &lt;a href="http://weblogs.asp.net/scottgu/archive/2011/05/03/asp-net-mvc-3-tools-update.aspx"&gt;ASP.NET MVC 3 tools update&lt;/a&gt; installed. Once you’ve the ASP.NET MVC project created, bring up the Nuget console (View-&amp;gt;Other Windows-&amp;gt; Package Manager console), and install the Nuget packages for Knockout and SignalR.&lt;/p&gt;  &lt;pre name="code"&gt;install-package knockoutjs&lt;/pre&gt;

&lt;p&gt;And SignalR &lt;/p&gt;

&lt;pre name="code"&gt;install-package signalr&lt;/pre&gt;

&lt;p&gt;Also, do install Entity Framework latest version if you don't have the same, so that we can use the Code first features&lt;/p&gt;

&lt;pre name="code"&gt;Install-Package EntityFramework&lt;/pre&gt;

&lt;p&gt;If you are already familiar with Knockout and SignalR, you may skip the next two titles and go directly to 'Building KsigDo' section.&lt;/p&gt;

&lt;h3&gt;Knockout&lt;/h3&gt;

&lt;p&gt;Knockout Js is an awesome Javascript library that allows you to follow the MVVM convention, to bind your User controls to a JavaScript view model. This is pretty cool, because it allows you to build rich UIs pretty easily, with very minimal code. Here is a quick example that shows how you can bind your HTML elements to a Javascript view model.&lt;/p&gt;
Here is a very simple view model. 

&lt;pre class="js" name="code"&gt;// This is a simple *viewmodel*
var viewModel = {
    firstName: ko.observable(&amp;quot;Bert&amp;quot;),
    lastName: ko.observable(&amp;quot;Bertington&amp;quot;)
};

// Activates knockout.js
ko.applyBindings(viewModel);&lt;/pre&gt;

&lt;p&gt;The attributes are of type ko.observable(..), and if you want to convert the viewModel to an object (where you can send over the wire), you can easily do that using ko.toJS(viewModel). Now, let us bind the above view model to a view. The binding happens in the data-bind attribute, you may see that we are binding the value of the textbox to the firstname and last name variables. When you call ko.applyBindings, Knockout will do the required wiring so that the view model properties are synced with the target control's property values. &lt;/p&gt;

&lt;pre class="xml" name="code"&gt;&amp;lt;!-- This is a *view* --&amp;gt;

&amp;lt;p&amp;gt;First name: &amp;lt;input data-bind=&amp;quot;value: firstName&amp;quot; /&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;Last name: &amp;lt;input data-bind=&amp;quot;value: lastName&amp;quot; /&amp;gt;&amp;lt;/p&amp;gt;&lt;/pre&gt;

&lt;p&gt;KnockoutJs is pretty easy to learn, the best way to start is by going through the interactive tutorial hosted by Knockout guys here at &lt;a href="http://learn.knockoutjs.com/"&gt;http://learn.knockoutjs.com/&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: Found that Shawn has wrote a comprehensive post on Knockout, &lt;a href="http://wildermuth.com/2011/11/20/Using_MVVM_on_the_Web_with_KnockoutJS"&gt;Read that as well&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;SignalR&lt;/h3&gt;

&lt;p&gt;SignalR is the “greatest &lt;em&gt;thing&lt;/em&gt; since &lt;em&gt;sliced bread”&lt;/em&gt; that happened for Microsoft developers recently. (To know why, you can read by post “&lt;a href="http://www.amazedsaint.com/2011/11/html5-is-in-killer-spree-may-kill-http.html"&gt;HTML5 is on a killer spree, may kill HTTP next at least partially&lt;/a&gt;”. Anyway, &lt;a href="https://github.com/SignalR/SignalR"&gt;SignalR&lt;/a&gt; is an Async signaling library for ASP.NET to help build real-time, multi-user interactive web applications. If you heard about Node, Backbone, Nowjs etc recently, you know what I’m talking about. If not, you’ll know pretty soon though.&lt;/p&gt;

&lt;p&gt;The easiest starting point to understand SignalR is, by having a look &lt;a href="https://github.com/SignalR/SignalR/wiki/QuickStart-Hubs"&gt;at the Hub Quickstart example&lt;/a&gt;. Have a look at that example and come back.&lt;/p&gt;

&lt;p&gt;You can inherit your Hub at the server side from SignalR.Hubs.Hub – and SignalR will generate the necessary light weight Javascript proxies at the client side so that you can make calls to your hub over the wire, even with support for typed parameters. Not just that. SignalR also provides dynamic “Clients” and “Caller” objects in your hub, so that you can invoke a client side method written in Javascript directly via your code in the server side. Pretty smart. And SignalR hides the entire implementation under its nice little APIs. &lt;/p&gt;

&lt;h2&gt;Building The KsigDo App&lt;/h2&gt;

&lt;p&gt;Now, let us go ahead and build our KsigDo app. Let us put together the bits step by step.&lt;/p&gt;

&lt;h4&gt;Task Model For Persistance Using Entity Framework Code First&lt;/h4&gt;

&lt;p&gt;In you ASP.NET MVC application, go to the Models folder, and add a new code first model file. Our model is very minimal, and as you can see, we have a taskId and a title for a task, and few validation rules defined, like title's length. Also, the completed property decides whether the task is a completed one or not.&lt;/p&gt;

&lt;p&gt;If you are not familiar with Entity Framework Code First, here is a &lt;a href="http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx"&gt;good read in Scott’s blog&lt;/a&gt;, and here are &lt;a href="http://msdn.microsoft.com/en-us/data/aa937723"&gt;few more resources&lt;/a&gt;&lt;/p&gt;

&lt;pre class="c#" name="code"&gt; public class KsigDoContext : DbContext
    {
        public DbSet&amp;lt;Task&amp;gt; Tasks { get; set; }

    }

  public class Task
    {
        [Key]
        public int taskId { get; set; }

        [Required] [MaxLength(140)] [MinLength(10)]
        public string title { get; set; }

        public bool completed { get; set; }
        public DateTime lastUpdated { get; set; }

    }&lt;/pre&gt;

&lt;p&gt;The DbContext and DbSet classes used above are provided as part of the EF4 Code-First library. Also, we are using the attributes like Key, Required etc for data annotations, for basic validation support.&lt;/p&gt;

&lt;h4&gt;TaskHub For Basic Operations&lt;/h4&gt;

&lt;p&gt;Create a new folder named 'Hubs' in your ASP.NET MVC project, and add a new TaskHub.cs file (No, we are not using Controllers now). And yes, you can place your Hubs any where. Here is our TaskHub, inherited from SignalR.Hubs.Hub class. You may see that we are using this Hub to perform most of the CRUD operations in our Task Model.&lt;/p&gt;

&lt;pre class="c#" name="code"&gt; public class Tasks : Hub
    {
        /// &amp;lt;summary&amp;gt;
        /// Create a new task
        /// &amp;lt;/summary&amp;gt;
        public bool Add(Task newTask)
        {
            try
            {
                using (var context = new KsigDoContext())
                {
                    var task = context.Tasks.Create();
                    task.title = newTask.title;
                    task.completed = newTask.completed;
                    task.lastUpdated = DateTime.Now;
                    context.Tasks.Add(task);
                    context.SaveChanges();
                    Clients.taskAdded(task);
                    return true;
                }
            }
            catch (Exception ex)
            {
                Caller.reportError(&amp;quot;Unable to create task. Make sure title length is between 10 and 140&amp;quot;);
                return false;
            }

        }

        /// &amp;lt;summary&amp;gt;
        /// Update a task using
        /// &amp;lt;/summary&amp;gt;
        public bool Update(Task updatedTask)
        {
            using (var context = new KsigDoContext())
            {
                var oldTask = context.Tasks.FirstOrDefault(t =&amp;gt; t.taskId == updatedTask.taskId);
                try
                {
                    if (oldTask == null)
                        return false;
                    else
                    {
                        oldTask.title = updatedTask.title;
                        oldTask.completed = updatedTask.completed;
                        oldTask.lastUpdated = DateTime.Now;
                        context.SaveChanges();
                        Clients.taskUpdated(oldTask);
                        return true;
                    }
                }
                catch (Exception ex)
                {
                    Caller.reportError(&amp;quot;Unable to update task. Make sure title length is between 10 and 140&amp;quot;);
                    return false;
                }
            }

        }


        /// &amp;lt;summary&amp;gt;
        /// Delete the task
        /// &amp;lt;/summary&amp;gt;
        public bool Remove(int taskId)
        {
            try
            {
                using (var context = new KsigDoContext())
                {
                    var task = context.Tasks.FirstOrDefault(t =&amp;gt; t.taskId == taskId);
                    context.Tasks.Remove(task);
                    context.SaveChanges();
                    Clients.taskRemoved(task.taskId);
                    return true;
                }
            }
            catch (Exception ex)
            {
                Caller.reportError(&amp;quot;Error : &amp;quot; + ex.Message);
                return false;
            }
        }

        /// &amp;lt;summary&amp;gt;
        /// To get all the tasks up on init
        /// &amp;lt;/summary&amp;gt;
        public void GetAll()
        {
            using (var context = new KsigDoContext())
            {
                var res = context.Tasks.ToArray();
                Caller.taskAll(res);
            }

        }
    }&lt;/pre&gt;

&lt;p&gt;The &lt;em&gt;Clients&lt;/em&gt; and &lt;em&gt;Caller &lt;/em&gt;properties are provided by SignalR as part of the Hub class definition. Surprise, these are dynamic objects that you can use conceptually to invoke a client side method written in JavaScript. SignalR does the plumbing using long polling or web sockets or what ever, and we don’t care. Also, as I mentioned earlier, SignalR will generate a client side proxy hub to invoke methods in our above written TaskHub, and we’ll soon see how to use this. For example, when a client invokes GetAll method in the above Hub during initialization, that client invoking the GetAll method (Caller) will get a callback to it’s &lt;em&gt;taskAll&lt;/em&gt; JavaScript method, with all the existing tasks.&lt;/p&gt;

&lt;p&gt;In the same way, assuming that our Client hub has Javascript methods like taskUpdated, taskAdded, taskRemoved etc – we are invoking those methods using the ‘Clients’ dynamic object, so that when ever an update, add or delete is happening, this information is broad casted all the clients connected right now.&lt;/p&gt;

&lt;h4&gt;The Main View&lt;/h4&gt;

&lt;p&gt;Now, let us go ahead and create our client side. Add a 'Home' controller, and an 'Index' action. Create a new 'Index' view. Also, just make sure you’ve the necessary Javascript Script wirings to import Knockout and SignalR libraries (See the code). &lt;/p&gt;

&lt;p&gt;Our Index page has got a couple of view models, and a bit of HTML (view). For view models, we’ve a taskViewModel, and a taskListViewModel, as shown below. You may note that our taskViewModel is having almost the same properties as we have in our actual Task model, so that SignalR can manage the serialization/mapping pretty easily when ever we call the methods in our TaskHub.&lt;/p&gt;

&lt;p&gt;You can see that in taskListViewModel, we are accessing the &lt;em&gt;$connection.tasks&lt;/em&gt; proxy which provides a proxy object to access methods in our TaskHub. Also, we are attaching methods like tasksAll, taskUpdated etc to the &lt;em&gt;$connection.tasks&lt;/em&gt; via the this.hub pointer, and these methods are ‘invoked’ from the TaskHub class as we’ve seen earlier to virtually ‘push’ data to the clients.&lt;/p&gt;

&lt;pre class="javascript" name="code"&gt;           $(function () {

             //---- View Models

             //Task View Model
            function taskViewModel(id, title, completed, ownerViewModel) {
                this.taskId = id;
                this.title = ko.observable(title);
                this.completed = ko.observable(completed);
                this.remove = function () { ownerViewModel.removeTask(this.taskId) }
                this.notification = function (b) { notify = b }

                var self = this;

                this.title.subscribe(function (newValue) {
                    ownerViewModel.updateTask(ko.toJS(self));
                });

                this.completed.subscribe(function (newValue) {
                    ownerViewModel.updateTask(ko.toJS(self));
                });

            }

            //Task List View Model
            function taskListViewModel() {

                //Handlers for our Hub callbacks

                this.hub = $.connection.tasks;
                this.tasks = ko.observableArray([]);
                this.newTaskText = ko.observable();

                var tasks = this.tasks;
                var self = this;
                var notify = true;

                //Initializes the view model
                this.init = function () {
                    this.hub.getAll();
                }

                //Handlers for our Hub callbacks
                //Invoked from our TaskHub.cs

                this.hub.taskAll = function (allTasks) {

                    var mappedTasks = $.map(allTasks, function (item) {
                        return new taskViewModel(item.taskId, item.title,
                                 item.completed, self)
                    });

                    tasks(mappedTasks);
                }

                this.hub.taskUpdated = function (t) {
                    var task = ko.utils.arrayFilter(tasks(), function (value) { return value.taskId == t.taskId; })[0];
                    notify = false;
                    task.title(t.title);
                    task.completed(t.completed);
                    notify = true;
                };

                this.hub.reportError = function (error) {
                    $(&amp;quot;#error&amp;quot;).text(error);
                    $(&amp;quot;#error&amp;quot;).fadeIn(1000, function () {
                        $(&amp;quot;#error&amp;quot;).fadeOut(3000);
                    });
                }

                this.hub.taskAdded = function (t) {
                    tasks.push(new taskViewModel(t.taskId, t.title, t.completed, self));
                };

                this.hub.taskRemoved = function (id) {
                    var task = ko.utils.arrayFilter(tasks(), function (value) { return value.taskId == id; })[0];
                    tasks.remove(task);
                };

                //View Model 'Commands'

                //To create a task
                this.addTask = function () {
                    var t = { &amp;quot;title&amp;quot;: this.newTaskText(), &amp;quot;completed&amp;quot;: false };
                    this.hub.add(t).done(function () {
                        console.log('Success!')
                    }).fail(function (e) {
                        console.warn(e);
                    });

                    this.newTaskText(&amp;quot;&amp;quot;);
                }

                //To remove a task
                this.removeTask = function (id) {
                    this.hub.remove(id);
                }

                //To update this task
                this.updateTask = function (task) {
                    if (notify)
                        this.hub.update(task);
                }

                //Gets the incomplete tasks
                this.incompleteTasks = ko.dependentObservable(function () {
                    return ko.utils.arrayFilter(this.tasks(), function (task) { return !task.completed() });
                }, this);

            }

            var vm = new taskListViewModel();
            ko.applyBindings(vm);
            // Start the connection
            $.connection.hub.start(function () { vm.init(); });

        });&lt;/pre&gt;

&lt;p&gt;When ever a taskViewModel is created, the instance of taskListViewModel will be passed as it’s ownerViewModel, so that we can invoke the updateTask method of taskListViewModel when ever the current task’s properties are changing. In taskListViewModel, we also have methods like addTask, removeTask etc, which are bound directly to our “View”. &lt;/p&gt;

&lt;p&gt;We are creating a new instance of taskListViewModel, and then calling Knockout to do the job of applying bindings with the view. Have a look at the “View” part.&lt;/p&gt;

&lt;pre class="xml" name="code"&gt;&amp;lt;div id=&amp;quot;error&amp;quot; class=&amp;quot;validation-summary-errors&amp;quot;&amp;gt;
&amp;lt;/div&amp;gt;

&amp;lt;h2&amp;gt; Add Task&amp;lt;/h2&amp;gt;

&amp;lt;form data-bind=&amp;quot;submit: addTask&amp;quot;&amp;gt;
   &amp;lt;input data-bind=&amp;quot;value: newTaskText&amp;quot; class=&amp;quot;ui-corner-all&amp;quot; placeholder=&amp;quot;What needs to be done?&amp;quot; /&amp;gt;
   &amp;lt;input class=&amp;quot;ui-button&amp;quot; type=&amp;quot;submit&amp;quot; value=&amp;quot;Add Task&amp;quot; /&amp;gt;
&amp;lt;/form&amp;gt;

&amp;lt;h2&amp;gt;Our Tasks&amp;lt;/h2&amp;gt;

You have &amp;lt;b data-bind=&amp;quot;text: incompleteTasks().length&amp;quot;&amp;gt;&amp;amp;nbsp;&amp;lt;/b&amp;gt; incomplete task(s)

&amp;lt;ul data-bind=&amp;quot;template: { name: 'taskTemplate', foreach: tasks }, visible: tasks().length &amp;gt; 0&amp;quot;&amp;gt;
&amp;lt;/ul&amp;gt;

&amp;lt;script type=&amp;quot;text/html&amp;quot; id=&amp;quot;taskTemplate&amp;quot;&amp;gt;
&amp;lt;!--Data Template--&amp;gt;
    &amp;lt;li  style=&amp;quot;list-style-image: url('/images/task.png')&amp;quot;&amp;gt;
        &amp;lt;input type=&amp;quot;checkbox&amp;quot; data-bind=&amp;quot;checked: completed&amp;quot; /&amp;gt;
        &amp;lt;input class=&amp;quot;ui-corner-all&amp;quot; data-bind=&amp;quot;value: title, enable: !completed()&amp;quot; /&amp;gt;
        &amp;lt;input class=&amp;quot;ui-button&amp;quot; type=&amp;quot;button&amp;quot; href=&amp;quot;#&amp;quot; data-bind=&amp;quot;click: remove&amp;quot; value=&amp;quot;x&amp;quot;&amp;gt;&amp;lt;/input&amp;gt;
    &amp;lt;/li&amp;gt;
&amp;lt;/script&amp;gt;

&amp;lt;span data-bind=&amp;quot;visible: incompleteTasks().length == 0&amp;quot;&amp;gt;All tasks are complete&amp;lt;/span&amp;gt;&lt;br /&gt;&lt;/pre&gt;

&lt;p&gt;If you look below the Add Task header, you’ll see that we are binding the textbox’s value to the ‘newTaskText’ property of our taskListViewModel, and the form submit to the addTask method in the taskListViewModel. The &amp;lt;ul&amp;gt; is bound to the tasks property of the view model. If you see, tasks property of taskListViewModel is a koObservableArray, which is almost like an ObservableCollection that notifies the bound controls when ever items are inserted/removed in the array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adding and Removing items&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Have a look at the addTaskMethod in the taskListViewModel, you’ll see that we are creating a new task, and then invoking the ‘add’ method of the ‘hub’, which internally calls the TaskHub’s Add method in the server. In the TaskHub’s Add method, you’ll see that we are broadcasting the added task to all the clients by invoking the taskAdded method in the client side back – and there we are updating the ‘items’ observable array, so that Knockout will internally manage the rendering of a new &amp;lt;li&amp;gt; under the &amp;lt;ul&amp;gt; based on the data template ‘tasktemplate’ (see the above view code where we have the tasktemplate. &lt;/p&gt;

&lt;p&gt;Delete also works in the same way, you can see the ‘x’ button is bound to the remove method of each individual taskViewModel, which internally calls the taskListViewModel’s removeTask method to invoke the Remove method in TaskHub using the hub proxy, and from there, the taskRemoved will be invoked on all the clients, where we actually remove the item from the items collection.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Updating an Item:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once an item is bound to the template, please note that we are subscribing to the change events of a task in taskViewModel. When ever a property changes, we call the updateTask method in&amp;#160; the ownerViewModel, which again calls hub’s update method which sends the task to our TaskHub’s update method – thanks to the wiring from SignalR. There, we try to save the item, and if everything goes well, the updated item will be broadcasted from the TaskHub to all clients, by invoking the taskUpdated Javascript method we attached to the hub, where we actually does the updates the properties of the item in all clients.&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;Surprise, we are done. Very minimal code, very little effort, Great results. Thank you ASP.NET, SignalR, Entity Framework and Knockout. And that is why I love .NET &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://lh3.ggpht.com/-U5G3uRNJASU/Tso272s5HsI/AAAAAAAABRg/RVbA2ZRW-_c/wlEmoticon-smile%25255B2%25255D.png?imgmax=800" /&gt;. Happy Coding, but follow me in twitter &lt;a href="http://twitter.com/amazedsaint"&gt;@amazedsaint&lt;/a&gt; and &lt;a href="http://www.feedblitz.com/f/?Sub=177555"&gt;subscribe to this blog&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You may also like these articles on a similar taste.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;HT&lt;a href="http://www.amazedsaint.com/2011/11/html5-is-in-killer-spree-may-kill-http.html"&gt;ML5 is on a killer spree, Web Sockets May partially “kill” HTTP as well&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://www.amazedsaint.com/2011/09/creating-10-minute-todo-listing-app-on.html"&gt;Creating a quick Todo listing app on Windows using IIS7, Node.js and Mongodb&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://www.amazedsaint.com/2011/11/chain-of-responsibility-design-pattern.html"&gt;Implementing Chain of Responsibility Design Pattern in C# using Managed Extensibility Framework (MEF)&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://www.amazedsaint.com/2011/10/c-vnext-roslynan-introduction-and-quick.html"&gt;Scripting and Code Analysis using Roslyn – And a first look at Roslyn CTP&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22141639-1575581218717303245?l=www.amazedsaint.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/KKBI5asjAxo3ukSW_BWZkmIUnJk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/KKBI5asjAxo3ukSW_BWZkmIUnJk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/KKBI5asjAxo3ukSW_BWZkmIUnJk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/KKBI5asjAxo3ukSW_BWZkmIUnJk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=88c9cPQFKfE:3QQ_rEy752E:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=88c9cPQFKfE:3QQ_rEy752E:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=88c9cPQFKfE:3QQ_rEy752E:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=88c9cPQFKfE:3QQ_rEy752E:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=88c9cPQFKfE:3QQ_rEy752E:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=88c9cPQFKfE:3QQ_rEy752E:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=88c9cPQFKfE:3QQ_rEy752E:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=88c9cPQFKfE:3QQ_rEy752E:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=88c9cPQFKfE:3QQ_rEy752E:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/amazedsaint/articles/~4/88c9cPQFKfE" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/amazedsaint/articles/~3/88c9cPQFKfE/introduction-ksigdo-knockout-signalr-to.html</link><author>noreply@blogger.com (Anoop Madhusudanan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/-9N_iDA2FERg/TsuoEO05YJI/AAAAAAAABSQ/7ruEpjwSaqk/s72-c/image_thumb1.png?imgmax=800" height="72" width="72" /><feedburner:origLink>http://www.amazedsaint.com/2011/11/introduction-ksigdo-knockout-signalr-to.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-22141639.post-8095222016613230363</guid><pubDate>Sun, 13 Nov 2011 17:04:00 +0000</pubDate><atom:updated>2011-11-13T22:53:27.661+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Javascript</category><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">Design And Architecture</category><category domain="http://www.blogger.com/atom/ns#">HTML5</category><title>HTML5 is on a killer spree, Web Sockets May partially “kill” HTTP as well</title><description>&lt;p&gt;&lt;a href="http://lh6.ggpht.com/-TZ4CFtbK2B4/Tr_4i5YvVZI/AAAAAAAABQk/erWwVHFa4go/s1600-h/image%25255B10%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" align="right" src="http://lh3.ggpht.com/-868jjgKjSyg/Tr_4mWnup7I/AAAAAAAABQs/JfuXR1eN35U/image_thumb%25255B6%25255D.png?imgmax=800" width="240" height="128" /&gt;&lt;/a&gt;We’ve already seen HTML5 killing few technologies on the presentation side – Adobe Just killed Flash for Mobile, and Microsoft ‘Positioned’ Silverlight as a tool for LOB apps and Phone apps instead of a cross platform presentation layer. &lt;/p&gt;  &lt;p&gt;As most organizations are now focusing on HTML5 as part of their next gen strategy for what ever reasons (mainly cross platform), it is pretty obvious that there is going to be wide spread adoption from all major user agents – and more importantly, a lot more tooling and frameworks will evolve for developing HTML5 applications (You might have already explored previews like Expression Blend for HTML5 if you are in the Microsoft World, along with improved support for HTML5 in VS). The evolution of HTML5 will definitely bring in a radical shift in the way we develop web applications as we have already seen – and a nice little part of the parcel is Web sockets - which allows you to implement full duplex TCP based communication between the user agent (browser) and the server. &lt;/p&gt;  &lt;h2&gt;The problem with HTTP and existing server stacks&lt;/h2&gt;  &lt;p&gt;Here is a short description of HTTP from W3C&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;The Hypertext Transfer Protocol (HTTP) is an application-level protocol for distributed, collaborative, hypermedia information systems. It is a generic, stateless, protocol which can be used for many tasks beyond its use for hypertext, such as name servers and distributed object management systems, through extension of its request methods, error codes and headers &lt;a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec17.html#bib47"&gt;[47]&lt;/a&gt;. A feature of HTTP is the typing and negotiation of data representation, allowing systems to be built independently of the data being transferred.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;HTTP works in a request/response way – The client should always initiate a request to obtain the data, and in other words, the server can never push data real time to client. A common work around is to use HTTP long polling, where the client makes a request, and the server holds the request till some data is available, and pass it back to the client. I believe from Http 1.1 onwards, persistent connections are the default behavior of the HTTP connection anyway – though the response/request HTTP model don’t allow the server to do real-time pushes.&lt;/p&gt;  &lt;h2&gt;Web Sockets&lt;/h2&gt;  &lt;p&gt;HTML5 draft specification includes Websockets - &lt;a href="http://dev.w3.org/html5/websockets/"&gt;http://dev.w3.org/html5/websockets/&lt;/a&gt; &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;b&gt;WebSocket&lt;/b&gt; is a technology providing for bi-directional, &lt;a href="http://en.wikipedia.org/wiki/Duplex_(telecommunications)#Full-duplex"&gt;full-duplex&lt;/a&gt; communications channels, over a single &lt;a href="http://en.wikipedia.org/wiki/Transmission_Control_Protocol"&gt;Transmission Control Protocol&lt;/a&gt; (TCP) &lt;a href="http://en.wikipedia.org/wiki/Internet_socket"&gt;socket&lt;/a&gt;. It is designed to be implemented in &lt;a href="http://en.wikipedia.org/wiki/Web_browser"&gt;web browsers&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Web_server"&gt;web servers&lt;/a&gt; but it can be used by any client or server application. The WebSocket API is being standardized by the &lt;a href="http://en.wikipedia.org/wiki/World_Wide_Web_Consortium"&gt;W3C&lt;/a&gt; and the WebSocket protocol is being standardized by the &lt;a href="http://en.wikipedia.org/wiki/Internet_Engineering_Task_Force"&gt;IETF&lt;/a&gt;.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;This is very interesting, because it opens up lot of possibilities. For example, &lt;a href="http://www.amazedsaint.com/2011/04/wpf-over-web-sockets-how-to-pump-wpf.html"&gt;I did a quick prototype for desktop windows streaming over web sockets here&lt;/a&gt;. Most importantly, with Web Sockets, web applications can be real time and can even have custom RPC implementations.&lt;/p&gt;  &lt;p&gt;With web sockets, which are fully duplex, you have some thing state full, which will allow you to build web applications which can satisfy real time requirements. This means better user experience, better speed, and overall better productivity. We’ll see a new range of web applications emerging, including more sophisticated games and better real collaboration tools. We’ll definitely see more matured and domain specific light weight RPC frameworks for servers and clients (As of now, I think frameworks like &lt;a href="http://nowjs.org/"&gt;NowJs&lt;/a&gt;/Socket.IO on top of Node and &lt;a href="https://github.com/SignalR/SignalR"&gt;SignalR&lt;/a&gt;&amp;#160; on to of IIS already has this in their implementation/roadmap in a general way - to wrap web sockets and has a fall back strategy on HTTP long polling if the client is not supporting web sockets yet).&lt;/p&gt;  &lt;p&gt;According the Web Socket API spec, when a web socket connection is made, &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;The &lt;i&gt;headers to send appropriate cookies&lt;/i&gt; must be a &lt;code&gt;Cookie&lt;/code&gt; header whose value is the &lt;i&gt;cookie-string&lt;/i&gt; computed from the user's cookie store and the URL &lt;var&gt;url&lt;/var&gt;; for these purposes this is &lt;em&gt;not&lt;/em&gt; a &amp;quot;non-HTTP&amp;quot; API.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Anyway, most of the current server stacks and related programming models, including LAMP, IIS/ASP.NET etc is modeled around the normal request/response HTTP stack -and once the focus on Web sockets increases, they need to optimize themselves to handle concurrent connections simultaneously with out affecting the performance. A new age web server may be almost like a re-labeled IRC server which can handle a number of real time connections simultaneously (On contrary, you may also argue that HTML5 web sockets may make IRC servers obsolete as well&lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="http://lh5.ggpht.com/-NlYnY48S_fM/Tr_4nVZYaMI/AAAAAAAABQ0/-qgOwpzXBDg/wlEmoticon-winkingsmile%25255B2%25255D.png?imgmax=800" /&gt;). &lt;/p&gt;  &lt;p&gt;Web Socket API specifications are not yet finalized. And as of now, based on &lt;a href="http://caniuse.com"&gt;http://caniuse.com&lt;/a&gt; – the following client side platforms are supporting Web Sockets specs. Between, I use &lt;a href="http://caniuse.com"&gt;http://caniuse.com&lt;/a&gt; often to see the platform adoption of HTML5 APIs and Semantics.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-mqfdF_E-ufE/Tr_4qNDGfyI/AAAAAAAABQ8/BO2r9GKZMpA/s1600-h/image%25255B6%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-2gHP-07vsHM/Tr_4s69KdrI/AAAAAAAABRE/aUcA9VYe33I/image_thumb%25255B4%25255D.png?imgmax=800" width="660" height="219" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I think, to some extent, this means a radical shift in the way we write web applications which need real time features. More importantly, you can bend the web in a better way – because you’ve access to a transport layer protocol (TCP) on top of which you can build your own custom/domain centric protocols, instead of getting constrained with the application level HTTP protocol. Also, I am pretty sure that most of the client side agents other than web browsers will also start supporting web sockets in no time.&amp;#160; &lt;/p&gt;  &lt;h2&gt;A Quick word on Server Side Events&lt;/h2&gt;  &lt;p&gt;As you read this far, it might be interesting to note that HTML5 specifications has another API named server side events (SSE), which allows you to Push data from server to client via an HTTP channel. &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;This specification defines an API for opening an HTTP connection for receiving push notifications from a server in the form of DOM events. The API is designed such that it can be extended to work with other push notification schemes such as Push SMS.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Anyway, Web Sockets are getting more attraction because it provides more control as it is on top of TCP, and more importantly, it is bidirectional. And what ever you can do with SSE can be implemented using Web Sockets, with a bit of custom code.&lt;/p&gt;  &lt;p&gt;Here are few links to follow.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.amazedsaint.com/2011/04/wpf-over-web-sockets-how-to-pump-wpf.html"&gt;Checkout this example of Web Sockets &lt;/a&gt; - This is a quick example that shows how I’m streaming WPF windows over web sockets to a browser, to draw it in a canvas&lt;/li&gt;    &lt;li&gt;&lt;a href="http://dev.w3.org/html5/websockets/"&gt;The Web Socket API&lt;/a&gt; – From W3C&lt;/li&gt;    &lt;li&gt;&lt;a href="http://cometdaily.com/2007/11/16/more-on-long-polling/"&gt;A nice post from Michael and Related Discussion&lt;/a&gt; – About Long polling vs Streaming approaches.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://nowjs.org/"&gt;NowJs&lt;/a&gt;/Socket.IO on top of Node and &lt;a href="https://github.com/SignalR/SignalR"&gt;Signal If you are&amp;#160; .NET developer&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.amazedsaint.com/2011/09/creating-10-minute-todo-listing-app-on.html"&gt;Here is one of my previous posts on getting Node working on IIS on Windows&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Happy Coding, but beware, HTML5 is just near your door.&amp;#160; Chances are that, pretty soon, almost half of the things you do today with classic HTTP stack will be replaced with wrapper implementations like NowJs or SignalR.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22141639-8095222016613230363?l=www.amazedsaint.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/enz6IXapGSAKc1UqaobDzA9T3cc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/enz6IXapGSAKc1UqaobDzA9T3cc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/enz6IXapGSAKc1UqaobDzA9T3cc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/enz6IXapGSAKc1UqaobDzA9T3cc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=nW4XHSV19tE:NQV7KBrBQJ0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=nW4XHSV19tE:NQV7KBrBQJ0:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=nW4XHSV19tE:NQV7KBrBQJ0:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=nW4XHSV19tE:NQV7KBrBQJ0:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=nW4XHSV19tE:NQV7KBrBQJ0:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=nW4XHSV19tE:NQV7KBrBQJ0:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=nW4XHSV19tE:NQV7KBrBQJ0:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=nW4XHSV19tE:NQV7KBrBQJ0:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=nW4XHSV19tE:NQV7KBrBQJ0:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/amazedsaint/articles/~4/nW4XHSV19tE" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/amazedsaint/articles/~3/nW4XHSV19tE/html5-is-in-killer-spree-may-kill-http.html</link><author>noreply@blogger.com (Anoop Madhusudanan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh3.ggpht.com/-868jjgKjSyg/Tr_4mWnup7I/AAAAAAAABQs/JfuXR1eN35U/s72-c/image_thumb%25255B6%25255D.png?imgmax=800" height="72" width="72" /><feedburner:origLink>http://www.amazedsaint.com/2011/11/html5-is-in-killer-spree-may-kill-http.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-22141639.post-6980596611604346778</guid><pubDate>Sun, 13 Nov 2011 08:11:00 +0000</pubDate><atom:updated>2011-11-13T13:57:32.467+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">Design And Architecture</category><category domain="http://www.blogger.com/atom/ns#">CSharp</category><title>Implementing Chain of Responsibility Design Pattern in C# using Managed Extensibility Framework (MEF)</title><description>&lt;p&gt;&lt;a href="http://lh6.ggpht.com/-IuQY8iN5ukk/Tr9ztDayo1I/AAAAAAAABO0/kylQbTI35tQ/s1600-h/image%25255B25%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" align="right" src="http://lh6.ggpht.com/-DtMKvDe4wsM/Tr97MsYUgjI/AAAAAAAABO8/4Pwu9ryvWXk/image_thumb%25255B13%25255D.png?imgmax=800" width="356" height="357" /&gt;&lt;/a&gt;This post is about implementing Chain Of Responsibility design pattern, and few possible extensions to the same. If you are new to design patterns, I suggest you should start with &lt;a href="http://www.amazedsaint.com/2008/01/design-patterns-part-i-and-ii.html"&gt;Practically Applying Design Patterns&amp;#160; – Thought Process&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Coming back to Chain of Responsibility - If you have a scenario where you need to chain multiple handlers to handle an incoming request or command, you better use Chain Of Responsibility. &lt;/p&gt;  &lt;p&gt;A typical example is your girlfriend requesting you something –&amp;#160; If she is requesting/commanding you something like “Do you want to come with me for my best friend’s Bachelorette party?”, you &lt;em&gt;will&lt;/em&gt; handle it directly. But if she is requesting/commanding you some thing like “Buy me a Porsche”, you say “Sorry Honey, I don’t have the money. Better you ask your dad for this, I’ll call him for you” –i.e, you pass the request to the next handler, in this case your girl friend’s Father. To sum up, in the above example, your girl friend is the client who is making the request, and you and your future father-in-law are handlers/approvers who handle/approve her requests. If you cannot handle it, you pass that responsibility to the next handler/approver in the chain. &lt;/p&gt;  &lt;h2&gt;A Minimal Example&lt;/h2&gt;  &lt;p&gt;To consider a more formal example, assume a scenario where you’ve a banking system, and you want to implement some kind of Loan approval. The customer may request a loan, and if it is below a specific amount, the cashier may&amp;#160; approve it directly. If it is above the specified amount, he might pass the request to his manager for approval.&lt;/p&gt;  &lt;p&gt;So you may use Chain Of Responsibility implementation to hand over the request/command to the correct approver. For an example, consider this implementation of the above Bank account scenario. Our business rule is something like, a cashier can approve the request if the amount is lesser than 1000 $$, other wise the approval should be passed to the manager. The manager can approve the request if the amount is lesser than 10,000 $$.&lt;/p&gt;  &lt;p&gt;We have the following components.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;LoanRequest – A concrete request &lt;/li&gt;    &lt;li&gt;IRequestHandler – Abstract request handler implementation      &lt;ul&gt;       &lt;li&gt;Concrete handlers like Cashier and Manager implements this &lt;/li&gt;        &lt;li&gt;Has a reference to the successor to pass the request &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Program – The main driver &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;To the code&lt;/p&gt;  &lt;pre class="c#" name="code"&gt;using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DesignPatternsCof
{

 
    //Request
    class LoanRequest
    {
        public string Customer { get; set; }
        public decimal Amount { get; set; }
    }

    //Abstract Request Handler
    interface IRequestHandler
    {
        string Name { get; set; }
        void HandleRequest(LoanRequest req);
        IRequestHandler Successor { get; set; }
    }

    //Just an extension method for the passing the request
    static class RequestHandlerExtension
    {
        public static void TrySuccessor(this IRequestHandler current, LoanRequest req)
        {

            if (current.Successor != null) 
            {
                Console.WriteLine(&amp;quot;{0} Can't approve - Passing request to {1}&amp;quot;, current.Name, current.Successor.Name);
                current.Successor.HandleRequest(req);
            }
            else
            {
                Console.WriteLine(&amp;quot;Amount invaid, no approval given&amp;quot;);                
            }
        }
    }

    //Concrete Request Handler - Cachier
    //Cachier can approve requests upto 1000$$
    class Cashier : IRequestHandler
    {
        public string Name { get; set; }
        
        public void HandleRequest(LoanRequest req)
        {
            Console.WriteLine(&amp;quot;\n----\n{0} $$ Loan Requested by {1}&amp;quot;,
                  req.Amount, req.Customer);

           if (req.Amount&amp;lt;1000)
               Console.WriteLine(&amp;quot;{0} $$ Loan approved for {1} - Approved by {2}&amp;quot;,
                    req.Amount,req.Customer, this.Name);
           else
               this.TrySuccessor(req);
        }

        public IRequestHandler Successor { get; set; }       
    }

    //Concrete Request Handler - Manager
    //Manager can approve requests upto 10000$
    class Manager : IRequestHandler
    {
        public string Name { get; set; }
        public void HandleRequest(LoanRequest req)
        {
            if (req.Amount &amp;lt; 10000)
                Console.WriteLine(&amp;quot;{0} $$ Loan approved for {1} - Approved by {2}&amp;quot;,
                         req.Amount, req.Customer, this.Name);
            else
               this.TrySuccessor(req);

        }
        public IRequestHandler Successor { get; set; }  
    }

   

    //Main driver
    class Program
    {
        static void Main(string[] args)
        {
            //Customers
            var request1 = new LoanRequest() { Amount = 800, Customer = &amp;quot;Jimmy&amp;quot;};
            var request2 = new LoanRequest() { Amount = 5000, Customer = &amp;quot;Ben&amp;quot;};
            var request3 = new LoanRequest() {Amount = 200000, Customer = &amp;quot;Harry&amp;quot;};

            //Approvers, chained together
            var manager = new Manager() {Name = &amp;quot;Tom, Manager&amp;quot;};
            var cashier = new Cashier(){ Name = &amp;quot;Job, Cachier&amp;quot;, Successor = manager};

            //All customers request cashier first to approve
            cashier.HandleRequest(request1);
            cashier.HandleRequest(request2);
            cashier.HandleRequest(request3);

            Console.ReadLine();
        }


    }
}&lt;/pre&gt;

&lt;p&gt;And this is what you’ll see upon execution.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh3.ggpht.com/-8iHzg3uVyBg/Tr97Ovh5yyI/AAAAAAAABPE/qQMY3Qbrb9E/s1600-h/image%25255B20%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-AypjAWfnk7M/Tr97QwEiPII/AAAAAAAABPM/vAZGo7evHnI/image_thumb%25255B10%25255D.png?imgmax=800" width="545" height="243" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, you may observe that Loan Requests from different customers are passed to the cashier in the above example, and the cashier in his approve method passes the request to his successor (i.e, the manager) if the amount is higher than what he can approve. The implementation is pretty minimal, as you can see.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh5.ggpht.com/--jee5fj0xVs/Tr97SoF_m_I/AAAAAAAABPU/soLCZqNi-1g/s1600-h/image12.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-MWHX3SnEU-A/Tr97VbJph5I/AAAAAAAABPc/ekE0ZFPXm-4/image_thumb8.png?imgmax=800" width="606" height="449" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We actually&amp;#160; have an Abstract request handler implementation &lt;em&gt;IReqeustHandler&lt;/em&gt; and two concrete request handlers, Cashier and Manager. Each request handler may hold a reference to the successor. You may see that we are setting the Successor of Cashier as Manager, so if the&amp;#160; amount requested his beyond a limit, the cashier may pass it to the manager for his approval. &lt;/p&gt;

&lt;h2&gt;Dynamically Injecting Approvers&lt;/h2&gt;

&lt;p&gt;Now, let us take a step back, and think how to implement this in such a way that the approval pipeline is extensible? As of now, our pipeline has two approvers, cashier and manager, and the manager can approve loans up to 10,000. Tomorrow, the Bank may decide that the General Manager can approve loans above 10,000 – and what you are going to do? Make the changes, Recompile the entire application, move it to QA, initiate a full recursion testing, and deploying everything to production? You may leverage a bit of extensibility here, and let us have a look at leveraging MEF (Managed Extensibility Framework) for the same.&lt;/p&gt;

&lt;p&gt;I recommend you to go through my introductory posts on MEF if you are not familiar with MEF concepts.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://www.amazedsaint.com/2009/11/mef-or-managed-extension-framework.html"&gt;MEF Introduction&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://www.amazedsaint.com/2010/06/mef-or-managed-extensibility-framework.html"&gt;MEF – Custom Export Attributes, Lazy and More&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let us go for a generic implementation, to load and compose the handlers leveraging MEF. Let us generalize the above implementation a bit, and introduce few more general purpose contracts and classes.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;IRequest – This contract should be implemented by all requests. &lt;/li&gt;

  &lt;li&gt;IRequestHandler – Same as earlier. Abstract request handler implementation &lt;/li&gt;

  &lt;li&gt;ExportHandlerAttribute – A custom attribute to export MEF parts &lt;/li&gt;

  &lt;li&gt;IRequestHandlerMetadata – Used internally for storing the successor information as a type &lt;/li&gt;

  &lt;li&gt;RequestHandlerGateway – Does the composition, and passes the request to successors in a chained fashion. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To the code&lt;/p&gt;

&lt;pre class="c#" name="code"&gt;    //Abstract Request 
    public interface IRequest { }


    //Abstract Request Handler
    public interface IRequestHandler
    {
        bool HandleRequest(IRequest req);
        IRequestHandler Successor { get; set; }
    }

    //A custom MEF Export attribute
    [MetadataAttribute]
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]  
    public class ExportHandlerAttribute : ExportAttribute 
    {
        public Type SuccessorOf { get; set; }

        public ExportHandlerAttribute()
            : base(typeof(IRequestHandler))
        {
        }

        public ExportHandlerAttribute(Type successorOf)
            : base(typeof(IRequestHandler))
        {
            this.SuccessorOf = successorOf;
        }
    }

    //The metadata to tie a handler to next successor
    public interface IRequestHandlerMetadata
    {
        Type SuccessorOf { get; }
    }

    //A gateway which stiches together the handlers, to accept a request to chain through the handlers
    //Note that this does the composition using MEF
    public class RequestHandlerGateway
    {
        [ImportMany(typeof(IRequestHandler))]
        public IEnumerable&amp;lt;Lazy&amp;lt;IRequestHandler,IRequestHandlerMetadata&amp;gt;&amp;gt; Handlers { get; set; }

        private IRequestHandler first = null;

        public RequestHandlerGateway()
        {
            ComposeHandlers();

            //Let us find and keep the first handler
            //i.e, the handler which is not a sucessor of any other handlers            
            first = Handlers.First
                    (handler =&amp;gt; handler.Metadata.SuccessorOf == null).Value;
        }

        //Compose the handlers
        void ComposeHandlers()
        {
            //A catalog that can aggregate other catalogs
            var aggrCatalog = new AggregateCatalog();
            //An assembly catalog to load information about part from this assembly
            var asmCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());

            aggrCatalog.Catalogs.Add(asmCatalog);

            //Create a container
            var container = new CompositionContainer(aggrCatalog);
            //Composing the parts
            container.ComposeParts(this);
        }

        //Try to handle the request, pass to successor if required
        bool TryHandle(IRequestHandler handler, IRequest req)
        {
            var s =
                Handlers.FirstOrDefault(
                    h =&amp;gt; h.Metadata.SuccessorOf == handler.GetType());

            if (handler.HandleRequest(req)) 
                return true;
            else if (s != null)
            {
                handler.Successor = s.Value;
                return TryHandle(handler.Successor, req);
            }
            else
                return false;
        }

        //Main gateway method for invoking the same from the driver
        public bool HandleRequest(IRequest request)
        {
            return TryHandle(first,request);
        }
    }    &lt;/pre&gt;

&lt;p&gt;Cool. So we have the basic stuff there, keep that handy. Now, to have a Chain Of responsibility implementation, you can simply create the concrete parts and export the same. We’ve the following concrete parts.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;LoanRequest – A concrete request&lt;/li&gt;

  &lt;li&gt;Cashier, Manager, and GeneralManager – Concrete request handlers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You may note that now we can chain the handlers using the Meta data. For example, when you export the manager, you can easily specify that Manager is the successor of Cashier, to approve the request. Similarly, you can specify General Manager as the successor of the Manager. The advantage is, you can simply deploy these components in a loosely coupled manager, and pick them up using the DirectoryCatalog of MEF during re composition. &lt;/p&gt;

&lt;pre class="c#" name="code"&gt;
    //Concrete Request
    public class LoanRequest : IRequest
    {
        public string Customer { get; set; }
        public decimal Amount { get; set; }
    }


    //Concrete Request Handler - Cachier
    //Cachier can approve requests upto 1000$$
    [ExportHandler]
    public class Cashier : IRequestHandler
    {
      
        public bool HandleRequest(IRequest r)
        {
            var req = (LoanRequest)r;
            if (req.Amount &amp;lt; 1000)
            {
                Console.WriteLine(&amp;quot;{0} $$ Loan approved for {1} - Approved by {2}&amp;quot;,
                                  req.Amount, req.Customer, this.GetType().Name);
                return true;
            }

            return false;

        }

        public IRequestHandler Successor { get; set; }
    }

    //Concrete Request Handler - Manager
    //Manager can approve requests upto 10000$
    [ExportHandler(SuccessorOf = typeof(Cashier))]
    public class Manager : IRequestHandler
    {
     
        public bool HandleRequest(IRequest r)
        {
            var req = (LoanRequest)r;
            if (req.Amount &amp;lt; 10000)
            {
                Console.WriteLine(&amp;quot;{0} $$ Loan approved for {1} - Approved by {2}&amp;quot;,
                                  req.Amount, req.Customer, this.GetType().Name);
                return true;
            }

            return false;
        }

        public IRequestHandler Successor { get; set; }
    }


    //Concrete Request Handler - Manager
    //Manager can approve requests upto 10000$
    [ExportHandler(SuccessorOf = typeof(Manager))]
    public class GeneralManager : IRequestHandler
    {

        public bool HandleRequest(IRequest r)
        {
            var req = (LoanRequest)r;
            if (req.Amount &amp;lt; 100000)
            {
                Console.WriteLine(&amp;quot;{0} $$ Loan approved for {1} - Approved by {2}&amp;quot;,
                                  req.Amount, req.Customer, this.GetType().Name);
                return true;
            }

            return false;
        }

        public IRequestHandler Successor { get; set; }
    }


    //Main driver
    class Program
    {
        static void Main(string[] args)
        {
            //Customers
            Console.WriteLine(&amp;quot;Enter Loan Amount:&amp;quot;);
            var amount = decimal.Parse(Console.ReadLine());

            var req = new LoanRequest() {Amount = amount, Customer = &amp;quot;Ben&amp;quot;};
            var gateway = new RequestHandlerGateway();
            if (!gateway.HandleRequest(req))
                Console.WriteLine(&amp;quot;Oops, too high. Rejected&amp;quot;);
            Console.ReadLine();
        }


    }&lt;/pre&gt;

&lt;p&gt;And this is what you’ll get. You can see that the request gets dispatched to the correct handler.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh6.ggpht.com/-RTGdJWPeW6k/Tr97XGdez2I/AAAAAAAABPk/nrgG3W4dSjE/s1600-h/image%25255B3%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-jINGSCDAD_Q/Tr97ZhMccDI/AAAAAAAABPs/VHrTb35lLPg/image_thumb%25255B1%25255D.png?imgmax=800" width="473" height="159" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh3.ggpht.com/-vapXt6YUuhI/Tr97cNtTdqI/AAAAAAAABP0/r2AOYgm0zw0/s1600-h/image%25255B8%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-5CluoUgf7no/Tr97enEubsI/AAAAAAAABP8/4S4Z9o_EnD8/image_thumb%25255B4%25255D.png?imgmax=800" width="505" height="159" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh4.ggpht.com/-LZTc3OCsazA/Tr97gW4nQ3I/AAAAAAAABQE/jWSoP3R6osQ/s1600-h/image%25255B12%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-refO_TwuCcA/Tr97inbkPsI/AAAAAAAABQM/Gdywc9SYml4/image_thumb%25255B6%25255D.png?imgmax=800" width="521" height="123" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh6.ggpht.com/-TI78rHOOM9c/Tr97j_gvrQI/AAAAAAAABQQ/D3urC_oJDv8/s1600-h/image%25255B16%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-6V9Yx9FBQfk/Tr97l9lXYpI/AAAAAAAABQc/X-8rK7Wpfhc/image_thumb%25255B8%25255D.png?imgmax=800" width="393" height="135" /&gt;&lt;/a&gt;&lt;/p&gt;







&lt;p&gt;There we go, happy coding with proper decoupling. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22141639-6980596611604346778?l=www.amazedsaint.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/2AuzSTYKXPR4xLjCD1UN74M4HUE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2AuzSTYKXPR4xLjCD1UN74M4HUE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/2AuzSTYKXPR4xLjCD1UN74M4HUE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2AuzSTYKXPR4xLjCD1UN74M4HUE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=q3j5MZtDD6M:k0ThXFhdIMU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=q3j5MZtDD6M:k0ThXFhdIMU:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=q3j5MZtDD6M:k0ThXFhdIMU:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=q3j5MZtDD6M:k0ThXFhdIMU:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=q3j5MZtDD6M:k0ThXFhdIMU:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=q3j5MZtDD6M:k0ThXFhdIMU:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=q3j5MZtDD6M:k0ThXFhdIMU:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=q3j5MZtDD6M:k0ThXFhdIMU:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=q3j5MZtDD6M:k0ThXFhdIMU:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/amazedsaint/articles/~4/q3j5MZtDD6M" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/amazedsaint/articles/~3/q3j5MZtDD6M/chain-of-responsibility-design-pattern.html</link><author>noreply@blogger.com (Anoop Madhusudanan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh6.ggpht.com/-DtMKvDe4wsM/Tr97MsYUgjI/AAAAAAAABO8/4Pwu9ryvWXk/s72-c/image_thumb%25255B13%25255D.png?imgmax=800" height="72" width="72" /><feedburner:origLink>http://www.amazedsaint.com/2011/11/chain-of-responsibility-design-pattern.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-22141639.post-2478914722477953787</guid><pubDate>Wed, 02 Nov 2011 16:46:00 +0000</pubDate><atom:updated>2011-11-03T00:12:51.987+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Software Development</category><category domain="http://www.blogger.com/atom/ns#">Design And Architecture</category><category domain="http://www.blogger.com/atom/ns#">cqrs</category><category domain="http://www.blogger.com/atom/ns#">Programming-Tips</category><title>The CQRS dilemma and related random thoughts</title><description>&lt;p&gt;&lt;a href="http://lh3.ggpht.com/-2-cf2a4OV6A/TrFzzRscdAI/AAAAAAAABOk/dRfzbABAmUI/s1600-h/image%25255B4%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" align="right" src="http://lh6.ggpht.com/-DUzBXb09mqM/TrFz0mEWOjI/AAAAAAAABOs/hLXXXgy6RF4/image_thumb%25255B2%25255D.png?imgmax=800" width="168" height="173" /&gt;&lt;/a&gt;I was very skeptical about CQRS (Command Query Responsibility Segregation) some time back, how ever after working on a CQRS implementation for the past few months for a customer in the telecom domain, I see better light. For some reason, there is a wide spread perception that CQRS is only for complex domains, how ever I think any true business system can benefit from CQRS principles. Here are few quick thoughts, mostly rants.&lt;/p&gt;  &lt;h2&gt;What is CQRS?&lt;/h2&gt;  &lt;p&gt;The basic idea of CQRS is pretty simple, this is from the &lt;a href="http://codebetter.com/gregyoung/2010/02/16/cqrs-task-based-uis-event-sourcing-agh/"&gt;CQRS summary post&lt;/a&gt; by Greg Young&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Starting with CQRS, CQRS is simply the creation of two objects where there was previously only one. The separation occurs based upon whether the methods are a command or a query (the same definition that is used by Meyer in Command and Query Separation, a command is any method that mutates state and a query is any method that returns a value).&lt;/p&gt;    &lt;p&gt;When most people talk about CQRS they are really speaking about applying the CQRS pattern to the object that represents the service boundary of the application. &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;As simple as that. I suggest you to read/bookmark the below posts.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://codebetter.com/gregyoung/2010/02/16/cqrs-task-based-uis-event-sourcing-agh/"&gt;An excellent summary from Greg where he clarifies the concept&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://cqrs.files.wordpress.com/2010/11/cqrs_documents.pdf"&gt;A super simple PDF document from Greg that briefs the concept from a design and business view point&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://cqrs.wordpress.com"&gt;CQRS blog where Set of nice resources are listed&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://codeofrob.com/archive/2011/09/28/cqrs-is-too-complicated.aspx"&gt;CQRS is too complicated – Nice post that analyzes the logic behind the implementation&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Code samples to start with (.NET stuff)&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="https://github.com/gregoryyoung/m-r"&gt;Greg’s “simplest possible thing”&lt;/a&gt;&amp;#160; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;So, most of the discussion happening these days is about the application possibilities and implementation details around CQRS, and these are just few random thoughts around the same, and these are not any pointers for anyone. &lt;/p&gt;  &lt;p&gt;For a moment, let us forget what exactly is CQRS, let us see how your system or business normally works. The users or stake holders or external system interact with your system in two ways – basically they’ll ask the system to do something (commands), and they also need to view/visualize the state of the system in different ways (queries). In most businesses, the system will be queried not just for the current state, but also for historical changes – i.e, you need to track the history of changes (as in an audit log) and need special logic to capture intelligence about events happened in the past. Say, to answer like &amp;quot;how many users are removing product x from their cart after adding product y&amp;quot;.&amp;#160; &lt;/p&gt;  &lt;p&gt;You could argue any system that is just CRUD is a database, and yes we can put any decoration on top of it to build some editing features. But any meaningful Business Context involves capturing intent from user, to validate the intent at times, handle it, and provide some meaningful read models to query.&lt;/p&gt;  &lt;p&gt;So, I think CQRS allows modeling the domain in a more natural way. You can pick commands directly from the use cases (if well written), and you can focus on what the domain does or what the domain should do when a state change happens, and use this information to construct how different stake holders view the system. In our scenario, we had multiple dimensions/read model snapshots. &lt;/p&gt;  &lt;h2&gt;Do I need CQRS?&lt;/h2&gt;  &lt;p&gt;It is all about the ROI, isn't it? Theoretically, you could argue any BC that models a set of business scenarios can be benefited leveraging the CQRS principles, because that means your system will be able to answer a lot of business related questions implicitly. Do you need that or not? That's a business call.&lt;/p&gt;  &lt;p&gt;Here is my top three reasons based on my limited exposure towards CQRS based models.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;The users or stake holders or external system interact with your system in two ways and if you are specifically focused on capturing the user intent– basically in any system, they’ll ask the system to do something (commands), and they also need to view/visualize the state of the system in different ways (queries). &lt;/li&gt;    &lt;li&gt;In case your system will be queried not just for the current state, but also for historical changes – i.e, you need to track the history of changes (as in an audit log in a stereotypical system) and need special logic to capture intelligence about events happened in the past. Say, as I mentioned, to answer like &amp;quot;how many users are removing product x from their cart after adding product y&amp;quot;. &lt;/li&gt;    &lt;li&gt;Your management/customer thinks it'll add value to them on the long run, i.e, the system will help them have an edge over the competition. Oh yea, you have to sell this to them. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;There is going to be a spike in the CapEx, may be because building Task Based/Inductive UIs are more costly than spread sheet like grids/CRUD focused forms where the user has to bring up the entire form to change the status from open to closed or what ever.&amp;#160; Other than that, I think the cost is totally dependent on the design and related details, and the way you implement CQRS along with other DDD patterns.&lt;/p&gt;  &lt;h2&gt;CQRS and Event Sourcing&lt;/h2&gt;  &lt;p&gt;CQRS can be a simple separation of commands and queries, but I think the real value is if you tie CQRS with Event sourcing - it allows you to capture the system as how it came to the current state, rather than what it is right now. So, you are adding a new dimension to the system, i.e, the time. And you can take snapshots of the system at different times, and then compare it, that is valuable business intelligence. I think we don't need to see the read model as just a static snapshot of the system at a given time - it can even be derived from the state of the system at two different times.&lt;/p&gt;  &lt;p&gt;And you can build read models based on multiple dimensions - to answer questions related to the system's behavior as well. For example, a stereotypical system can't answer even simple questions like &amp;quot;how many users are removing product x from their cart after adding product y&amp;quot; with out explicit design to capture the scenario. In a CQRS system this is implicit.&lt;/p&gt;  &lt;p&gt;You can plugin a new dimension that constructs a read model to answer the query. About the cost - I think the key is in bringing in the mindset and selling this idea to the stake holders - even if the initial investment is a bit high, that will significantly improve their ROI and place them ahead of the competition. &lt;/p&gt;  &lt;p&gt;How ever, the problem is, the world may be too corrupted with people like us, who were trying hard to persist a single state snapshot of the system in a mismatching ER model and then trying to keep it up to date and worrying about all related issues, to further mess it up with audit logs and all other mining crap when business starts asking critical questions. &lt;/p&gt;  &lt;p&gt;Related Reads:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://martinfowler.com/eaaDev/EventSourcing.html"&gt;Event Sourcing&lt;/a&gt; from Fowler’s bliki&lt;/li&gt;    &lt;li&gt;&lt;a href="http://codebetter.com/gregyoung/2010/02/13/cqrs-and-event-sourcing/"&gt;CQRS and Event Sourcing&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;h2&gt;CQRS and REST&lt;/h2&gt;  &lt;p&gt;Related Reads&lt;/p&gt;  &lt;p&gt;Based on the recent experience, I’ve got a feeling that REST and CQRS goes well together, and there is a bit to explore there.&amp;#160;&amp;#160; To start with, they way we implemented Commands in one of the recent system is over a REST API, where the URL scheme represents the commands.&lt;/p&gt;  &lt;p&gt;Say, for example, if the user need to close and issue, the end point will be like &lt;a href="http://server/issue/close"&gt;http://server/issue/close&lt;/a&gt;&amp;#160;&amp;#160; - The end points are used to identify the command handler and pass it to the same. Command handlers are registered in a container, in our case we used MEF to export the command handlers, something like &lt;/p&gt;  &lt;p&gt;Message is essentially a key value store as in a dictionary, and this allows us to cope up with versioning.&amp;#160; We had a REST based Querying API too. And we were federating the commands to the results/DTOs as in Hypermedia&lt;/p&gt;  &lt;p&gt;i.e, here is an example&lt;/p&gt;  &lt;pre class="c#" name="code"&gt;[ExportCommandHandler(&amp;quot;Issue&amp;quot;,&amp;quot;Close&amp;quot;)]
public void CloseIssueCommandHandler(int id) {..}&lt;/pre&gt;

&lt;p&gt;I couldn't figure out a defined way for the Task Based UI to find out possible commands based on the current state. Probably this is more or less an implementation related aspect and all of us are free to choose. We could do the validation of the command after it is issued, but in some scenarios, it is better to prevent the user from issuing the command in first place. &lt;/p&gt;
I.e, let us consider a DTO, 

&lt;pre class="c#" name="code"&gt;&amp;lt;issue&amp;gt;
  &amp;lt;id&amp;gt;1&amp;lt;/id&amp;gt;
  &amp;lt;description&amp;gt;A bug is trying to hug me&amp;lt;/description&amp;gt;
  &amp;lt;otherfields/&amp;gt;
  &amp;lt;link rel=&amp;quot;rc:closeissue&amp;quot; url=&amp;quot;/issue/close/1&amp;quot;&amp;gt;
&amp;lt;/issue&amp;gt;&lt;/pre&gt;

&lt;p&gt;Now, when a user closed an issue, a &lt;b&gt;CloseIssue&lt;/b&gt;&lt;b&gt; &lt;/b&gt;command has gone in and if the operation succeeds, an &lt;b&gt;IssueClosed&lt;/b&gt; event has been logged to our event store - Now, as the issue is already closed, you don't need to (or you should not) provide the CloseIssue action to another user again, because the Issue is already closed by some one. &lt;/p&gt;

&lt;p&gt;So, in our scenario, we had some decorators on top of the Query builder to evaluate the current state, so that only the required commands are federated to a returned result. So, the Task Based UI can be more intelligent (and the TB UI is anyway issuing commands based on the DTO information it has). &lt;/p&gt;

&lt;p&gt;Related Reads:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://www.google.co.in/url?sa=t&amp;amp;rct=j&amp;amp;q=rest%20and%20hypermedia%20glenn%20block&amp;amp;source=web&amp;amp;cd=1&amp;amp;ved=0CBsQFjAA&amp;amp;url=http%3A%2F%2Fcodebetter.com%2Fglennblock%2F2011%2F05%2F09%2Fhypermedia-and-forms%2F&amp;amp;ei=QnOxTofOI4mGrAea--lU&amp;amp;usg=AFQjCNEObtkg-zDAyb0U4zKPreYcOCxZkQ&amp;amp;sig2=KFtG9jOVzNEsAoyxx1f0ig"&gt;Hypermedia and Rest&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://martinfowler.com/articles/richardsonMaturityModel.html"&gt;Steps towards the Glory of REST&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Alright, I warned you early enough that these were some random thoughts.&amp;#160; Happy coding!!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22141639-2478914722477953787?l=www.amazedsaint.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/CdvJnzz4hIF--735mWSHJtvRfhg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/CdvJnzz4hIF--735mWSHJtvRfhg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/CdvJnzz4hIF--735mWSHJtvRfhg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/CdvJnzz4hIF--735mWSHJtvRfhg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=IL4CDAEGeIg:RIH01V60EHg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=IL4CDAEGeIg:RIH01V60EHg:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=IL4CDAEGeIg:RIH01V60EHg:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=IL4CDAEGeIg:RIH01V60EHg:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=IL4CDAEGeIg:RIH01V60EHg:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=IL4CDAEGeIg:RIH01V60EHg:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=IL4CDAEGeIg:RIH01V60EHg:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=IL4CDAEGeIg:RIH01V60EHg:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=IL4CDAEGeIg:RIH01V60EHg:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/amazedsaint/articles/~4/IL4CDAEGeIg" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/amazedsaint/articles/~3/IL4CDAEGeIg/cqrs-dilemma-and-related-random.html</link><author>noreply@blogger.com (Anoop Madhusudanan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh6.ggpht.com/-DUzBXb09mqM/TrFz0mEWOjI/AAAAAAAABOs/hLXXXgy6RF4/s72-c/image_thumb%25255B2%25255D.png?imgmax=800" height="72" width="72" /><feedburner:origLink>http://www.amazedsaint.com/2011/11/cqrs-dilemma-and-related-random.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-22141639.post-5205397690375261287</guid><pubDate>Sat, 22 Oct 2011 10:12:00 +0000</pubDate><atom:updated>2011-10-25T01:34:51.701+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">CSharp5</category><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">CSharp</category><category domain="http://www.blogger.com/atom/ns#">Programming-Tips</category><title>Scripting and Code Analysis using Roslyn – And a first look at Roslyn CTP</title><description>&lt;p&gt;&lt;img style="display: inline; float: right" alt="I Love C#" align="right" src="http://lh3.ggpht.com/__Mw4iY-4nuY/TJ8yJRPaLsI/AAAAAAAAA7A/aklc9wj3Tf4/image_thumb%5B46%5D.png?imgmax=800" /&gt;Microsoft recently released Roslyn CTP, which previews the upcoming features of C# and VB.NET. Roslyn CTP is a pretty exciting release, and it opens up lot of possibilities for C# and VB.NET programmers. Roslyn provides language services and APIs on top of .NET’s compiler services, and this will enable .NET developers to do a lot more things – including using C# and VB.NET as scripting languages, use compiler as a service in your own applications for code related tasks, develop better language and IDE extensions etc. &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.microsoft.com/download/en/details.aspx?id=27746"&gt;Download Roslyn CTP&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/roslyn"&gt;MSDN Roslyn CTP Page and Related Resources&lt;/a&gt;&amp;#160; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Also, Roslyn provides a lot of possibilities for developers to write code analysis and manipulation tools around Visual Studio IDE, and provides APIs that’ll enable you to develop Visual Studio enhancements pretty quickly. The Roslyn APIs will have full fidelity with C# and VB for syntax, semantic binding, code emission, etc – and you’ll see soon a lot of language bending around C# and VB.NET, and possibly new DSLs and lot of meta programming ideas.&lt;/p&gt;  &lt;p&gt;Roslyn has mainly four API Layers.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Scripting APIs      &lt;ul&gt;       &lt;li&gt;Provides a run time execution context for C# and VB.NET, Now you can use C#/VB.NET in your own applications as a scripting language &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Compiler APIs      &lt;ul&gt;       &lt;li&gt;For accessing the Syntax and Semantic model of your code. &lt;!--EndFragment--&gt;&lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Workspace APIs      &lt;ul&gt;       &lt;li&gt;Provides an object model to aggregate the code model across projects in a solution. Mainly for code analysis and refactoring around IDEs like Visual Studio, though the APIs are not dependent on Visual Studio. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Services APIs      &lt;ul&gt;       &lt;li&gt;Provides a layer on top of Visual Studio SDK (VSSDK) for features like Intellisense, code formatting etc. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;In this post, we’ll have a sneak peak towards the Scripting APIs and Compiler APIs.&lt;/p&gt;  &lt;h2&gt;Scripting APIs&lt;/h2&gt;  &lt;p&gt;Some time back, I posted about how to use &lt;a href="http://www.amazedsaint.com/2010/09/c-as-scripting-language-in-your-net.html"&gt;Mono C# Compiler as a Service in your .NET applications&lt;/a&gt; to leverage C# as a scripting language. Thanks to Roslyn, now we’ll be having a first class Scripting API soon to .NET.&lt;/p&gt;  &lt;p&gt;The Roslyn.Scripting.* namespace provides types for implementing your own scripting sessions, using C# and VB.NET. You can create a new Scripting session using Session.Create(..) method. The Session.Create method can also accept a Host object, and the methods of the Host object will be directly available to the runtime context.&lt;/p&gt;  &lt;p&gt;To execute some code, you can create an instance of a ScriptEngine by providing the required assembly references and name space import information, and invoke the Execute method of the Scripting Engine. To demonstrate how this works, let us create a simple ScriptingHost which wraps a scripting session. For demonstration, we’ll also create a ScriptedDog class, and the purpose of this example is that we can Create dogs and train them through the scripting environment. Once you install Roslyn, create a new Console application, and here is the code that demonstrates a simple scripting environment.&lt;/p&gt;  &lt;pre class="c#" name="code"&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using Roslyn.Compilers;
using Roslyn.Compilers.CSharp;
using Roslyn.Scripting;
using Roslyn.Scripting.CSharp;

namespace ScriptingRoslyn
{
    //Our Dog class so that we can train dogs later
    public class OurDog
    {
        private string _name = string.Empty;
        public OurDog(string name)
        {
            _name = name;
        }

        public string Name
        {
            get { return _name; }
        }

        public void Byte(OurDog other)
        {
            Console.WriteLine(&amp;quot;{0} is byting the tail of {1}&amp;quot;, _name, other.Name);
        }

        public void Walk()
        {
            Console.WriteLine(&amp;quot;{0} is Walking&amp;quot;, _name);
        }

        public void Eat()
        {
            Console.WriteLine(&amp;quot;{0} is Eating&amp;quot;, _name);
        }
    }


    //Let us create a Host object, where we'll wrap our session and engine
    //The methods in the host class are available directly to the environment
    public class ScriptingHost
    {
        private ScriptEngine engine;
        private Session session;

        //Methods in the Host object can be called directly from the 
        //environment
        public OurDog CreateDog(string name)
        {
            return new OurDog(name);
        }

        public ScriptingHost()
        {
            //Create a session
            session = Session.Create(this);

            //Create the engine, just pass the assemblies and namespaces
            engine = new ScriptEngine(new Assembly[]
                                {
                                    typeof(Console).Assembly,
                                    typeof(ScriptingHost).Assembly,
                                    typeof(IEnumerable&amp;lt;&amp;gt;).Assembly,
                                    typeof(IQueryable).Assembly
                                },
                                new string[] 
                                { 
                                    &amp;quot;System&amp;quot;, &amp;quot;System.Linq&amp;quot;, 
                                    &amp;quot;System.Collections&amp;quot;,
                                    &amp;quot;System.Collections.Generic&amp;quot;
                                }
                            );

        }

        //Pass the code to the engine, nothing much here
        public object Execute(string code)
        {
            return engine.Execute(code, session);
        }

        public T Execute&amp;lt;T&amp;gt;(string code)
        {
            return engine.Execute&amp;lt;T&amp;gt;(code, session);
        }

    }

    //Main driver

    class Program
    {
        static void Main(string[] args)
        {
            var host = new ScriptingHost();
            Console.WriteLine(&amp;quot;Hello Dog Trainer!! Type your code.\n\n&amp;quot;);


            string codeLine = string.Empty;
            Console.Write(&amp;quot;&amp;gt;&amp;quot;);
            while ((codeLine = Console.ReadLine()) != &amp;quot;Exit();&amp;quot;)
            {
                try
                {
                    //Execute the code
                    var res = host.Execute(codeLine);

                    //Write the result back to console
                    if (res != null)
                        Console.WriteLine(&amp;quot; = &amp;quot; + res.ToString());
                }
                catch (Exception e)
                {
                    Console.WriteLine(&amp;quot; !! &amp;quot; + e.Message);
                }

                Console.Write(&amp;quot;&amp;gt;&amp;quot;);
            }
        }
    }
}&lt;/pre&gt;

&lt;p&gt;I assume the code is self explanatory, we are creating a Host class where we wrap the session and execute the code using the ScriptEngine in that session. A very simple REPL example - So, now let us go and train the dogs.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh5.ggpht.com/-DZBMa-bCTgw/TqXE2nMdsHI/AAAAAAAABOQ/H-sBZ3SaeiY/s1600-h/image%25255B3%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-ELB3vxlRXfM/TqXE4Sz6WEI/AAAAAAAABOY/3m-kmwHJtSc/image_thumb%25255B1%25255D.png?imgmax=800" width="561" height="243" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find that we are invoking the CreateDog method with in our Host class to create the dogs, and then we are training them – Though I’m not sure if we really need to train them to bite each other. Anyway, I hope the idea is clear.&lt;/p&gt;

&lt;h2&gt;Compiler APIs&lt;/h2&gt;

&lt;p&gt;Compiler APIs has object models for accessing the syntax and semantic models of your code. Using compiler APIs, you can obtain and manipulate Syntax trees. The common Syntax APIs are found in the Roslyn.Compilers and the Roslyn.Compilers.Common namespace, while the language specific Syntax APIs are found in Roslyn.Compilers.CSharp and Roslyn.Compilers.VisualBasic.&lt;/p&gt;

&lt;p&gt;‘Syntax’ is the grammatical structure whereas ‘Semantics’ refers to the meaning of the vocabulary symbols arranged with that structure. If you consider English, &amp;quot;Dogs Are Cats&amp;quot; is grammatically correct, but semantically it is nonsense. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Building Syntax Trees and Accessing Semantic Model&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Roslyn provides APIs for building syntax trees, and also for semantic analysis. So let us write some code that'll parse a method and creates syntax tree. It also shows how to get the method symbol from the semantic model of our syntax tree &lt;/p&gt;

&lt;pre class="c#" name="code"&gt;            //Parse some code
            SyntaxTree tree = SyntaxTree.ParseCompilationUnit
                    (@&amp;quot;class Bar { 
                        void Foo() { Console.WriteLine(&amp;quot;&amp;quot;foo&amp;quot;&amp;quot;); }
                          }&amp;quot;);

            //Find the first method declaration inside the first class declaration
            MethodDeclarationSyntax methodDecl = tree.Root
                .DescendentNodes()
                .OfType&amp;lt;ClassDeclarationSyntax&amp;gt;()
                .First().ChildNodes().OfType&amp;lt;MethodDeclarationSyntax&amp;gt;().First();

            //Create a compilation unit
            Compilation compilation = Compilation.Create(&amp;quot;SimpleMethod&amp;quot;).AddSyntaxTrees(tree);


            //Get the associated semantic model of our syntax tree
            var model = compilation.GetSemanticModel(tree);

            //Find the symbol of our Foo method
            Symbol methodSymbol = model.GetDeclaredSymbol(methodDecl);


            //Get the name of the method symbol
            Console.WriteLine(methodSymbol.Name);  &lt;/pre&gt;

&lt;p&gt;In the above example, you can easily figure out how we are parsing the code to a SyntaxTree, Getting the semantic model associated with that syntax tree, and then looking up for information in the Semantic model. In this case, we are getting the method symbol corresponds to the first method declaration with in the first class declaration in the syntax tree.&amp;#160; I.e, DescendentNodes() .OfType&amp;lt;ClassDeclarationSyntax&amp;gt;() .First() of the root node gives us the first class declaration node - and ChildNodes().OfType&amp;lt;MethodDeclarationSyntax&amp;gt;().First() gives us the first method declaration node with in that class declaration. To keep the point short, traversing the syntax tree using the object model is pretty easy.&lt;/p&gt;

&lt;p&gt;The symbols we obtain from the semantic model can be used for a wide range of scenarios, including code analysis. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A bit more about Syntax Trees&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Instead of parsing the entire code to a syntax tree, you can also parse code and for child Syntax Nodes nodes – For example, you can parse a statement to a StatementSyntax.&lt;/p&gt;

&lt;pre class="c#" name="code"&gt;StatementSyntax statement=Syntax.ParseStatement(&amp;quot;for (int i = 0; i &amp;lt; 10; i++) { }&amp;quot;);&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Syntax trees hold the entire source information in full fidelity - which means it contains every peice of the source information. Also, they can be round tripped to form the actual source code back from the syntax tree or the node. Syntax trees and nodes are immutable and thread safe.&amp;#160; &lt;/p&gt;

&lt;p align="left"&gt;How ever, it is possible to replace a node entirely in the current syntax tree by using the ReplaceNode function to create a tree with the old node replaced with the new node. For now, that is it. Enjoy coding, and &lt;a href="http://twitter.com/amazedsaint"&gt;follow me in twitter&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22141639-5205397690375261287?l=www.amazedsaint.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/YZlqO-MgfO7B_Z6ZcV4goJaGMy8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/YZlqO-MgfO7B_Z6ZcV4goJaGMy8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/YZlqO-MgfO7B_Z6ZcV4goJaGMy8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/YZlqO-MgfO7B_Z6ZcV4goJaGMy8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=_A7fG40LVBE:mvJ2d-i9Gz0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=_A7fG40LVBE:mvJ2d-i9Gz0:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=_A7fG40LVBE:mvJ2d-i9Gz0:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=_A7fG40LVBE:mvJ2d-i9Gz0:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=_A7fG40LVBE:mvJ2d-i9Gz0:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=_A7fG40LVBE:mvJ2d-i9Gz0:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=_A7fG40LVBE:mvJ2d-i9Gz0:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=_A7fG40LVBE:mvJ2d-i9Gz0:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=_A7fG40LVBE:mvJ2d-i9Gz0:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/amazedsaint/articles/~4/_A7fG40LVBE" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/amazedsaint/articles/~3/_A7fG40LVBE/c-vnext-roslynan-introduction-and-quick.html</link><author>noreply@blogger.com (Anoop Madhusudanan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh3.ggpht.com/__Mw4iY-4nuY/TJ8yJRPaLsI/AAAAAAAAA7A/aklc9wj3Tf4/s72-c/image_thumb%5B46%5D.png?imgmax=800" height="72" width="72" /><feedburner:origLink>http://www.amazedsaint.com/2011/10/c-vnext-roslynan-introduction-and-quick.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-22141639.post-2283078957350087240</guid><pubDate>Sun, 18 Sep 2011 20:37:00 +0000</pubDate><atom:updated>2011-09-19T22:57:20.962+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">xaml</category><category domain="http://www.blogger.com/atom/ns#">CSharp</category><category domain="http://www.blogger.com/atom/ns#">windows8</category><title>HelloTiles – A Simple C# Xaml Application for WinRT/Windows8 to demonstrate Metro Tile Updates</title><description>&lt;p&gt;&lt;a href="http://lh6.ggpht.com/-jNsZYpQEgPg/TnZWYG9bsaI/AAAAAAAABMM/xQ2n1eT62LM/s1600-h/image%25255B15%25255D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" border="0" alt="image" align="right" src="http://lh4.ggpht.com/-b-IaYE9UmqY/TnZWZaWQJcI/AAAAAAAABMQ/iQmBeY1PDMU/image_thumb%25255B9%25255D.png?imgmax=800" width="200" height="200" /&gt;&lt;/a&gt; To get the taste of Windows8 and WinRT, Let us develop a quick C# + Xaml application that sends notifications to the Metro UI Tiles. Before jumping in, make sure you read about&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.amazedsaint.com/2011/09/buildwindows-8-thoughts.html" target="_blank"&gt;Windows 8 Quick Overview&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.amazedsaint.com/2011/09/developing-for-winrt-and-windows8-basic.html" target="_blank"&gt;Basic Concepts Regarding WinRT and Windows 8 Development&lt;/a&gt;&amp;#160; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;So, let us create a quick app. Here we go.&lt;/p&gt;  &lt;h3&gt;About Tiles&lt;/h3&gt;  &lt;p&gt;As you might have already seen in the Demos, Windows 8 start screen features Tiles, as start points of the application. Your applications can send notifications to tiles, so that they are displayed in the start screen, above the tile. The types for Tile manipulations are in the namespace Windows.UI.Notifications&lt;/p&gt;  &lt;p&gt;Basically, we are interested in three classes.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.notifications.tilenotification(v=VS.85).aspx"&gt;TileNotification&lt;/a&gt;       &lt;ul&gt;       &lt;li&gt;Defines an update to a tile, including its visuals, identification tag, and expiration time. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.notifications.tileupdatemanager(v=VS.85).aspx"&gt;TileUpdateManager&lt;/a&gt;       &lt;ul&gt;       &lt;li&gt;Creates TileUpdater objects used to change and update Start menu tiles. This class also provides access to the XML content of the system-provided tile templates so that you can customize that content for use in updating your tiles. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.notifications.tileupdater(v=VS.85).aspx"&gt;TileUpdater&lt;/a&gt;       &lt;ul&gt;       &lt;li&gt;Changes the appearance or content of the specific tile that the updater is bound to. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;About Our HelloTiles Application&lt;/h3&gt;  &lt;p&gt;The Samples pack that comes with Windows 8 SDK has a Javascript/HTML sample for basic and advanced tile manipulation, so I thought about putting together a quick C#/XAML application along the same lines. So, you can see our tile, just under the “Weather” tile, with notification &lt;strong&gt;“tiles are cool”&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-umVLwV1kcl8/TnZWaZL-LdI/AAAAAAAABMU/prcCKiGHdPo/s1600-h/tilesarecool%25255B4%25255D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="tilesarecool" border="0" alt="tilesarecool" src="http://lh4.ggpht.com/-l1CPiH3XP2Q/TnZWbeyoZzI/AAAAAAAABMY/7sI7kcry9jw/tilesarecool_thumb%25255B2%25255D.png?imgmax=800" width="640" height="360" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;So, to start with, we’ll create a simple C#/XAML application for Windows RT, with a very simple Textbox and Button, and when the user enter some notification and click Send, the tile will be updated in the Start screen. This is just a demo scenario, and you know how to do better in an actual application –i.e, you can send a notification when something interesting happens in your application. Tiles are just one way to notify the user, but for now, let us keep things simple and create a quick notifier application, some what like this.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-hRw4L5H_PLo/TnZWcM7wCyI/AAAAAAAABMc/XccldTW4ZaM/s1600-h/ui%25255B4%25255D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ui" border="0" alt="ui" src="http://lh4.ggpht.com/-LWknwKnEo5k/TnZWdDZNDXI/AAAAAAAABMg/midxeuuo_GQ/ui_thumb%25255B2%25255D.png?imgmax=800" width="640" height="360" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h3&gt;Creating The Project and Punching in some code&lt;/h3&gt;  &lt;p&gt;Time for some action. Let us fire up Visual Studio 2011, and create a new C#/XAML Metro application. Name it HelloTiles.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-XrSKNkSrncU/TnZWeMR6JgI/AAAAAAAABMk/hV4Zv8gYHY4/s1600-h/image%25255B4%25255D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-ipMvekOuhMk/TnZWfckPPbI/AAAAAAAABMo/wZEq-urkWcw/image_thumb%25255B2%25255D.png?imgmax=800" width="640" height="411" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The project will get created, and you’ll find the App.xaml and MainPage.xaml files in the Project explorer. This should not surprise you if you have worked with Silverlight/WPF projects earlier. How ever, &lt;a href="http://www.amazedsaint.com/2011/09/developing-for-winrt-and-windows8-basic.html" target="_blank"&gt;as I mentioned in my earlier article&lt;/a&gt; remember that the Xaml libraries are now directly part of WinRT and no longer run on top of the CLR, so most of the Xaml controls and types are now moved under Windows.UI* namespaces.&lt;/p&gt;  &lt;p&gt;Along with the Xaml files, you’ll also find&amp;#160; a Package.appxmanifest file. Open that and change the “Initial Rotation” to Landscape. Also, specify a suitable image for the wide logo so that the notification display will work correctly (by default it is not there, add a new image of the specified dimension to the images, and pick it against the wide logo field).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-Lr6KgqC-gik/TnZWgTYOI6I/AAAAAAAABMs/eO2Supxj9Q4/s1600-h/image%25255B10%25255D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-V4g_2X9YtZA/TnZWhii3LbI/AAAAAAAABMw/jzAYcZ93FHY/image_thumb%25255B6%25255D.png?imgmax=800" width="642" height="443" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now, let us write some code.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;1 – The UI Code&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The UI code is very minimal, let us open MainPage.xaml and replace the Xaml code there with this. Basically, we have a very simple stack panel, and a text box and a button.&lt;/p&gt;  &lt;pre class="xml" name="code"&gt;  &amp;lt;UserControl x:Class=&amp;quot;HelloTiles.MainPage&amp;quot;
    xmlns=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;
    xmlns:x=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;
    xmlns:d=&amp;quot;http://schemas.microsoft.com/expression/blend/2008&amp;quot;
    xmlns:mc=&amp;quot;http://schemas.openxmlformats.org/markup-compatibility/2006&amp;quot;
    mc:Ignorable=&amp;quot;d&amp;quot;
    d:DesignHeight=&amp;quot;768&amp;quot; d:DesignWidth=&amp;quot;1366&amp;quot;&amp;gt;
    
    &amp;lt;StackPanel HorizontalAlignment=&amp;quot;Center&amp;quot;  VerticalAlignment=&amp;quot;Center&amp;quot; x:Name=&amp;quot;LayoutRoot&amp;quot; &amp;gt;
        &amp;lt;TextBlock Text=&amp;quot;Tile Notifier&amp;quot; FontSize=&amp;quot;100&amp;quot; VerticalAlignment=&amp;quot;Center&amp;quot;/&amp;gt;
        &amp;lt;StackPanel Orientation=&amp;quot;Vertical&amp;quot; Margin=&amp;quot;20&amp;quot; &amp;gt;
            &amp;lt;TextBox Text=&amp;quot;Message to send&amp;quot; Name=&amp;quot;txtMain&amp;quot; Width=&amp;quot;500&amp;quot; VerticalAlignment=&amp;quot;Center&amp;quot; Margin=&amp;quot;2&amp;quot;/&amp;gt;
        &amp;lt;Button Content=&amp;quot;Send Notification&amp;quot; Click=&amp;quot;Button_Click&amp;quot; HorizontalAlignment=&amp;quot;Center&amp;quot;/&amp;gt;
        &amp;lt;/StackPanel&amp;gt;
    &amp;lt;/StackPanel&amp;gt;
        
&amp;lt;/UserControl&amp;gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;2 – Code behind for sending notifications&lt;/strong&gt;&lt;/p&gt;
Now, let us send the notification to the tile when ever the user clicks the button. See that we already have a Button_Click event handler as part of the XAML, so now let us add some meat behind. Open Manpage.xaml.cs, and add the button handler, and the ClearTileNotification and SendTileNotification methods there. I had a look at the Javascript example, and almost did a quick line by line translation. Remember, we are accessing WinRT types and methods from here as well as from Javascript, so it was very easy. 

&lt;pre class="c#" name="code"&gt; using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.UI.Notifications;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;

namespace HelloTiles
{
    partial class MainPage
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            ClearTileNotification();
            SendTileTextNotification(this.txtMain.Text,30);
        }

        void ClearTileNotification()
        {
            // the same TileUpdateManager can be used to clear the tile since 
            // tile notifications are being sent to the application's default tile
            TileUpdateManager.CreateTileUpdaterForApplication().Clear();            
        }

        void SendTileTextNotification(string text, int secondsExpire)
        {
            // Get a filled in version of the template by using getTemplateContent
            var tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWideText03);

            // You will need to look at the template documentation to know how many text fields a particular template has       

            // get the text attributes for this template and fill them in
            var tileAttributes = tileXml.GetElementsByTagName(&amp;amp;quot;text&amp;amp;quot;);
            tileAttributes[0].AppendChild(tileXml.CreateTextNode(text));

            // create the notification from the XML
            var tileNotification = new TileNotification(tileXml);

            // send the notification to the app's default tile
            TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);
        }
    }
}
&lt;/pre&gt;

&lt;p&gt;The app is pretty simple, what we are doing is, &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Getting the Tile Template type by calling GetTemplateContent as an Xml document &lt;/li&gt;

  &lt;li&gt;Modify the text in the Xml &lt;/li&gt;

  &lt;li&gt;Create a tile notification using that Xml &lt;/li&gt;

  &lt;li&gt;Sending that to the Tile. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As I mentioned in the above step, make sure you are setting a valid logo for the Wide logo, and changing the initial rotation to Landscape. For available tile formats, you can refer the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.notifications.tiletemplatetype(v=VS.85).aspx" target="_blank"&gt;Tile schema&lt;/a&gt; if you are interested to see the available tile templates and how they look like.&lt;/p&gt;

&lt;p&gt;Run the application, enter something in the textbox, and click the button. Now, hit your Win key and go to the Start screen, you should see the notification there. Ensure that your tile is in landscape mode, you can right click a tile to modify it’s properties or to un-install the application. Happy Coding!!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22141639-2283078957350087240?l=www.amazedsaint.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/QQvVoiuCtyaqYEoT8WQlDqWIoP8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/QQvVoiuCtyaqYEoT8WQlDqWIoP8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/QQvVoiuCtyaqYEoT8WQlDqWIoP8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/QQvVoiuCtyaqYEoT8WQlDqWIoP8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=kFfAIgWXh48:pnKXzaKaGu4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=kFfAIgWXh48:pnKXzaKaGu4:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=kFfAIgWXh48:pnKXzaKaGu4:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=kFfAIgWXh48:pnKXzaKaGu4:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=kFfAIgWXh48:pnKXzaKaGu4:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=kFfAIgWXh48:pnKXzaKaGu4:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=kFfAIgWXh48:pnKXzaKaGu4:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=kFfAIgWXh48:pnKXzaKaGu4:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=kFfAIgWXh48:pnKXzaKaGu4:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/amazedsaint/articles/~4/kFfAIgWXh48" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/amazedsaint/articles/~3/kFfAIgWXh48/hellotiles-simple-c-xaml-application.html</link><author>noreply@blogger.com (Anoop Madhusudanan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/-b-IaYE9UmqY/TnZWZaWQJcI/AAAAAAAABMQ/iQmBeY1PDMU/s72-c/image_thumb%25255B9%25255D.png?imgmax=800" height="72" width="72" /><feedburner:origLink>http://www.amazedsaint.com/2011/09/hellotiles-simple-c-xaml-application.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-22141639.post-2954140684720832891</guid><pubDate>Sun, 18 Sep 2011 18:53:00 +0000</pubDate><atom:updated>2011-09-19T00:30:53.925+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">winrt</category><category domain="http://www.blogger.com/atom/ns#">windows8</category><title>Developing for WinRT and Windows8 – Basic Concepts</title><description>&lt;p&gt;&lt;a href="http://lh5.ggpht.com/-ZSPGbhTQ8Ko/TnY-LapNapI/AAAAAAAABL8/xv3LnUOt69s/s1600-h/image%25255B3%25255D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="image" border="0" alt="image" align="right" src="http://lh4.ggpht.com/-tcaOuXjCYgY/TnY-MtKzpQI/AAAAAAAABMA/sCEjGKHyQgk/image_thumb%25255B1%25255D.png?imgmax=800" width="128" height="240" /&gt;&lt;/a&gt; I gave a bullet point overview about Build conference &lt;a href="http://www.amazedsaint.com/2011/09/buildwindows-8-thoughts.html" target="_blank"&gt;here&lt;/a&gt; in my last past. If you havn’t yet got Windows 8 Dev Preview up and running, &lt;a href="http://dev.windows.com/" target="_blank"&gt;go grab it here&lt;/a&gt;. There are several ways to get up and running with Windows 8.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.hanselman.com/blog/GuideToInstallingAndBootingWindows8DeveloperPreviewOffAVHDVirtualHardDisk.aspx" target="_blank"&gt;Scott’s guide about installing and booting from a VHD&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.pcworld.com/article/240117/how_to_download_and_install_windows_8_into_a_virtual_machine.html" target="_blank"&gt;Installing and booting from a Virtual Machine&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;In my case, I downloaded the ISO image of Developer preview with tools (the 4+ GB One), Extracted it to a USB drive and made the USB drive bootable, Booted from that and then installed Windows 8 on a Local HD Partition in my home machine. Now, it is dual bootable, Windows 8 and Windows 7, and all is well. &lt;/p&gt;  &lt;p&gt;Let us get in to the business. Windows 8 comes with WinRT, a new object oriented native/unmanaged API for developing ‘Metro’ applications for Windows. WinRT APIs are expected to replace the Win32 APIs. WinRT projects types using meta data, and is fully object oriented, so you can access WinRT directly from managed languages like C#. Here are a couple of interesting reads about WinRT.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.infoq.com/news/2011/09/WinRT-API" target="_blank"&gt;InfoQ Article on WinRT&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://tirania.org/blog/archive/2011/Sep-15.html" target="_blank"&gt;WinRT Demystified&lt;/a&gt; from Miguel.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;WinRT is going to the ‘the runtime’ for Windows, across multiple devices like PCs, Tablets etc. You can develop Windows Metro style applications on top of WinRT in&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-EZ0ZKFk7Jw8/TnY_N3DnSZI/AAAAAAAABME/zHwynqjJ_4M/s1600-h/image%25255B9%25255D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-Cclfs7gozwo/TnY_PTO8DzI/AAAAAAAABMI/bwH64l3EJDE/image_thumb%25255B5%25255D.png?imgmax=800" width="640" height="412" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;1 - C#/VB.NET and Xaml&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;ul&gt;     &lt;li&gt;Xaml libraries with WinRT are now re-written in C++, and don’t have any .NET dependencies&lt;/li&gt;      &lt;li&gt;WinRT XAML is a subset of the earlier XAML libraries that was available with .NET, and doesn’t support some features like DataTriggers etc as of now&lt;/li&gt;      &lt;li&gt;Presently, you can access only a subset of the .NET BCL/Runtime from your C#/VB.NET + XAML WinRT application. &lt;/li&gt;      &lt;ul&gt;       &lt;li&gt;This doesn’t even support .NET Client Profile, it is just .NET core profile with access to a minimum set of .NET namespaces, combined with XAML namespaces now in Windows.UI. &lt;/li&gt;        &lt;li&gt;The entire CLR will be loaded at the time of execution, but you’ll be able to access only a subset of that. As simple as that. This is to ensure that you are running in a sandboxed environment, and CLR comes into play as a thin layer only for binding your calls to WinRT at run time. As WinRT is object oriented and has managed data, you are any way developing directly against WinRT&lt;/li&gt;     &lt;/ul&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;2 - C++ and XAML&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;ul&gt;     &lt;li&gt;If you are developing in C++ and XAML, your code will be compiled directly to an unmanaged library.&lt;/li&gt;      &lt;li&gt;I assume this provides the maximum performance advantage, as your code is directly compiled to native code.&lt;/li&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;3 - Javascript + HTML5&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;ul&gt;     &lt;li&gt;From Javascript, you can call WinRT methods directly and in that sense it is native. The UI is rendered in HTML5. If your application is a Javascript + HTML5 application, it will be run in a ‘shell’ which uses the same rendering engine in IE10.&lt;/li&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;p&gt;You may continue to develop .NET/C#/Silverlight applications for classic desktop scenarios, but if you need to develop Metro applications, then you have to develop against WinRT. &lt;/p&gt;  &lt;p&gt;Other than the XAML UI services, Win RT also Provides APIs for&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Communication – Sockets, Streams and all&lt;/li&gt;    &lt;li&gt;Devices – Geolocation, Sensors, Near Field Communication etc&lt;/li&gt;    &lt;li&gt;Media – Playback, Capture, Effects&lt;/li&gt;    &lt;li&gt;Other OS Services – Application services, Threading, Memory Management, Authentication etc.&lt;/li&gt; &lt;/ul&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22141639-2954140684720832891?l=www.amazedsaint.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/OZLwQDsCGGO7jcOu_rB2bO-6x78/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/OZLwQDsCGGO7jcOu_rB2bO-6x78/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/OZLwQDsCGGO7jcOu_rB2bO-6x78/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/OZLwQDsCGGO7jcOu_rB2bO-6x78/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=AJkkkMxyhUo:oovlC8KxOXY:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=AJkkkMxyhUo:oovlC8KxOXY:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=AJkkkMxyhUo:oovlC8KxOXY:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=AJkkkMxyhUo:oovlC8KxOXY:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=AJkkkMxyhUo:oovlC8KxOXY:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=AJkkkMxyhUo:oovlC8KxOXY:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=AJkkkMxyhUo:oovlC8KxOXY:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=AJkkkMxyhUo:oovlC8KxOXY:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=AJkkkMxyhUo:oovlC8KxOXY:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/amazedsaint/articles/~4/AJkkkMxyhUo" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/amazedsaint/articles/~3/AJkkkMxyhUo/developing-for-winrt-and-windows8-basic.html</link><author>noreply@blogger.com (Anoop Madhusudanan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/-tcaOuXjCYgY/TnY-MtKzpQI/AAAAAAAABMA/sCEjGKHyQgk/s72-c/image_thumb%25255B1%25255D.png?imgmax=800" height="72" width="72" /><feedburner:origLink>http://www.amazedsaint.com/2011/09/developing-for-winrt-and-windows8-basic.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-22141639.post-2129232949533018689</guid><pubDate>Tue, 13 Sep 2011 19:31:00 +0000</pubDate><atom:updated>2011-09-14T01:07:55.130+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Javascript</category><category domain="http://www.blogger.com/atom/ns#">Software Development</category><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">HTML5</category><category domain="http://www.blogger.com/atom/ns#">windows8</category><title>//Build/–Windows 8 Thoughts</title><description>&lt;p&gt;Game on. After going through the Day 1 keynote for the Build event, I should say I’m pretty much convinced that Microsoft has got the equation correct. They corrected the Tablet part of the equation, and got the entire Cloud &amp;lt;-&amp;gt; Tablet stack in place, with proper platforms and a nice set of developer tools. And with out doubt, Windows 8 devices are going to be a definite competitor for iPad/iOS, and Microsoft has officially entered the post PC era.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-K_KmppUkkY0/Tm-vgHeAnhI/AAAAAAAABL0/RHfaYk8JRH4/s1600-h/image%25255B4%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-oajX827J_SQ/Tm-vhj7HqxI/AAAAAAAABL4/QXat3o58s14/image_thumb%25255B2%25255D.png?imgmax=800" width="633" height="376" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Here are few quick observations, mainly on the developer side.&lt;/p&gt;  &lt;h3&gt;About Metro UI&lt;/h3&gt;  &lt;ul&gt;   &lt;ul&gt;     &lt;li&gt;Metro applications are now officially the first class applications that&amp;#160; can fully leverages the touch features of Windows 8. &lt;/li&gt;      &lt;li&gt;The new start screen looks very refreshing, with dynamic tiles.&lt;/li&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;h3&gt;For Developers&lt;/h3&gt;  &lt;ul&gt;   &lt;ul&gt;     &lt;li&gt;Develop application in HTML5&amp;lt;-&amp;gt;JS&amp;lt;-&amp;gt;WinRT or XAML&amp;lt;-&amp;gt;.NET&amp;lt;-&amp;gt;WinRT&lt;/li&gt;      &lt;ul&gt;       &lt;li&gt;You can develop native Windows applications either using Javascript and HTML or using .NET and XAML. This also means, ability to access native WinRT APIs straight from Java script. &lt;/li&gt;        &lt;li&gt;This is particularly interesting because Javascript development model suits a lot of cloud based applications, and now JS developers can develop first class Windows 8 applications.&lt;/li&gt;     &lt;/ul&gt;      &lt;li&gt;Visual Studio vNext, .NET 4.5&lt;/li&gt;      &lt;li&gt;IE10 Engine powers the JS/HTML5 Apps&lt;/li&gt;      &lt;li&gt;A lot of asynchronous programming everywhere&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt; Expression Blend 5 now supports editing HTML5, much like you use it for editing XAML.&lt;/li&gt;    &lt;li&gt;To a great extent, your XAML assets can be reused across multiple devices – desktops, slates and phone.&lt;/li&gt;    &lt;li&gt;Windows 8 Store&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;Transparent approval proces&lt;/li&gt;      &lt;li&gt;Developers can publish applications right from Visual Studio.&lt;/li&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;h3&gt;New APIs and Extension Points&lt;/h3&gt;  &lt;ul&gt;   &lt;ul&gt;     &lt;li&gt; Charms&lt;/li&gt;      &lt;ul&gt;       &lt;li&gt;Apps can share charms, to inter-operate. For example, an “Insert Picture” dialog box can show you results from other applications that can handle the image/picture data type. &lt;/li&gt;     &lt;/ul&gt;      &lt;li&gt;Direct Compute API&lt;/li&gt;      &lt;ul&gt;       &lt;li&gt;Enables you to leverage the power of GPU in your applications&lt;/li&gt;     &lt;/ul&gt;      &lt;li&gt;Sensor Fusion API&lt;/li&gt;      &lt;ul&gt;       &lt;li&gt;A Single API for all your sensors like Accelerometer, magnetometer and gyroscope&lt;/li&gt;     &lt;/ul&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;h3&gt;Windows Live integration&lt;/h3&gt;  &lt;ul&gt;   &lt;ul&gt;     &lt;li&gt;The whole suite of Windows Live services are neatly integrated to Windows 8. &lt;/li&gt;      &lt;li&gt;All these Windows Live applications (Mail, Calendar, Photos) are now developed in Javascript/HTML5 and is native.&lt;/li&gt;      &lt;li&gt;You can connect multiple devices via Windows Live &lt;/li&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;h3&gt;Support for Wide Variety of Hardware&lt;/h3&gt;  &lt;ul&gt;   &lt;ul&gt;     &lt;li&gt;The hardware support for Windows 8 seems really awesome. The demos features Windows 8 running on a variety of hardware devices&lt;/li&gt;      &lt;li&gt;New and improved features include&lt;/li&gt;      &lt;ul&gt;       &lt;li&gt;Multi monitor support with start button on all screens&lt;/li&gt;        &lt;li&gt;Hyper V Support for client&lt;/li&gt;        &lt;li&gt;USB 3 Support&lt;/li&gt;        &lt;li&gt;Hardware acceleration for all applications&lt;/li&gt;        &lt;li&gt;Malware detection in boot strapper&lt;/li&gt;        &lt;li&gt;A boot mode called “Cold Boot“ which is super fast&lt;/li&gt;     &lt;/ul&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;p&gt;You can download Windows 8 Developer Release and related development tools from &lt;a href="http://msdn.microsoft.com/en-us/windows/home/"&gt;http://msdn.microsoft.com/en-us/windows/home/&lt;/a&gt; by 8 PM PST. Enjoy, happy coding!!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22141639-2129232949533018689?l=www.amazedsaint.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/zxy299quodGuFiT0V_ao6uozS5M/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zxy299quodGuFiT0V_ao6uozS5M/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/zxy299quodGuFiT0V_ao6uozS5M/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zxy299quodGuFiT0V_ao6uozS5M/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=Pu08qHn8YdQ:xxupdC14Cno:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=Pu08qHn8YdQ:xxupdC14Cno:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=Pu08qHn8YdQ:xxupdC14Cno:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=Pu08qHn8YdQ:xxupdC14Cno:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=Pu08qHn8YdQ:xxupdC14Cno:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=Pu08qHn8YdQ:xxupdC14Cno:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=Pu08qHn8YdQ:xxupdC14Cno:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=Pu08qHn8YdQ:xxupdC14Cno:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=Pu08qHn8YdQ:xxupdC14Cno:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/amazedsaint/articles/~4/Pu08qHn8YdQ" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/amazedsaint/articles/~3/Pu08qHn8YdQ/buildwindows-8-thoughts.html</link><author>noreply@blogger.com (Anoop Madhusudanan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/-oajX827J_SQ/Tm-vhj7HqxI/AAAAAAAABL4/QXat3o58s14/s72-c/image_thumb%25255B2%25255D.png?imgmax=800" height="72" width="72" /><feedburner:origLink>http://www.amazedsaint.com/2011/09/buildwindows-8-thoughts.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-22141639.post-1654793351760959482</guid><pubDate>Thu, 01 Sep 2011 12:16:00 +0000</pubDate><atom:updated>2011-09-01T17:57:53.803+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Javascript</category><category domain="http://www.blogger.com/atom/ns#">node</category><category domain="http://www.blogger.com/atom/ns#">Design And Architecture</category><category domain="http://www.blogger.com/atom/ns#">HTML5</category><category domain="http://www.blogger.com/atom/ns#">asp.net</category><title>Creating a quick Todo listing app on Windows using IIS7, Node.js and Mongodb</title><description>&lt;p&gt;As I mentioned in my last post, more and more organizations &lt;a href="http://www.amazedsaint.com/2011/08/woa-is-here-to-stay-and-why-new-wcf.html"&gt;are leaning towards Web Oriented Architecture (WOA)&lt;/a&gt; which are highly scalable. If you were exploring cool, scalable options to build highly performing web applications, you know what &lt;a href="http://nodejs.org/"&gt;Node.js&lt;/a&gt; is for.&lt;/p&gt;  &lt;p&gt;After following &lt;a href="http://www.hanselman.com/blog/InstallingAndRunningNodejsApplicationsWithinIISOnWindowsAreYouMad.aspx"&gt;the recent post from Scott Hanselman&lt;/a&gt;, I was up and running quickly with Node.js. In this post, I’ll explain step by step how I’ve setup Node.js and Mongodb to create a simple Todo listing application.&lt;/p&gt;  &lt;h2&gt;Setting up Node.js&lt;/h2&gt;  &lt;p&gt;This is what I’ve done.&lt;/p&gt;  &lt;p&gt;1 – Goto &lt;a href="http://nodejs.org/"&gt;http://nodejs.org/&lt;/a&gt;, scroll down and download &lt;strong&gt;node.exe&lt;/strong&gt; for Windows, and place it in your &lt;strong&gt;c:\node&lt;/strong&gt; folder&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-U6qVlirgOYc/Tl93OpXG9wI/AAAAAAAABKU/Mfv8bM_0YHc/s1600-h/image12.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-sWBCM-iwiUs/Tl93P_zSADI/AAAAAAAABKY/BNKKIELl2T8/image_thumb6.png?imgmax=800" width="640" height="403" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;2 – Goto IIS Node project in Git at &lt;a href="https://github.com/tjanczuk/iisnode"&gt;https://github.com/tjanczuk/iisnode&lt;/a&gt;, download the correct ‘retail’ link of IIS Node zip file (I downloaded the already built retail package, otherwise you can download and build from the source).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-pLqpyMh-C84/Tl93RLIgDsI/AAAAAAAABKc/YbKqaOI4Zxc/s1600-h/image17.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-wbCrrH5wGaE/Tl93SSpq03I/AAAAAAAABKg/QwXXIScG2Ds/image_thumb9.png?imgmax=800" width="640" height="403" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;3 – Extract the zip file some where, and run the install.bat or install_iisexpress.bat depending on your IIS Version. If you don’t have IIS installed, try installing IIS 7.5 express &lt;a href="http://www.microsoft.com/download/en/details.aspx?id=1038"&gt;here from MS download center&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-DBHR93baVlw/Tl93Tlc-OkI/AAAAAAAABKk/9faTDoK20DM/s1600-h/image24.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-6uYN0ELZP8s/Tl93VPeuX-I/AAAAAAAABKo/G70-L_O42EI/image_thumb12.png?imgmax=800" width="644" height="454" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;4 – Make sure you have IIS URL rewrite module installed, so that some node.js samples with URL rewriting will work correctly. &lt;a href="http://www.iis.net/download/urlrewrite"&gt;Install URL Rewrite module&lt;/a&gt; if you don’t have it, and restart IIS.&lt;/p&gt;  &lt;h2&gt;Verifying that all is well&lt;/h2&gt;  &lt;p&gt;Once Step 3 is over, this will configure the required modules and virtual directories, and you should be able to access the node virtual directory at &lt;a href="http://localhost/node"&gt;http://localhost/node&lt;/a&gt; – which points to the www folder where you extracted the iisnode zip file.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-auAsyu2kPHY/Tl93WZDweFI/AAAAAAAABKs/ggO0FPVxvUE/s1600-h/image28.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-y2EDtGy4yMg/Tl93X6lqtgI/AAAAAAAABKw/Z4yi2sa0Bd0/image_thumb14.png?imgmax=800" width="644" height="437" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now, go to the end point &lt;a href="http://localhost/node/helloworld/hello.js"&gt;http://localhost/node/helloworld/hello.js&lt;/a&gt; and see if everything works well. You can also open the hello.js file in the corresponding www\helloworld\ folder to have a look at the node hello world code.&lt;/p&gt;  &lt;pre class="js" name="code"&gt;var http = require('http');

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello, world! [helloworld sample]');
}).listen(process.env.PORT);  &lt;/pre&gt;

&lt;p&gt;&lt;a href="http://lh3.ggpht.com/-Z6qvLCRDtlA/Tl93YyUcBYI/AAAAAAAABK0/_zbTXNrUA9E/s1600-h/image38.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-OHBWYKMfEgo/Tl93acpomDI/AAAAAAAABK4/QXoTeOpT-OQ/image_thumb20.png?imgmax=800" width="599" height="499" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So as we’ve Node.js up and running, let us create a quick Todo listing application using Node.js and Mongodb by modifying this helloworld application.&lt;/p&gt;

&lt;h2&gt;Setting up Mongodb&lt;/h2&gt;

&lt;p&gt;Mongodb is a scalable, high performance, document database that goes well with node.js. See &lt;a href="http://mongodb.org"&gt;http://mongodb.org&lt;/a&gt; for more. In Mongodb, records are stored as JSON style &lt;strong&gt;documents&lt;/strong&gt;, and documents are stored in &lt;strong&gt;collections&lt;/strong&gt;. For now, consider that a collection is the NoSQL equivalent of a table, and a document is the NoSQL equivalent of a record.&lt;/p&gt;

&lt;p&gt;1- First of all, you may need to install Mongodb. Goto &lt;a href="http://www.mongodb.org/downloads"&gt;http://www.mongodb.org/downloads&lt;/a&gt;, download the correct zip package, and extract it. &lt;/p&gt;

&lt;p&gt;2- Create a folder &lt;strong&gt;‘data’&lt;/strong&gt; in the path where you extracted Mongodb zip file. See the data folder.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh4.ggpht.com/-HIpE0OHSEPY/Tl93bUq_cpI/AAAAAAAABK8/7oghNTmUa2g/s1600-h/image43.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-4m3D-3BBQb8/Tl93cY8gdvI/AAAAAAAABLA/ODblPc-9L4w/image_thumb23.png?imgmax=800" width="590" height="295" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3- Now, you should start mongod process. So, open command prompt, CD the folder where you extracted Mongodb, and start Mongod with &lt;em&gt;data&lt;/em&gt; as the db folder using the command &lt;strong&gt;mongod –dbpath data &lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;4- You should see the mongod process running, as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh6.ggpht.com/-4UBsb7ZXFbQ/Tl93dSRRmoI/AAAAAAAABLE/_YwPWhDZGDQ/s1600-h/image48.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-5Vl-biyG4Lc/Tl93ei92nRI/AAAAAAAABLI/49C_a8TVuIA/image_thumb26.png?imgmax=800" width="681" height="322" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;5- Now, let us insert few records to the todo collection of the database. For that, fire up &lt;strong&gt;mongo.exe&lt;/strong&gt; client from the folder where you extracted the mongo db zip file, and insert few documents to the todo collection as shown below. Please note that&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh4.ggpht.com/-KDJlkrxodA8/Tl93fTqDdaI/AAAAAAAABLM/jm7JY32zcps/s1600-h/image52.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-VRoOblt8p5Q/Tl93gouZRvI/AAAAAAAABLQ/LZqJe1Are_k/image_thumb28.png?imgmax=800" width="681" height="226" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, we have Mongodb running now, with a collection named todo with few documents in it.&lt;/p&gt;

&lt;h2&gt;Setting up Mongodb Module for Node.js&lt;/h2&gt;

&lt;p&gt;Normally, setting up packages/modules for Node.js is quite easy, it can be done using the Node package manager &lt;a href="http://npmjs.org"&gt;http://npmjs.org&lt;/a&gt; – How ever, I don’t think an NPM port is available for Windows right now. So, let us configure the Mongodb driver for Node.js manually.&lt;/p&gt;

&lt;p&gt;1 – Goto &lt;a href="https://github.com/christkv/node-mongodb-native"&gt;https://github.com/christkv/node-mongodb-native&lt;/a&gt; and get the zip package. I downloaded v0.9.3 package, and extract it.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh4.ggpht.com/-W4P9ddfeVsg/Tl93hgj2L1I/AAAAAAAABLU/sOYK-hwJY0A/s1600-h/image56.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-T5pw26uQuF0/Tl93igRCnjI/AAAAAAAABLY/O3qToYTAktM/image_thumb30.png?imgmax=800" width="638" height="405" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2 – Goto the&amp;#160; &lt;strong&gt;www\helloworld&lt;/strong&gt; folder where you examined hello.js earlier. Now, create a folder &lt;strong&gt;node_modules&lt;/strong&gt; under the helloworld folder and create the &lt;strong&gt;mongodb&lt;/strong&gt; folder under this, and copy the contents of the package to the &lt;strong&gt;mongodb&lt;/strong&gt; folder as shown below. It seems that the folder name under &lt;strong&gt;node_modules&lt;/strong&gt; should match the package name defined in index.js.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh6.ggpht.com/-iDJB9xlAMfQ/Tl93j6SbJnI/AAAAAAAABLc/rPE8O3P7uUI/s1600-h/image60.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-LtYwqe07xM0/Tl93k7bKakI/AAAAAAAABLg/x0Nf9ZaYNsA/image_thumb32.png?imgmax=800" width="590" height="424" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h2&gt;Now let us write some code&lt;/h2&gt;

&lt;p&gt;Once you are through with installing Node.js, Mongodb and Mongodb module for Node.js, it is time to write some code. Fire up the hello.js file in the helloworld folder, and write some code to fetch the todo collection from Mongodb and return it as HTML.&lt;/p&gt;

&lt;pre class="javascript" name="code"&gt;GLOBAL.DEBUG = true;

//Load modules
var http = require('http');
var mongo = require('mongodb');
var sys = require(&amp;quot;sys&amp;quot;);
var test = require(&amp;quot;assert&amp;quot;);

var Db = require('mongodb').Db, Connection = require('mongodb').Connection,
  Server = require('mongodb').Server,
  BSON = require('mongodb').BSONNative;

//Default server and port
var host = process.env['MONGO_NODE_DRIVER_HOST'] != null ? 
			process.env['MONGO_NODE_DRIVER_HOST'] : 'localhost';
var port = process.env['MONGO_NODE_DRIVER_PORT'] != null ? 
			process.env['MONGO_NODE_DRIVER_PORT'] : Connection.DEFAULT_PORT;

sys.puts(&amp;quot;Connecting to &amp;quot; + host + &amp;quot;:&amp;quot; + port);


http.createServer(function (req, res) {

//Client connected
	res.writeHead(200, {'Content-Type': 'text/html'});    	
	res.write('&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;Todo List&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;');
	res.write('&amp;lt;body&amp;gt;');
	res.write('&amp;lt;h1&amp;gt;Todo list&amp;lt;/h1&amp;gt;');
        var db = new Db('test', new Server(host, port, {}), {native_parser:false});
	db.open(function(err, db) {
	db.collection('todo', function(err, collection) {
	collection.find(function (err, cursor){
		res.write('&amp;lt;ul&amp;gt;');
		cursor.each( function (err, item) {                                   
				if (item == null) {
						res.write('&amp;lt;/ul&amp;gt;');
						res.end('&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;');
						 db.close();
						}
				else 
				 res.write('&amp;lt;li&amp;gt;' + item.title + '&amp;lt;/li&amp;gt;');
		});
	});
	});

	});	
}).listen(process.env.PORT);   &lt;/pre&gt;

&lt;p&gt;You may find that we are opening the database, and iterating through the collection and creating a list out of that and spitting out the html. This should work as long as you followed the steps I briefed above. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh5.ggpht.com/-_CnU_9ea7dA/Tl93mNtpPMI/AAAAAAAABLk/q5dO70SiBNY/s1600-h/image%25255B4%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-vTos9KMkLrA/Tl93nEvtgSI/AAAAAAAABLo/kZA7B6vIk9Q/image_thumb%25255B2%25255D.png?imgmax=800" width="638" height="504" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And yes, you just opened the Pandora’s box – start playing with various Node.js modules and samples on your Windows box. Follow some Node.js tutorials, and experiment further. It is important to note that the Node.js port for Windows is not yet perfect from a production point of view, but now Windows developers have a good way to start exploring options related to node.js and related modules. &lt;/p&gt;

&lt;p&gt;And follow me in twitter @ &lt;a href="http://twitter.com/amazedsaint"&gt;http://twitter.com/amazedsaint&lt;/a&gt; for further updates, Keep in touch. Happy Coding!!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22141639-1654793351760959482?l=www.amazedsaint.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/j4zZP3e4miCfHJcOTPZasFhO0ew/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/j4zZP3e4miCfHJcOTPZasFhO0ew/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/j4zZP3e4miCfHJcOTPZasFhO0ew/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/j4zZP3e4miCfHJcOTPZasFhO0ew/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=8JTFE1v7c70:YUnePlXRY10:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=8JTFE1v7c70:YUnePlXRY10:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=8JTFE1v7c70:YUnePlXRY10:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=8JTFE1v7c70:YUnePlXRY10:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=8JTFE1v7c70:YUnePlXRY10:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=8JTFE1v7c70:YUnePlXRY10:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=8JTFE1v7c70:YUnePlXRY10:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=8JTFE1v7c70:YUnePlXRY10:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=8JTFE1v7c70:YUnePlXRY10:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/amazedsaint/articles/~4/8JTFE1v7c70" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/amazedsaint/articles/~3/8JTFE1v7c70/creating-10-minute-todo-listing-app-on.html</link><author>noreply@blogger.com (Anoop Madhusudanan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/-sWBCM-iwiUs/Tl93P_zSADI/AAAAAAAABKY/BNKKIELl2T8/s72-c/image_thumb6.png?imgmax=800" height="72" width="72" /><feedburner:origLink>http://www.amazedsaint.com/2011/09/creating-10-minute-todo-listing-app-on.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-22141639.post-6877307344323683596</guid><pubDate>Wed, 31 Aug 2011 17:15:00 +0000</pubDate><atom:updated>2011-09-01T11:43:05.464+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Software Development</category><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">Design And Architecture</category><category domain="http://www.blogger.com/atom/ns#">WCF</category><title>Web Oriented Architecture is here to Stay, and Why Microsoft’s new WCF Stack is interesting.</title><description>&lt;p&gt;For the last few months, I was working closely with few customers across domains including telecom, e-learning, health care etc.. There are few recurring themes I’ve observed across the line, and I think some of them are realistic indicators regarding the adoption of WOA in the mainstream. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-uAOnEQ0aZ-w/Tl5sGKUr_OI/AAAAAAAABKM/fkmZ1WGHL4w/s1600-h/image%25255B6%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" align="right" src="http://lh4.ggpht.com/-KVtiS3fWSxw/Tl5sJRgAAsI/AAAAAAAABKQ/pSS6KJd1Wx8/image_thumb%25255B4%25255D.png?imgmax=800" width="240" height="225" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;Decision Drivers&lt;/h3&gt;  &lt;p&gt;Organizations are understanding the necessity of making their business logic and data available to multiple end points. REST is evolving more and more as a default choice for building a public service layer, around your existing data and intelligence. So, here are few common concerns for CIOs.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Generalizing Investments - How to maximize the ROI by ensuring that your features and functionalities are accessible to a variety of devices. &lt;/li&gt;    &lt;li&gt;Ensuring Governance - How to ensure a common governance scheme that encompasses all your ‘delta’ investments &lt;/li&gt;    &lt;li&gt;Ensuring Reusability - How to ensure reusability across your business investments. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;And almost all of the above concerns boil down to a strategy where you have a Web Oriented Architecture layer, and a Common Service Layer as part of that which can expose your business over Http to a range of devices. I recommend you to read this article &lt;a href="http://www.infoq.com/news/2009/06/hinchcliffe-REST-WOA"&gt;“REST Is A Style, WOA is the Architecture”&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The faster you move your investments on top of the value chain and expose your data and business to a wider range of devices, the better is your chance to survive in business.&amp;#160; To quote from this article &lt;a href="http://www.computerworld.com/s/article/9219149/Consumerization_of_IT_Lessons_for_enterprise_applications"&gt;“Consumerization of IT”&lt;/a&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;The consumerization of IT is real. &lt;a href="http://unisys.com/unisys/ri/videos/detail.jsp?id=1120000970016710180"&gt;A recent IDC survey sponsored by Unisys&lt;/a&gt; showed that 40% of devices used to access business applications are personally owned, up 10 percentage points from 2010.&lt;/p&gt; &lt;/blockquote&gt;  &lt;h3&gt;Building your WOA Stack&lt;/h3&gt;  &lt;p&gt;Now, from an architecture and development stand point, this decomposes to techniques, tools and technologies that’ll enable you to build a useful “WOA full” stack. When you start, most of the so called “REST” APIs disintegrate to mere HTTP APIs, but at least that is a start. Slowly, you can bring in purity for your design by&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Bringing in a generic WOA container that’ll enable you to deploy, monitor and manage your REST Services with zero configuration &lt;/li&gt;    &lt;li&gt;Bring in Composition, Hypermedia – so that you enrich your data also with links that represents actions that are possible on the data. &lt;/li&gt;    &lt;li&gt;Bring in subscriptions and notifications – For example, a service accepting a URL from a subscriber to trigger notification. &lt;/li&gt;    &lt;li&gt;Bring in load balancing – A per call design will enable you to bring in easy load balancing &lt;/li&gt;    &lt;li&gt;Bring in caching – If you have a Relational Database, a high performance caching layer like Redis on top of your Database will enable high scalability for your services. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The benefits you leverage out of a proper WOA stack is really straight forward to observe.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;It exposes your data and logic available to a range of devices including smart phones, tablets, IPTVs, customized browser and desktop apps , social media plugins etc. &lt;/li&gt;    &lt;li&gt;Data composed with proper hypermedia brings a high degree of abstraction, and will allow the clients to be truly decoupled (from data and operations on top of the data) &lt;/li&gt;    &lt;li&gt;Provides high degree of scalability because WOA is very light weight. &lt;/li&gt;    &lt;li&gt;Clients consuming your services are first class consumers – you don’t need proxies that require concrete data contracts. &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;The new WCF Stack from Microsoft&lt;/h3&gt;  &lt;p&gt;WCF vNext Web Apis is a promising offering from Microsoft, but the key is evolving curry frameworks and tooling on top of the new Web APIs to support address common WOA concerns. WOA is more or less a set of best practices than a well defined methodology, so I’m not sure to what extent this can be abstracted. &lt;/p&gt;  &lt;p&gt;Anyway, the new WCF APIs allows more control for sure, which includes &lt;a href="http://blogs.msdn.com/b/gblock/archive/2010/11/01/wcf-web-apis-http-your-way.aspx"&gt;first class support for HTTP and custom media types and formats&lt;/a&gt;, and I’ve seen few recent posts from Glenn Block on &lt;a href="http://blogs.msdn.com/b/gblock/archive/2011/05/09/hypermedia-and-forms.aspx"&gt;Hypermedia and Forms&lt;/a&gt; which is definitely another interesting read about the concept itself. &lt;/p&gt;  &lt;p&gt;How ever, I would like to see more provisioning extensions in the new WCF Framework – like a common container where you can deploy and manage services, scale it etc. It might be interesting to see how the new WCF Web API Stack will compare with similar light weight implementations like Node.js. Also, Microsoft is making a significant effort to bring Node.js to Windows server stack (IIS/Azure). I’ll follow up about that in next couple of posts.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22141639-6877307344323683596?l=www.amazedsaint.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/de1BMlWklg-gKUpwknm1MsL5AMY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/de1BMlWklg-gKUpwknm1MsL5AMY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/de1BMlWklg-gKUpwknm1MsL5AMY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/de1BMlWklg-gKUpwknm1MsL5AMY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=Bax1GT7Fhxc:MUiW0nu9dGw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=Bax1GT7Fhxc:MUiW0nu9dGw:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=Bax1GT7Fhxc:MUiW0nu9dGw:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=Bax1GT7Fhxc:MUiW0nu9dGw:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=Bax1GT7Fhxc:MUiW0nu9dGw:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=Bax1GT7Fhxc:MUiW0nu9dGw:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=Bax1GT7Fhxc:MUiW0nu9dGw:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=Bax1GT7Fhxc:MUiW0nu9dGw:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=Bax1GT7Fhxc:MUiW0nu9dGw:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/amazedsaint/articles/~4/Bax1GT7Fhxc" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/amazedsaint/articles/~3/Bax1GT7Fhxc/woa-is-here-to-stay-and-why-new-wcf.html</link><author>noreply@blogger.com (Anoop Madhusudanan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/-KVtiS3fWSxw/Tl5sJRgAAsI/AAAAAAAABKQ/pSS6KJd1Wx8/s72-c/image_thumb%25255B4%25255D.png?imgmax=800" height="72" width="72" /><feedburner:origLink>http://www.amazedsaint.com/2011/08/woa-is-here-to-stay-and-why-new-wcf.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-22141639.post-7790405727626009203</guid><pubDate>Sun, 24 Apr 2011 15:05:00 +0000</pubDate><atom:updated>2011-04-24T20:35:35.671+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">CSharp5</category><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">Design And Architecture</category><category domain="http://www.blogger.com/atom/ns#">Back To Basics</category><category domain="http://www.blogger.com/atom/ns#">CSharp</category><title>Revisiting C# - Published New Free Ebook</title><description>&lt;p&gt;I just collated some of my posts on C#, and published an Ebook – Revisiting C#. Have a look at the same here.&lt;/p&gt;  &lt;p&gt;This book is intended to be a value adding reading material for beginner to intermediate C# programmers. It may also be used for accelerating the learning about new and upcoming features in C#, and also to get an introduction about new libraries in .NET. You may find random articles and alternate perspectives related to various aspects of C# - ranging from delegates, lambdas, fluent interfaces, dynamic features etc. with practical examples. &lt;/p&gt; &lt;a style="margin: 12px auto 6px; display: block; font: 14px helvetica,arial,sans-serif; text-decoration: underline; font-size-adjust: none; font-stretch: normal; -x-system-font: none" title="View Revisting C# V1.0 on Scribd" href="http://www.scribd.com/doc/53728207/Revisting-C-V1-0"&gt;Revisting C# V1.0&lt;/a&gt;&lt;iframe style="height: 1499px" id="doc_38850" class="scribd_iframe_embed" height="600" src="http://www.scribd.com/embeds/53728207/content?start_page=1&amp;amp;view_mode=list&amp;amp;access_key=key-2dunzm5j6dzfaftxzzxx" frameborder="0" width="100%" scrolling="no" data-aspect-ratio="0.772727272727273" data-auto-height="true" data-auto-resized="true"&gt;&lt;/iframe&gt;&lt;script type="text/javascript"&gt;(function() { var scribd = document.createElement("script"); scribd.type = "text/javascript"; scribd.async = true; scribd.src = "http://www.scribd.com/javascripts/embed_code/inject.js"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(scribd, s); })();&lt;/script&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22141639-7790405727626009203?l=www.amazedsaint.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/hVUw-6fyVoC5tGQWCM1Az9eUZHo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hVUw-6fyVoC5tGQWCM1Az9eUZHo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/hVUw-6fyVoC5tGQWCM1Az9eUZHo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hVUw-6fyVoC5tGQWCM1Az9eUZHo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=d3zVelsNbBU:SgjaQ__aEfc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=d3zVelsNbBU:SgjaQ__aEfc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=d3zVelsNbBU:SgjaQ__aEfc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=d3zVelsNbBU:SgjaQ__aEfc:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=d3zVelsNbBU:SgjaQ__aEfc:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=d3zVelsNbBU:SgjaQ__aEfc:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=d3zVelsNbBU:SgjaQ__aEfc:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=d3zVelsNbBU:SgjaQ__aEfc:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=d3zVelsNbBU:SgjaQ__aEfc:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/amazedsaint/articles/~4/d3zVelsNbBU" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/amazedsaint/articles/~3/d3zVelsNbBU/revisiting-c-published-new-free-ebook.html</link><author>noreply@blogger.com (Anoop Madhusudanan)</author><feedburner:origLink>http://www.amazedsaint.com/2011/04/revisiting-c-published-new-free-ebook.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-22141639.post-7367465169821537912</guid><pubDate>Mon, 11 Apr 2011 08:53:00 +0000</pubDate><atom:updated>2011-04-11T14:30:08.465+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Software Development</category><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">Design And Architecture</category><category domain="http://www.blogger.com/atom/ns#">Tech Trends</category><title>5 Cool Hacks And Prototypes For .NET devs – Node.js in Azure, Kinect as Windows 7 controller, WCF web sockets, WPF over Web and more</title><description>&lt;p&gt;&lt;a href="http://lh3.ggpht.com/__Mw4iY-4nuY/TaLBcolKqaI/AAAAAAAABCM/RRkQoO2RjXU/s1600-h/image%5B3%5D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px 0px 0px 25px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" align="right" src="http://lh4.ggpht.com/__Mw4iY-4nuY/TaLBd63CsAI/AAAAAAAABCQ/Zrb9AGLN8qI/image_thumb%5B1%5D.png?imgmax=800" width="240" height="195" /&gt;&lt;/a&gt;Who won’t love adventurous, out of the box hacks and prototypes? The joy of being a developer is to experiment with hot new ideas, and to do things others haven't done yet. For a developer, a hack is a source of joy - just as a poet who finds his real joy in unleashing his creativity, than in selling the same to others.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;In modern computing terminology, a &amp;quot;&lt;b&gt;hack&lt;/b&gt;&amp;quot; is a solution to a problem, doing a task, or fixing a system (whether hardware or software) that is inefficient, inelegant, or even unfathomable, but which nevertheless (more or less) works.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Here are few super cool hacks I explored and found in the last couple of weeks. &lt;/p&gt;  &lt;h3&gt;Node.Js Running on top of Azure&lt;/h3&gt;  &lt;p&gt;Paul has experimented with Node.Js and Azure, and wrote a couple of posts on running Node.Js on &lt;a href="http://www.microsoft.com/windowsazure/"&gt;Windows Azure.&lt;/a&gt; And I got interested because &lt;a href="http://nodejs.org/"&gt;Node.js&lt;/a&gt; is among the new cool kids in the town, and looks pretty interesting &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://lh5.ggpht.com/__Mw4iY-4nuY/TaLBm8U370I/AAAAAAAABCU/ZpLPL6B2azY/wlEmoticon-smile%5B2%5D.png?imgmax=800" /&gt;.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Node.Js is an Evented I/O for &lt;a href="http://code.google.com/p/v8/"&gt;V8 JavaScript&lt;/a&gt;.&lt;/p&gt;    &lt;p&gt;An example of a web server written in Node which responds with &amp;quot;Hello World&amp;quot; for every request.&lt;/p&gt;    &lt;pre&gt;var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(8124, &amp;quot;127.0.0.1&amp;quot;);
console.log('Server running at http://127.0.0.1:8124/');&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="http://pofallon.blogspot.com/2010/11/javascript-in-cloud-with-nodejs-and.html"&gt;Have a look at the post from Paul here&lt;/a&gt;. Also watch out for this Session from Steve Marx on running Node.Js, Python, PHP etc in Azure &lt;a href="http://channel9.msdn.com/Events/MIX/MIX11/SVC04"&gt;http://channel9.msdn.com/Events/MIX/MIX11/SVC04&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;Using Kinect to control Windows 7 Apps And More Kinect hacks&lt;/h3&gt;

&lt;p&gt;Evoluce has released a video that shows leveraging Kinect for controlling the Windows 7 UI using Kinect. The hack is pretty awesome, it simulates almost all mouse movements, and to some extent, multi touch and features like that.&lt;/p&gt;
&lt;iframe title="YouTube video player" height="349" src="http://www.youtube.com/embed/2HkKcFKzorQ?rel=0" frameborder="0" width="560" allowfullscreen="allowfullscreen"&gt;&lt;/iframe&gt;

&lt;p&gt;Sounds interesting? You may also checkout &lt;a href="http://kinecthacks.net/tools-and-resources/"&gt;http://kinecthacks.net/tools-and-resources/&lt;/a&gt; to see a great list of tools and resources to start doing your own Kinect hacks. They’ve a cool list of various Kinect hacks. Also, recently there are few more interesting Kinect hacks in response to Gmail Motion Prank .&lt;/p&gt;

&lt;p&gt;You may Watch the videos of those Kinect based hacks in response to Gmail Motion prank &lt;a href="http://goo.gl/EtYcN"&gt;http://goo.gl/EtYcN&lt;/a&gt; by ICT and &lt;a href="http://goo.gl/8JC2zy"&gt;http://goo.gl/8JC2zy&lt;/a&gt; by &lt;a href="http://twitter.com/ramaprasanna"&gt;Ramaprasanna&lt;/a&gt; here&lt;/p&gt;

&lt;h3&gt;Accessing WPF windows over a Web browser using Websockets and Canvas&lt;/h3&gt;

&lt;p&gt;Let me shamelessly plugin this hack here. Over the weekend, I just put together a hack for pumping WPF windows over Websockets and rendering it using HTML5 canvas – also with basic mouse input support. For each user connecting to the server, a new window instance is created, and screen will be pumped over web sockets to the browser as base64 encoded images. These images are painted on an HTML5 canvas. Have a look at the same here&lt;/p&gt;
&lt;iframe title="YouTube video player" height="349" src="http://www.youtube.com/embed/iA4D2M-Nbzk?rel=0" frameborder="0" width="560" allowfullscreen="allowfullscreen"&gt;&lt;/iframe&gt;

&lt;p&gt;You may see that the mouse input on top of the canvas is pumped back to the server, to simulate mouse events, and the results are refreshed in the browser. &lt;a href="http://www.amazedsaint.com/2011/04/wpf-over-web-sockets-how-to-pump-wpf.html"&gt;Have a look at the post and source code here&lt;/a&gt;. &lt;/p&gt;

&lt;h3&gt;Html5 Prototypes from Microsoft Web Labs And WCF Websockets&lt;/h3&gt;

&lt;p&gt;Microsoft Html5 Web Labs has a couple of interesting prototypes around HTML5 Draft Specifications. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;IndexedDB&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;IndexedDB is a draft Web specification for the storage of large amounts of structured data in the browser.&amp;#160; &lt;a href="http://html5labs.interoperabilitybridges.com/prototypes/available-for-download/indexeddb"&gt;View details.&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;The IndexedDB API is currently being standardized by the &lt;a href="http://www.w3.org/2008/webapps/"&gt;W3C Web Applications Working Group&lt;/a&gt;. IndexedDB can be used for browser implemented functions like bookmarks, and as a client-side cache for web applications such as email.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;WebSockets&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;WebSockets simplifies bi-directional, full-duplex communications channels, over a single TCP socket. &lt;a href="http://html5labs.interoperabilitybridges.com/prototypes/available-for-download/websockets"&gt;View details.&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;WebSockets&lt;/strong&gt; is a technology designed to simplify much of the complexity around bi-directional, &lt;a href="http://en.wikipedia.org/wiki/Duplex_(telecommunications)#Full-duplex"&gt;full-duplex&lt;/a&gt; communications channels, over a single &lt;a href="http://en.wikipedia.org/wiki/Transmission_Control_Protocol"&gt;Transmission Control Protocol&lt;/a&gt; (TCP) &lt;a href="http://en.wikipedia.org/wiki/Internet_socket"&gt;socket&lt;/a&gt;. It can be implemented in &lt;a href="http://en.wikipedia.org/wiki/Web_browser"&gt;web browsers&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Web_server"&gt;web servers&lt;/a&gt; as well as used by any client or server application. The WebSockets API is currently being standardized by the &lt;a href="http://www.w3.org/2008/webapps/"&gt;W3C Web Applications Working Group&lt;/a&gt; and the protocol is being standardized by &lt;a href="http://datatracker.ietf.org/wg/hybi/charter/"&gt;IETF Hypertext Bidirectional (HyBi) Working Group.&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;Saving Energy with .NET Micro Framework&lt;/h3&gt;

&lt;p&gt;This is a very interesting project using .NET Micro Framework and Netdunio to control water heater temperature based on weekly usage patterns. The article is &lt;a href="http://channel9.msdn.com/coding4fun/articles/Saving-energy-with-the-NET-Micro-Framework"&gt;there at Coding4Fun blog&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;The application is built on the open source &lt;a href="http://netduinohelpers.codeplex.com/"&gt;'netduino.helpers' library&lt;/a&gt; which provides a set of hardware drivers written in C# targeting the netduino family of .Net Micro Framework micro-controllers.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt; NetDunio is an open source electric platform using Microsoft .NET Micro Framework, and if you want to hack on that, go get the resources and tools here. &lt;a href="http://www.netduino.com/downloads/.More"&gt;http://www.netduino.com/downloads/&lt;/a&gt; resources.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt; NetDunio &lt;a href="http://www.netduino.com/downloads/gettingstarted.pdf"&gt;getting started guide&lt;/a&gt; (pdf)&lt;/li&gt;

  &lt;li&gt;&amp;#160; &lt;a href="http://msdn.microsoft.com/en-us/library/ee436350.aspx"&gt;.NET Micro Framework&lt;/a&gt; (online help)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Happy Coding!!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22141639-7367465169821537912?l=www.amazedsaint.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/LAbqb8iaQZDU9BcQamrT29w4mPc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/LAbqb8iaQZDU9BcQamrT29w4mPc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/LAbqb8iaQZDU9BcQamrT29w4mPc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/LAbqb8iaQZDU9BcQamrT29w4mPc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=E27mNaWNAyc:IwAbTblnyrQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=E27mNaWNAyc:IwAbTblnyrQ:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=E27mNaWNAyc:IwAbTblnyrQ:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=E27mNaWNAyc:IwAbTblnyrQ:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=E27mNaWNAyc:IwAbTblnyrQ:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=E27mNaWNAyc:IwAbTblnyrQ:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=E27mNaWNAyc:IwAbTblnyrQ:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=E27mNaWNAyc:IwAbTblnyrQ:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=E27mNaWNAyc:IwAbTblnyrQ:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/amazedsaint/articles/~4/E27mNaWNAyc" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/amazedsaint/articles/~3/E27mNaWNAyc/5-cool-hacks-and-prototypes-for-net.html</link><author>noreply@blogger.com (Anoop Madhusudanan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/__Mw4iY-4nuY/TaLBd63CsAI/AAAAAAAABCQ/Zrb9AGLN8qI/s72-c/image_thumb%5B1%5D.png?imgmax=800" height="72" width="72" /><feedburner:origLink>http://www.amazedsaint.com/2011/04/5-cool-hacks-and-prototypes-for-net.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-22141639.post-5273062679300147482</guid><pubDate>Sat, 09 Apr 2011 10:39:00 +0000</pubDate><atom:updated>2011-04-09T17:08:16.628+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Weekend Hacks</category><category domain="http://www.blogger.com/atom/ns#">WPF</category><category domain="http://www.blogger.com/atom/ns#">JQuery</category><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">HTML5</category><title>Wpf Over Websockets (WoW) – How to Pump WPF windows &amp; animations to browsers over HTML5 Websockets And Canvas</title><description>&lt;p&gt;&lt;a href="http://lh5.ggpht.com/__Mw4iY-4nuY/TaA3-rY2KhI/AAAAAAAABB8/3N_2q8O5qnU/s1600-h/image%5B3%5D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" align="right" src="http://lh6.ggpht.com/__Mw4iY-4nuY/TaA3_Q_cywI/AAAAAAAABCA/9Hyeg_BXBXE/image_thumb%5B1%5D.png?imgmax=800" width="129" height="134" /&gt;&lt;/a&gt;Over the weekend, I just put together a hack for pumping WPF windows over Websockets and rendering it using HTML5 canvas – also with basic mouse input support. For each user connecting to the server, a new window instance is created, and screen will be pumped over web sockets to the browser as base64 encoded images. These images are painted on an HTML5 canvas. The entire source code is here at codeplex – &lt;a href="http://wow.codeplex.com"&gt;http://wow.codeplex.com&lt;/a&gt; &lt;/p&gt;  &lt;h3&gt;What does this mean?&lt;/h3&gt;  &lt;p&gt;Once HTML5 specification is final - it is almost certain that it’ll be the most widely adopted platform for delivering applications to end users. With Websockets in HTML5, we are going beyond the unidirectional, stateless http to a full duplex, high speed connection infrastructure between the server and the client. This will definitely bring up lot of interesting possibilities, including exciting and feature rich user experiences. WPF is already a widely adopted, feature rich desktop application development platform, and this hack is a quick POC to bring the WPF experience over the web to the end user using HTML5 web sockets and canvas.&lt;/p&gt;  &lt;p&gt;You can see that I’m accessing my WPF application over multiple browsers in the below video. Just to clarify, it is rendered in the browser purely using HTML5 canvas – No Silverlight or Flash &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://lh4.ggpht.com/__Mw4iY-4nuY/TaA5l3SAzhI/AAAAAAAABCE/eY0YphLW3Mg/wlEmoticon-smile%5B2%5D.png?imgmax=800" /&gt;&lt;/p&gt;  &lt;p&gt;&lt;iframe title="YouTube video player" height="390" src="http://www.youtube.com/embed/iA4D2M-Nbzk" frameborder="0" width="640" allowfullscreen="allowfullscreen"&gt;&lt;/iframe&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;Rendering the screen in the browser&lt;/h3&gt;  &lt;p&gt;HTML5 draft specification includes Websockets - &lt;a href="http://dev.w3.org/html5/websockets/"&gt;http://dev.w3.org/html5/websockets/&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;b&gt;WebSocket&lt;/b&gt; is a technology providing for bi-directional, &lt;a href="http://en.wikipedia.org/wiki/Duplex_(telecommunications)#Full-duplex"&gt;full-duplex&lt;/a&gt; communications channels, over a single &lt;a href="http://en.wikipedia.org/wiki/Transmission_Control_Protocol"&gt;Transmission Control Protocol&lt;/a&gt; (TCP) &lt;a href="http://en.wikipedia.org/wiki/Internet_socket"&gt;socket&lt;/a&gt;. It is designed to be implemented in &lt;a href="http://en.wikipedia.org/wiki/Web_browser"&gt;web browsers&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Web_server"&gt;web servers&lt;/a&gt; but it can be used by any client or server application. The WebSocket API is being standardized by the &lt;a href="http://en.wikipedia.org/wiki/World_Wide_Web_Consortium"&gt;W3C&lt;/a&gt; and the WebSocket protocol is being standardized by the &lt;a href="http://en.wikipedia.org/wiki/Internet_Engineering_Task_Force"&gt;IETF&lt;/a&gt;.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Here is a pretty minimized implementation of the page that opens a web socket, retrieve the image data, and draws the same on a canvas&lt;/p&gt;  &lt;pre class="javascript" name="code"&gt;var socket = new WebSocket(&amp;quot;ws://localhost:8181/main&amp;quot;);
socket.onopen = function () {

}

socket.onmessage = function (msg) {
	var canvas = document.getElementById(&amp;quot;canvas&amp;quot;);
	var ctx = canvas.getContext(&amp;quot;2d&amp;quot;);
	var img = new Image;
	img.onload = function () {
		ctx.clearRect(0, 0, canvas.width, canvas.height)
		ctx.drawImage(img, 0, 0); // Or at whatever offset you like
	};
	img.src = &amp;quot;data:image/gif;base64,&amp;quot; + msg.data; ;
}&lt;/pre&gt;

&lt;h3&gt;The server&lt;/h3&gt;
I was planning to implement a quick socket server based on draft specifications – but I found that there are already a couple of .NET based implementations out there. One among them is Nugget - &lt;a href="http://nugget.codeplex.com/"&gt;http://nugget.codeplex.com/&lt;/a&gt; – I’m having a thin layer on top of Nugget for creating a window instance when ever a client socket connects to the server. 

&lt;pre class="c#" name="code"&gt;	var srv = new WebSocketServer(port, origin, &amp;quot;ws://&amp;quot; + server + &amp;quot;:&amp;quot; + port);
	srv.RegisterHandler&amp;lt;ElementSocket&amp;lt;T&amp;gt;&amp;gt;(&amp;quot;/&amp;quot; + name);
	srv.Start();
	return srv;&lt;/pre&gt;

&lt;p&gt;Most of the logic required for creating window instances, and pumping them back to the connected client socket goes in my ElementSocket implementation.&lt;/p&gt;

&lt;h3&gt;Capturing User Inputs&lt;/h3&gt;
Presently, the support for input devices (mouse, keyboard) etc is minimal. Only Mousebutton down and Mouse button up events are supported. To do this, we are capturing the mouse inputs using JQuery, and then pumping it back to the server. 

&lt;pre class="javascript" name="code"&gt;            $(&amp;quot;#canvas&amp;quot;).mousedown(function (e) {
                var point = getXY(e);
                socket.send(&amp;quot;mousedown;&amp;quot; + point.X + &amp;quot;;&amp;quot; + point.Y);
            });

            $(&amp;quot;#canvas&amp;quot;).mouseup(function (e) {
                var point = getXY(e);
                socket.send(&amp;quot;mouseup;&amp;quot; + point.X + &amp;quot;;&amp;quot; + point.Y);
            });&lt;/pre&gt;
On the server side, the incoming messages are used to simulate the events on the WPF window instance that corresponds to the socket, like 

&lt;pre class="c#" name="code"&gt;                var pnt=this.TranslatePoint(new Point(x, y), this);
                var res=VisualTreeHelper.HitTest(this, pnt);
            
                if (res != null &amp;amp;&amp;amp; res.VisualHit != null &amp;amp;&amp;amp; res.VisualHit is UIElement)
                {
                    SimulateEvent(res, action);
                }&lt;/pre&gt;

&lt;h3&gt;Challenges&lt;/h3&gt;

&lt;p&gt;There are a number of challenges – Ideally we should push only the region copies once it is modified. As of now, I’m pushing the entire screen image (bad) as that’s pretty easy (This is a weekend hack, remember&lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="http://lh6.ggpht.com/__Mw4iY-4nuY/TaA-Y9NGiQI/AAAAAAAABCI/qqoRNuRk94M/wlEmoticon-winkingsmile%5B2%5D.png?imgmax=800" /&gt;). Now, another challenge is proper user input simulation on the instance windows – I still need to find a good way to trigger user inputs to the specific windows, with out affecting the actual input devices. For example, when one user moves the mouse, the move message should be triggered to the corresponding server side window instance, with out affecting the actual mouse cursor. May need to have a look at the WM_ messages, not sure to what extend it can be applied on WPF top level windows.&lt;/p&gt;

&lt;h3&gt;Related Reads &amp;amp; Hacks&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Html5 Labs Interop&amp;#160; Web sockets implementation Is here- &lt;a href="http://html5labs.interoperabilitybridges.com/"&gt;http://html5labs.interoperabilitybridges.com/&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;A nice GTK + HTML5 Hack – More mature - &lt;a href="http://blogs.gnome.org/alexl/2010/11/23/gtk3-vs-html5/"&gt;http://blogs.gnome.org/alexl/2010/11/23/gtk3-vs-html5/&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;Enabling Websockets in Firefox 4 - &lt;a href="http://techdows.com/2010/12/turn-on-websockets-in-firefox-4.html"&gt;http://techdows.com/2010/12/turn-on-websockets-in-firefox-4.html&lt;/a&gt; – It is disabled by default in Firefox, though it is available in Chrome. IE9 has a draft version&lt;/li&gt;

  &lt;li&gt;You can simulate Websockets using the Flash proxy, if your browser won’t support websockets - &lt;a href="https://github.com/gimite/web-socket-js"&gt;https://github.com/gimite/web-socket-js&lt;/a&gt; – Most browsers do support Canvas though.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As I mentioned, the entire source code of this hack is there at &lt;a href="http://wow.codeplex.com"&gt;http://wow.codeplex.com&lt;/a&gt; – Enjoy.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22141639-5273062679300147482?l=www.amazedsaint.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/OZT-CJMB7ieq_VWQxYbDqrpvZLE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/OZT-CJMB7ieq_VWQxYbDqrpvZLE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/OZT-CJMB7ieq_VWQxYbDqrpvZLE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/OZT-CJMB7ieq_VWQxYbDqrpvZLE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=q0AZ6THxC8s:sqCOG2ED3HY:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=q0AZ6THxC8s:sqCOG2ED3HY:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=q0AZ6THxC8s:sqCOG2ED3HY:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=q0AZ6THxC8s:sqCOG2ED3HY:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=q0AZ6THxC8s:sqCOG2ED3HY:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=q0AZ6THxC8s:sqCOG2ED3HY:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=q0AZ6THxC8s:sqCOG2ED3HY:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=q0AZ6THxC8s:sqCOG2ED3HY:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=q0AZ6THxC8s:sqCOG2ED3HY:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/amazedsaint/articles/~4/q0AZ6THxC8s" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/amazedsaint/articles/~3/q0AZ6THxC8s/wpf-over-web-sockets-how-to-pump-wpf.html</link><author>noreply@blogger.com (Anoop Madhusudanan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh6.ggpht.com/__Mw4iY-4nuY/TaA3_Q_cywI/AAAAAAAABCA/9Hyeg_BXBXE/s72-c/image_thumb%5B1%5D.png?imgmax=800" height="72" width="72" /><feedburner:origLink>http://www.amazedsaint.com/2011/04/wpf-over-web-sockets-how-to-pump-wpf.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-22141639.post-4079801217380775353</guid><pubDate>Sat, 26 Mar 2011 14:12:00 +0000</pubDate><atom:updated>2011-03-26T20:13:17.580+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Software Development</category><category domain="http://www.blogger.com/atom/ns#">Community</category><title>Microsoft TechEd India 2011 – An event to remember</title><description>&lt;p&gt;Tech Ed India 2011 was a great experience. Tech Ed events are always awesome. The level of energy you experience in Tech Ed is amazing – You’ll meet lot of great people, exchange a number of ideas, share your concerns, find solutions, seek ways to improve, learn together, share the passion, and much more. For me, Tech Ed is always a source of inspiration.&lt;/p&gt;  &lt;p&gt;Note: I’ve Created An Archive of #TechEdIn tweets here : &lt;a href="http://archivist.visitmix.com/amazedsaint/12"&gt;http://archivist.visitmix.com/amazedsaint/12&lt;/a&gt;&amp;#160; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Meeting Experts via The Roundtables and Providing direct feedback&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;As I’m part of the MVP community, one great opportunity in Tech Ed is to meet the experts via the Roundtable conferences. I was part of some high energy conversations with &lt;a href="http://blogs.msdn.com/b/jasonz/"&gt;Jason Zanders&lt;/a&gt; , &lt;a href="http://www.microsoft.com/presspass/exec/de/Khalidi/default.mspx"&gt;Yousef Khalidi&lt;/a&gt;, Rajiv Kumar (MS IDC Hyderabad) etc. Some of the information you get via these conversations are under NDA ;), but one serious concern I shared with Jason is the strategy of Microsoft when it comes to Tablets and IPTVs. I also suggested Yousef that it’ll be great if Microsoft can evolve the Azure storage to match NoSQL use cases. &lt;/p&gt;  &lt;p&gt;Also, during the conversations with Jason and Yusuf, I realized how seriously Microsoft takes the input from the community.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/__Mw4iY-4nuY/TY3zE2NF5lI/AAAAAAAABBM/FptV4oNOx8A/s1600-h/202177_10150433972950504_500895503_17730765_7918838_o%5B4%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="202177_10150433972950504_500895503_17730765_7918838_o" border="0" alt="202177_10150433972950504_500895503_17730765_7918838_o" src="http://lh3.ggpht.com/__Mw4iY-4nuY/TY3zGNixxpI/AAAAAAAABBQ/ko7Mh2AVHBo/202177_10150433972950504_500895503_17730765_7918838_o_thumb%5B2%5D.jpg?imgmax=800" width="640" height="480" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/__Mw4iY-4nuY/TY3zH-vg-FI/AAAAAAAABBU/g45M7QKsDzI/s1600-h/192151_10150433968145504_500895503_17730718_5546549_o%20%281%29%5B4%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="192151_10150433968145504_500895503_17730718_5546549_o (1)" border="0" alt="192151_10150433968145504_500895503_17730718_5546549_o (1)" src="http://lh5.ggpht.com/__Mw4iY-4nuY/TY3zJaSuq6I/AAAAAAAABBY/n1AHQK0-jrE/192151_10150433968145504_500895503_17730718_5546549_o%20%281%29_thumb%5B2%5D.jpg?imgmax=800" width="640" height="479" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Conversations &amp;amp; Idea Networking&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;In Tech Ed, you’ll network with a lot of people. The MVP community in India is very open and vibrant - so that you can network with experts and MVPs in various Microsoft related technology areas, and can have intense idea exchanges, debates and discussions. I met a number of great guys, and had a handful of very interesting conversations - with guys like Abhijit, Abhishek, Lohit, Suprotim, Vijay, Ravikanth, Dhananjay, Hima, Krishna, Harish, Ram, Shravan, Alpesh etc – Just to name a few. I had detailed conversations on plug in support for IE9, leveraging the web sockets and HTML5 for something very interesting (secret), Code contracts in C#, BDD etc to name a few – with various guys.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/__Mw4iY-4nuY/TY3zMkQJUAI/AAAAAAAABBc/UkG_cp9By7E/s1600-h/image%5B23%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/__Mw4iY-4nuY/TY3zUZX0hyI/AAAAAAAABBg/KJYjUXi7pM4/image_thumb%5B15%5D.png?imgmax=800" width="640" height="362" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/__Mw4iY-4nuY/TY3zY_cqdEI/AAAAAAAABBk/o7-wUt55Fcc/s1600-h/image%5B18%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/__Mw4iY-4nuY/TY3zhxqb9iI/AAAAAAAABBo/wziI52ANUQw/image_thumb%5B12%5D.png?imgmax=800" width="640" height="480" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/__Mw4iY-4nuY/TY3zrItPsWI/AAAAAAAABBs/P2mkBYDGhWE/s1600-h/image%5B6%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/__Mw4iY-4nuY/TY3z4XqWnCI/AAAAAAAABBw/v1ITZixen6I/image_thumb%5B4%5D.png?imgmax=800" width="640" height="416" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/__Mw4iY-4nuY/TY30DE2MVvI/AAAAAAAABB0/FRPc-K2FJc4/s1600-h/image%5B13%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/__Mw4iY-4nuY/TY30NBOVbTI/AAAAAAAABB4/6aBA5uTPsFQ/image_thumb%5B9%5D.png?imgmax=800" width="640" height="468" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Keynotes and Presentations&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;One visible part of Tech Ed event is the Keynotes and presentations on various areas – I mentioned it last because I thought I should highlight the less known aspects of Tech Ed first. This Tech Ed had a lot of great sessions, from distinguished speakers and community rock stars. Especially, I liked the Keynote from Jason on Day 3, and also sessions from (the ones I attended) &lt;a href="http://blogs.ExtremeExperts.com"&gt;Vinod Kumar&lt;/a&gt;, &lt;a href="http://www.microsoft.com/presspass/exec/de/Khalidi/default.mspx"&gt;Yousef&lt;/a&gt; etc.&lt;/p&gt;  &lt;p&gt;Overall, it was great fun, learning and networking - I enjoyed every bit of it. Thanks to all of you for making the event that much interesting!!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22141639-4079801217380775353?l=www.amazedsaint.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Ajog37jXVS8cjKt8mwtdlUaI4ns/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Ajog37jXVS8cjKt8mwtdlUaI4ns/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Ajog37jXVS8cjKt8mwtdlUaI4ns/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Ajog37jXVS8cjKt8mwtdlUaI4ns/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=142OvS4O8ec:bBrd4oD_m-g:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=142OvS4O8ec:bBrd4oD_m-g:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=142OvS4O8ec:bBrd4oD_m-g:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=142OvS4O8ec:bBrd4oD_m-g:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=142OvS4O8ec:bBrd4oD_m-g:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=142OvS4O8ec:bBrd4oD_m-g:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=142OvS4O8ec:bBrd4oD_m-g:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=142OvS4O8ec:bBrd4oD_m-g:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=142OvS4O8ec:bBrd4oD_m-g:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/amazedsaint/articles/~4/142OvS4O8ec" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/amazedsaint/articles/~3/142OvS4O8ec/microsoft-teched-india-2011-event-to.html</link><author>noreply@blogger.com (Anoop Madhusudanan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh3.ggpht.com/__Mw4iY-4nuY/TY3zGNixxpI/AAAAAAAABBQ/ko7Mh2AVHBo/s72-c/202177_10150433972950504_500895503_17730765_7918838_o_thumb%5B2%5D.jpg?imgmax=800" height="72" width="72" /><feedburner:origLink>http://www.amazedsaint.com/2011/03/microsoft-teched-india-2011-event-to.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-22141639.post-7960076551603164433</guid><pubDate>Sat, 05 Mar 2011 19:00:00 +0000</pubDate><atom:updated>2011-03-06T00:38:19.695+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">CSharp</category><title>The Case of Switch-Case in C#</title><description>&lt;p&gt;&lt;img style="display: inline; margin-left: 0px; margin-right: 0px" align="right" src="http://lh3.ggpht.com/__Mw4iY-4nuY/TJ8yJRPaLsI/AAAAAAAAA7A/aklc9wj3Tf4/image_thumb%5B46%5D.png?imgmax=800" /&gt;A quick rant on using switch-cases in C#. In Javascript, most developers prefer creating a lean object that can be re-used, instead of a stubborn switch case. For example, instead of this Switch Case implementation, &lt;/p&gt;  &lt;pre class="javascript" name="code"&gt;
switch (foo) {
	case 'case1':
		alert('case1 code');
		break;
	case 'case2':
		alert('case2 code');
		break;
	default:
		alert('hm, default code');
		break;
}&lt;/pre&gt;
a number of developers may consider this one as more elegant - because it is re-usable and more testable. 

&lt;pre class="javascript" name="code"&gt;var mySwitch= {
'case1' : function() {
	alert('case1 code');
},
'case2' : function() {
	alert('case2 code');
},
'default' : function() {
	alert('default code');
}
};


if (mySwitch[foo]) {
	mySwitch[foo]();
} else {
	mySwitch['default']();
}&lt;/pre&gt;
I was thinking about implementing something along similiar lines in C#, to re-factor few fat switch cases using a Dictionary. Obviously, this is context specific - one approach won't fit all the scenarios. Here is a quick example to clarify the point. 

&lt;pre class="c#" name="code"&gt;

    public class SwitchCase : Dictionary&amp;lt;string,Action&amp;gt;
    {
        public void Eval(string key)
        {
            if (this.ContainsKey(key))
              this[key]();
            else
             this[&amp;quot;default&amp;quot;](); 
        }
    }


    //Now, somewhere else

            var mySwitch = new SwitchCase
            {
                { &amp;quot;case1&amp;quot;,  ()=&amp;gt;Console.WriteLine(&amp;quot;Case1 is executed&amp;quot;) },
                { &amp;quot;case2&amp;quot;,  ()=&amp;gt;Console.WriteLine(&amp;quot;Case2 is executed&amp;quot;) },
                { &amp;quot;case3&amp;quot;,  ()=&amp;gt;Console.WriteLine(&amp;quot;Case3 is executed&amp;quot;) },
                { &amp;quot;case4&amp;quot;,  ()=&amp;gt;Console.WriteLine(&amp;quot;Case4 is executed&amp;quot;) },
                { &amp;quot;default&amp;quot;,()=&amp;gt;Console.WriteLine(&amp;quot;Default is executed&amp;quot;) },
            };

            mySwitch.Eval(c);&lt;/pre&gt;
This provides loose coupling, and you can even modify the logic for each case easily using a setter or so. Happy Coding!!

  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22141639-7960076551603164433?l=www.amazedsaint.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/UhMl8OUoxAeb5zWekPCNfavEebI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UhMl8OUoxAeb5zWekPCNfavEebI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/UhMl8OUoxAeb5zWekPCNfavEebI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UhMl8OUoxAeb5zWekPCNfavEebI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=toAIISBacCs:qyjGDLL-XNs:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=toAIISBacCs:qyjGDLL-XNs:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=toAIISBacCs:qyjGDLL-XNs:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=toAIISBacCs:qyjGDLL-XNs:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=toAIISBacCs:qyjGDLL-XNs:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=toAIISBacCs:qyjGDLL-XNs:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=toAIISBacCs:qyjGDLL-XNs:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=toAIISBacCs:qyjGDLL-XNs:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=toAIISBacCs:qyjGDLL-XNs:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/amazedsaint/articles/~4/toAIISBacCs" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/amazedsaint/articles/~3/toAIISBacCs/case-of-switch-case-in-c.html</link><author>noreply@blogger.com (Anoop Madhusudanan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh3.ggpht.com/__Mw4iY-4nuY/TJ8yJRPaLsI/AAAAAAAAA7A/aklc9wj3Tf4/s72-c/image_thumb%5B46%5D.png?imgmax=800" height="72" width="72" /><feedburner:origLink>http://www.amazedsaint.com/2011/03/case-of-switch-case-in-c.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-22141639.post-7167142398904342245</guid><pubDate>Tue, 01 Mar 2011 08:44:00 +0000</pubDate><atom:updated>2011-03-08T20:18:23.027+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">MVVM</category><category domain="http://www.blogger.com/atom/ns#">JQuery</category><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">linq</category><title>MVVM And Linq In Javascript for .NET Programmers</title><description>&lt;p&gt;&lt;a href="http://lh5.ggpht.com/__Mw4iY-4nuY/TWyxuieOJQI/AAAAAAAABAs/c_JGz0KsahE/s1600-h/image%5B4%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" border="0" alt="image" align="right" src="http://lh5.ggpht.com/__Mw4iY-4nuY/TWyxzkAGuCI/AAAAAAAABAw/Q6_dC3HWihY/image_thumb%5B2%5D.png?imgmax=800" width="219" height="230" /&gt;&lt;/a&gt; If you are not using a well structured javascript library like &lt;a href="http://jquery.com/"&gt;JQuery&lt;/a&gt;, and still manage to do web development, you are .. hm.. probably interested in contributing too much to the garbage that is already there in the web (I am being nice here :)). &lt;/p&gt;  &lt;p&gt;Anyway, this post is about few more cool Javascript libraries other than JQuery, that may generate a lot of interest for .NET Programmers (I am talking with &lt;a href="http://twitter.com/vinayakkamat"&gt;Vin&lt;/a&gt; lately a lot about this). In this post, I’ll cover two nice little JavaScript libraries, that’ll bring Model View View Model and LINQ to JavaScript.&lt;/p&gt;  &lt;h3&gt;&lt;strong&gt;1 – Knockcout.js&lt;/strong&gt;&lt;/h3&gt;  &lt;p&gt;Knockcout is a cool Javascript library that’ll bring the MVVM concepts to the Javascript. If you are already familiar with MVVM, you are good to use Knockout once you learn the little syntax differences. Here is a quick example that shows how to bind a text variable and a command.&lt;/p&gt;  &lt;pre class="javascript" name="code"&gt;&amp;lt;div&amp;gt;
    You've clicked &amp;lt;span data-bind=&amp;quot;text: numberOfClicks&amp;quot;&amp;gt;&amp;lt;/span&amp;gt; times
    &amp;lt;button data-bind=&amp;quot;click: clickCommand&amp;quot;&amp;gt;Click me&amp;lt;/button&amp;gt;
&amp;lt;/div&amp;gt;
 
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;
    var viewModel = {
        numberOfClicks : ko.observable(0), 
        clickCommand : function() {
            var previousCount = this.numberOfClicks();
            this.numberOfClicks(previousCount + 1);
        }
    };
&amp;lt;/script&amp;gt;&lt;/pre&gt;

&lt;p&gt;In the viewModel, we’ve a numberOfClicks variable, and also a clickCommand. You’ll see that we are binding the &lt;em&gt;clickCommand&lt;/em&gt; to the button. When ever the button is clicked, the numberOfClicks variable is incremented. If you are wondering why we are using ko.observable to assign value to our numberOfClicks property, it is because&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;you need to declare your model properties as&lt;em&gt; observables&lt;/em&gt;, because these are special JavaScript objects that can notify subscribers about changes, and can automatically detect dependencies.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Also, note that to get/set values to our numberOfClicks property, we are relying on methods (), to ensure cross browser compatibility. For this reason, all observable objects are functions. Also, note the data-bind attribute we use for binding the view model variables to the UI elements. Apart from these little differences, it is pretty easy to sail through knockout, and you can easily master MVVM in Javascript&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Knockout is a JavaScript library that helps you to create rich, responsive display and editor user interfaces with a clean underlying data model. Any time you have sections of UI that update dynamically (e.g., changing depending on the user’s actions or when an external data source changes), KO can help you implement it more simply and maintainably.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Have a look at &lt;a href="http://knockoutjs.com/"&gt;http://knockoutjs.com/&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;2 – Linq.js&lt;/h3&gt;

&lt;p&gt;If you love Linq, you’ll love Linq.js – it is an almost complete implementation of Linq for Javascript. You can use Enumerable.From(…) to convert an Array to an enumerable, to query them. Here is a quick example.&lt;/p&gt;

&lt;pre class="javascript" name="code"&gt;var array = [100, 200, 30, 40, 500, 40, 200];
var ex1 = Enumerable.From(array).Distinct().ToArray(); // [100, 200, 30, 40, 500]&lt;/pre&gt;

&lt;p&gt;Linq.js also has a JQuery extension, which is very handy.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Features include&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;implementation of all .NET 4.0 methods and many extra methods (inspiration from &lt;a href="http://msdn.microsoft.com/en-us/devlabs/ee794896.aspx"&gt;Rx&lt;/a&gt;, &lt;a href="http://d.hatena.ne.jp/NyaRuRu/20080115/p1"&gt;Achiral&lt;/a&gt;, Haskell, Ruby, etc...) &lt;/li&gt;

    &lt;li&gt;complete lazy evaluation &lt;/li&gt;

    &lt;li&gt;full IntelliSense support for VisualStudio &lt;/li&gt;

    &lt;li&gt;two versions - linq.js and jquery.linq.js (jQuery plugin) &lt;/li&gt;

    &lt;li&gt;support Windows Script Host &lt;/li&gt;

    &lt;li&gt;binding for Reactive Extensions for JavaScript(RxJS) and IntelliSense Generator -&amp;gt; see &lt;a href="http://linqjs.codeplex.com/documentation?referringTitle=Home"&gt;documentation&lt;/a&gt; &lt;/li&gt;

    &lt;li&gt;NuGet install support(linq.js, linq.js-jQuery, linq.js-Bindings) &lt;/li&gt;
  &lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Get it from &lt;a href="http://linqjs.codeplex.com/"&gt;http://linqjs.codeplex.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Happy coding, Enjoy.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22141639-7167142398904342245?l=www.amazedsaint.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/P0RQUHze7EjWmrPMYBFPXUE0cq4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/P0RQUHze7EjWmrPMYBFPXUE0cq4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/P0RQUHze7EjWmrPMYBFPXUE0cq4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/P0RQUHze7EjWmrPMYBFPXUE0cq4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=_71TMnAVkaE:-2VpSswfV1o:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=_71TMnAVkaE:-2VpSswfV1o:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=_71TMnAVkaE:-2VpSswfV1o:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=_71TMnAVkaE:-2VpSswfV1o:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=_71TMnAVkaE:-2VpSswfV1o:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=_71TMnAVkaE:-2VpSswfV1o:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=_71TMnAVkaE:-2VpSswfV1o:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=_71TMnAVkaE:-2VpSswfV1o:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=_71TMnAVkaE:-2VpSswfV1o:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/amazedsaint/articles/~4/_71TMnAVkaE" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/amazedsaint/articles/~3/_71TMnAVkaE/mvvm-and-linq-in-javascript.html</link><author>noreply@blogger.com (Anoop Madhusudanan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/__Mw4iY-4nuY/TWyxzkAGuCI/AAAAAAAABAw/Q6_dC3HWihY/s72-c/image_thumb%5B2%5D.png?imgmax=800" height="72" width="72" /><feedburner:origLink>http://www.amazedsaint.com/2011/03/mvvm-and-linq-in-javascript.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-22141639.post-2418815816358065224</guid><pubDate>Fri, 25 Feb 2011 06:57:00 +0000</pubDate><atom:updated>2011-02-25T12:44:50.441+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Tools</category><category domain="http://www.blogger.com/atom/ns#">JQuery</category><category domain="http://www.blogger.com/atom/ns#">Fun</category><category domain="http://www.blogger.com/atom/ns#">Community</category><title>Chrome PageGuide Extension to View related pages &amp; tweets, Linked pages &amp; tweets etc</title><description>&lt;p&gt;I’m an ardent user of Google Chrome, and often wanted to have a plug-in that can show me related pages when I read a page, show pages and tweets linked to the current page etc. So, I wrote one myself and released a new extension for Google Chrome – named PageGuide.&lt;/p&gt;  &lt;p&gt;&lt;img style="margin: 5px 0px; display: inline" align="right" src="https://chrome.google.com/extensions/img/hdegmgbeejbpmfjjckaledabkgmoggfo/1298540826.5/screenshot_big/5001?hl=en" /&gt;&lt;/p&gt;  &lt;p&gt; You may &lt;a href="https://chrome.google.com/extensions/detail/hdegmgbeejbpmfjjckaledabkgmoggfo"&gt;&lt;strong&gt;install PageGuide from the Chrome Web Store&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;With Page Guide Extension, you can&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Get recommendations and view Related Pages when you are reading a page &lt;/li&gt;    &lt;li&gt;View pages Linked to the current page you've open &lt;/li&gt;    &lt;li&gt;Vew tweets from @usernames you've in this web page &lt;/li&gt;    &lt;li&gt;Tweets linking to the current page &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Get instant recommendations when you read something, or use it to find out other pages linked to your blog page.&amp;#160; &lt;/p&gt;  &lt;p&gt;You can open the plugin window by clicking the PageGuide button that will appear below any web page, and hide it by clicking the title.&lt;/p&gt;  &lt;p&gt;It is mainly around JQuery, and I’ll share the source code soon.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22141639-2418815816358065224?l=www.amazedsaint.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/9zPDHpeEc4QFH9bz3duU0AIrt18/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9zPDHpeEc4QFH9bz3duU0AIrt18/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/9zPDHpeEc4QFH9bz3duU0AIrt18/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9zPDHpeEc4QFH9bz3duU0AIrt18/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=EGEMUfn-CM4:hJY4TYZTQ2c:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=EGEMUfn-CM4:hJY4TYZTQ2c:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=EGEMUfn-CM4:hJY4TYZTQ2c:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=EGEMUfn-CM4:hJY4TYZTQ2c:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=EGEMUfn-CM4:hJY4TYZTQ2c:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=EGEMUfn-CM4:hJY4TYZTQ2c:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=EGEMUfn-CM4:hJY4TYZTQ2c:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=EGEMUfn-CM4:hJY4TYZTQ2c:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=EGEMUfn-CM4:hJY4TYZTQ2c:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/amazedsaint/articles/~4/EGEMUfn-CM4" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/amazedsaint/articles/~3/EGEMUfn-CM4/chrome-pageguide-extension.html</link><author>noreply@blogger.com (Anoop Madhusudanan)</author><feedburner:origLink>http://www.amazedsaint.com/2011/02/chrome-pageguide-extension.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-22141639.post-8736341761062988903</guid><pubDate>Sat, 19 Feb 2011 07:33:00 +0000</pubDate><atom:updated>2011-02-19T13:14:51.670+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">Philosophy</category><category domain="http://www.blogger.com/atom/ns#">Programming-Tips</category><category domain="http://www.blogger.com/atom/ns#">Community</category><title>Find Your “Worth As a Developer Score” (WDS) – A Self Rating Map for .NET Developers</title><description>&lt;p&gt;I thought about putting together a simple self rating mechanism for developers - mainly .NET developers. “Worth As A Developer Score” is a rating system out of 1000, that’ll help you rate yourself across a set of competencies in multiple areas. It is modeled around the following aspects.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Familiarity in basic concepts, common frameworks, tools and programming languages&lt;/li&gt;    &lt;li&gt;Cross skill quotient and ability to work between platforms (with in .NET framework).&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Here is how to find your Worth As a Developer (WDS) Score. Nice Acronym, huh?&amp;#160; Consider the chart below. You are allowed to replace a framework/tool/Lib in the below map with a similar framework/tool/lib that is not there in the map&amp;#160; (For eg, you can replace NInject with AutoFac or EF with Subsonic) – But make sure that the number of items in a quadrant remain unchanged.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/__Mw4iY-4nuY/TV9yIrOLm6I/AAAAAAAABAY/ES0cbYtlBCg/s1600-h/image%5B10%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/__Mw4iY-4nuY/TV9yPcG8dPI/AAAAAAAABAc/4IVbQGqieIA/image_thumb%5B6%5D.png?imgmax=800" width="660" height="456" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Now, calculating your WDS Score is pretty simple&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;For each item in the ‘Basics’ quadrant (SOLID, TDD etc) - rate yourself out of 40 (0 least, 40 best). There are ten items there, so the maximum score you can have is 400.&lt;/li&gt;    &lt;li&gt;Now for *all* items in *all* the other quadrants other than the ‘Basic’ quadrant – rate yourself out of 10 (0 least, 10 best). There are a total of 60 Items across the remaining quadrants, so the maximum score you can have is 600.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Add up both the scores (what you got out of 400 + what you got out of 600), and this is your WDS score as a .NET developer out of 1000. Simple, huh? :) &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22141639-8736341761062988903?l=www.amazedsaint.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/S_X1OjTXWkr5YjdCR8OX1wAe_-s/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/S_X1OjTXWkr5YjdCR8OX1wAe_-s/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/S_X1OjTXWkr5YjdCR8OX1wAe_-s/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/S_X1OjTXWkr5YjdCR8OX1wAe_-s/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=jHkpuoSlAFY:EDP6P2xQtn4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=jHkpuoSlAFY:EDP6P2xQtn4:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=jHkpuoSlAFY:EDP6P2xQtn4:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=jHkpuoSlAFY:EDP6P2xQtn4:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=jHkpuoSlAFY:EDP6P2xQtn4:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=jHkpuoSlAFY:EDP6P2xQtn4:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=l6gmwiTKsz0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=jHkpuoSlAFY:EDP6P2xQtn4:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?i=jHkpuoSlAFY:EDP6P2xQtn4:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/amazedsaint/articles?a=jHkpuoSlAFY:EDP6P2xQtn4:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/amazedsaint/articles?d=TzevzKxY174" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/amazedsaint/articles/~4/jHkpuoSlAFY" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/amazedsaint/articles/~3/jHkpuoSlAFY/find-your-worth-as-developer-score-wds.html</link><author>noreply@blogger.com (Anoop Madhusudanan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/__Mw4iY-4nuY/TV9yPcG8dPI/AAAAAAAABAc/4IVbQGqieIA/s72-c/image_thumb%5B6%5D.png?imgmax=800" height="72" width="72" /><feedburner:origLink>http://www.amazedsaint.com/2011/02/find-your-worth-as-developer-score-wds.html</feedburner:origLink></item></channel></rss>

