First Program with WorkFlow

Thursday, July 17, 2008

  • Download .Net Framework 3.0 runtime components ( dotnetfx3setup.exe) and run the setup.
  • Install Windows SDK
  • Install Visual Studio Extension for Workflow.


Visual Studio 2005 Support for WF fall into 2 main categories:

a. Visual Editing – drag drop functionality

b. Templates – for adding workflow-based projects, it adds assemblies’ references.

As usual, we would create first ‘console-based’ workflow project. In Visual Studio open a new project. In project types pane expand Visual C#, click on Workflow and select “Sequential Workflow Console Application”. Clicking on “OK” creates basic project for you and bring up the workflow visual designer user interface. It will create 2 files for you.

i. Program.cs

ii. Workflow1.cs

In solution explorer you can select Workflow1.cs and click on toolbox.

Drop IfElse activity. We would use this to check whether the input string is a valid postal code or not? When you drop IfElse activity you will see the exclamatory sign that tells that you have not written the code for the decision and gives compile time error. Click on left branch go to properties and set condition property to “Code Condition”. And it will ask for the name of event that needs to be fired for evaluation. Type event name as EvaluatePostalCode in “Condition” Property (Child Property of Condition). Now drop the Code activity on the left branch to add code that will execute when EvaluatePostalCode returns true. Select property “ExecuteCode” and write PostalCodeValid.

So what Visual Studio 2005 has done, It has inserted events that will execute code that we will provide. The first event handler, EvaluatePostalCode, executes when the workflow needs to evaluate the test condition. The second event handler, PostalCodeValid executes when the left branch is taken.

Similarly we can add Code to right branch and name the event PostalCodeInvalid.

0 comments: