Tuesday 12 March 2013

Unable to connect to TFS Preview …

These days, it is encouraged to have all your stuff on cloud and being a developer, it is good to have your version control on cloud too. Microsoft offers a free online TFS service and all that you need is a Windows Live ID. Just go to http://tfs.visualstudio.com and create a TFS account for yourself. You could create any number of projects ( I believe this is going to be for a limited time only) and up to 5 users for free.

You can host all your source code in TFS online with a url of your choice (eg: http://kiranbanda.visualstudio.com or http://kb.tfspreview.com ).

I am not yet clear with the difference between a .visualstudio.com and a .tfspreview.com although the interface of these two sites looks identical.

To connect to the online TFS, you need to have VS 2010 (with service pack 1) and an update (KB2581206) for VS.

The steps to access online TFS are very well explained @ http://blogs.msdn.com/b/visualstudioalm/archive/2011/12/07/connect-visual-studio-2010-to-your-tfs-preview-account.aspx

However, there are cases when you have two live IDs ( or one from hotmail.com and another from live.com) and you might be using one for your personal mail address and the other for your office work (like I do). In such cases, VS 2010 Team explorer refuses to connect to the TFS Preview and it errors out saying that the user is not authorized. The irritating thing here is that it doesn’t tell you the credentials that it used to connect to TFS nor does it allow you to use a different account !!

You could use Fiddler to find out the credentials that VS uses to connect to TFS during this error.

Now, how do you clear those credentials and key in one that works ? You could try clearing off all your browser cache yet things won’t work.

The fix to this problem lies in the least frequently used menu command in VS IDE – the web browser Open-mouthed smile

  • Open web browser in VS IDE (View –> Other Windows –> Web Browser)
  • Type www.live.com or www.hotmail.com and observe that it logs you in automatically with a cached credential.
  • Sign out and sign in with a different credentials (your office ID) or just leave it as is.
  • Now try connecting using the team explorer and this time the explorer prompts you to key in your credentials (in a web page).

I found the above steps from a  forum on the web and I thought this is a more often case for developers working with VS and online TFS.

The credentials might get cached in one of the following cases:

  • Log in to a Microsoft related site via browser
  • Sign in to Live Messenger
  • Sign in to Skype using your Microsoft Account !

Hope this helps.

Thursday 7 March 2013

IIS URL Rewrite

Change is inevitable and changes in technology are quite common.As a web developer you might have a developed a website on an older technology and some time down the line, you might be required to port the application to a newer technology. By experience, the most common issues around figuring the amount of code that could be reused.However, if your application is a public facing website, then one of the major issues that often developers overlook is with the 404 errors that your users experience when they access the links via a search engine. Search engines might have crawled your older website and give your old (fashioned) pages as hyperlinks that no longer exist in the new version !!

To be in the business and to avoid users from getting 404 errors when they access stale links from search engine results, the item that you should consider is “URL rewriting”.

URL Rewriting comes as a module in the recent versions of IIS and configuring this feature in IIS is a pretty straightforward task (although a bit laborious due to the number of pages/ possible hyperlinks in your website). On the other hand, if you are still stuck at an older version of Windows servers (like Windows 2003), you should consider IIRF.

A more detailed step-by-step instructions on getting IIRF to work is here.

I recommend that you read this article (don’t forget to watch the video on this page) for more details on the URL Rewrite module that is available in the latest versions of IIS on Windows servers. Also checkout the link @ http://www.iis.net/learn/extensions/url-rewrite-module/using-the-url-rewrite-module for some basics in getting this module to work for your requirement.

Tuesday 26 February 2013

Your mobile is your best friend …

The advent of smart phonesNokia-Lumia-620-front-png has radically changed the life of a mobile user. The latest smart phone is very close to a personal computer. Not limited to making and accepting calls / sending SMS, a wide range of applications allow you to be a bit more organized and connected.
I am a big fan of Nokia and I was carrying a broken Nokia xpress music phone until I finally bought a Lumia 710 (now runs Windows 7.8 update). I was really excited at the design of Windows mobile OS along with the way Nokia phones are built.
Some of the highlights of Lumia are:
  • MS Office (especially outlook and one note are awesome)
  • Integration with Skydrive & Windows Live (You don’t have to back up things now as they reside safely on skydrive and your contacts get synced to Windows live  / Google (however you set up).
  • Nokia maps, Nokia Drive and Nokia City lens – you are not a stranger at a new place anymore Smile
  • Windows Market place has tonnes of apps that you can play with and get organized.
You can find more information on the features of a Lumia from various websites on the web.
In this post, I intend to list down a few features that I wish to have, atleast in the coming versions of Lumias:
  • Text reply without answering a call (I know that this is available in Win 8 mobile phones and I wish there is an update for loyal customers like me that bought 7.5 / 7.8 compatible mobiles (Lumia 510, 610, 710, 800, etc).
  • An easier way to share contact numbers  (via SMS or business cards).
  • Be able to change the color of a tile (just the tile and not the entire theme).
  • Persistent connection even when the phone is in standby mode (I don’t get notified now when I get new email / IM buzzer !)
  • Be able to edit a forwarded content – This is specific to Outlook and I observed that while forwarding a message, the original content is made readonly.
  • … and the list might get bigger if people that used other variants of smartphones can contribute Smile

Saturday 16 February 2013

ASP.NET MVC model binding

I have been working on ASP.NET MVC ever since its inception and I love working on it. Having worked on several projects using ASP.NET MVC, often I have seen developers getting confused when it comes to how routing works and how the model binding happens.

ASP.NET MVC along with Jquery offers a powerful programming platform towards building content rich, user-friendly, highly responsive web applications. Programming ASP.NET MVC based applications is a breeze if one has a thorough knowledge on HTTP and HTML. I am not saying that you need to have the spec by heart, but a developer should know how a browser renders the markup, the way DOM is structured and how the browser finds the elements in the DOM and sends them as name-value pairs as part of an HTTP request (be it GET or POST).

In this blog, I would like to focus on “model-binding” – a concept where you send some parameters via a HTTP request, your action method on your controller accepts an object of a type that encapsulates your parameters and ASP.NET MVC uses these parameters to build the object that your action method wants.

For reference purposes, let’s create an example scenario where I have two classes (model) – Person and Company and there is a one-to-one association between Person and Company (Person class having a reference to an object of type Company).

Here is the structure of my model classes:

public class Company
{
public string Name { get; set; }
}
public class Person
{
public string FirstName { get; set; }
public string Lastname { get; set; }
public DateTime? DOB { get; set; }
public string Address { get; set; }
public Company Company { get; set; }
}

Let’s start by creating an ASP.NET MVC 4 application in VS 2010 and build an action method in HomeController to render a view that looks like this:


ModelBinding-Form


The form looks very basic as the focus is more on the javascript that we deal with than the aesthetics of this form Smile


From here on, we are going to be submitting the form using Jquery.ajax method (and not as a conventional form submit).


There are various alternatives to submitting data using $.ajax and let’s take a closer look at them.


Approach # 1 : Using $.serializeArray() to bind a simple data structure


Consider a form with form elements rendered not using the Html Helper classes as shown below:

<form id="frmPersonalData" action="javascript:void(0);" method="post">
<p>
<label for="firstname">First Name</label>
<input type="text" id="txtFirstName" name="FirstName" />
</p>
<p>
<label for="lastname">First Name</label>
<input type="text" id="txtLastName" name="LastName" />
</p>
<!-- some code is omitted for brevity -->
<p>
<label for="CompanyName">Company Name</label>
<input type="text" id="txtCompanyName" name="Name" />
</p>



The following is the javascript to post the above form to an action method that accepts Person class as a parameter:

$(function () {
    $("#btnSubmit").click(function () {
        /* Posting the data using Array of values */
        var postData = $("#frmPersonalData").serializeArray();
       
        $.ajax({
        type: 'POST',
        url: '@Url.Action("Index", "Home")',
        traditional: true,
        cache: false,
        async: true,
        data: postData,
        success: function (msg) {
        alert(msg.Status);
        }
        });});

Action method:

[HttpPost]
public ActionResult Index(Person person)
{
if (person == null || string.IsNullOrEmpty(person.FirstName))
{
return Json(new { Status = "Model binding failed. Could not parse the submitted data as Person" });
}
return Json(new { Status = "Successfully parsed the post data as Person"});
}

The issue with the above approach is that the person object gets built properly but the associated company reference won’t !!


Approach # 2 : Using $.serializeArray() to bind complex data structures


If you just change the mark up a bit, then we could get the person object and its associated company reference built correctly Smile

<label for="CompanyName">Company Name</label>
<input type="text" id="txtCompanyName" name="Company.Name" />

Approach # 3 : Using custom javascript objects


Let’s define a custom class that mimics Person and it’s associated Company classes as follows:

// Javascript object
    function Company() {
        this.Name = '';
    }
function Person()
{
    this.FirstName = '';
    this.LastName = '';
    this.DOB = '';
    this.Address = '';
    this.Company = new Company();
   
}

The other approach to posting data without using serializeArray() is to post the custom javascript object itself as follows:

var person = new Person();
        person.FirstName = $("#txtFirstName").val();
        person.LastName = $("#txtLastName").val();
        person.DOB = $("#txtDOB").val();
        person.Address = $("#txtAddress").val();
        person.Company.Name = $("#txtCompanyName").val();         $.ajax({
        type: 'POST',
        url: '@Url.Action("Index", "Home")',
        traditional: true,
        cache: false,
        //contentType: 'application/json',
        //dataType : 'json',
        async: true,
        data: person,
        success: function (msg) {
        alert(msg.Status);
        }
        });

In this approach, the properties on the Person class gets set properly while the company object (the reference) would be null !!


Approach # 4 : Using JSON.stringify()


If you wish to post a custom javascript object, then you should use JSON.stringify (), an API available from json2.js (an open source javascript library). The beauty of this API is that it takes care of escaping the JSON special characters ( { } “ ‘ : and ; ) too.


The following javacript illustrates the usage of JSON.stringify() to post the data to our action method:

$.ajax({
            type: 'POST',
            url: '@Url.Action("Index", "Home")',
            traditional: true,
            cache: false,
            // Model binding doesn't happen without the following two lines!
            contentType: 'application/json',
            dataType: 'json',
            async: true,           
            data: JSON.stringify(person),
            success: function (msg) {
                alert(msg.Status);
            }
        });

The source code for the above POC is available here

Thursday 5 July 2012

JQuery MultiSelect plugin (enhanced)...

HTML Select is one of those controls (File upload is the other) that doesn't support styling out-of-the-box and that is when web developers choose to use Jquery plugins that could render these select elements with a cool look-and-feel. Jquery Chosen, StyleSelect and Dropkick are a few of the plugins that I used in my projects. Some of these plugins support multi-option selectable lists too.

A few of the issues that I ran into while using these plugins are:
  1. Issues while using them as cascading dropdowns (eg: Country & State dropdowns)
  2. The plugin uses the actual select element and renders a set of
    or tags. Any change to the underlying select doesn't update the rendered tags !
  3. Present a "disabled" select properly.
For multi-select jquery plugins in particular, I like the one @ http://www.quasipartikel.at/multiselect/

The original one looks like this and the primary issue with the look-and-feel is that it has the selected items to the left and from a usability point of view, having the selected items on the left is good.

The other issue is that this plugin doesn't handle "disabled" lists !

On the other  hand, the advantage with this plugin is that it supports "destroy" which is very handy while recreating the control from a programmatically modified list.

I am for this control with the fixes to the above issues and I have modified the source code to adjust the control to fit my needs.
Here are the screenshots from the modified implementation and the source code can be downloaded from here

Selected items to the right
Disabled multi-select

Jquery StickyNote plugin

Jquery is undoubtedly one of the best javascript frameworks especially when it comes to parsing HTML DOM. What is even more interesting is a "jquery plugin". I published one article - Jquery lookup plugin, a few months ago. This time, I came up with one other plugin that looks like the one in the image.

I personally use 7 Sticky notes program to track my "TODO" list, however, having one such thing for a web application is what I found interesting.

Developing a jquery plugin is easy if you follow the structure and the published best practices. I tried to implement the plugin following the guidelines @ http://docs.jquery.com/Plugins/Authoring

The plugin is a simple javascript accompanied by a bit of css for the look-and-feel. I have created a small ASP.NET MVC application that uses this sticky note plugin. One of the highlights of this plugin is the way it persists the content as well as visibility across pages.

Download the source code from here and hope you find it useful.


Saturday 26 May 2012

Track My PIE

I am back from hibernation and this time with a tool that can help you manage your expenses and income.

Of late, I am busy working on things like ASP.NET MVC3, MVC4, developing apps for mobile using MVC4 and JQuery mobile and at times trying to make my hands dirty with interesting javascript frameworks like Ember.js and knockout.js.

With lot of action in life, I found that I should put up something on the web (for free, to start with) that most of us could use.

Let me take a couple of examples here just to set the background for what I have developed:

All of us (or rather most of us) are money conscious and we would like to track our expenses / income and we might not be able to do that though. I attempted to track my expense / income in excel spreadsheets and gave up just because I was lazy or fed up maintaining data in excel sheets. I tried Google docs too.

I was on a look out for good websites out there that offer this service and I ran into money manager softwares (there are many of them). Not to take names with due respect to the effort behind those portals, I found that the available tools offer me more than what I want and a bit complex to use too. Frankly speaking, I am very poor at Math so am at Money. All that I am looking for is a piece of software that helps me record my expense and income.

But is that all what I want ? Nope !

I felt that I would not be recording my own expenses / income all the time.. I am treasurer for my apartment and I am required to track the transactions w.r.t my apartment, I also take care of my brother's transactions .. this means that you will end up recording transactions that do not necessarily of yours yet when you list them down, you might end up segregating them and I think that's pain :D

So the first thing that my software should offer is a way I can tag the transactions so that I can differentiate them pretty easily.

Suppose that you have recorded a bunch of transactions for a particular purpose - say, you celebrated your daughter's first birthday or you are working on interiors of your flat or you went on a holiday with your loved ones, etc,etc... Now, one of your friends might be following your actions - say your friend bought a flat and is working on interiors - Wouldn't your friend be interested in checking with you on what all did it cost for you while working on your interiors?

Wouldn't it help if you have a list of items your friend purchased for the interiors along with the cost of each item ?  Wouldn't it give you a check list to start with so that you don't miss something ? Wouldn't it also allow you to plan your budget?

The thing I am talking about is "sharing transactions" with friends.

That's primarily what I wanted to target and I came up with a software called "TrackMyPIE - Track my Personal Income and Expense". It is available for free now @ http://trackmypie.in

There is a very small wish list that I am working on to allow users record transactions on the move.

Take a look at the software, register and get a login and play with it and please do not hesitate in leaving feedback either as a comment here for this post or there is an option that you could use to "write to me" through the web app.

Hope it helps.

Cheers.