Datasheet

Chapter 1: Work ow Programming Principles
29
Now let s walk through the implementation of the Activity_Closed event handler. This event handler
first removes itself from the list of event handlers registered for the Closed event of the new copy of the
child activity of the WhileActivity activity:
e.Activity.Closed -= this.Activity_Closed;
Next, it casts its first argument to the ActivityExecutionContext type. Keep in mind that this
ActivityExecutionContext object represents the global activity execution context:
ActivityExecutionContext executionContext =
sender as ActivityExecutionContext;
It then accesses the ActivityExecutionContextManager object that manages the child execution context
that the WhileActivity activity creates and invokes the GetExecutionContext method on this object,
passing in the reference to the new copy of the child activity of the WhileActivity activity, to return a
reference to the ActivityExecutionContext object that represents the child execution context:
ActivityExecutionContext childExecutionContext =
executionContext.ExecutionContextManager.GetExecutionContext(e.Activity);
Next, it calls the CompleteExecutionContext method on the same ActivityExecutionContextManager
object, passing in the ActivityExecutionContext object that represents the child execution context, to
complete and to consequently discard the child execution context:
executionContext.ExecutionContextManager.CompleteExecutionContext(
childExecutionContext);
Finally, it checks whether the condition is met again. If so, it repeats the same steps discussed earlier to
deep copy the child activity of the WhileActivity activity and all its descendant activities once again,
create a new child execution context, and schedule the Execute method of the new copy of the child
activity for execution.
Developing Custom Conditions
As you saw, the WhileActivity activity exposes a property named Condition, which is of the
ActivityCondition type. You must assign an ActivityCondition object to this property before executing
the WhileActivity activity. The WhileActivity activity invokes the Evaluate method on this
ActivityCondition object at the beginning of every iteration to determine whether to execute the iteration
or complete its execution. Recall that the ActivityCondition is an abstract class. Every activity condition
must inherit from this abstract base class or one of its subclasses.
In this section we ll develop a custom condition named CustomCondition that inherits from the
ActivityCondition class and overrides its Evaluate method, as shown in Listing 1 - 11 . My main goal in
this example is to show you that the full power of the SharePoint object model is at your disposal when
you re developing a custom activity or condition.
c01.indd 29c01.indd 29 8/25/08 4:02:59 PM8/25/08 4:02:59 PM