Friday, November 17, 2006

Windows Workflow Foundation (WWF)-Base Activity

Windows Workflow Foundation (WWF)-Base Activity
In this session, we will explore the concept of Base activity in WWF. This is in continuation of my previous post which deals with Custom Activity.

Create a new project in Visual Studio 2005 by selecting Sequential Workflow Console Application template. Name the project as "swcaCustomPropertySample".
Your designer will have graphical representation of the workflow .
In Program.cs, you can see few auto generated code lines, which includes WorkflowCompleted and WorkflowTerminated events. Do not change the code. Compile the project and make sure that it is successful.
Our next step is to add an activity project to the solution. Then we will add two code activities in to the activity project.
Create a new project in Visual Studio 2005 by selecting Workflow Activity Library template. Name the project as "swcaBaseActivityLibrary".
You can see the designer with "Drop Activities Here".
Right click on the item "Activity1" and select the Properties. You can see the properties of Activity1 in property window.
We will concentrate on "Base Class" property now.
Click on "..." button and go to "Browse and select a .NET type" window.
Under Type tab, select System.Workflow.ComponentModel. This will display "Activity" and "CompositActivity".
Select "Activity".Click on Ok button.
View the change that happend to the designer window.
Right click on Activity1 and select "View Code" menu. This will take you to the code behind file.
You can see the following code by default:
public Activity1()
{
InitializeComponent();
}
Place the cursor bellow the last bracket and right click and select "Insert Sniplet". From the context menu, double click on "Workflow". Select "DependencyProperty-Property"
This will add few lines of code. We need to customize this as bellow:
public static DependencyProperty FirstNameProperty =
System.Workflow.ComponentModel.DependencyProperty.Register("FirstName", typeof( string), typeof(Activity1));
[Description("First Name")]
[Category("NameActivity")]
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public string FirstName
{
get
{
return ((string)(base.GetValue(Activity1.FirstNameProperty)));
}
set
{
base.SetValue(Activity1.FirstNameProperty, value);
}
}
protected override ActivityExecutionStatus Execute(ActivityExecutionContext
executionContext)
{
Console.WriteLine(FirstName);
Console.ReadKey();
return ActivityExecutionStatus.Closed;
}
Your activity has 1 custom property. You can add more properties as per your interest.
Rebuild the solution and make sure that it is successful. After rebuild, you can see your activity in the ToolBox.
Double click on the designer in swcaCustomPropertySample project you created.
Add the activity you have created into "Drop Activities to create a Sequential Workflow".
Right click on the added activity and select "Properties" menu. You can see the property window. Specify the value for "FirstName" property. Type "karada". You MUST enclose the value in "quots".
Run the application and watch the output!!!

Note: This is the very basic behaviour of a workflow. We can create very complex system later.
write me if you have any doubts: soshekar@gmail.com

No comments: