Skip to main content

Posts

Showing posts from 2008

The "Dot" Behaviour

Its just my opinion about dynamic languages, so no need to be harsh.
Something that I miss in dynamic languages is IDE support, even if it exists, the "dot" behaviour is likley to be not there.
I mean that thing I like about Java and .Net editors is that you can easily make use of it for a quick dirty tool you need to implement, even though you might not no a thing about where to find which APIs, you hit the "dot" and you get a list of APIs supported by the class.
Now this behaviour is hard to find in dynamic langauge editors (for the reason the language type are dynamic), although you can write quick code using dynamic languages compared to Java or .Net, its not easy as every one says it is.
Either you have to go through the whole documentation to find out what your are looking for or try all possibilities.
Yes, you would have to do this sometimes in languages in .Net or Java (and strongly recommend the you read the documents before your use APIs for the sake of knowin…

Back to The Desk

Well, last 2 weeks went in a jiffy, I was on annual leave for 2 weeks and was hopping to spend some time with my family, but it turned out to be that I had to submit 4 assignments and had spend most of my time reading. I have backlogged so much of lectures that I thought its time for me to catch up, and it was boring some times, just proofs, theorm and out of the world ideas, but I think I am kind of liking this Masters.
Anyway, my desk at home is filled with thick books, Networks, Algorithams, Database systems, Coding theory etc...
I am proud to note that, we had some guest lectures from Virtusa to do some presentations and the one that happened last was by Sabri Sawad, Sr S/W Archectect, he did a presentation on Software Archetecture and some times back a presentation from Riza Wadood. Sr Business Consultant.
At office, I'll be doing a training on UML next week for some junior collegues, that better be good. Also had some time to download a tool that was pretty cool, but don't …

CLIP for VS 2008

The Microsoft Captions Language Interface Pack (CLIP) is a simple language translation solution that uses tooltip captions to display translations for English user interface terms for Visual Studio 2008.
CLIP can help those users who are not good in English to learn and use Visual Studio 2008 by providing translation for the most common user interface elements of the Visual Studio Integrated Development Environment (IDE).
CLIP for Visual Studio 2008 is available in Arabic, Czech, Hebrew, Hindi, Malayalam, Oriya, Polish, Tamil and Turkish, i.e. it will display translations from English into these languages.
You can download CLIP for your langauge here.

CRS and Me Getting Fatter

Picked this picture from Shuail's blog. That my first project, CRS...I would say the golden age.
I dont see most of them alot, either they are not in the same location or not in the company at all.
Well, you can seem me in the corner in a yellows striped shirt, and I was wondering how fat I have become. Me and the workout machine dont go together I guess, every morning I try to get on it and then I think, well lets sleep a liitle bit more..and I never get to do it.
Most recently I serviced my bicycle, so that I could at least ride that on the weekends and get some calories burning..well that did not turn out well either.Anyway the post is about CRS and not about how fat I have become (partially correct). There are some missing in that picture, Rasika, Prabath, Chandima and Mahasen.

No Time For Blog Posting

This is a post to let u'll guys know what I have been upto these days. It has been past one month since I have posted something.
So this is what has been happening, at office..we are targeting on beta and it has been a tough time putting up with defects, so I am sort of going home a bit late these days.
I started my MSc in Computer Science at the University of Colombo last month, so there goes my Saturdays and also some of my other free times where I was learning new stuff and watching technical videos.
The only day left then was Sunday, which I take some time to have a nap and the rest of the day I spend watching movies (all animated ones). I have given up on action, horror and romantic movies as they drag on for 2 hours or so, but animated ones just go until 1 or 1.5 hours.
So, all this adds up to no blog posting..but I am working on a plan to get some free time.

Going Bad with UI Prototypes

This whole month went busy at office, it was challenging work, made a number of mistakes and I am happy to say, by the end of the day I learnt out of it.I was tyring to get the module working with little knowledge of what the requirment was, this led me to lot of re-work and most of the time was spent discussing with the team what API should be given and how things should be done. Now I think it would have been better if we could have understood what we were really building. I have been developing the front end, most of the time it invloved only UI logic, the only thing that I had to do was, make service calls, get the data and display it, the requirment was based on a document that provided what the UI should provide, that was easy...I started designing the the UI, got a bunch of APIs from the service team, and started filling in, what I did not understand was the whole idea behind the requierment. As days went on, issues started to rise, and I had to sit with the service team and ask …

Dynamic Language Runtime (DLR), IronRuby and Advantages

What's being popular out there right now is something called IronRuby, which is an implementation of the Ruby language in .Net, which is built indirectly on top of the CLR.
So let’s talk a little about how IronRuby fits into the .Net world, something that you should know at this point is that Microsoft is building a common platform for dynamic languages called the Dynamic Language Runtime or DLR for the short, which runs as a service on top of the CLR.
DLR provides common functionalities like MSIL generation, GC, so that dynamic language implementers can focus on the implementing there dynamic language on top of this without worrying about the “gooing” part to the CLR.All that the language implementer needs to do at runtime is to parse the language, tokenize it and create a tree structure containing the expressions and statements and pass it on to the DLR.
At the next step the DLR is going to generate MSIL from these trees, and the MSIL would execute under the CLR. Some pretty intere…

Don't Try To Handle What You Cannot Handle

One thing that came up last week was that the sorting on one of the paged grid did not work, ok…so we were hunting the bug down, but lucky something popped up in the log file and saved the day.
Clicking on the sort headers, makes a service call to retrieve the sorted data, and the UI code was written in such a way that the service call is trapped inside a try-catch block, and if any exception occurred, the exception is logged and empty data returned.
And unfortunately the service query had a bug on it. So which brings me to the point, you should catch exceptions only when you can handle it, for example, you might have anticipated that a DuplicateNameException would be thrown, well go ahead, catch it and show a nice message to the user, but if you cant, don’t put it inside a catch block and bypass the exception just for the sake of not crashing the UI.
If you really want to log it, fine, log it then remember to re-throw the exception although re-throwing as its own performance cost.
And to…

The Same Old Story Continues and Continues...

I have put my source to build, hence have some time to write a post…
It’s been a while since there was a new post on this blog, reason?..ah work. There is much change that’s going on that does not give me time to write anything new. But this does not stop me from reading and experementing something new, so let me give you an insight on what I have been doing on my weekends.
I have been hooked up on learning about the Microsoft Dynamic Language Runtime (DLR), have been going through some videos and articles on that, and also to get a feel on all this, I started learning Ruby and started using IronRuby (the Microsoft implementation of Ruby). I am still in the process of learning more on this...but as it seems the process is slow as a worm.
Well,I hope I’ll be back again to blogging anytime sooner…I miss those free times

ADO.NET Data Services

In Traditional web applications, you request a page and the the server, process the request, makes some database calls if needed and put your data and HTML together and pass on to the client.This model has now changed with RIA, using AJAX, Silverlight and others Take for an example a hotel reservation page that uses AJAX for user interactions. Maybe the intital page loads with all available countries in a combo box. and when the user selects a country, all the hotels for that country is retrived through a AJAX call.
Now, this is different form the typical web model, initially by requesting this page, the server send out HTML and presentation logic (javascript in this case for AJAX) to the client. The request for the hotels for a particular country is a pure data call, where only data flows in the form of XML.

This example was just used to demonstrate the change from the traditionl web model, but you would find a lot more pure data calls then just one (like in this case) in real world we…

Making Applications Offline With Microsoft Sync Framework

Computers are not just on dektops anymore, we see mobile computing theses days. With the heavy use of laptops and smart phone.
When data is on the move, there are advantages of taking your data offline, this would typically mean that your client would have a data cache locally.

Having data locally has its own advantages, for example, your data is highly available, you can work offline even without connecting to your network (maybe while your flying). This model also reduces the network congestion, as users have there own copy of the data, they do not need to access the data via a network (this would be mostly true, when your applications is a few updates to the data but requires a large number of reads).

So, then again, you can work offline but you would also want to persist your changes or use the upto date date.This is where sycronization comes in, and so does Microsoft Sync Framework.
The Microsoft Sync Framework, is a set of libraries that can be used to develop offline applications, …

PEX - Automated Exploratory Program Testing

One of the prodcuts that is being reserched at Microsoft is PEX (program exploration).The team released a 0.5 version product last month and you can download it here.So what is PEX anyway, what does it try to solve?, Remeber how you wrote a method with "amazing" logic and you also wrote nice test cases to test this function, if the function is not very complex and have only a few paths it can take, you would end up with maybe a test case or two and some set of input data.But if your function is very complex and has a complex , you have to go through each and every path the program would take and generate you test data (and not to metion the test cases).
What PEX does is, it "scans" your program (the method you want to test) and comes with a set of test data for each and every path. Lets take an example.

[TestMethod]// mark this as a test case
[PexMethod]//PEX attribute
public void TestMethod1(int i, int y)
{
GetNumber(i, y);
}

//The method you want to test
private int GetNu…

ATOM and WCF Syndication

Something that got me intrested is, syndication feeds, more particularly on ATOM 1.0.This might not be new news for most of us, but for the sake of a post after a long time, I had to do this !.
Most of us might use feed readers, I use Feedreader, and for the people who dont know what this is all about, let me give you an intro.
Think of you visiting my blog, every day to see if I have posted something new, well thats hactic, but instead the feed reader can do this for you.
You simply subscribe to the Atom feed in the blog using your feed reader and your feed reader would periodically check if the blog has been updated, if so it will retrive a summary of the recently updated posts in the blog, and if you want to view the details, you can just click on a link and go there.
ATOM is the standard that these blogs expose there post summaries, so the feed reader knows exactly how to display the information.you can read more about ATOM here..
ATOM can also be used in business applications, for an …

WinForms : DesignMode

Back to WinForms...It was a user control which calls a service, I knew that if I wrap the service call inside a ComponentModel.DesignMode, I could get away with the service call being called at design time and the designer throwing me exceptions...Now this is not an issue at all when your are designing the control, cos' Visual Studio does not create an instance of the user control that is being designed, instead it creates a base class, UserControl, this is also true when you designing a form, a Form instance is created. Therefore .ctor of the control being designed is never called, so doesn't the service call.Now if I drag an drop this control (ctrl1) into another a control(ctrl2), the control's DesignMode property is true, but if I now drag the ctrl1 into a form, the DesignMode of ctrl1 is false.This basically means that ctrl2 is sited in the form and not ctrl1, makes sense right?.There are two work around that you can use to avoide this...1) See if the current process t…

Going Parallel With Parallel Extension For .Net 3.5

Now a days, almost all computers being used have multiple cores, for an example technologies like dual core.But, although you have dual core, generally you write programs that run on a single core, this does not utilize the total power of the multiple CPU or core that you have.
This is exactly the power what Microsoft Parallel Extensions for .NET Framework 3.5 (a.k.a PFX).gives you.
With PFX, you can write flexible programs that would take advantage of utilizing multiple cores in the environment it is deployed in, giving you high performance and scalabilty.
PFX comes in 2 "Flavours", Task Parallel Library (TPL) and PLINQ.
TPL gives you general APIs that can be used to make your program run in parallel, for an example , take the for loop below
for(int i = 0; i < 1000000; i++ )
{ //Do something that is not dependent on other iterations }

the for loop does 1000000 iterations, and does something that is not dependent on other iterations.Running this program in a mulit core machine …

Weekend at Namunukala.

Last weekend we took some time off, at Bandarawela. Climbing the Namunkala mountain and visiting some natural pools. It was a fun guranteed trip after all. This is our team.



Velocity : Distributed Caching

Caching is one way you could increase your applications response time. For an example, take
a hotel reservation system, where you might need to show a list of hotels for a particular
country in your reservation page.
For each and every reservation made by users, a service call or a direct database call is onvloved to fetch the list of hotels for the country the user has selected, and when the number of concurrent users to your system increases, the performance of your system decreases too.
To avoid these hits, caching of your hotel objects or a hotel dataset can be used, so you application can use these to respond to a request without calling the service or making a call to the database, further more the cache is updated at periodic intervals to accomadate changes to the underlying data.
Velocity is an in-memory distibuted caching solution from Microsoft, still in it's CTP,
addresses application scalabilty.
In typical applications you would cache your data in the host your application is…

Better Late Then Never

It's been a few weeks since I have blogged, was a bit hooked up on catching on with some of the MS technologies.I started learning the ADO.Net entity Framework, downloaded some videos, samples and ye, did some pretty intresting stuffs with it.Then there was last week, when one of my friends asked me a question on web services, got a bit confused and I had to dig into some of the ws-* standards and WCF Security, and finally thought of going through the specificaions at w3c, and I ended up reading the ws-security and ws-addressing spec.Then there was this week, started looking at some presentations on the ADO.Net data services on MIX 08, still doing this !!!. and another thing about all these is that I am getting not much of time to do all these readings, cos' I have hooked up into some of the old cartoons that I always wanted to watch, like the X-Men, King Artuher, The Mask etc...Well for all, I guess its better late then never !!!

.NET Framework Client Profile

The .NET framwork keeps on growing and so does the size, so it has become apparent that a lighter version of the .NET Framework is needed.
Last week, Microsoft released the Visual Studio 2008 and .NET Framework 3.5 SP1 Beta. This includes the .NET Framework Client Profile,a smaller, optimized verson of the .NET framework needed for clients applications to run.The size of this framework is approximatley 27 MB (not that small), some of the assemblies that still lies in the beta but will be removed in the RTM version are

System.Management,
System.Messaging,
System.ServiceProcess,
System.Web,
System.Web.RegularExpressions

Visula Studio 2008 also has an option where you can make sure that an application targeted for the Client Profile Framework does not reference assemblies that are not included in the Client Profile Framework.You can have a look at the list of assemblies that are inluded in the client profile here

WS-* and REST, Which Is Better and Why?

I have been hooked up to REST these days after having some times to go through the WCF Web Programming Model (I know I am lagging behind in technologies !).
While looking at the pros and cons of REST and WS-*, I could see more then few web pages, blogs, on the debate of what’s the best solution for SOA.
REST is easy to use, no SOAP-client tool kits needed to generate web service proxies, as the fundamental concept behind REST being every operation is accessed by its unique URI, it's just a matter of typing it in your web browser, this also makes testing easier for developers (as all they need to do to see if the service is working, is to type the url in the browser !)
Further more if your are practicing an asynchronous pattern such as using AJAX, it might be very easy to call a REST service, get the response in JSON and do the processing on the client side, this is much easier then using the typical DOM method to parse XML.
When it comes to coupling, REST is more loosely coupled then …

RESTful Example

Here is an example on how you would create a RESTful webservice with the WCF Web programming model. I assume that you know how to write a WCF service and host it in IIS.
In this example I am going to create a service that will say "Hello" plus a string that is passed into the service, further more the service is going to be hosted in IIS.
the following is a WCF service class,
[ServiceContract]
public interface ITest
{
[OperationContract]
[WebGet(UriTemplate="/SayHello/{str}",ResponseFormat= ebMessageFormat.Xml)]
string SayHello(string str);
}
public class TestImpl : ITest
{
public string SayHello(string str) { return "Hello " + str; }
}

SayHello is our service operation. Note that this is a general WCF service with addittion of a [WebGet] attribute on top of our service operation. by using the [WebGet] attribute we mean that the operation is to be invoked with the HTTP GET verb.The next step is to define our .svc file for our service, the content of the .svc file…

RESTful Web Services and the WCF Web Programming Model

REST (Representational State Transfer) is not a new thing to the web service world; you can find a lot about what it is on the net, but for formality...REST is an architectural style (not a standard) it simply means web services are identified as resources and each operation as a unique URI assigned to it.You invoke the object's operation using the HTTP verbs like GET, POST etc...
Most web services are being shifted to using this style, for an example yahoo web services use REST. But some companies continue to have a REST service in addition to the SOAP based service.
One of the advantages of using REST over SOAP based services is that REST is light weight, as there is not much XML markup; for an example, REST does not use the SOAP header which is chunky.
Another benefit of REST is that the client accessing the service does not need special SOAP tool kit to use the service, as the service operation is identified as a URI, it is just a matter of accessing it like a web page in a brows…

Finalization, Know What it Costs

This is a post about object finalization in .NET.
Finalization is not as inexpensive as we think, it increases the pressure put on GC.All objects that need finalization are moved into a finalizable queue and the actual finalization happens in a separate thread. Because the objects full state may be needed, the object itself and all the object it points to are promoted to the next generation (this is needed so that GC does not clean these objects off in the current round), and these objects are cleaned up only after the following GC.
Due to this reason, resources that need to be released should be wrapped in as small a finalizable object as possible, for instance if your class needs a reference to an unmanaged resource, then you should wrap the unmanaged resource in a separate finalizable class and make that a member of your class and furthermore the parent should be a non-finalizable
class. This approach will assure that only the wrapped class (class that contains the unmanaged resource)…

Prabath Siriwardena on Open Id

When I joined in has as a software engineer, one of my first mentors was Prabath Siriwardena. Although it was just 5-6 months in his team, I learnt a lot from him, ranging from writing good code to, team work. He recently acquired his MSc in computer Science from the University of Moratuwa. and today works at WSO2 in the open id integration team. You can listen to his pod cast on Open id here, in this talk he mentions about what open id tries to solve and it's advantages.

Initializer Running in The Opposite Order as Constructors

What would be the output of this C# program be?

class Program
{
static void Main(string[] args)
{
new Derived();
}
}

public class Base
{
A ob = new A("Initialized base A");
public Base() { Console.WriteLine("In base constructor");}
}

public class Derived : Base
{
A ob = new A("Initialized derived A");
public Derived() { Console.WriteLine("In derived constructor");}
}

public class A
{
public A(string str) { Console.WriteLine(str);}
}

if your answer was :
Initialized base A
In base constructor
Initialized derived A
In derived constructor
Then you are wrong !!!, actually the answer is

Initialized derived A
Initialized base A
In base constructor
In derived constructor
Weird right?, the order is reversed, the initializers are called first in the order derived then base, then
the constructors get called from base to derived.

Imagine that one day you thought of putting a abstract method in the class Base and which you implement in the Derived class , but the
implimentaion of the abstrac…

Unity Explained

I had some time in the night to make use of the MS Unity applcation block, and I thought of writting a post on an example written uing Unity.
To use the dependency injection in your code via Unity is just 2 steps.
1) Create an instance of the Unity container, like this.
//Import UnityContainer container = new UnityContainer();
UnityContainer container = new UnityContainer();

2) Register your type with the Unity container. This can be done through a configuration file or thorugh code, for our example we are using the latter approach.
container.RegisterType <IService, ServiceImpl>();

