Friday, November 17, 2006

Windows Workflow Foundation (WWF)-Composite Activity

I was searching for a good article with step by step example for WWF activity. I wondered, i could not find a good article. I am always interested in sharing my knowledge to the world. So thought to write a small white paper which talks about Composite Activity in WWF.
***
Activities are the primary unit of execution and can be reused in different ways.
In this lession, I will teach you to create Composite Activity using WWF.
A composite activity is the one created by the user and is available in Visual Studio 2005 ToolBox.
You can drag and place to your designer the way you do with Base activity. A Base activity is the one you are seeing in ToolBox by default.
Activity is nothing but a class.
This class will have the methods to execute.

  • Create a new project in Visual Studio 2005 by selecting Sequential Workflow Console Application template.
  • Name the project as "swcaCompositeActivity".
    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 "swcaCompositeActivityLibrary".
    You can see the designer with "Drop Activities Here".
  • Drag a code activity from the tool box and drop it on "Drop Activities Here".
    Now you can see a code activity in the work area.
  • Double click on this code activity. You can see a new event named codeActivity1_ExecuteCode automatically generated.
    Write a greeting message inside the event.
  • Your code should look like this:
    private void codeActivity1_ExecuteCode(object sender, EventArgs e)
    {
    Console.Write("hello ,");
    }
    Now, go back to the designer by selecting the menu View->Designer
    Drag one more code activity. Double click on this activity to see its ExecuteCode.Modify the ExecuteCode as follows:
    private void codeActivity2_ExecuteCode(object sender, EventArgs e)
    {
    Console.Write("where are you?");
    Console.ReadLine();
    }
  • Compile the project and make sure that it is successful.
    Double click on swcaCompositeActivity design template. You can see "Drop Activities to create a Sequential Workflow"
  • In ToolBox, you should see the activity you have created in swcaCompositeActivityLibrary.
  • Drag this activity into to Drop Activity place.
    The code activities we have created will execute sequentially.
    Run the application and you should see "Hello ,where are you?" message in console window.
    To terminate the application just press enter key.
    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: