Chapter 1 – Workflow Program (Part 2)

MS WWF 4.0 Cookbook

Customizing a MyReasLine activity with Bookmark

To pass data from the caller into the workflow when it’s executing – Using BOOKMARK

New workflow console application,”UseBookMark”, next add a code file and name the file MyReasLineActivity.

Edit the MyReasLineActivity.cs. This will be compiled as a toolbox that can be dragged into WF Designer. (function: read line input and pass it to executing workflow)

Go a build solution and the MyReadLine will show up in the toolbox:

WF Designer and add one variable and one argumnet


Click on MyReadLine, and enter the values:

Executing…. (during the execution, get input from caller, and then pass the input inside the workflow, keep processing, and end)

Converting a WF Program instance to XAML

In real applications, we’d like to write and test WF programs in imperative code, while storing, running and transmitting workflow as an XAML string or file. In this task, we will convert a WF program instance to an XAML string.

New workflow consol application, “ConvertWFInstancetoXAML”, delete the Workflow1.xaml. Open Program.CS, enter the codes:

Loading up a WF Program from an XAML File

Run a WF program by loading it from an XAML file.

New Workflow Consol application, “LoadUpWorkFlowFromXAML”. A simple workflow. Go to the source of the WF Designer, copy the XAML source, and save it as a *.XAML file in a different folder, such as C:\WF.XAML. Then delete the workflow1.xaml. This practice is to test whether we can load and run a xaml file that’s not part of a project.


Code to load and invoke the workflow. This can load an run any arbitery XAML workflows. Should be very useful.

Testing a WF Program with a Unit test FrameWork

Create a test project to do unit testing for a WF program

Add a Test Project to solution, and name the project as “UnitTestForWFProgram”.


Add a new item à Workflow à Activity

Add an argumnet; WF designer:

Create unit test Code: (UnitTest1.CS) Ctrl + F5 wouold start the test. It compare the output message with the string provided and see if it’s the same.

in the preceding code, [TestClass] indicates it is a unit test class, whereas [TestMethod] indicates a test method. When the Test Project runs, the test method wll be executed automatically.

Debugging a WF Program

how to debug a WF Program

Create new Workflow Console Application, named “DebugWFProgram”

Program.CS

Click on an Activity to insert a BreakPoint:

You can also debug the source of XAML code:

Advertisements
Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: