Monday, May 26, 2008

A Detailed Look into Customizing Windows Workflow Runtime

http://www.odetocode.com/Articles/457.aspx

Workflow Foundation Basics

Excerpts from here:
1. You only need one instance of the workflow runtime for each process, and you are not allowed to have more than one instance for each AppDomain. The best thing you can do here is to create the required instance directly in the form's constructor. The same runtime object can take care of a variety of workflow instances. The runtime distinguishes instances based on their GUID, and receives private data for each specific instance.


2. There are two general approaches for receiving data into a workflow from the host application when it is instantiated;—parameters and events.

3. Two Type of Workflows: Sequential and State Machine - A sequential workflow is a predictable workflow. The execution path might branch, or loop, or wait for an outside event to occur, but in the end, the sequential workflow will use the activities, conditions, and rules we've provided to march inevitably forward. The workflow is in control of the process.
A state-machine workflow is an event driven workflow. That is, the state machine workflow relies on external events to drive the workflow to completion. We define the legal states of the workflow, and the legal transitions between those states. The workflow is always in one of the states, and has to wait for an event to arrive before transitioning to a new state. Generally, the important decisions happen outside of the workflow. The state machine defines a structure to follow, but control belongs to the outside world.
We use a sequential workflow when we can encode most of the decision-making inside the workflow itself. We use a state machine workflow when the decision-making happens outside the workflow. In this chapter, we will take a closer look at how state machines operate.
Read More here.

4. When you create a new Sequential Workflow Console Application project. The Visual Studio 2005 Solution Explorer will contain two files—workflow1.cs and, initially hidden from view, workflow1.designer.cs. These two files represent the workflow being created. A Windows Workflow Foundation workflow consists of the workflow model file and a code file class. The workflow1.cs class is the code file class where you can write your own workflow business logic. The workflow1.designer.cs class represents the description of the activities map. This file is managed automatically by Visual Studio 2005 in much the same way it happens with forms in a Microsoft Windows Forms project. As you add activities to the workflow, Visual Studio 2005 updates the designer class with Microsoft C# code that programmatically builds the map of activities. To continue with the Windows Forms analogy, a workflow is like a form, whereas activities are like controls.
You can choose another form of persistence for the activity layout—the XML workflow markup format. To try this approach, you delete the workflow1.cs file from the project and add a new workflow item “Sequential Workflow (with code separation)”
Now your project contains two files—workflow1.xoml and workflow1.xoml.cs. The former contains the XML workflow markup that represents the workflow model; the latter is a code file class, and contains source code and event handlers for the workflow.


5. At run time, changes to the collection of activities are also possible, and give you the ability to make changes to a running instance of a workflow.Workflow changes are motivated by business changes that were not known at design time, or by the need for business logic that modifies and then completes the business process. In any case, it should involve limited changes;—perfecting rather than redesigning.

6. Workflow can be exposed as a webservice. The Windows Workflow Foundation framework supports Web service interoperability, which includes the ability to expose a workflow as Web service to ASP.NET clients and to other workflows. Windows Workflow Foundation supports publishing a workflow as an ASP.NET Web service on a Web server or server farm running ASP.NET on Microsoft IIS 6.0. The Windows Workflow Foundation framework activity set contains the WebServiceReceive and WebServiceResponse activities, which enable a workflow to be used as Web service endpoints.

In a real time application, it may take weeks or more for workflow to reach a final/complete state. Fortunately, state machine workflows can take advantage of workflow services, like tracking and persistence (both described in Hosting Windows Workflow). A persistence service could save the state of our workflow and unload the instance from memory, then reload the instance when an event arrives weeks later.






Friday, May 16, 2008

Passionate about ?

I have always been passionate about three things; Cooking, Singing & Acting, but by profession, i am a software engineer and i do enjoy it. I have been in this profession since four years. But unfortunately i had to take a break for few months because the company i was working for two years could not assign work to me any more.
I was so upset because i would earn nothing for a period and had a sense of job insecurity too (i knew, finding a new job was not a big deal, for me but i am in US for just next two months and for this small period i would not struggle).

Then god shown me a ray of hope. I was cooking a lot since i moved to US, so i just thought of starting cooking classes because i had seen many people who would love Indian and Vegetarian food here. I just planned and posted some fliers at few places and some people seemed to be interested. And now i am enjoying welcoming and introducing people to the world of spices, Indian Cooking!!! Such a nice break!!!

I never thought that i would really ever get chance to do something interesting in any one of my passions but wow, i got a chance to do lots of cooking and now i am running cooking classes for a while.

What i have learned from this situation is "never get upset and believe in yourself", this belief can turn worst thing into the best thing in your life. grin !!

Wednesday, May 14, 2008

Object Oriented design???

As per my understanding following points should be Kept in mind while designing an OO system:

1. Encapsulate what varies: This makes code maintenance easy because by encapsulating what varies we have moved the code more susceptible to changes to one place and it can be modified without affecting the stable code, if needed in future. This way we have introduced low coupling b/w the code which varies and the code which stay same.

2. Program to an interface not an implementation: Stable code is the one which is closed for modification but open for extension. So by programming to an interface or abstraction we can actually modify the actual implementation anytime when required without affecting the code that uses interface. So this way we have flexible and extensible code.

3. Favor composition over inheritance: It allows to delegate some of the responsibilities to the composition objects.This way we can make
changes to composition object implementation independently.

4. Classes should be open for extension but closed for modifications.

There is more to come...

Thursday, May 8, 2008

IQueryable and IQueryProvider

This post by Bart Linq to Active Directory gives good insight of how linq to anything works but it was based on .Net 3.5 Beta1 release and used IQueryable interface because IQueryProvider was introduced while Beta2.

Actually, the IQueryable interface was factored into two interfaces while Beta2 release:

1. IQueryable
2. IQueryProvider

If you use Visual Studio to ‘Go to definition’ you get something that looks like this:

public interface IQueryable : IEnumerable {

Type ElementType { get; }

Expression Expression { get; }

IQueryProvider Provider { get; }

}

public interface IQueryProvider {

IQueryable CreateQuery(Expression expression);

IQueryable CreateQuery(Expression expression);

object Execute(Expression expression);

TResult Execute(Expression expression);

}

Through Linq to Amazon example you can see how it would change the Linq to Active Directory implementation by Bart.

Good resource: Linq to Everything: A List of LINQ Providers


ASP.Net 2.0 Compilation Model

The ASP.NET compiler (aspnet_compiler.exe) was originally introduced in ASP.NET 2.0 as a way of completely precompiling an entire site, making it possible to deploy nothing but binary assemblies (even .aspx and .ascx files are precompiled).
This is compelling because it eliminates any on-demand compilation when requests are made, eliminating the first postdeployment hit seen in some sites today. It also makes it more difficult for modifications to be made to the deployed site (since you can't just open .aspx files and change things), which can be appealing when deploying applications that you want to be changed only through a standard deployment process.
The compiler that ships with the release version of ASP.NET 2.0 supports this binary-only deployment model, but it has also been enhanced to support an updatable deployment model, where all source code in a site is precompiled into binary assemblies, but all .aspx and .ascx files are left basically intact so that changes can be made on the server (the only changes to the .aspx and .ascx files involve the CodeFile attribute being removed and the Inherits attribute being modified to include the assembly name). This model is possible because of the reintroduction of inheritance in the codebehind model, so that the sibling partial classes containing control declarations can be generated and compiled independently of the actual .aspx file class definitions.


So, there are three Deployment Mode; vs2005 deploys a site using updatable mode by default but using aspnet_compiler.exe utility one can use other two option as well that is all source and all binary.

All Source Mode: This mode is generally used while in development phase.

All Binary Mode
When the binary deployment option is used

aspnet_compiler -v /MyWebSite -p "F:\Samples\MyWebSite" "C:\Inetpub\wwwroot\MyWebSite". It results in
1) The .aspx files in the deployment directory, they are just marker files with no content. They have been left there to ensure that a file with the endpoint name is present in case the "Check that file exists" option for the .aspx extension in an IIS app is set.
2) The PrecompiledApp.config file is used to keep track of how the app was deployed and whether ASP.NET needs to compile any files at request time.
3) A precompiled dll which includes all the codebehind files for .aspx(separate assembly per directory) , .ascx(separate assembly per directory) , .master files and App_Code folder.

Updatable (mixed) Mode

To generate the "updatable" site, you would add a -u to the command line, and the resulting .aspx files would contain their original content (and not be empty marker files). Note that this functionality can also be accessed graphically through the Build | Publish Web Site menu item of Visual Studio 2005, as you can see in Figure 5. Both the command-line tool and Visual Studio rely on the ClientBuildManager class of the System.Web.Compilation namespace to provide this functionality.

Deploying a website executing the following command
aspnet_compiler -v /MyWebSite -p "F:\Samples\MyWebSite" -u "C:\Inetpub\wwwroot\MyWebSite"

results in a precompiled dll which includes all the codebehind files for .aspx(separate assembly per directory) , .ascx(separate assembly per directory) , .master files and App_Code folder.


Things to be cautious
Another thing to keep in mind when considering the file-to-assembly mapping is that the use of the internal keyword to prevent external assemblies from accessing methods in your classes may work in some deployment scenarios and not others, because of the different assembly mapping options. Unless you plan ahead of time which deployment option you will be using, it is probably best to avoid internal methods in your pages and stick to the type-scoped protection keywords: public, protected, and private.

How often do you let other people

I have found an interesting read and posting here as it is, so i do not lose it.

How often do you let other people's nonsense change your mood? Do you let a bad driver, rude waiter, curt boss, or an insensitive employee ruin your day?

However, the mark of a successful person is how quickly she can get back her focus on what's important.