3) Get the required instance from the container, using the Resolve()
DisplayClass display = container.Resolve<DisplayClass>();

The complete code example is as follows :
using System;

using Microsoft.Practices.Unity;
using Microsoft.Practices.ObjectBuilder2;
namespace unity1

{
class Program
{
static void Main(string[] args)
{
//Create the container
UnityContainer container = new UnityContainer();

//Register the our t…

Dependency injection and MS Unity Application Block

Building flexible and maintainable application means to achieve decoupled or very loosely coupled design.
Loosely coupled application also mean that you can test them easily using mocks.
Two ways of achieving loosely coupled nature in an application is via techniques Dependency injection and service locator.
When we talk about dependency injection we are talking about plug-in based development and it's all about how to get a concrete implementation into your application without re-compiling your code..
You can read about dependency injection here, but this post is not about what dependency injection is but about frameworks that lets us do this in a productive manner.
Frameworks like Spring uses dependency injection techniques and there are other containers available.
What I am interested about is the container that Microsoft released last week, the Unity Application block.
This is a container that allows you use dependency injection in a productive manner in the .Net applications:

Unity t…

Exception Handling Best Practices

Thought of writing some thing on exception and how it should be handled. These are some of the practices to be followed when managing exceptions in code to give you some more performance.

1) Do not use exceptions to control application logic. Throwing an exception is expensive (building the stack trace, etc are expensive). For an example when searching for a student and when it does not exist, do not throw a StudentNotFoundException, as this is a common scenario, return a boolean to indicate this or else another way is to return an enumerated type to denote error.

2) Use validation code to avoid exceptions, examples like checking for null etc..can avoid unnecessarily generating exceptions.

3) Use a “finally “ block to ensure resources are released (everyone knows that by default.)

