Saturday, January 25, 2014

WebAPI (REST Service) - How To Run in VS2010 ?

To Run WebAPI using VS2010 (i.e framework 4.0)

Open your project first. then

Go to package Manager Console in VS (under tools) [NuGet] -> type following version

Install-Package Microsoft.AspNet.WebApi -Version 4.0.30506

The reason is, the latest WebApi is compatible only to .net 4.5. so if you try to install without specifying exact version number, it will bring latest and try to install in your project and will finally complaint that the version is not compatible.

The good thing is, along with WebAPI abstraction classes (system.web.http) it will also install Newton.Soft.JSON class too, which is a must in REST service to reduce payload. Roughly if you use JSON rather XML your payload size will come down to about average 60% lower.

I am very much impressed with this video, which explains very basics of WebAPI- Thanks Shiv Kumar.

ASP.NET Web API and RESTful Services - Part 1 






Monday, September 23, 2013

SVN - a real Tree - An Anology



Working with SVN is somewhat like growing a tree:
  • a tree has a trunk and some branches
  • branches grow from the trunk, and thinner branches grow from thicker branches
  • a tree can grow with a trunk and no branch (but not for long)
  • a tree with branches but no trunk looks more like a bundle of twigs fallen on the floor
  • if the trunk is sick, so are the branches and eventually, the whole tree can die
  • if a branch is sick, you can cut it, and another one may grow
  • if a branch grows too much, it may become too heavy for the trunk, and the tree will fall down
  • when you feel your tree, your trunk, or a branch is nice looking, you can take a picture of it to remember how nice it was that day

Wednesday, August 22, 2012

JQuery Tabs

Now it is very easy to build a Tab control in Web applications using JQuery Tabs.

Steps to do.

Step - 1
Include following javascripts file to the page.

  • jquery-1.1.3.1.pack1.js
  • jquery.tabs.pack.js
Css plays a major role in building tab appearance in the page, hence include jquery.tabs.css too ( This can be made custom too)

Step- 2

Add a Div and  include the tabnames in <ul>  <li><a 
After that include each tab content in seperate Div but still inside main Div. Note that the href given to the anchor should have the corresponding id in DIV too.
  1. <div id="container1">
  2.         <ul>
  3.               <li><a href="#tabs1">Tab1</a></li>
  4.               <li><a href="#tabs2">Tab2</a></li>
  5.         </ul>
  6.         <div id="tabs1">
  7.             Display something
  8.         </div>
  9.         <div id="tabs2">
  10.             Display something
  11.         </div>
  12.     </div>

Step -3
 Finally add following javascript to hook the DIV with jquery Tab plugin.
  1. <script type="text/javascript">
  2.     $(function () {
  3.         $('#container1').tabs();
  4.     });
  5.  </script>
Done !!!

An Example is



  1. <html>
  2. <head runat="server">
  3.     <title></title>
  4. <script type="text/javascript" src="Components/Resources/Scripts/jquery-1.1.3.1.pack.js"></script>
  5. <script type="text/javascript" src="Components/Resources/Scripts/jquery.tabs.pack.js"></script>
  6. <link rel="stylesheet" href="Components/Resources/css/jquery.tabs.css" type="text/css">
  7. </head>
  8. <body>
  9.     <form id="form1" runat="server">
  10.      <div id="container1">
  11.         <ul>
  12.               <li><a href="#tabs1">Tab1</a></li>
  13.               <li><a href="#tabs2">Tab2</a></li>
  14.         </ul>
  15.         <div id="tabs1">
  16.             Display something
  17.         </div>
  18.         <div id="tabs2">
  19.             Display something
  20.         </div>
  21.     </div>
  22. <script type="text/javascript">
  23.     $(function () {
  24.         $('#container1').tabs({ fxSlide: true, fxFade: true, fxSpeed: 'normal' });
  25.     });
  26.         </script>
  27.     </form>
  28. </body>
  29. </html>


Thursday, May 3, 2012

Javascript Fun

1) Open any website in browser

 2) Copy the following javascipt
javascript:document.body.contentEditable='true'; document.designMode='on'; void 0
3) Paste in browser console / in address bar and tap . Now try editing the text inside the website. :)

 Perfect to take screen shots with text change......

Monday, February 13, 2012

How TDD can be fun !!!

Let me introduce couple of TDD tools, which can improve the productivity to a great extend

NCrunch (http://www.ncrunch.net/)

NCrunch is an automated parallel continuous testing tool for Visual studio.net. It intelligently takes responsibility for running automated tests so that you don’t have to do it and it give you a huge amount of useful information about your tests.

It is an amazing tool , as the developer need not to even save the code, the NCrunch will run in background and will show the different color indicators for code coverage, error, long running process etc.

A must tool for TDD.

NSubstitute (http://nsubstitute.github.com/)

NSubstiture is a wonderful Mock framework which has great flexibility to create mock objects with little code, couple of cool features that I found interesting is the ability to use more than one interface in one mock class. It also support the use of Lambda expressions which also give a great flexibility. I haven’t seen any other existing mock framework that has this amount of features. At the same time, NSubstitute is also very simple and easy to implement.

SharpText Ex (http://sharptestex.codeplex.com/)

An extension class to the regular Assert method. This class can be used to chain the assertion. Very simple and easy too.

Tuesday, October 25, 2011

What is the difference between $(document).ready() - pageLoad() - Application Init


$(document).ready()

  • Ideal for onetime initialization.
  • Optimization black magic; may run slightly earlier than pageLoad().
  • Does not re-attach functionality to elements affected by partial postbacks.

pageLoad()

  • Unsuitable for onetime initialization if used with UpdatePanels.
  • Slightly less optimized in some browsers, but consistent.
  • Perfect for re-attaching functionality to elements within UpdatePanels.

Application.Init

  • Useful for onetime initialization if only ASP.NET AJAX is available.
  • More work required to wire the event up.
  • Exposes you to the “sys is undefined” error if you aren’t careful.
details here