Create OxyPlot pie-chart for Xamarin.Forms application

Currently, I am testing the waters of mobile development using Xamarin.Forms. For those who have not heard of it yet, as per its developer guides

“Xamarin.Forms is a cross-platform, natively backed UI toolkit abstraction that allows developers to easily create user interfaces that can be shared across Android, iOS, Windows and Windows Phone.”

It’s a great way to delve into mobile development for a C# developer. It allows to build native user interfaces for iOS, Android and Windows Phone wherein nearly 75% of the app code is shared across these platforms.

As a part of my pet project, I needed a pie-chart  and came across OxyPlot , an open source plot generation library, which was suitable for me. However, I had to overcome a number of hurdles before I could get everything working. So, this is my effort to document the steps of creating OxyPlot pie-chart for a mobile app built using Xamarin.Forms. So, here it goes! Continue reading


qTip Implementation in MVC Partial View

Recently, I came across a task wherein I had to show a list of dynamic information in a tooltip in a MVC project. So, I started playing around with qTip. My intent was to load the dynamic information within partial view and to load that partial view inside a qTip tooltip.

This article outlines the steps to show partial view in a tooltip using qTip. For demonstration purpose, we will create a list of events and will show the event details in the tooltip.

1. Create a MVC application.  The first step would be to download the necessary javascript files and css files to implement qTip2. This can be done by either using CDN from or by installing the Nuget Package using the following command. This will install the necessary jquery dependencies, script files and css files.


Continue reading

Breadcrumbs in ASP.NET MVC4

In this article, I will explain how we can setup and use the ASP.NET MVC Sitemap provider which consists of a full set of sitemap tools such as node navigation and breadcrumbs. It is recommended to get an idea on how the sitemaps work on ASP.NET website as most of the principals used in ASP.NET MVC are similar.

Here is a step-by-step guidelines for easy implementation.

1. Create a new ASP.NET MVC project. I have used MVC4 and chosen blank template for ease of demonstration.



Continue reading

Capture IP Address of Client Machine

For one of my recent user story, I had to find the IP address of the client machine. Nothing to worry about here. I just used the following property as suggested by several posts that I googled.

<br />string clientIp = HttpContext.Current.Request.UserHostAddress;<br />

The user story was completed and accepted. Everyone forgot about it.

But then after a couple of weeks, we got a defect story that says the IP address returned is not that of the client machine, but that of the load balancer. I was like WHAT???

Then, after a couple of hours of diving into the details, I found out what was the causing this issue. It turns out that the issue was with the property HttpRequest.UserHostAddress. We had used this property to get the IP host address of the remote client machine, which simply returns the server variable REMOTE_ADDR. This server variable returns the IP address of the remote host making the request. If there is a proxy server or a load balancer in the middle, this property returns the IP address address of that machine, and not that of the client machine.

So, to resolve this issue, we used another server variable HTTP_X_FORWARDED_FOR. For cases where load balancer or proxy machines are used, this variable contains the correct IP address.

The resulting code looked like this:

</p><p>string clientIp = String.Empty;</p><p>&lt;br/&gt;if(Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)</p><p>{</p><p>     clientIp = Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];</p><p>}</p><p>else</p><p>{</p><p>      clientIp = Current.Request.UserHostAddress;</p><p>}</p><p>

Thus, the defect story was closed!! Yay!!

Lesson learnt for me: Need to dive into details for any built-in property or functions that I use from today onwards!! 🙂

Happy Coding!!!:)

type=Timestamp in NHibernate

Recently, I was working on a user story that required recording login events to the database. The pieces of information that I had to audit were related to user such as userName, userId and login events such as event type, timestamp. Seems a pretty easy thing to do! Right? It is, except I came across an interesting issue, with a trivial solution, of course!


I had to record the timestamp at which the login event occurred. The datatype of the database table was set to timestamp(6).


This should provide a fractional seconds precision as per this. So I was expecting my login timestamps to be recorded with milliseconds precision. But I kept getting 000000 in the milliseconds portion. As you can imagine, I was like Argghh!!


Go Fishing:

Now I had to go fishing for the solution. I went back to my C# code, the portion where the object for login audit was saved to the database. The timestamp was simply set to System.DateTime.Now.


The issue was not resolved even after trying various formatting methods.


After hours of banging my head and googling (of course!), I found the solution. Thanks to NHibernate, the ORM that I was using then. The fix was just adding the “type=Timestamp” attribute to the EventTime field in the mapping file (.hbm.xml).


And now, thanks to NHibernate documentation, I am one happy person looking at my login audits. 🙂


Happy Coding!!! 🙂

Mocking HttpContext for unit tests

In this post, I will share the problem that I stumbled upon while writing unit tests for the code block that pulls values off the HttpContext. And yes, I started out writing unit tests finally, after several years of .NET programming.


I needed to unit test a module that pulls a value (in my case, it was the IP address of a client machine) off the HttpContext.


The problem was that when I tried to unit test this code block, I could not mock HttpContext directly since it is sealed. Also, I kept getting null reference exception as the current context did not exist when called from the unit test method. So, my unit test threw exception and did not run and kept on turning RED. 😦

Continue reading

ASP.NET MVC Starter Series – 2. How ASP.NET MVC works?

In the previous post What is ASP.NET MVC?, I provided a basic overview on the ASP.NET MVC, its advantages over traditional web forms and its components.

For this post, as the title suggests, I will focus on how ASP.NET MVC works. The figure shown below (fig 2.1) will help understand how the user request is handled in a MVC application.

fig 2.1 MVC workflow
fig 2.1 MVC workflow

Continue reading