Saturday, December 27, 2008

Inside AppManifest.xaml
The file contains the following:


<Deployment xmlns="
http://schemas.microsoft.com/client/2007/deployment"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
EntryPointAssembly="HelloSilverlightApp"
EntryPointType="HelloSilverlightApp.App"
RuntimeVersion="2.0.31005.0">
<Deployment.Parts>
<AssemblyPart x:Name="HelloSilverlightApp"
Source="HelloSilverlightApp.dll" />
</Deployment.Parts>
</Deployment>

The manifest specifies the entry point assembly which should be loaded by the Silverlight host and within the assembly it requires a type derived from System.Windows.Application for start executing the application.

Here, the assembly is “HelloSilverlightApp.dll” and type is “App” in the namespace HelloSilverlightApp.

Warning: System.Windows.dll is part of Silverlight and not the one we used for WinForm development.
I read in some web sites those explained that XAP also contains a set of required Silverlight assemblies which are needed by this application. But I tried with lot of examples, the XAP contains application's assembly and this manifest. Need to check.

Inside HelloSilverlightApp.dll Assembly

It contains two parts:

  1. The typical .NET type declaration of specific Siverlight application's App and one or more Page. In this example,

    1. HelloSilverlightApp.App

    2. HelloSilverlightApp.Page

  2. Resource: HelloSilverlightApp.g.resources. It contains the declarative artifacts of this application:

    1. page.xaml

    2. app.xaml

I would like to share some of my basic understanding of Silverlight internals in this series.

XAP File

When you build a Silverlight 2.0 application, the final outcome would be:

1. ApplicationName.dll
2. AppManifest.xaml
3. ApplicationName.xap

When a request is made for a page which contains a Silverlight, the server sends the page with the Silverlight part as "xap" file to the client. The XAP is a normal archive file you use archive manager like 7-Zip to extract the content. It contains RequestSilverlightApp.dll and AppManifest.xaml. The silverlight CLR at the client side consumes these. This should be specified in either ASPX or HTML file which is the actual client requested page.

You use OBJECT tag along with DIV and IFRAME to load Silverlight host and specify the target XAP needs to be loaded.


<object data="data:application/x-silverlight,"
type="application/x-silverlight-2" width="100%" height="100%">


<param name="source" value="HelloSilverApp.xap"/>


In your ASPX, you can use ASP.NET server side control to specify Silverlight host and specify the target XAP. In the above declaration, the XAP file has been specified in the "source" parameter.


<asp:Silverlight ID="Xaml1" runat="server"
Source="~/ClientBin/HelloSilverApp.xap" MinimumVersion="2.0.31005.0"
Width="100%" Height="100%" />



In the above declaratin, the XAP file has been specified in the "Source" attribute.

Friday, November 14, 2008

After a long while, I tried to start SQL Server in my home laptop.  It throws the following error message in the event log:

The file "C:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\DATA\master.mdf" is compressed but does not reside in a read-only database or filegroup. The file must be decompressed.

When I opened the files in my $$SQL SERVER$$\DATA folder, all are getting compressed.  It might be by Disk Cleanup utility.  I just let the tool to compress old items.  Huh!

I disabled the compress mode of these files by select all files -> righ-click -> Properties -> Advanced -> deselect Compress contents to save disk space.

After that I started SQL Server, it was started well.

Sunday, October 26, 2008

Since I was mostly spent my time on behind-the-scene technology, I had put a hold on "Silverlight". Also, I am waiting for its final customer release.

Installed all Silverlight ingredients on my Visual Studio 2008 box successfully. Struck up with VS2008 SP1 update, because of its online 781MB installar size. Finally, I got an offline installar and finished all formalities.

I was starting the journey with Silverlight Web Script project. Created the following:

1. HelloWorld.xaml
2. HelloWorld.js
3. HelloWorld.html

When I tried to open in my browser, nothing was displayed. ;)

After a WinMerge comparision of HelloWorld.html with Default.html, found the issue that
<script .../>