4) Re-throwing exceptions with the “throw” keyword is expensive this is same as throwing a new exception.

5) Don’t catch exception that you can’t handle. The best way is to let it propagate up the call stack so…

Same Old Story...

Ok, here we go again..it's a new project, a new cubical and a code base that I need to start familiarizing...well that adds up to, I don’t get time to blog or at least read something new, ye the same old story..
After much consideration I applied for an ADSL line at home, my first thought was not too, as the weekends are allocated for family, friends and long hours of sleep, but then again I could at least do something...so I went for it.
The funniest thing was that I applied through SLT last month and still my ADSL line was not activated. Finally I called the branch I applied the line through, to find out that my application never reached the ADSL division, great!!!.
I had something to say to SLT that day over the phone...and the operator called me back after 10 minutes to apologize and to say that she will submit it to the ADSL division right away. So hopefully I will be back to blogging in a couple of days.

The Whole New Environment...

I should have learnt from my lessons! Every time I move into a new project, it seems that everything goes wrong, why?My development environment tends to work counter to my expectation.I have noticed this in almost all the projects I have worked in, the reason being, the tools and other stuff specific to the previous project play almost against the environment needed for the current project. How to overcome this issue? Simple, take a backup of all your souvenirs in your machine and format. This seems to do the stuff as always and I think this should be the case, starting with a whole new environment for your new system (just my opinion).

