Bollywood ringtones is now available in Windows Phone Marketplace


Today I received the email from Windows Phone Marketplace team that  my application, Bollywood ringtones is now published. Well this is my first windows phone 7 app in the market place. This blog post shares my experience right from the conceptual idea to the final publishing. I always intended to keep my blog technical but this post would be a bit exceptional but I assure you that I will share the secrets and some tricks which I discovered during this pet project of mine with the community in future posts. And later or sooner if time permits I will make this app an open source and will publish on codeplex.


You can call me fan boy of Microsoft. The company and its technologies have always inspired me and motivated me to such a extent that even after 12 years of industry experience I feel hard to get detached from the technology. I was early adopter of Windows Phone device as soon as hit the Indian shores. I was also a vivid user of Windows Mobile right from Win CE 5.0 to Win mobile 6.5 . It really amazed me the things I could do on this 4 inch device. So I used to check my emails and surf the net on my mobile device even eight years back Smile. Do you remember those HP-ipaq , Qtek PDA’s. One thing I must admit that those devices were extremely flexible and the SDK or .net Compact Framework had a very rich API’s and you could do wonders with them. Let me give you example of one small feature which was like a big push for me to develop this app. I could make any mp3 file as the ringtone by just long hold or right click on the selected file, a context menu would appear and all I need was to do select and option “Set as Ringtone”.  Windows Phone 7 is designed keeping consumer or end user in the mind rather than the developer (We developers want to do everything impossible Winking smile). So no wonder there wasn’t any such features in WP7 available which could go at OS level. There wasn’t even an api also available in pre mango SDK for setting up the custom ringtone. I hope the SDK will mature in up coming releases which will allow developer to flex their muscles.

I always missed it as I am great music lover and always keep on changing my ringtones every week to my favorite songs. There are other apps also in the marketplace which allows to set ringtones but not the Bollywood songs. Their lists are also pretty static and don’t keep updates. The USP of Bollywood ringtones is that I shall keep updating the ringtones every two weeks . If you as a user doesn’t find you favorite tune in the list just email me with its attachment and take my word it will be available in less than 48 hours. Below are some cool screen shots of the application.


MainPage RingtoneDetails RingtoneDetails1


I know you must be itching by now enough of talking share some tech info with us. So here we go. Bollywood ringtones is my pet project. I used to work on weekends for this. After long week of hard work at my day job somehow I used to get energy to sit down again and do the coding for my dream project. The app uses  Caliburn Micro 1.3.1 framework to achieve the MVVM pattern. Boss this is amazing stuff developed by Rob Eisenberg and has really impressed me. The learning curve was very little as I was already aware of this design pattern and there is an extensive documentation and examples available on the codeplex. The community support is immense I got answers to my queries in less than 24 hours which was really good and I was able to keep the pace of my development. Some of features used from this Framework are Actions, Coroutines, Tasks, EventAggregator ,StorageHandler etc.

The server part was done using Web Api. Again a cool technology from Microsoft makes development breeze. Though I am client side developer it didn’t appear a rocket science to me and I got up and running in less than 1 hour of time. Thanks to Glenn Block for his guidance and help. I used Entity Framework 4.3 with code first approach and MVC 4 Beta (It comes with GO-LIVE license) for developing my api methods / controllers.

I also used the Telerik RAD controls for Windows Phone 7. This is not a breaking news that Telerik is leader in custom controls and their products speak for themselves what more I could say about them. Their examples project which comes as a part of download helped me lot to get started with the controls. I have a confession to be made over here that I am developer and not a designer so the entire artwork was done by my younger brother Nazim (@nazqu5). He was immense help to me for making the application look sexy and sweet. I provided him few guidance in Blend and gave him design time data for developing in Blend. All the images were developed in Photoshop.

I also wrote Unit Tests for every viewmodels in the project. I used Jeff Wilcox unit test framework to test them. It was very pleasing to eyes that every tests was green. Last but not least I used Marketplace Testkit for making my app marketplace ready. No wonder that my app got certified in the first attempt itself.


  1. SharpGIS GzipWebClient from Morten
  3. Metro Grid Helper
  4. Isolated storage Explorer


For me developing app for Windows Phone 7 platform was very easy as I already knew Silverlight and WPF. If I calculate the hours spent on developing the fully functional app took twelve hours of coding. This include writing MVC code also. I have not included the art work and unit testing in this. Those are separate. Though Bollywood ringtones is free it supports ads. I know that I wont become millionaire from this but at least I would be able to make enough money to meet my per month fuel expenses Smile. I would strongly emphasize that every developer must try their hands on it and grab this rising opportunity. Microsoft India has great contest for the developers which can won you Windows Phone device. So start rolling your app today.


Dynamic Theme Switching in Silverlight Prism App



In my recent consulting assignment I was asked the question by one of the developer , that how can we get dynamic theming working in Prism application.My answer was that you can implement in the same manner as you do in the standard Silverlight application. But then he further asked that there are various regions in the RegionManager and how each views loaded in the different content regions can get unified theme , this encouraged me to try this out and see how it works.I started working on it and viola my answer was correct , there is no difference in implementing dynamic theming in prism specific app. In this blog post I explain you the same. I assume that readers are already aware of Prism library. If you are not then I strongly recommend that you acquire the knowledge of the same. In my example you will see the very basics of Prism app but the library has much more to offer.


I created a very simple PRISM application which had only one Module (ModuleA). This module is loaded on demand when you click on the menu link which is under the ShellView.The application default gets loaded in the BlueTheme but it allows you to change the theme on the fly from the Themes menu. See the screen shot below of both themes.




The application has two content regions (MainContent and FooterContent).

Code Snippet
  1. <menu:Menu Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Top">
  2.             <menu:MenuItem Header="Modules">
  3.                 <menu:MenuItem Header="Load Module A" Command="{Binding LoadModuleCommand}"/>
  4.             </menu:MenuItem>
  5.             <menu:MenuItem Header="Themes">
  6.                 <menu:MenuItem Header="Blue" Command="{Binding Path=ChangeThemeCommand}"
  7.                                        CommandParameter="BureauBlue.xaml"
  8.                                        IsChecked="{Binding IsBlueThemeSelected}"/>
  9.                 <menu:MenuItem Header="Black" Command="{Binding Path=ChangeThemeCommand}"
  10.                                        CommandParameter="ExpressionLight.xaml"
  11.                                        IsChecked="{Binding IsBlackThemeSelected}"/>
  12.             </menu:MenuItem>
  14.         </menu:Menu>
  15.         <ContentControl prism:RegionManager.RegionName="MainContentRegion" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="12" />
  16.         <ContentControl prism:RegionManager.RegionName="FooterContentRegion" Grid.Row="2" Margin="12"/>

Let me show you the code which does the magic of dynamic theming.

Code Snippet
  1. public DelegateCommand<string> ChangeThemeCommand
  2.         {
  3.             get
  4.             {
  5.                 if (_changeThemeCommand == null)
  6.                 {
  7.                     _changeThemeCommand = new DelegateCommand<string>(x =>
  8.                     {
  9.                         Application.Current.Resources.MergedDictionaries.RemoveAt(0);
  10.                         var theme = Application.GetResourceStream(new System.Uri("/Shell;component/Assets/" + x, System.UriKind.Relative));
  11.                         var rd = (ResourceDictionary)(XamlReader.Load(new StreamReader(theme.Stream).ReadToEnd()));
  12.                         Application.Current.Resources.MergedDictionaries.Add(rd);
  13.                         if (x == "BureauBlue.xaml")
  14.                         {
  15.                             IsBlueThemeSelected = true;
  16.                         }
  17.                         else
  18.                         {
  19.                             IsBlackThemeSelected = true;
  20.                         }
  21.                     }, y => _moduleLoaded);//only allow to change themes when module is loaded
  22.                 }
  24.                 return _changeThemeCommand;
  25.             }
  26.         }

The ChangeThemeCommand is DelegateCommand of String type. The command argument excepts the filename of theme. All theme files are located in Assets folders of the Shell project. The default theme is initialized in the App.xaml file with special syntax. It removes the current theme and loads the selected theme and merges it into the Resource Dictionary.