So, use <script></script>

Yes, <script/> gives lot of trouble in normal HTMl also.

Okay, let me continue the journey.

Sunday, July 27, 2008

This is part 2 of C# 3.0: From "C++" to "Ruby" Family - Part I. In this part, I will brief the remaining part of "Generics".
Applying your constraints on Generic


What is the real usage of allowing any type into my generic method or in class. We know that TransferAccount() method relies on bank account which could be either savings, current, etc. It is not sensible to allow any type of objects as parameter. In such case, you can apply constraint on Generic by C#2.0 new keyword "where" as:

  • generic type should be derived from this base class or should implement this interface (where T : base-class-name interface-name)

  • generic type should be a none other than class for example struct (where T:class)

  • generic type should have default constructor (where T : new())

For example, let us refactor our previous code like:

public TAccount CreateInstance<TAccount>(long accountNumber) where T : Account
{
// create either savings, current account instance based on account number
}

The above code apply the constraint "only allow types derived from "Account" base class" into CreateInstance.


Anonymous Methods followed by Lamda Expression:

I had been unbalanced with OOP/procedural and functional programming concepts year back, because of the mix of these two concepts will make programming more tasteful and better. Because of this reason only, I love Ruby and JavaScript programming (of course C# is mixed in the life of a programmer).
One nice thing about functional programming is "closure" methods or "lamda expression".

Let us see our famous C# delegate:

delegate int Calculator(int a, int b);

static void Main(string[] args)
{
Calculator add = Add;
Console.WriteLine(add(2, 3));
Console.ReadLine();
}

public static int Add(int x, int y)
{
return x + y;
}

In the above code, I have declared a delegate "Calculator" and used this for "Add" method. As per "Not every theoretical can be used in practical", in most of the situation, we are in a position to define a delegate and then we need to apply one or more methods one time only like the above example. In such case, defining a delegate and then defining method for that delegate results less "beautiful code". C# 2.0 introduced "anonymous methods" eliminates and save developer productivity and the code. By this,
Calculator add = delegate(int x, int y) { return x + y; };
Console.WriteLine(add(2, 3));
Without defining "Add" method, we can define anonymous methods.

Why Lamda Expression?

This is in place of anonymous delegate instance . See the below code:
Calculator add = (int x, int y) => { return x + y; };
Console.WriteLine(add(2, 3));
Visually whats the different? "delegate" has been removed and "=>" introduced. Otherwise, the same in visual perspective. But under C#'s regime, lamda expression is something different from "anonymous methods". (For me, it provides functional programming feature.)
The code within {...} denotes an expression tree of type Expression<T>. This allows the lamda expression to be interpreted at runtime and not in compile time. Greatna.!

Thursday, July 10, 2008

Download Example Source Code

This is part 2 of WF: Exception Handling with State Machine Workflow.

Solution Sample
In the previous article we discussed issues when handling exception in state machine workflow and specified that we can resolve the issue by using CallExternalMethod activity. Last time, I've explained the issue by giving RoseIsRose sample. In this solution, I've two project, one is state machine workflow library called RoseIsRoseWorkflow and another one is console application which is host for workflow named RoseIsRoseConsole.

The objective is if any exception happens in the state machine workflow, the workflow should propagate it to host.

For sake of simplicity, the workflow in the library named RoseWorkflow has only one state named "BudState". This state has only one EventDrivenActivity called "onPluckFlowersEvent". It has one HandleExternalEvent named "handlePluckFlowersEvent".



The code for above workflow's InterfaceType is following:


using System;
using System.Workflow.Activities;

namespace RoseIsRoseWorkflow
{
[ExternalDataExchange]
public interface IRoseWorkflowService
{
event EventHandler PluckFlowers;
void DelegateException(Exception ex);
void RaisePluckFlowersEvent(Guid instanceId);
}
}


What about the fault handlers and what we need to redesign for propagating exception to host?

In IRoseWorkflowService, I have declared a method "DelegateException" which will be called by "CallExternalMethod" from the workflow. The "RaisePluckFlowersEvent" is used by host to invoke "PluckFlowers" event in IRoseWorkflowService which is actually handled at RoseWorkflow.



Before "callExternalMethodActivity1", I have used one code handler named "onPluckFlowersEventFaultCodeHandler" for just displaying debug message. The code behind of RoseWorkflow.cs is


namespace RoseIsRoseWorkflow
{
public sealed partial class RoseWorkflow : StateMachineWorkflowActivity
{
private object _sender;
public object Sender
{
get { return _sender; }
set { _sender = value; }
}

private Exception _delegatedException;
public Exception DelegatedException
{
get { return _delegatedException; }
set { _delegatedException = value; }
}

private ExternalDataEventArgs _eventArgs;
public ExternalDataEventArgs EventArgs
{
get { return _eventArgs; }
set { _eventArgs = value; }
}

public RoseWorkflow()
{
InitializeComponent();
}

private void handlePluckFlowersEvent_Invoked(object sender, ExternalDataEventArgs e)
{
_delegatedException = new Exception("In this stage, you cannot pluck flowers");
throw _delegatedException;
}

private void onPluckFlowersEventFaultCodeHandler_ExecuteCode(object sender, EventArgs e)
{
FaultHandlerActivity faultHandler = ((Activity)sender).Parent as FaultHandlerActivity;
Console.WriteLine("Handle exception in workflow itself. Details: {0}",
faultHandler.Fault.Message);
}
}
}


At the host side, I have implemented part of IRoseWorkflowService in RoseWorkflowService.cs:



using System;
using System.Workflow.Activities;
using RoseIsRoseWorkflow;

namespace RoseIsRoseConsole
{
[Serializable]
public class RoseWorkflowService : IRoseWorkflowService
{
#region IRoseWorkflowService Members

public event EventHandler PluckFlowers;
public Exception DelegatedException;

public void DelegateException(Exception ex)
{
DelegatedException = ex;
}

public void RaisePluckFlowersEvent(Guid instanceId)
{
if (PluckFlowers != null)
PluckFlowers(null, new ExternalDataEventArgs(instanceId));
while (DelegatedException == null) ;
Console.WriteLine("Externally handled exception '{0}'. Details: {1}",
DelegatedException.GetType().Name, DelegatedException.Message);
DelegatedException = null;
}

#endregion
}
}


Note that "DelegateException" will be called by workflow. Whenever, it is getting called it assigned the exception details to the public field "DelegatedException". In the "RaisePluckFlowersEvent" method, once it raised "PluckFlowers" event, the method going on a while until the "DelegatedException" is null. After that, it just handle the exception (either rethrow it to calling client or logged at host place).

The Program.cs is


namespace RoseIsRoseConsole
{
class Program
{
static void Main(string[] args)
{
using(WorkflowRuntime workflowRuntime = new WorkflowRuntime())
{
AutoResetEvent waitHandle = new AutoResetEvent(false);
workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) {waitHandle.Set();};
workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
{
Console.WriteLine(e.Exception.Message);
waitHandle.Set();
};

ExternalDataExchangeService dataExchange = new ExternalDataExchangeService();
workflowRuntime.AddService(dataExchange);
RoseWorkflowService roseWorkflowService = new RoseWorkflowService();
dataExchange.AddService(roseWorkflowService);

WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(RoseWorkflow));
instance.Start();

roseWorkflowService.PluckFlowers += new EventHandler(roseWorkflowService_PluckFlowers);
roseWorkflowService.RaisePluckFlowersEvent(instance.InstanceId);
waitHandle.WaitOne();
}
}

static void roseWorkflowService_PluckFlowers(object sender, ExternalDataEventArgs e)
{
Console.WriteLine("Handling PluckFlowers event");
}
}
}


The output:

Handling PluckFlowers event
Handle exception in workflow itself. Details: In this stage, you cannot pluck flowers
Externally handled exception 'Exception'. Details: In this stage, you cannot pluck flowers


For further reference, download the example project.

Thursday, July 03, 2008

This is part 2 of Event Watch: Moblin - Intel's Mobile Flavour Part 3.

After getting all the components, I could start Xephyr on the MIC device target terminal window. But, it did not keep me smile. The Xephyr window was broken immediately and I got the following error


(T: HelloMoblinApp)root@sheik-laptop:/# ...
Xlib: connection to ":0.0" refused by server


It was my mistake that I forgot to install LibOSSO library. Then I installed it on the target terminal.


(T: HelloMoblinApp)root@sheik-laptop:/# apt-get install libosso-dev


After that I started Xephyr, this time it throws


(T: HelloMoblinApp)root@sheik-laptop:/# ume-xephyr-start
Setting screen resolution to 1024x600
DISPLAY already set to :0.0
Starting dbus
* system message bus already started; not starting.
Starting UI in Xephyr

Extended Input Devices not yet supported. Impelement it at line 625 in ../../../../hw/kdrive/src/kinput.c
Could not init font path element /usr/share/fonts/X11/cyrillic, removing from list!
Could not init font path element /var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType, removing from list!
X connection to :0.0 broken (explicit kill or server shutdown).
xinit: connection to X server lost.


Then I've gone thorugh some mail-list and I found a workaround at http://www.moblin.org/archives/html/dev/2008-04/msg00101.html. It said that use


# pkill gconfd

It kills parent's gconfd and uses target environment's gconfd. After that Xephyr started successfully but it throws same warning message, just skip that.

After that I was trying to compile and execute the given hello-world-1.-c at Moblin.org site. However, I am not able to compile, it says


(T: HelloMoblinApp)root@sheik-laptop:/usr/src/hello# gcc -o hello-world-1 hello-world-1.c `pkg-config --cflags --libs gtk+-2.0`
Package gtk+-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk+-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtk+-2.0' found
-su: gcc: command not found

Ha ha interesting, I was not in the situation whether gtk+-2.0 is already there in my Ubuntu or not. I just given


(T: HelloMoblinApp)root@sheik-laptop:/# sudo apt-get install libgtk2.0-dev


After that you have to install gcc on the target terminal

(T: HelloMoblinApp)root@sheik-laptop:/# sudo apt-get install gcc


After that I have successfully executed the hello world app.

Thank God.

One good thing is that the packages "gcc" and "libgtk2.0-dev" are got from host app only. It is nice thing about Moblin.

Let us see with more code on Moblin.

Monday, June 30, 2008

This is part 2 of Event Watch: Moblin - Intel's Mobile Flavour.

After spending two hours, the Mobile Image Creator (MIC) created Moblin environment on my development machine. During these period, it swallow 1GB and after completing all the target environment swallow 600+MB of my hard drive (Hope that each target only took 373.8MB, others are one time update of necessary components).

Okey, let me write about the remaining notes about the seminar. Moblin is nothing but a emulator of the target device. It contains all set of libraries to develop rich interactive, power saved mobile applications. You can develop and deploy your C++/Python source code into the environment.

The lunch was excellent and one of the high attractive point in this seminar.

After the lunch, Thamarai Selvi from Anna University presented a full length of theoretical session about various mobile communication. Its good to her to explain all brief about Wifi, WiMax and other non-matured technologies. But she just forgot that this is neither academic class room nor off-room lecturer.

The final session "Ubuntu in the Mobile Space" was given by Prakash from Canonical, a sponsor of Ubuntu. He provided good and humorous speech about Ubuntu's Notebook edition (a very thin laptop) and he talked about Ubuntu's mobile edition Linux on Moblin.

A Simple Hello World! Application
I followed the steps to create a sample Hello World application in Moblin at http://moblin.org/toolkits/prepDev/toolkits_prepDev_useImgCrtr.php.

One very important thing while create project, add target and setting FSets is that please connect your system with a broad band internet connection. It gets lots and lot of things from Moblin.org.