IE 8 Beta

Here is the link where you can download Internet Explorer 8 beta., There are some new features that has been added, you can read more about it here.The only reason I installed IE 7 was due to it's "Tab" feature, but after some use I understood it was not like IE 6 but lot of hangs, crashes and was not much of a stable product. No offence but, it's my opinion.IE 8 beta was released for download, I think 2 weeks back, but I did not have much intrest but then again it does have some new features, maybe it will prove much better to me then IE7.

Ranking Functions : ROW_NUMBER

One of the features that was included in SQL Server 2005 were ranking functions and I bumped into one of these last week, The ROW_NUMBER().
This function allows you to provide a sequential integer value to the results of your query. This comes in handy when you want to rank your data according to some criteria.
Let me throw an example…I have a table that has a set of student marls, I can use a query shown below to actually rank the students according to there marks.

SELECT ROW_NUMBER() OVER(ORDER BY Score DESC) AS Rank,
StudentName, Score
FROM Students
ORDER BY StudentName.

In the OVER() clause you can specify multiple order-by clauses.
This function also as its use when it comes to pagination of data. Take a look at the query below.

SELECT *
FROM (SELECT ROW_NUMBER() OVER(ORDER BY score DESC, StundentName) AS rownum,
StudentName, Score
FROM Students) AS D
WHERE rownum BETWEEN 4 AND 6
ORDER BY score DESC, StudentName.