Sixteen years ago I learned this lesson. I learned it in the backseat of a New York City taxi cab. Here's what happened.

I hopped in a taxi, and we took off for Grand Central Station. We were driving in the right lane when all of a sudden, and I mean without warning, a black car jumped out of a parking space right in front of us. My

taxi driver slammed on his brakes, skidded and missed the other car's back end by just inches.

Here's what happened next. The driver of the other car, the guy who almost caused a big accident, whipped his head around and he started yelling bad words at us.

Now, here's what blew me away. My taxi driver just smiled and waved at the guy. And I mean, he was friendly. So, I said, "Why did you just do that?

This guy almost ruined your car and sent us to the hospital!" And this is when my taxi driver told me what I now call, " *The Law of the Garbage Truck."**

*

Many people are like garbage trucks. They run around full of garbage,

full of frustration, full of anger, and full of disappointment. As their

garbage piles up, they need a place to dump it. And if you let them, they'll

dump it on you.

When someone wants to dump on you, don't take it personally. You just smile,

wave, wish them well, and move on. You'll be happy you did. I guarantee it.

So this was it: The "Law of the Garbage Truck." I started thinking, how

often do I let Garbage Trucks run right over me? And how often do I take

their garbage and spread it to other people: at work, at

home, on the streets? It was that day I said, "I'm not going to do it

anymore."

Well now "I see Garbage Trucks." I see the load they're carrying. I see them

coming to drop it off. And like my Taxi Driver, I don't make it a personal

thing; I just smile, wave, wish them well, and I move on.

Good leaders know they have to be ready for their next meeting.

Good parents know that they have to welcome their children home from school

with hugs and kisses.

Leaders and parents know that they have to be fully present, and at

their best for the people they care about.

The bottom line is that successful people do not let Garbage Trucks take over their day. What about you? What would happen in your life, starting today, if you let more garbage trucks pass you by?

Here's my bet. You'll be happier. I guarantee it.

Trip to Victoria, BC, Canada

Last weekend, we had been to Canada for the last time, as our visa would expire on 9th may.
We went to Victoria city (situated on Vancouver island), BC state, Canada and that trip was the most exciting and exhilarating, we ever had in Canada.

It is such a beautiful city, and the wealthiest city i have ever seen.We left saturday morning 4 am and took a ferry after entering the Canada, Vancouver city (by car) around 7am and reached Victoria (Vancouver island) around 9am.
Vancouver island and Vancouver city are different, but both in BC state, so do not get confused.
Then we went to the miniature world and after spending 2.5 hours there we just walked and reached the wax museum and then back to hotel. we all were very tired by that time but did not sleep. Rather we ate something and then just walked to get look and feel of the city. While returning back to hotel Anjal (my kiddo) fell asleep in my arms, we also went to bed just after doing little planning for the next day.

Sunday, we got up early and left hotel around 6:45 am just to see the beaches; all were on the same drive called as beach drive. Our eyes captured the real beauty, wealth (houses; very big and beautiful and the whole infrastructure was so good) of the city while driving around the city and reaching various beaches and several view points in between.

Then we returned back to hotel and after getting refreshed did checkout from hotel and targeted for our next spot that was "The Butchart Garden"; it was very huge, full of myriads of flowers. We reached there 12:30 pm and left around 4 pm to take the return ferry starting at 5 pm to Vancouver city (Bc, canada).
we drove from Vancouver city to Anacortes (where we live) for about 2.5 hours and then we were at sweet home. Fully tired but satisfied with the weekend. :)


Thursday, May 1, 2008

What matters for you? Money in pocket OR Brain in mind!!!

Software engineers earn good money. And i have seen many people who are willing to have or get very quick promotions. But i don't want to be a manager soon. I want to spend much time as a developer. I want to learn and understand so many things because i think manager do not get time for learning and have busy schedules, sometimes i think how do they get time for their personal life, family? i have seen people who have calls untill late night. Life is not just about spending weekends with family, is it? On weekdays working hours should be normal for anyone, not more than 9-10 hours.

Today, i was reading an article and i liked one line (title of this article) very much and thought for a while about it. I realised that it says a lot.

I think, If we are running madly after promotion (indirectly after money, i do not mean that promotions are bad but they should be through usual ladder and it varies from person to person), we are probably gaining nothing but compromising our peaceful life and losing valuable moments of life just to get early promotions. And that too for something which will not stay longer; we will spend it somewhere pretty soon.

I would prefer doing things using brain (no hurries) and working for myself not just for the purpose of completing an assigned task and pleasing my manager. While doing my job i want to learn as much as possible and know internals of technologies (because it gives me satisfaction), does not matter if it earns me less money.
And i have experienced that willingness to gain detailed knowledge gives ultimate satisfaction and that is what we want from our lives.

I know some of the readers might not agree with what i said but this is what i think and we all free to write what we think? :)

My choice is brain in mind over money!!!!!