It is pleasure for Intel to give all required components in a separate development CD/DVD kit.

Two things I would like to tell Intel.

1. Atleast provide the entire Moblin kit in a DVD.
2. Be sure what is needed to be conveyed to the large audience, because now you are targeting the developers and you should touch their heart as like as the one and only Microsoft and its various TechEd/TechMela/Day events those are nothing but a magic point on which all developers are focused.

Caution: You have to spend more than two hours when you selected a full target function sets on the selected target. For Samsung full function set It downloads more than 450 components from Internet. What a wonderful repository? Actually, why Intel organized Moblin like this way. God only knows.

Friday, June 27, 2008

This is second time in Chennai, Intel had arranged developer session on their new mobile environment Moblin (Mobile Linux).

Microsoft came into mobile software arena very latetly. Like, Intel also has entered into the mobile hardware market very lately. Surprisingly it comes along "Moblin" platform.

When I had received the registration email from Intel, two things gave me surprise. One is repetition of the event in the same city and the location was Anna University campus. Although the campus was surrounded by old aged trees, I would like to request the university board to improve the ambiance of the campus. One of the sign board informs wrong direction to Muthain Auditorium. At the time I reached the place, the first session was almost in the final stage given by an official from CDAC (Centre for Development of Advanced Computing). He was talked about pervasive computing. One of my manager and me had a quick chat with him about the public participation on pervasive computing. They do not have any idea about this.

I was started to download the Moblin on my Ubuntu 8.04 machine by following the instruction given at http://moblin.org/toolkits/prepDev/toolkits_prepDev_instImgCrtr.php half hour before writing this post by "git" clone.

Prerequisites:

  • git-core (intltoolize also)
  • automake
  • autotools-dev
  • build-essential
  • dh-make
  • fakeroot
  • python
  • debootstrap
  • syslinux
In Ubuntu 8.04, python and syslinux have already installed. But need to install the remaining using "sudo". Other than the above, we have to install "curl" and "intltoolize" also by

$ sudo apt-get install curl
$ sudo apt-get install intltool

Note that have to give "intltool", and not "intltoolize". After installing the MBs of these prerequisites, I gave the below command to get moblin-creator from moblin.org.


$ git clone http://moblin.org/repos/tools/moblin-image-creator.git


Beware it took more than half hour in my broad band internet connection.

After getting the kit, key the following:


$ cd moblin-image-creator
$ ./autogen.sh
$ sudo make install
$ sudo image-creator


Really I would like to write about the my very fist hello world in Moblin in this post, let us see, since after executing "moblin-image-creator" (simply MIC), and add new platform project, it took more than half hour. It simply said "Please wait while installing HelloMoblin". Woooop!

Narendra Bhandri from Intel gave session about "Mobility Trends & Moblin Overview". Its the same old presentation given in the previous seminar. Oops, still MIC retrieving and validating large number of libs and tools. The session was about the internet experience and usability of the current mobile devices. And, of course he talked about Intel's new processor for mobile devices oh, sorry MIDs (Mobile Internet Devices) "Atom" from its famous Centrino platform.

Oo God, still MIC retrieving and validating. This time I found that It start from tool with name starting "a" and in the ascending order. More than 40 minutes over. I did not worry about the time it took, because it completely created the image of Moblin Linux environment. After a while, It extract, unpack and configure various Moblin components. Oh God, my hard drive space. let us see.


Santhosh from Intel gave session about "Software Framework for Mobile Devices". He directly talked about the Moblin stack. Wait..are you confused about "What is really mean Moblin?".
Most of the attendees in the hall had the same confusion (may be still), because none of the speaker clearly explain and convey the real aspect of Moblin.

-To be continued on next part (my wife called me thrice to shutdown the system) bye!!

Tuesday, June 24, 2008

Every day comes with some new wishes and challenges. Today my team struck up with handling in a state machine workflow. They digged the web for finding a solution, unluck.
Problem: How to rethrow an exception from a state machine workflow to the workflow runtime host?
Description: I have designed one of our product as the service interface layer (WCF) invokes some of the business functionalities through workflow. We can say "workflow enabled business functionalities". This is a state machine workflow (I don't find real enterprise level usage of sequential workflow, of course you can use it at UI level). We have instrumented (exception handling and logging) well the non-workflow enabled services and business functionalities. Whenever a request comes from the clients of these services (currently, we have only one ASP.NET client) to perform a business operation, each layer do their responsibilities well. In case of any failure, they respond to the client gently with all necessary details. However, we were not able to handle exception in our "workflow enabled business functionalities". Laughing...! Initially, I was also felt that we have missed something. After a while, my team found that this is the issue with WF itself. Actually, you can handle exception within the workflow runtime, but how can you respond to your client there is a fault while executing their requested business functionality.

By its asynchronous nature of state machine workflow, even though WF provides rethrow activity, it cannot propagate upto the calling place which is the host of the workflow instance. This is common for any type of host such as Console, ASP.NET, etc.

How to reproduce:

1. Create a state machine workflow (for an example, RoseWorkflow) and add an event driven activity (onPluckFlowersEvent) on the initial state (Bud State).
2. In the onPluckFlowersEvent handling code, forcefully throw an exception (throw new Exception("You cannot pluck flowers in this state"));. The value of the properties of this external event handler activity are:
Name: handlePluckFlowersEvent
InterfaceType: RoseIsRoseWorkflow.IRoseWorkflowService
EventName: PluckFlowers
e: Activity=RoseWorkflow, Path=EventArgs
sender: Activity=RoseWorkflow, Path=Sender
For both sender and e, I've declared two properties named "EventArgs" of type ExternalDataEventArgs and "Sender" of type object.


private void handlePluckFlowersEvent_Invoked(object sender, ExternalDataEventArgs e)
{
// here _delegatedException is the member of RoseWorkflow
_delegatedException = new Exception("In this stage, you cannot pluck flowers");
throw _delegatedException;
}

3. Add fault handler activity (onPluckFlowersEventFaultHandler) for the event and set its "FaultType" property as "System.Exception".
4. If need, add normal code activity to handle the exception, like

private void onPluckFlowersEventFaultCodeHandler_ExecuteCode(object sender, EventArgs e)
{
FaultHandlerActivity faultHandler = ((Activity)sender).Parent as FaultHandlerActivity;
Console.WriteLine("Handle exception in workflow itself. Details: {0}", faultHandler.Fault.Message);
}

5. Add Throw activity, and set the following properties:
Fault: Activity=onPluckFlowersEventFaultHandler, Path=Fault
FaultType: Activity=onPluckFlowersEventFaultHandler, Path=FaultType
6. Host it into a console:


class Program
{
static void Main(string[] args)
{
using(WorkflowRuntime workflowRuntime = new WorkflowRuntime())
{
AutoResetEvent waitHandle = new AutoResetEvent(false);
workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) {waitHandle.Set();};
workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
{
Console.WriteLine(e.Exception.Message);
waitHandle.Set();
};
ExternalDataExchangeService dataExchange = new ExternalDataExchangeService();
workflowRuntime.AddService(dataExchange);
RoseWorkflowService roseWorkflowService = new RoseWorkflowService();
dataExchange.AddService(roseWorkflowService);
WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(RoseWorkflow));
instance.Start();
roseWorkflowService.PluckFlowers += new EventHandler(roseWorkflowService_PluckFlowers);
try
{
roseWorkflowService.RaisePluckFlowersEvent(instance.InstanceId);}catch(Exception e){Console.WriteLine("from host. {0},{1}", e.GetType().Name, e.Message);
}
waitHandle.WaitOne();
}
Console.WriteLine("Press to quit");
Console.ReadLine();
}
static void roseWorkflowService_PluckFlowers(object sender, ExternalDataEventArgs e)
{
Console.WriteLine("Handling PluckFlowers event");
}
}

I used RoseWorkflowService as one of my local service which implement my IRoseWorkflowService which is used in my workflow.
IRoseWorkflowService:


[ExternalDataExchange]
public interface IRoseWorkflowService
{
event EventHandler PluckFlowers;
void RaisePluckFlowersEvent(Guid instanceId);
}

RoseWorkflowService:


[Serializable]
public class RoseWorkflowService : IRoseWorkflowService
{
#region IRoseWorkflowService Members
public event EventHandler PluckFlowers;

public void RaisePluckFlowersEvent(Guid instanceId)
{
if (PluckFlowers != null)
PluckFlowers(null, new ExternalDataEventArgs(instanceId));
}
#endregion
}

Now run the application. It never reaches to host place.
Solution (Workaround): You can resolve it through by "CallExternalMethod" activity. I will explain about this on next part with downloadable source code.

Although I am very irregular to Orkut, one of my friend called me from US one day about his new application in Orkut.
This application lets you scrap graphically and you can share it with your friends. As a novice Orkut user, I am alleged about the real usage of this application. It could be very helpful to convey my though process in a graphical manner. I like the terms "Ort" for "Art" and Ortist. It lets you save your "Ort" also.
I have faced two issues when using this application:
1. Where is my eraser? May be it is not visible for my eyes.
2. Dedicated tool for writing. Even though I can decrease the thickness of "Pencil" tool, its not convenient for me to write anything in the "Ort".
Wishes to my friend for this nice idea. Let the world to use it successfully. Happy Programming.
For more details: http://ortist.wordpress.com/about-ortist/

Monday, June 23, 2008

Though, I am very comfortable with other Microsoft Live services, but I am very much comfortable with Blogger when it is blog.

After two plus years in Space blog (http://udooz.spaces.live.com/), I have come back to blogger.

Hope that your system has loaded with Microsoft's new Visual Studio 2008. I was really excited when I saw the new features of C# 3.0. In this article, I am going to brief you about the new features of C# 2.0 and 3. The reason I have taken C#2.0 also is for "Generics".
If your company yet to buy VS2008, don't worry. You can download FREE express edition of VS2008 at http://www.microsoft.com/Express/Download/.

Let us start.

When I have a chance to see Ruby code a year before, I was really astonished by its clean syntax of. Three main aspects that are impressed me lot. These are:
1. Clean syntax
2. Simple syntax
3. Smart syntax

After a long while, I saw the new features of C# 3.0 those are just inspired by Ruby's syntax and features. After gone through the small exercise on various new features, I just really love C# 3. Before looking into these, it could be helpful to know about Generics, a feature derived from C++.

Generics
If you are coming from C++ (learned in academic also a worth), you know the "Templates". It provides a kind of reusability. When you need to store a collection of objects, the first choice was ArrayList in the days of .NET 1.x. It lets you store a collection of any type. When you iterate through the collection, you should very careful about type casting of the object in the collection. To store a collection of objects with same type, then Plain Old Array (please do not try to create another TLA - Three Letter Acronym POA) is the best choice. Then what is the necessary for Generics.

The first concern with .NET 1.x collection types is the type casting a.k.a boxing/unboxing. These collections only knows "System.Object". Each time when storing or retrieving, we have to pay the cost of boxing/unboxing.

The second concern is the need of strongly-typed collection. Suppose you want to store a collection of object of type "Account", you have two choices based on the usage frequency of "Account" collection. Either you have to create custom collection by deriving IEnumerable. Otherwise, the illiterate "ArrayList".

The above two are the main reasons for the born of C# Generics inspired by its grand father "C++" in its version 2.0.

Assume that whenever you need to implement common behavior for more than one type, you can just put a place holder on the type declaration. Suppose, I want to implement common behavior for object storage with "Stack" model, in .NET 1.x period, I have to declare it as:


public class Stack
{
private int _position;
private object[] _elements = null;

public void Push(object element)
{
if(_position <= _elements.Length) _elements[_position++] = element; // else through exception } public object Pop() { if(_position >= 0) return _elements[_position];
}
}


In the modern age of .NET 2.0, I can put a place holder for type declaration like:


public class MyStack<T>
{
private int _position;
private T[] _elements = null;

public MyStack(int capacity)
{
_elements = new T[capacity];
_position = 0;
}

public void Push(T element)
{
if (_position < _position =" _elements.Length">= 0) return _elements[_position--];
return default(T);
}
}

In line 1, I have declared MyStack class with the place holder T. You can use any name within the angle bracket (< >). But you should use the same name across the code. After specified the place holder, I have assumed and used T as a strong type.

In line 15, you can see that the Pop() method returns either the element at the head of "null" value of the type. How can you specify the null value of a type. Here, the problem is I have to return "null" for reference type and default value for value types. For this, C# provides "default" keyword which returns default value of the given type. Ok, now how can you use this class for all variety of types:


MyStack<int> s = new MyStack<int>(2);
try
{
s.Push(100);
s.Push(200);
s.Push(300);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

Console.WriteLine("1: {0}", s.Pop());
Console.WriteLine("2: {0}", s.Pop());
Console.WriteLine("3: {0}", s.Pop());

You can see the output like this:

Stack full
1: 200
2: 100
3: 0

Here, when I tried to get the top element third time, it returns default value of "int" type 0.

You can declare Generic on struct and interface also. .NET 2.0 provides the following interfaces:
  • ICollection
  • IComparer
  • IDictionary
  • IEnumerable
  • IEnumerator
  • IList
And, it provides generic based collections under the namespace System.Collection.Generics.

Generic Method
You can also use/apply Generic in a method which might be a static or non-static member of either generic and non-generic type. Like the declaration of Generic type declaration, you specify the template like the following:
public void MyGenericMethod<T>(T arg1);


Generic methods change the way we use factory methods. For example, in .NET 1.x, we declared factory method like the following:

public object CreateInstance(Type t);


If you need to use this method, you have to use boxing/unboxing, like:

Account myAccount = (Account) MyClass.CreateInstance(typeof(Account));


But, when you use Generic on this method like
public T CreateInstance<T>();


You can simply use CreateInstance like:
Account myAccount = MyClass.CreateInstance<Account>()


See the clear syntax of the Generic method. And it is not necessary to apply type casting also.

Obviously you can use Generics in delegates also.
-to be continued.

Wednesday, June 11, 2008

After attending Intel Developer Network meeting regarding their Moblin community, I was really liked to install Ubuntu on my machine.

After a month, I got a Live DVD of Ubuntu 8.04 LTS. I was really stunned the way Ubuntu organize the installation steps. Wit 7 smart steps, you can install Ubuntu without any technical challenges. But I've faced issues in disk allocation in Live CD mode. The guided option is not soo smart. It tried to swallow my Windows partition. The manual option throws error. After that I came into installation mode and used manual disk allocation. This time Ubuntu installed successfully.

Once completed the installation, I have configured my Internet connection through my Wifi without any issues.

One thing I hate with major Linux distros is that they have installed most of the softwares under a same category. For example, for Programming, KDevelop, QtDesigner, etc have been installed. But Ubuntu is very clear on this. If you want then install.

Ofcourse, one thing I still feel bad is the unhealthy fonts.

Friday, February 29, 2008

In an alternate to Ajax, or along with it, "Comet" is a server-pushing technology, as we know this as one of the Web Patterns.
Ajax is a technique to asynchronously contact server to get data and update UI (Microsoft calls this as Partial Page Update). In this way of programming, you can get the latest data from the server manually calling the server either by UI events or periodical polling to the server. Assume that your web application has stock market update, in order to get latest update, it needs to poll the server periodically. This will make overhead in both client and server side in one way. For example, assume that there are thousands client periodically polling the server at the same period, however there is no new information/state change in the server. Its an overhead for server.
Comet tries to resolve this by server "broadcasting" state change/new information to the listening clients. Its a king of "Server Push" pattern.