Datasheet
Chapter 1: Workfl ow Programming Principles
25
As you ’ ll see in next chapter, when you initiate a workflow on a SharePoint list item, SharePoint
automatically invokes the CreateWorkflow method on the workflow run time. This method, among
other things, creates the global execution context for the workflow instance. If you do not create child
execution contexts (I ’ ll show you shortly how to do this), all execution methods of all activities making
up the current workflow will be executed within the global execution context.
WF allows composite activities to create child execution contexts within which the child activities of the
composite activity can execute. The ActivityExecutionContext exposes a property named
ExecutionContextManager, which is of the ActivityExecutionContextManager type. This type exposes
the methods and properties that you can use to create, access, and remove child execution contexts. The
following code listing presents these members:
public sealed class ActivityExecutionContextManager
{
public void CompleteExecutionContext(ActivityExecutionContext childContext);
public void CompleteExecutionContext(ActivityExecutionContext childContext,
bool forcePersist);
public ActivityExecutionContext CreateExecutionContext(Activity activity);
public ActivityExecutionContext GetExecutionContext(Activity activity);
public ActivityExecutionContext GetPersistedExecutionContext(Guid contextGuid);
public ReadOnlyCollection < ActivityExecutionContext > ExecutionContexts { get; }
public IEnumerable < Guid > PersistedExecutionContexts { get; }
}
The next section uses an example to show you how to use the methods and properties of the
ActivityExecutionContextManager type.
Listing 1 - 9 presents the implementation of the WhileActivity activity, which is the WF counterpart of the
C# “ while ” flow control construct.
Listing 1 - 9: The WhileActivity activity
using System.Workflow.ComponentModel;
using System.Workflow.Runtime;
using System;
namespace Chapter1
{
public class WhileActivity : CompositeActivity
{
public static readonly DependencyProperty ConditionProperty =
DependencyProperty.Register(“Condition”,
typeof(ActivityCondition),
typeof(WhileActivity));
public ActivityCondition Condition
{
get {
return (ActivityCondition)base.GetValue(ConditionProperty);
}
set { base.SetValue(ConditionProperty, value); }
(continued)
c01.indd 25c01.indd 25 8/25/08 4:02:58 PM8/25/08 4:02:58 PM