The Activity base class
Listing 1 - 1: The Activity base class
public class Activity : DependencyObject
{
// Events
public event EventHandler < ActivityExecutionStatusChangedEventArgs >
Canceling;
public event EventHandler < ActivityExecutionStatusChangedEventArgs >
Closed;
public event EventHandler < ActivityExecutionStatusChangedEventArgs >
Compensating;
public event EventHandler < ActivityExecutionStatusChangedEventArgs >
Executing;
public event EventHandler < ActivityExecutionStatusChangedEventArgs >
Faulting;
// Methods
protected internal virtual ActivityExecutionStatus
Cancel(ActivityExecutionContext executionContext);
protected internal virtual ActivityExecutionStatus
Execute(ActivityExecutionContext executionContext);
protected internal virtual ActivityExecutionStatus
HandleFault(ActivityExecutionContext executionContext, Exception exception);
protected internal virtual void Initialize(IServiceProvider provider);
protected internal virtual void Uninitialize(IServiceProvider provider);
// Properties
public string Description { get; set; }
public bool Enabled { get; set; }
public ActivityExecutionResult ExecutionResult { get; }
public ActivityExecutionStatus ExecutionStatus { get; }
public bool IsDynamicActivity { get; }
public string Name { get; set; }
public CompositeActivity Parent { get; }
}
活动Activity就好像是行为,一个或这一系列的行为。活动有两种类型,叶子活动Leaf Activity和复合活动Composite。
1、开发自定义的Leaf Activity
接下来,我将说一下上面这个Leaf Activity基类的相关部分,如果你打算从这个基类继承来实现你自定义的活动的话,你就要充分的理解这个活动基类,因为你的自定义活动需要重写一些基类中的恰当的方法。
1)Activity Initialization活动初始化
活动的初始化方法是活动执行的第一个方法,用来初始化活动本身。请记住,当这个方法运行的时候,活动还没有开始执行,因为活动的执行方法Execute Method还没有被运行。当从初始化方法返回的时候,活动处于一种叫做“Initialized”的状态,和另外一个状态“Executing”是不一样的,处于“Initialized”状态的活动的Execute Method处于运行计划中。