Executing sequential workflow using the freeformdesigner

Hi!

I am rehosting the workflow designer using the freeform designer. I can move and resize the activites on the surface. I can also connect them with arrows.I have some trouble to write the execute method that will execute the workflow in a sequential order, and I hope someone could help me with that.

First of all I have a classBaseActivity: The class has the properties; NextActivityName and StartActivityName. StartActivityName contain the name of the startActivity within a compositeActiviy.

publicpartialclassBaseActivity :SequenceActivity,IActivityEventListener<ActivityExecutionStatusChangedEventArgs>

{

...

publicstaticDependencyProperty NextActivityNameProperty = System.Workflow.ComponentModel.DependencyProperty.Register("NextActivityName",typeof(String),typeof(BaseActivity));

publicstaticDependencyProperty StartActivityNameProperty = System.Workflow.ComponentModel.DependencyProperty.Register("StartActivityName",typeof(String),typeof(BaseActivity));

...

// Here I have override the execute method. Let's check it up later.

}

Then I have two classes that inherit from BaseActivity;MyActivity andMyCompositeActivity. This is the two activities I can drag and drop into the surface. MyActivity can't contain other activities, and will only do some code. MyCompositeActivity can contain other activites (like MyActivity and MyCompositeActivity).

The root activity is an instance of the class MyCompositeActivity.

Now, let's have a look at the execute method I have implemented in the BaseActivity class:

protectedoverrideActivityExecutionStatus Execute(ActivityExecutionContext executionContext)

{

if (!this.StartActivityName.Equals(""))

{

ActivityExecutionContext context = executionContext.ExecutionContextManager.CreateExecutionContext(this.GetActivityByName(this.StartActivityName));

context.Activity.Closed += onCloseActivity;

context.ExecuteActivity(context.Activity);

returnActivityExecutionStatus.Executing;

}

else

{

returnActivityExecutionStatus.Closed;

}

}

privatevoid onCloseActivity(object sender,ActivityExecutionStatusChangedEventArgs e)

{

BaseActivity activity = e.ActivityasBaseActivity;

BaseActivity parent = (BaseActivity)activity.Parent;

ActivityExecutionContext executionContext = senderasActivityExecutionContext;

if (!activity.NextActivityName.Equals(""))

{

ActivityExecutionContext context = executionContext.ExecutionContextManager.CreateExecutionContext(parent.GetActivityByName(activity.NextActivityName));

context.Activity.Closed += onCloseActivity;

context.ExecuteActivity(context.Activity);

}

}

And in the MyActivity class I have overrided the execute method like this:

protectedoverrideActivityExecutionStatus Execute(ActivityExecutionContext executionContext)

{

executeCode();

returnActivityExecutionStatus.Closed;

}

The execution works great up to an extend. Everything works fine as long as the execution goes down in the three. My problem is that the execution stops. Let's say I have the following three:

MyCompositeActivity(root)

MyActivity

MyActivity

MyCompositeActivity

MyActivity

MyActivity (*)

MyActivity

The execution will stop after the (*). This is probably because the onCloseActivity method won't be called after MyCompositeActivity is done or closed. How can i fire this event?

I look forward to an answer, thanks a lot!

[7575 byte] By [FassaBortolo] at [2007-12-24]
# 1

From the description it looks like you are setting the startactivity of the second MyCompositeActivity to Myctivity and next activity to MyActivity(*). I am also guessing from the the tree described you dont have MyActivity(*) set the next activity as the last Myactivity. this is why you dont see execution reaching there.

If you change the startactivity from s single activity to a list of children activities and fire eachof the children before you fire the next activity on the closed event of the composite you'll do fine.

I would recommend the following: in execute, run each of the children activity and subscribe to their closed events, in the on closed make sure you get all children closed and then fire the nextevent.

Finally make sure you wire up the workflows just as shown in the tree.

Thanks,

Vignesh

VigneshKannappan-MSFT at 2007-8-31 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...

Software Development for Windows Vista

Site Classified