This query fetches the rows between 4 to 6.
You can find more about ranking functio…

IIS 7 admin pack

One of the core features of IIS 7 is that developers can write .Net modules and plug it in and extend the web server’s functionalities.This also meant the MS can release future pack to easily extend IIS features.And last week MS released a technical preview for the IIS 7 admin module; this includes some cool features that web developers can benefit. Some of the new features include:1)Built in report visualization of IIS log reporting.2)A configuration editor that provides control over editing configuration files (web.config).3)Built-in SQL Server database management, including the ability to create, delete, and edit tables and indexes, create/edit SPROCs and execute custom queries - which means you can use the module to remotely manage your hosted applications4)And more…

Wrestle Mania 24

My favorite sport is wrestling, and really I don’t care if it’s real or not…as long as I enjoy it. Just like the world cup in cricket, in WWE it’s Wrestle Mania, and this time the event is taking place on the 30th of this month.There is going to be some real matches this time and some of the ones that I will not try to miss are:Batista vs UmagaEdge vs The Undertaker for the World Heavy Weight ChampionshipJohn Cena vs Triple H vs Randy Orton for the WWE ChampionshipYou can find more information on WWE

Tech-talk on LINQ

I presented a Tech-talk to my fellow Virtusan’s on LINQ last Monday. Around 25 people came in and in no time the place was turned it to a question base. Well, fortunately I was prepared and it was great answering those questions. Some of the areas I covered were on query expression, LINQ to objects and LINQ to SQL. The presentation was planned for 1 hour but it took an additional 20 minutes for me to finish but still there was something more for me to tell them.Today I got the rating and the comments from the people who attended and it was 4.25 out of 5, not bad for the first Tech-talk. Anyway most of the comments indicated that they wanted to learn more about LINQ and at the end of the day I was happy that I was able to do something that other people really like.

