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.
public
partialclassBaseActivity :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:
protected
overrideActivityExecutionStatus 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!

