本文整理匯總了C#中System.Workflow.ComponentModel.Activity.Clone方法的典型用法代碼示例。如果您正苦於以下問題:C# Activity.Clone方法的具體用法?C# Activity.Clone怎麽用?C# Activity.Clone使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Workflow.ComponentModel.Activity
的用法示例。
在下文中一共展示了Activity.Clone方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CreateExecutionContext
public ActivityExecutionContext CreateExecutionContext(Activity activity)
{
if (this.ownerContext == null)
throw new ObjectDisposedException("ActivityExecutionContextManager");
if (activity == null)
throw new ArgumentNullException("activity");
if (!this.ownerContext.IsValidChild(activity, true))
throw new ArgumentException(SR.GetString(SR.AEC_InvalidActivity), "activity");
Activity copiedActivity = activity.Clone();
((IDependencyObjectAccessor)copiedActivity).InitializeInstanceForRuntime(this.ownerContext.Activity.WorkflowCoreRuntime);
//Reset the cloned tree for execution.
Queue<Activity> activityQueue = new Queue<Activity>();
activityQueue.Enqueue(copiedActivity);
while (activityQueue.Count != 0)
{
Activity clonedActivity = activityQueue.Dequeue();
if (clonedActivity.ExecutionStatus != ActivityExecutionStatus.Initialized)
{
clonedActivity.ResetAllKnownDependencyProperties();
CompositeActivity compositeActivity = clonedActivity as CompositeActivity;
if (compositeActivity != null)
{
for (int i = 0; i < compositeActivity.EnabledActivities.Count; ++i)
{
activityQueue.Enqueue(compositeActivity.EnabledActivities[i]);
}
ISupportAlternateFlow alternateFlow = compositeActivity as ISupportAlternateFlow;
if (alternateFlow != null)
{
for (int i = 0; i < alternateFlow.AlternateFlowActivities.Count; ++i)
{
activityQueue.Enqueue(alternateFlow.AlternateFlowActivities[i]);
}
}
}
}
}
// get active context activities and add it to this one
IList<Activity> activeContexts = (IList<Activity>)this.ownerContext.Activity.ContextActivity.GetValue(Activity.ActiveExecutionContextsProperty);
if (activeContexts == null)
{
activeContexts = new List<Activity>();
this.ownerContext.Activity.ContextActivity.SetValue(Activity.ActiveExecutionContextsProperty, activeContexts);
}
activeContexts.Add(copiedActivity);
// prepare the copied activity as a context activity
ActivityExecutionContextInfo contextInfo = new ActivityExecutionContextInfo(activity.QualifiedName, this.ownerContext.WorkflowCoreRuntime.GetNewContextActivityId(), Guid.NewGuid(), this.ownerContext.ContextId);
copiedActivity.SetValue(Activity.ActivityExecutionContextInfoProperty, contextInfo);
copiedActivity.SetValue(Activity.ActivityContextGuidProperty, contextInfo.ContextGuid);
ActivityExecutionContext newExecutionContext = null;
try
{
// inform workflow runtime
this.ownerContext.Activity.WorkflowCoreRuntime.RegisterContextActivity(copiedActivity);
// return the new context
newExecutionContext = new ActivityExecutionContext(copiedActivity);
this.executionContexts.Add(newExecutionContext);
newExecutionContext.InitializeActivity(newExecutionContext.Activity);
return newExecutionContext;
}
catch (Exception)
{
if (newExecutionContext != null)
{
this.CompleteExecutionContext(newExecutionContext);
}
else
{
activeContexts.Remove(copiedActivity);
}
throw;
}
}
示例2: CreateExecutionContext
public ActivityExecutionContext CreateExecutionContext(Activity activity)
{
ActivityExecutionContext context2;
if (this.ownerContext == null)
{
throw new ObjectDisposedException("ActivityExecutionContextManager");
}
if (activity == null)
{
throw new ArgumentNullException("activity");
}
if (!this.ownerContext.IsValidChild(activity, true))
{
throw new ArgumentException(SR.GetString("AEC_InvalidActivity"), "activity");
}
Activity item = activity.Clone();
((IDependencyObjectAccessor) item).InitializeInstanceForRuntime(this.ownerContext.Activity.WorkflowCoreRuntime);
Queue<Activity> queue = new Queue<Activity>();
queue.Enqueue(item);
while (queue.Count != 0)
{
Activity activity3 = queue.Dequeue();
if (activity3.ExecutionStatus != ActivityExecutionStatus.Initialized)
{
activity3.ResetAllKnownDependencyProperties();
CompositeActivity activity4 = activity3 as CompositeActivity;
if (activity4 != null)
{
for (int i = 0; i < activity4.EnabledActivities.Count; i++)
{
queue.Enqueue(activity4.EnabledActivities[i]);
}
ISupportAlternateFlow flow = activity4;
if (flow != null)
{
for (int j = 0; j < flow.AlternateFlowActivities.Count; j++)
{
queue.Enqueue(flow.AlternateFlowActivities[j]);
}
}
}
}
}
IList<Activity> list = (IList<Activity>) this.ownerContext.Activity.ContextActivity.GetValue(Activity.ActiveExecutionContextsProperty);
if (list == null)
{
list = new List<Activity>();
this.ownerContext.Activity.ContextActivity.SetValue(Activity.ActiveExecutionContextsProperty, list);
}
list.Add(item);
ActivityExecutionContextInfo info = new ActivityExecutionContextInfo(activity.QualifiedName, this.ownerContext.WorkflowCoreRuntime.GetNewContextActivityId(), Guid.NewGuid(), this.ownerContext.ContextId);
item.SetValue(Activity.ActivityExecutionContextInfoProperty, info);
item.SetValue(Activity.ActivityContextGuidProperty, info.ContextGuid);
ActivityExecutionContext context = null;
try
{
this.ownerContext.Activity.WorkflowCoreRuntime.RegisterContextActivity(item);
context = new ActivityExecutionContext(item);
this.executionContexts.Add(context);
context.InitializeActivity(context.Activity);
context2 = context;
}
catch (Exception)
{
if (context != null)
{
this.CompleteExecutionContext(context);
}
else
{
list.Remove(item);
}
throw;
}
return context2;
}
開發者ID:pritesh-mandowara-sp,項目名稱:DecompliedDotNetLibraries,代碼行數:76,代碼來源:ActivityExecutionContextManager.cs