Weekend at Ahungalla

This weekend the the whole account here at Virtusa are leaving for "Heritance" at Ahungalla to take a day off from the "busy" work life. It seems that there is going to be a quiet a lot of fun planned.
However I will not be able to join them, as I got a family function to attend to...ye ..bad luck.
Last time we went on our quartely project trip, it was fun though...thought of posting a pic out of that trip. Belive me I was not drinking !!!


One-to-Many mapping in LINQ

Thought of posting about how you can map a simple one-many reletionship in LINQ.
Lets take for an example the relationship between a country and its cities, which is one to many, one country can have many cities, If I define a class called Country and City and then ofcourse two table called Country and City,
I can map the reletionship in a simple way that looks like this

[Table]
class Country
{
[Column(IsPrimaryKey=true)]
public int CountryId{get; set;}

[Colum]
public string CountryName{get; set;}

[Association(OtherKey="CountryId")]
public EnitySet Cities{get; set;}
}

I guess the example explains it all. The Association attribute on the cities property actually
iniitiates this reletionship and you can see the return type is a EntitySet of type City.
The OtherKey property of the Association attribute is used to provide the property name on the
City class which should be comapred with the CountryId in the Country class.
The names of all the names of types in the class …

Automatic Properties

I was writing a piece of test code in VS2008 and the prop code snippet want just generate the private field, did some goggling around and found this out.
Well, you may remember in the days of VS2003 when you had to write your private fields and then write the property getter and setter for it, that was cumbersome, I remember when it became to hard for me to write all these properties and I had to write a tool to generate the properties (not a very cool tool though). What’s worse some properties only set the passed parameter into the private field and return it in the getter, like thisprivate string studenName_;public string StudentName{ get {return studentName_;} set {studentName_ = value;}}In .Net 3.5 , through a feature called Automatic properties you can write the above code aspublic string StudentName { get; set; } andat compile time the compiler will emite code to construct a privet field.

