Datasheet
Chapter 1: Workfl ow Programming Principles
27
The WhileActivity activity exposes a property named Condition, which is of the ActivityCondition type,
as defined in Listing 1 - 10 . As you can see, this type is an abstract type that exposes a single method
named Evaluate, which takes the following two parameters and returns a Boolean value specifying
whether the condition is met:
activity: Pass the C#
this keyword as the value of this parameter.
provider: Pass the ActivityExecutionContext object passed into your execution method as the
value of this parameter.
The subclasses of the ActivityCondition type must override the Evaluate method where they must
use the preceding two parameters and execute the required custom code to determine whether the
condition is met. A subclass ’ s implementation of the Evaluate method can use the IServiceProvider
object passed into it as its second argument to access whatever local services it needs. As you ’ ll see in the
next chapter, SharePoint registers numerous SharePoint - specific local services that the Evaluate method
can access through the IServiceProvider object.
Listing 1 - 10: The ActivityCondition type
public abstract class ActivityCondition : DependencyObject
{
public abstract bool Evaluate(Activity activity, IServiceProvider provider);
}
Next, I ’ ll walk you through the implementation of the WhileActivity activity, starting with the
implementation of its Execute method. The Execute method first checks whether the WhileActivity
activity contains a child activity. If not, then it returns ActivityExecutionStatus.Closed to inform the
workflow run time that it has completed its execution and is ready to transition to its Closed state.
If the WhileActivity activity contains a child activity, and if the condition evaluates to true, then the
Execute method takes these steps:
1. It accesses the ActivityExecutionContextManager object referenced through the
ExecutionContextManager property of the ActivityExecutionContext object and invokes the
CreateExecutionContext method on this ActivityExecutionContextManager object, passing in a
reference to the child activity of the WhileActivity activity, to create a child execution context:
ActivityExecutionContext childExecutionContext =
executionContext.ExecutionContextManager.CreateExecutionContext(
this.EnabledActivities[0]);
Under the hood, the CreateExecutionContext method takes these steps:
It deep copies the child activity of the WhileActivity activity and all its descendant
activities. In other words, it deep copies the activity branch rooted at the child activity. The
WhileActivity activity, just like the C# “ while ” , contains a single child activity. This
requirement is enforced through a component known as an activity validator . WF ships
with an activity validator that ensures that the WhileActivity activity does not contain
more than one child activity. However, the topic of Activity validation is beyond the scope
of this book.
❑
❑
❑
c01.indd 27c01.indd 27 8/25/08 4:02:59 PM8/25/08 4:02:59 PM