Janka's rambilng on boring stuff
Janka's Blog
10Jul/100

SQL Search in database from Management Studio

Posted by Janak Gheewala

Have you ever wanted to change one of he fields in the database table? I am sure changing the field is not a problem but the issue is a huge issue when we try to find out where in the whole database is this column referenced. There is a brilliant too by Red Gate called Sql Search. Its very quick and its Free as well! Worth giving it a go.

  • Print
  • PDF
  • RSS

Share
9Jul/100

Translation to & from Gujarati.

Posted by Janak Gheewala

I have always wanted a good translator to translate to and from gujarati. It has got loads of features like Phonic keyboard for those who need to see what they are typing. Its got a dictionary, Opposites, Thesarus, Idioms, Proverbs and other interesting features. Please visit Gujaratilexicon for more info

  • Print
  • PDF
  • RSS

Share
8Jul/100

Disposing Proxy calls to WCF Services

Posted by Janak Gheewala

How many times have we had this issue, you call a WCF (of infact any other service) and due to some exception the the call to the service is not disposed and will eventually eat up all the resource.

A classic example of such issue is

<pre>
<pre>	public void Save(Message message)
	{
		IService _service = new ServiceClient();
		SaveMessageRequest request = new SaveMessageRequest{Message = message};
		_service.SaveMessage(request);
	}


To resolve this ussye we will make changes in two steps.

Step 1:

We will define a partial class with dispose method.


    public partial class ServiceClient : IDisposable
    {
        /// <summary>
        /// A partial class for ServiceClient
        /// Used to correctly close or abort a WCF proxy call.
        /// You MUST wrap the proxy call with a USING statement as DISPOSE will ALWAYS be called
        /// </summary>
        void IDisposable.Dispose()
        {
            // Check to see if the call has faulted
            if (State == CommunicationState.Faulted)
            {
                // We must abort the proxy as closing it will cause an exception
                Abort();
            }
            else
            {
                // Close the proxy
                Close();
            }
        }
    }

Step 2:

 We will change the save method to look as below. This will make sure that before the execution exits the using, the dispose method is called to dispose the service client.  

	public void Save(Message message)
	{
		using (ServiceClient smsProxy = new ServiceClient())
		{
			SaveMessageRequest request = new SaveMessageRequest{Message = message};
			smsProxy.SaveMessage(request);
		}
	}
  • Print
  • PDF
  • RSS

Share
8Jul/100

Online Chess Puzzles

Posted by Janak Gheewala

I came across these two online chess puzzle websites. I think this is a good way to improve your tactical game!

  • Print
  • PDF
  • RSS

Share
8Jul/100

AJAX & JQuery Paging with ASP.NET MVC

Posted by Janak Gheewala

I am currently doing a small project on MVC. With web development, there is a basic requirement for presentiong data. paging ... you will find a lot of articles on both this. I came across an article which was very useful. This article by Martijn Boland is a very good article if you want to use microsoft ajax.

Of course, in these days, nothing is ever good enough if it's not using JQuery. I have done a small demo app to show this. You can download the demo app from here.

Right.  After a bit of tweaking I have the code ready. I have used the sample application of NerdDinner for this demo. So you can get the code from Codeplex and make the necessary change. Please complete the following steps to make the changes.

Step 1:

We will first Add a list Model. We will call it DinnerListModel. The definition of which is given below.

<pre>using System.Collections.Generic;
namespace NerdDinner.Models
{
public class DinnerListModel
{
public IEnumerable<Dinner> Dinners { get; set; }
public int TotalRowsCount { get; set; }
}
}

Step 2:

We will Add a partial view to show the paged data. The contents of the partial view is listed below.

<pre><%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DinnerListModel>" %>
<%@ Import Namespace="NerdDinner.Models" %>
<ul>
<% foreach (var dinner in Model.Dinners)
{
%>
<li>
<%= Html.ActionLink(dinner.Title,"Details", new{id=dinner.DinnerId})%>
on
<%=Html.Encode(dinner.EventDate.ToShortDateString())%>
@
<%=Html.Encode(dinner.EventDate.ToShortTimeString())%>
</li>
<%
}%>
</ul>

Note that the partial class is now inheriting from DinnerListModel instead of IEnumerable<Dinner>. Also the foreach loop now selects from Models.Dinner instead of Model.

Step 3:

The contents of content placeholder "MainContents" will look as follows.

<pre><pre>	<script type="text/javascript">
	    function pageselectCallback(page_index, jq) {
		    $.get("/Dinners/", { page: page_index, pageSize: 10 },
				   function (data) {
				       $('#ListResults').html(data);
				   });
		}

		jQuery(function ($) {
			$('#Pagination').pagination('<%= Model.TotalRowsCount %>', {
				callback: pageselectCallback
			});
		});
	</script>
	<h2>Upcoming Dinners</h2>
<div id="ListResults">
<%
Html.RenderPartial("~/Views/Dinners/DinnerResults.ascx", Model); %>
</div>
<div id="Pagination"></div><br />
	<p>
		<%: Html.ActionLink("Create New", "Create") %>
	</p>

The changes we have made is replacing the foreach loop to show data by a div tag called "ListResults" which will load the partial view. Also added is a div tag for pagination. The JQuery code will fetch the records based on page selected and number of record per page. Here as well the Page tag will change to

<pre><%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<DinnerListModel>" %>

Step 4:

Don't forget to add the Jquery files to script folder and Pagination.css to Content folder. These will be referenced in the site.master file by the following lines.

<script src="/Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.pagination.js" type="text/javascript"></script>

You can download the JQuery library from here. The pagination css can be downloaded from here.

Step 5:

After this I will a a new Method Called GetDinnerResults on DinnersControls.

<pre>        private DinnerListModel GetDinnerResults(int? page, int? pageSize)
{
IEnumerable<Dinner> upCommingDinners = _repository.FindUpCommingDinners().ToList();
IEnumerable<Dinner> selectedDinners = upCommingDinners.Skip((page ?? 0) * (pageSize ?? 10)).Take(10);

return    new DinnerListModel
{
Dinners = selectedDinners,
TotalRowsCount = upCommingDinners.Count()
};
}

Step 6:

The Index method will change to

<pre>        public ActionResult Index(int? page, int? pageSize)
{
DinnerListModel dinners = GetDinnerResults(page, pageSize);

if (Request.IsAjaxRequest())
{
return PartialView("DinnerResults", dinners);
}
else
{
return PartialView(dinners);
}
}

The above code indicates that we should load the partial onto the index page when the code is executed for the first time. For all other subsequent pages it will not the load he whole page but only load the partial view DinnersResults.

  • Print
  • PDF
  • RSS

Share
8Jul/100

How to use Inversion of Control containers

Posted by Janak Gheewala

Today I came up with a very good blog entry on IOC  by Krzysztof Koźmic. This, together with RichP's blog would form a very good understanding on IOC.

  • Print
  • PDF
  • RSS

Share
8Jul/100

Building a class from type defined in config

Posted by Janak Gheewala

Last week I came across a situation where it was required that a class was to be created of type provided in config. Ideally this should be done via IOC. But there is an alternative way.

the following method explains the same

public static ISomeClass Build(string typeToCreate)
{
	Type instanceType = Type.GetType(typeToCreate);
	ISomeClass someClass = (ISomeClass)Activator.CreateInstance(instanceType);

	return someClass;
}

the class type in config is as follows

<?xml version="1.0" encoding="utf-8" ?>
<SomeClassConfiguration
...
  someClassType="Some.Class.Defined.SomeClass, Some.Class.Defined"
...
>
</SomeClassConfiguration>
  • Print
  • PDF
  • RSS

Share
7Jul/100

Google Distance calculator

Posted by Janak Gheewala

Ever wanated to know what is the exact on-road distance between any two point in google map? try using daftlogic.

  • Print
  • PDF
  • RSS

Share
21May/100

Buy a home in UK – A Beginers guide

Posted by Janak Gheewala

Yes, I want to buy a home in UK. Not sure when. But I thought I did start some research for my presonal benifit.