Pre-Allocated

Not much of work these days, the truth is there is no work at all. I already blogged about the project I am currently allocated being closed off at the end of March, however, I am “sort” of pre-allocated to another project again from the same client I was working on earlier Surprisingly, the project is called “Sorcerer”.This one is a bit on the domain and there seems to be new modules coming in for development, but again this is again on .NET 1.1, but I agreed on it for the only reason that I can’t still figure out.Anyway, this is supposed to be going on until July or August, but I doubt it…And again I am preparing for a tech-talk that I am going to present on LINQ next week, so I am a bit hooked up on the presentations and some more reading on LINQ. So for the moment I have run out of work but I guess they are not planning to keep me in this state for long.

LINQ to SQL

This is an abstract of LINQ to SQL; this provides a better way to linq your entites class to the database tables. For example lets say you have a table called “tbl_customer” with fields “customer_name” and “customer_id”, you would map your entity class “Customer” as follows[Table(Name=”tbl_customer”)]public class Customer{ [Column(Name=”customer_id”)] public int CustomerId; [Column(Name=”customer_name”)] public string CustomerName}You can query you database by making use of the DataContext class, like this…DataContext db = new DataContext(databaseConnectinString);Table<Customer> customers = db.GetTable<Customer>();var query = from cust in customers where cust.CustomerId = 12 select cust;Simple right?This is a simple snippet of what you can do, but LINQ to SQl provides more flexibility, like sql type conversions, complied queries etc.Some of you would not like the mapping that done in code…I don’t either, you can use …

Project closure...End of March

It’s another month to go !. Ye, I am talking about my project; I was working on the security, task scheduling and logging component of an ETL application. It’s been 1+ years since I started on this project, it’s based on a J2ee backend, and .Net 1.1 front end.At first I did not like the project as it was being developed in .Net 1.1, but as it went on I learnt many things especially on designing, globalization techniques and most off all managing customer communication.I was also exposed to working with several teams (as we were handling the common service), and this proved to be very challenging and useful when it came to different viewpoint and opinions.I did not learn any new technologies in this project but I did learn most of the things that I might be able to carry forward in other projects in the future.Yesterday, the clients officially announced that project is getting closed down, and probably it would stay until the end of March.Well, I know what I am going to really miss whe…

ASP.NET MVC Framework

ASP.NET MVC Framework is another extension that has been added to .net 3.5, this framework allows developers to create ASP.NET projects using the MVC pattern (of course as the name suggests!).I took a look at it and it seems pretty easy to use. You can learn more about it here.
Just to give an idea about how easy controllers can be implemented, take a look at the code below...
public class CustomerController : Controller
{
[ControllerAction]
public void ListCustomers()
{
}
}

The CustomerController class extends the base class System.Web.MVC.Controller, this base class does most of the job.
For an example, when a request comes in the form www.mainsite.com/Customers/ListCustomers, the framwork automatically calls the above method , cool ne?

