Sunday, August 12, 2007

Workflows, their data and dependency Injection of session - part one

The Session:
Web applications generally start simple with a few pages, transitions between pages and a few things to be communicated between pages. The data needed between pages are either passed on as query string or stored and retrieved from session.

Slowly, more and more pages start sprouting in the application. Each of these start needing some data captured or processed from the user in some page on the way to the current page. They also want to store some of their own information.

The application is functional, we can hit the web site and start browsing and shopping for articles on it. As time passes, we start discovering that a few knots are being formed over the items in the session. A few chinks in the armor are found when, objects stored in the session start getting removed, replaced or added without intention.

These spurious errors happen due to pollution of key names in the session.
There is a good chance that register user page would have saved the user registering time by:
Session["StartDate"] = DateTime.Today;
Similarly, assume the user is on a trial period for a subscription from tomorrow, the subscribe page might have:
Session["StartDate"] = DateTime.Today.AddDays(1);
So, without knowledge we have polluted the key space and tied our self with our own shoe laces. Now!, you might say, that's a school boy mistake.

You could avoid this at first by having keys like "User_Start_Date" or even have a constant string defined in a global constants class available in all pages. This way all keys are visible in one file and it is less likely to end up with same key names.

So, you would now use it like:

public class SessionKeys
{
public const string UserStartDate = "UserStartDate";
public const string TrialStartDate = "TrialStartDate";
}

Session[SessionKeys.UserStartDate] = DateTime.Today;
Session[SessionKeys.TrialStartDate] = DateTime.Today.AddDays(1);

But, there is still enough room for human mistakes to creep in. Further more, when I am done with creation of trial subscription for the user, I have to make sure of clearing of all information I created in the process but keep other information still in session.

It seems like we are missing an abstraction here. We will look at that in the next part.

Monday, April 16, 2007

Index of Janya Raagas

Problem:
A good list of janya raagas is compiled on Wikipedia. It has over 950 entries. I use it frequently to recognize and understand a raaga or to relate it to its Janaka Raaga. But, I need to spend a lot of time to find the raaga on the list.

Diagnosis:
An index of raagas to their melakarta raagas is needed.

Solution:
Used WatinN, a simple yet powerful open source web testing tool. Wrote a program to load the raagas from the janya raaga list and then produced the indexed list. Further, the melakarta raagas are in bold to recognize them upfront.

Result:
Download the quick index of raagas. Feel free to take a print out and take it your next carnatic concert along with a print out of the janya raaga list to quickly find related raagas or to lookup the ascending and descending scales.

Source Code:
If you are interested in source of WatinN Script written to convert the raaga list, you can download the solution.

Monday, March 12, 2007

Trouble Accessing USB Hard disk in Windows XP

Problem:
Took a 20GB, 2.5" laptop hard disk in an aluminium case with USB interface.
Windows recognizes disk but cannot assign a drive (Missing in "My Computer")

Diagnosis:
Possibly has a file system not recognized by Windows.

Solution: (Will loose data on the drive)
Ran command: diskmgmt.msc
Deleted Partition And Formatted to FAT32, assigned a drive letter(H:)

Takes some time to finish formatting. (In "My Computer", Drive is visible, but the free & used sizes are not visible)

Result:
All set to use it in windows.
Haven't yet checked whether the (FAT32) drive now works fine with Linux (Ubuntu).