The plan is to buy a house which is either 30 miles from Office (RG21 6YJ).  If need be I will broaden the seartch by selected any town which is 30 miles from Basingstoke. The reason to do that is that I am an IT professional. I may end up having a job in London. So I want to be in a position where I can commute easily to London.

Where do I want to buy my house?

For that I have selected the following county's. If you click on the link, it will show you the list of towns in the county.

At the moment, I want to stay south/ south-west of London. If need be I will explore other regions later on. To get an idea of Range I am looking into please see the County Maps.

What Kind of houses do I want to buy?

House types:

The following concepts helps us in selection of house.

  • Preowned :  Somebody is moving out, or its a repositioned house.
  • New: Buy house from a new builder / build your own house.
  • Part owned / Part Rented: Mostly flats come unders this criteria. This is mainly because the house is on a leased land. The owner owns part of the house (mostly 60%) and you own the rest. This kind of house can be selected if your budget is very low and you have a very small / no family.
  • Free Hold: Best deal. You own the land and the house. Hence it is your liability / responsibility to maintain the land.
  • Leased: You own the property but not the land. After the lease of the land is over, anything can happen to your house. The land owner may claim the house with the land (TBC).
  • Flat: We also call it appartment. How you would love to have a penthouse!
  • Terraced house: This is similar to the concept of row-house in othe countries. Out of 4 walls, 2 walls are common and shared with your neighbour.
  • Semi detached: Only 1 wall is shared and you wond the other 3 walls.
  • Detached: Hurray! You own all the 4 walls. Ususally you have a floor in this house.
  • Bunglow: Very similar to Detached house, the only differece being that you don't have a floor here. Its the most expensive types of house as the amount of land is more.

I also found a link of chain free houses (Area + 30 miles of Basingstoke)

Some more links that may be useful are shown below.

List of Home Builders - 1
List of Home Builders - 2
Find a Land
New Homes - Houses from UK House builders
More Information on new homes
Leagel Process information

More info can be found on Pranav's Blog.

  • Print
  • PDF
  • RSS

Share
Tagged as: , , , No Comments
11May/100

Adding a reference of a WCF task hosted into a test Harness

Posted by Janak Gheewala

TDD is the in thing...

Recently I had to write a WCF task which was to be hosted in Windows services rather than IIS.

Although I did write a some test cases around it, the business case I was working on required me to write a test harness (it was a long running process & hence the decision to host it in Windows service & write a test harness)

Now since I already had a WCF service host client within the solution (see this post for more details), I could not add the reference to the test harness without an error as shown below

System.ServiceModel.AddressAlreadyInUseException: There is already a listener on IP endpoint 0.0.0.0:8532. Make sure that you are not trying to use this endpoint multiple times in your application and that there are no other applications listening on this endpoint. ---> System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted

at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)

at System.Net.Sockets.Socket.Bind(EndPoint localEP)

at System.ServiceModel.Channels.SocketConnectionListener.Listen()

--- End of inner exception stack trace ---

at System.ServiceModel.Channels.SocketConnectionListener.Listen()

at System.ServiceModel.Channels.BufferedConnectionListener.Listen()

at System.ServiceModel.Channels.ExclusiveTcpTransportManager.OnOpen()

at System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener channelListener)

at System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback selectTransportManagerCallback)

at System.ServiceModel.Channels.ConnectionOrientedTransportChannelListener.OnOpen(TimeSpan timeout)

at System.ServiceModel.Channels.TcpChannelListener`2.OnOpen(TimeSpan timeout)

at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)

at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)

at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)

at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)

at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)

at Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo info)Only one usage of each socket address (protocol/network address/port) is normally permitted

The reason for this error is that as soon as your try and add a reference to the WCF task, it will spin up the existing WCF host client in the solution and hence the error above. To be fair, it will still add the reference to the test harness.

I wanted to get rid of this, it is then that I had a chat with Mr. Fenton and he suggested me a quick work around for this issue. Here's what I did.

* Remove the test harness from the solution
* spin up the test harness project as a separate project.
* then add the reference to the wcf task.

lo, job done.

  • Print
  • PDF
  • RSS

Share
Tagged as: , , No Comments