Extension methods and Lambda expressions

Maybe it’s a bit late for me to post about .Net 3.5 + VS 2008, but that’s what I am exactly doing these days.
My first interest in the language was on Lambda expressions and extension methods and then LINQ.
I have learnt quite some stuff about LINQ, meaning the basic, but still did not have a time to try out LINQ to SQL, maybe I will, in the coming week.

Just to give you an idea about Lambda expressions, this is an evolution of anonymous methods in .Net 2.0 and this comes in handy when using LINQ. You can read more about Lambda function here.
Extension methods are really cool stuff, this allow you to add new methods to the public contract of an existing CLR type, without having to sub-class it or recompile the original type. So for an example you can write a extension method like Print() and add it to the string class and you can use is it like this.

String str = “Say Hello World”;
str,Print();
You can read more about Extension methods here.

Another thing that I tried out was the object Initi…

LINQ

LINQ, Language Integrated Query is a new feature in .Net 3.5. Tradiationally, a programmer
needs to different query language to query different datasources, for example, data sources like
Sql databases, XML and in-memory objects. This meant the programmer needed to learn
different query languages for each and every technology. There was another problem as well, queries were
written in string form and cannot be validated at complie time.
LINQ tries to address these problems, by giving the programmer a singel query language
for any data source for which providers are available.
The cool thing about LINQ is, it is in-built into the language such as C# and VB.Net and Visual studio provides Intellsense support.
This is a sample query of what LINQ can do:

public void Linq11() {
List products = GetProductList();//Get an ArrayList of products, not from the database

var productInfos =
from p in products
select new {p.ProductName, p.Category, Price = p.UnitPrice};

Console.WriteLine("Product Info:")…

Being part of an interview

I always wanted to be part of an interview, and today I got the chance. I was given a chance to accompany one of the interviewers at Virtusa. I got a chance to throw some question as well, not very hard once but you know…basically I did not have much questions.Anyway, kind of liking this, maybe I should do this often.

Memory leaks in managed code

This was something we ran into in our application used custom GUI components, and well those were rough days…You sometimes hear that a managed language like C# or Java does away with memory leaks, and frees the programmer from having to think about freeing objects from memory. Well this is not especially true for GUI code.The main reason for this is the use of the Observer pattern. While a good thing in it self, the observer pattern leads to the “Lapsed Listener” anti-pattern. This is when an object A subscribed to an event of object B which is a long living object (for an example a child form subscribing to event in the parent MDI form) goes out of play without unsubscribing to the event on object B (the child form closes but without unsubscribing from the event on the MDI parent).This would result in object A never being garbage collected until object B is out of business, what’s worse, if object A reference other objects C and D , this will also not get garbage collected as well.Th…

SharePoint training

I was having my usual time at home today when I remembered “my god I have a training to catch”…I had to race into office and finally made it at around 10 AM. The training was on Microsoft SharePoint server, the trainer was Joy Pradeep one of the MVP of Sri Lanka.The training was good but the first few hours were mostly concentrated on the administration side of SharePoint, I did not get a chance to look into the development section of as I had to attend to another one of those “urgent” tasks.I remember the same thing happening when I was in a BizTalk training, the first day was great (with some network games on the training lab), and as it turned out be the 2nd day I had to miss it.

ILMerge

Cool tool for .Net, ILMerge. This allows you to merge two assemblies into one target assembly. One most obvious use for this would be when you have two project one written in C# and one in VB.Net, using ILMerge you can combine these assemblies to distribute to your customer as if you have developed it in one project !!!.
span>

Debugging WCF services hosted in IIS 6.0

I have been doing some sample projects in WCF (hosted in IIS 6.0), and today I was trying to debug the service like I have done with web services and ASP.net but with no luck, the break point does not get hit at all !!!, After some goggling found out that direct debugging of projects in the same solution is not possible with WCF.The work around is to run your client and then attach to the external process aspnet_wp.exe and your break points will hit.Debugging of WCF services in the same solution will be possible in VS 2008.

Back for good!!!

Ok guys I am back in the mood to blog, I do remember I said this before but this time it’s for the best...I have been having a hard time at work and did not fins sufficient time to send a post.I have made up mind to take some time of my work to post a message or two at least every week !!!