Code Snippet
  1. <Application.Resources>
  2.         <ResourceDictionary>
  3.             <ResourceDictionary.MergedDictionaries>
  4.                 <ResourceDictionary Source="/Shell;component/Assets/BureauBlue.xaml" />
  5.             </ResourceDictionary.MergedDictionaries>
  6.         </ResourceDictionary>
  7.     </Application.Resources>

This special syntax allows to access the files across different assemblies or xap files via relative paths.


This was super simple to implement it and I highly recommend the devs to implement this feauture in their apps. Last a ninja tip. Always mark your assemblies in the module projects to CopyLocal=false if they are already referenced it in the Shell project. Download the sample code from here.

Windows Phone geocoding with Rx


I had heard lot about Reactive Extensions (Rx) in the past but never got a chance to play with it until recently one of my project requirements were idle to make use of this great library.In this post I share my experience on how I used this library. Before we jump into code I would like to summarize the definition of Rx for the readers who haven’t known about it.


Up till now we had heard that computers came up with multiprocessors and gigabytes of memory but now we are hearing the same for even mobile devices. The new models do come with dual core processers and enough memory. As a developer you need to adopt some special programming techniques to unleash this power. You must write concurrent and asynchronous code to scale up to the hardware. When we talk about the asynchronous programming lot of caution needs to be taken for threading and deadlock issues. Fortunately Rx.NET does all this heavy lifting for you and gives you a fluent api for Async programming with LINQ flavour.Rx.NET is developed at Microsoft Labs and comes for full .net Framework, Silverlight, Windows Phone and JavaScript.
Rx is based on the Observer pattern from the world of object oriented programming. This pattern is based on the Observable collection, known as a Subject. You register or subscribe as an Observer for this Subject and you get notified whenever there is a change in the collection. Let me explain you this with example code.

var numbers = Observable.Range(1,50);
numbers.Subscribe(x =>
textBlock1.Text += String.Format(" OnNext: {0}", x),
ex => textBlock1.Text += String.Format(" OnError: {0}", ex.Message),
() => textBlock1.Text += " OnCompleted");

In the above example the numbers collection is between 1 to 50. I subscribe to this collection for getting notifications. This is achieved by specifying the first argument of the subscribe method which is OnNext action method. The second argument is OnError , which is again the action method, you can handle the errors here and finally the OnCompleted, where you can do the cleanup if required or do the final processing.
Rx is entirely based on the LINQ and support all its extension methods like Where,Take,Skip etc. LINQ works with collections that implement IEnumerable,which are known as enumerable collections. Rx works with collections that implement an extension to IEnumerable, IQueryable, which is refer to as observable collections. Hope you must have got the fair idea of Rx by now for further study I would redirect you to Rx official site where there are great tutorials and samples to get you started.


As mentioned above Rx library is available for Windows Phone 7 also, It is part of the SDK itself and you don’t need a separate download. All you need to add reference to your project two assemblies.
In the sample application we display the GPS status and its coordinates coming from the location emulator. The user clicks on the Start button and then clicks on the location emulator to see the coordinates getting changed in the phone emulator. See the screenshot below for more clarity.


To capture the latitude and longitudes you need to handle the PositionChanged event of GeoCoordinateWatcher class. The eventargs of this event is of prime importance to us as we will be using it to get the positions. See the code below.

var positions = Observable.FromEvent>(watcher, "PositionChanged").Where(g => !Double.IsNaN(g.EventArgs.Position.Location.Latitude) && !Double.IsNaN(g.EventArgs.Position.Location.Longitude));

positions.ObserveOnDispatcher().Subscribe(geo =>
this.txtPositon.Text = string.Format("{0:###.0000N;###.0000S;0}, {1:###.0000E;###.0000W;0}"
, geo.EventArgs.Position.Location.Latitude
, geo.EventArgs.Position.Location.Longitude


In the above code one thing to look is the Observable.FromEvent(watcher, “StatusChanged”). I am telling the Rx to Capture all the values coming from the observable collection of GeoPositionChangedEventArgs on the watcher object which is of type GeoCoordinate and the event name is PostionChanged. This will dump all the values of incoming coordinates in the positions variable. And then further I am interested in this collection so I will subscribe to it and will be notified whenever this collection gets changed. If you remember on the top I mentioned that Rx goes hand in hand with Linq and supports all its extension methods. Here in the above code I using Where to get only valid lats and longs which is having proper double values rest will be discarded. On receiving the notification that is onNext Action method ,I simply update my TextBlock Text in proper format of gps position.To avoid the cross thread issues I am using the ObserveOnDispatcher extension method.


I have barely scratched the surface of Rx there is a lot to it. I strongly recommend that all devs should acquire its knowledge and used it in their projects.Rx makes Async programming breeze which makes it as an idle choice to work with webservices.
Download the sample code of this post from here.

Cheers :)

How to create Tag Cloud in Silverlight



A tag cloud is a collection of texts that gets classified into the level of the importance. Text with greater importance are shown in the bigger size followed by the preceding importance , in short they are arranged in descending order. The importance is identified by one of the property usually a numeric value. It is one of the popular way for data visualizations. It is really gaining great heights in Business Intelligence 2.0 world. In this post I shall teach you how you can create tag cloud in Silverlight.


To showcase my example we will take the top ten stocks that were traded on the stock exchange by their last trading price. See the screen shot below.


As you can see from the above picture. The company names text font size are appearing based on their last trading price. I have taken only two colors (Magenta and Blue) but the developer can implement a random color logic also here.


To generate the tag cloud in Silverlight is super simple. I have taken a wrap panel control available in Silverlight toolkit. I then add each textblock as children of this wrap panel. All this is done using MVVM Light Toolkit version 4 , which is still in Beta state but it is pretty stable. Let us dive into the code to have better idea.

public class MainViewModel :ViewModelBase

        public MainViewModel()

            GenerateCommand=new RelayCommand(()=>
                                    var stocks = GetStocks();
                                    double minLastPrice = stocks.Min(a => a.LastPrice);
                                    double maxLastPrice = stocks.Max(b => b.LastPrice);
                                    double diffLastPrice = maxLastPrice - minLastPrice;
                                    const double minFontSize = 15.0;
                                    const double maxFontSize = 40.0;
                                    const double diffFontSize = maxFontSize - minFontSize;
                                    for (int i = 0; i < stocks.Count(); i++)
                                        Messaging.RaiseAddTextBlock.Send(new TextBlock { Text = stocks[i].Company, Foreground = i % 2 == 0 ? new SolidColorBrush(Colors.Magenta) : new SolidColorBrush(Colors.Blue), Margin = new Thickness(3), FontSize = minFontSize + stocks[i].LastPrice * diffFontSize / diffLastPrice });


        public RelayCommand GenerateCommand { get; private set; }       

        private List<Stock> GetStocks()
            var stocks = new List<Stock>
            new Stock { Company = "TATAPOWER", LastPrice= 105.25},
            new Stock { Company = "TATAMOTORS", LastPrice= 169.90},
            new Stock { Company = "DLF", LastPrice= 228.55},
            new Stock { Company = "SESAGOA", LastPrice= 214.35},
            new Stock { Company = "IDFC", LastPrice= 121.15},
            new Stock { Company = "TATASTEEL", LastPrice= 434.70},
            new Stock { Company = "INFY", LastPrice= 2597.50},
            new Stock { Company = "STER", LastPrice= 117.40},
            new Stock { Company = "RELIANCE", LastPrice=829.20},
            new Stock { Company = "WIPRO", LastPrice= 344.65}
            return stocks;


The above code is not a brainer and it is self explanatory . The only thing that needs to be considered is the FontSize property of the textblock where I put the logic of displaying the size as per the LastPrice property of the stock class. The datasource of my Tag Cloud is hard coded collection but it could be dynamic also.


Silverlight as a platform as a tremendous potential to develop BI apps. You can create great data visualizations from the toolkit available or from the third party controls from the different vendors. I encourage developer to explore this area and create a appealing user experience for your BI users. Download the sample code from here and enjoy Smile.

What is stored for developers in Windows 8

Now that the BUILD conference comes to end. It time to reflect what were the announcements made in it. I would especially give my thoughts from the developer perspective. I will summarize it in few points that matter most to the developers.

  • SILVERLIGHT IS ALIVE AND KICKING : I think Microsoft has silent its critics who were telling that Silverlight is dead and HTML 5 and JavaScript would be native development technology for Windows 8. With new version of Silverlight about to release by this fall. Tons of new features and improvements have been done in new version and I’m looking forward to develop my first production app. Microsoft has also given importance to new trend where the competition is heading that is HTML 5 and JavaScript. The developer has the option to develop in this language also. My old friends of C++ don’t get disheartened your skills are still in demand and you can program on Windows 8. So this summarizes that there is not one technology on which you can develop apps. Folks at Microsoft has kept their promise of backward compability.


  • WINDOWS RUNTIME (WINRT): Welcome to this new acronym. Uptill now you must have heard about .net framework but to develop the apps for Win8 you would require to enter new arena of Windows Runtime. This still will be managed code according to the speculations it is the subset of .net framework only where MS has picked and choose the namespaces and classes which could very well gel with new platform. Tim has a great blog post mystifying the facts and speculations of new runtime. You can read it over here.


  •  METRO STYLE APPS : Get yourself acquainted with this new style. As windows 8 natively support touch input natively. All the apps that you would be developing should support this style. This is something that is derived from Windows Phone 7. I had always loved Metro theme, smooth and fluid. All the apps should be touch centric and chromeless. You need to get your application certified before publishing it to the store. There are guidelines available and once you follow them there are 100 % chances that your application would pass in one attempt. As mentioned above keeping the backward compability in mind you can still continue to develop the apps in traditional old style like desktop or standard web apps running in the browser. MS has committed that whatever that is running in Windows 7 will run in Windows 8. All you need is to switched to the desktop mode. You have Visual Studio 2011 IDE for doing the development of this types of apps. It comes with preinstalled templates and each template comes with lot of boiler plate code to get you quickly started. Blend 5 now support HTML authoring also.


  • HARDWARE AGNOSTIC : This is the perhaps the best feature I like about new platform. As windows 8 runs equally well on all the form factors (various screen sizes ranging from dual monitors to tablets). It will run on Intel based processers as well as ARM based. I was mesmerized when I saw the demo where Steven Sinofsky showing Win8 running on ATOM based processor with 1 GIG of RAM. Awesome simply awesome. Imagine here the opportunities that lies for you as a developer, your app running on laptops,desktops and now even tables or slates. You can always monetize your efforts and earn few extra bucks besides your day job. I am not saying that it will make you millionaire Smile , but opportunity is definitely there.


I have been in this industry now for more than decade and this is probably the best time I am having in my career span. Lot of excitement times ahead and huge opportunities for developers to seize.

So start brushing up your skills


Creating Fault Tolerant Silverlight Applications



As an enterprise application developer you have to face lot of challenges. You are responsible for designing and developing highly scalable and fault tolerant systems. The systems that you develop are life line for your enterprise any downtime in it can cause a rippling effects and sometimes even loss of revenue. Your worries get more when you come to know that the application that you are working on shall be deployed on shared hosting environment. Though you have the SLA with the hosting company of  99.9 % uptime but servers do get crash and they backup or failover servers gets replaced so that your users get minimum downtime. I recently overcome this challenge and wants to share my experience with the community. The application that I developed was deployed on shared hosting environment with SQL Server on a separate box. The hosting company had a failover mechanism in place where by which if the server on which my database was running had some problems it will be taken over by the failover server. Now the question over here how will my application know that the main server is down and I have to switch over to the failover server because the connection string was already hardcoded in the web.config file which was pointing to the main server.This application was developed using Silverlight and WCF Ria Services. I took up this challenge and in the end came out with the elegant solution. So keep reading.


I need to device a solution by which my app knows that which sql server it needs to point out before retrieving or submitting the data. For the  readers information both the database servers were always sync with the data , there was bi-directional synchronization mechanism already in place by the hosting company. So I was assured that my users would never get any stale data. After doing a bit of head scratching I found the way out. As I was using Entity Framework ,Visual Studio generates code based on your logical model when the solution was build. This generated code can be found under your .edmx file. It has the extension .designer.cs . Refer to the figure below.


If you open this file you would find one partial class which inherits from the ObjectContext. As this class was partial I can always extend it in other class and use its existing partial methods. In my case I used the partial method OnContextCreated . The code of this this extended partial class is shown below.



The above code is no teaser. In the OnContextCreated method I check for the main server connection is working or not by calling the function CheckIfSqlServerisRunning() . If this function returns me false then I call another function which gets me the alternate connection for the failover sql server. CheckIfSqlServerisRunning function will return me true if I am able to open the connection successfully else it will return false. But the real potatoes and meat is in GetAlternativeConnection function. This function builds up the dynamic Sql connection string using SqlConnectionStringBuilder class and then I use the EntityConnectionStringBuilder class to make the Entity connection string.

The OnContextCreated method will be called whenever your domain service methods wants to perform any database operations and that is the catch. You always ensure that you give a valid sql connection to the service so it doesn’t fails and your user can get data seamlessly without knowing from which database server the data is coming from. You change the connection on the fly if the main server is down.


As the saying goes “WITH GREAT POWER COMES GREAT RESPONSIBILITIES” , the same thing applies to a developer. You carry a loads of responsibilities on your shoulder for the enterprise to become successful. Any bad code written by you can not only ruin you but your organization too. So first think and then code.


How to work with Hierarchal data in Entity Framework


A couple of years back I blogged about how to retrieve the hierarchical data using T-SQL features. You can read that blog post here. Today life brought to me the same cross roads and I decided to take new route , so instead of using the T-SQL approach I preferred to go towards the Entity Framework. Microsoft has recently done some great enhancements in this data access framework especially with the release of version 4.1 , you can also take the advantage of code first approach. In this post I show you how you can get hierarchal data from your database using Entity Framework. So let us get started.


In this post I am using the same example which I used for my earlier post. We have same employee table but this time it is self referencing table. The EmployeeId column, which is the primary key in the table is referencing to the ManagerId column (Allow null is set to true) in the same table. See the screen shot below.

Self referncing Employee table

The following is the sample data in this table

Employee table data

In the above screen shot you must observe that the ManagerId for the first row is null, which means this is the root in the hierarchy.

So now when you import this table into your model using the Entity Framework wizard , as this is self referencing table the wizard will create two navigational properties called Employee1 and Employee2 respectively. Refer to the screen shot below.


These two properties does not make any sense to the developers, so let us try to rename it. Right click on the Employee1 property and select properties from the context menu. In the properties window you will see that the multiplicity is set to multiple, which means that the association is of Many type. Check out the screen shot below.

Employee1 property

In the same manner let us also rename Employee2 property , if you right click this property and see the properties window you will find that multiplicity of this column is set to 0..1 , which means that the association end can be null or one. We will rename this column to Manager as seen in the screen shot below.


Let me explain you further about the database relationships. Any relationship in the database has three characteristics.

  1. Degree : is the number of entity types that participates in the relationship. Unary and Binary relationship are most common.
  2. Multiplicity : is the number of entity types on each end of the relationship. Few examples are 0..1 (zero or one), 1 (one) and * (many).
  3. Direction : This can be unidirectional or bidirectional

In our example Degree is of unary type , as only Employee entity is involved in the relationship. Multiplicity is 0..1 and * and direction is bidirectional.

I hope that the above discussion have cleared your concepts about the database relationships, let us see now some code which displays the hierarchal data.


The above code loops through employee entity and checks whether the manager property is null and based on that writes the output . See the output for this code below.



Anything new that comes out from Microsoft stable excites me. I always make a point to utilize the new technology whenever I get new project or opportunity. This blog post was also the result of the same passion. I encourage developers to keep the learning passion always alive because if that dies then consider your career to be finish. Let me know your thoughts on it in the form of comments.