我有一个自定义Activity,它应该根据InArgument中传递的名称调用子工作流。
public class CallSubWorkflowActivtiy:NativeActivity {
public InArgument<String> SelectedWorkflow { get; set; } protected override void Execute(NativeActivityContext context) { Activity subWorkflow = ActivityFactory.CreateActivity(SelectedWorkflow.Get(context)); context.ScheduleActivity(activity); } protected override void CacheMetadata(NativeActivityMetadata metadata) { }
}
我首选的解决方案是使用context.ScheduleActivity
调用子活动。这不起作用,因为我无法在metadata.AddImplementationChild(subWorkflow)
中添加CacheMeta(context)
,因为此时我无法访问InArguments。
解决方案可能是破解这一访问CacheMetadata中的InArguments。但这不是一个应该实施的解决方案。
我提出的另一个解决方案是使用WorkflowInstance或WorkflowInvoker来执行子工作流活动。
public class CallSubWorkflowActivtiy:NativeActivity { public InArgument SelectedWorkflow {get;组; }
protected override void Execute(NativeActivityContext context) { Activity subWorkflow = ActivityFactory.CreateActivity(SelectedWorkflow.Get(context)); WorkflowApplication wfInstance = new WorkflowApplication(subWorkflow); }
}
此解决方案实际上可行。但我不确定如何在子工作流中处理持久性,以及父工作流在子工作流完成时如何继续。
我现在的问题是:
metadata.AddImplementationChild(subWorkflow)
答案 0 :(得分:0)
我解决了我的问题如下:
protected override void CacheMetadataInternal(System.Activities.NativeActivityMetadata metadata)
{
InArgument<String> workflowVersionArgument = SelectedWorkflow;
if (workflowVersionArgument != null && workflowVersionArgument.Expression != null)
{
String selectedWorkflowString = workflowVersionArgument.Expression.ToString();
if (selectedWorkflowString != null)
{
WorkflowVersion wfVersion = WorkflowVersion.LoadFromXML(selectedWorkflowString);
if (wfVersion != null && wfVersion.WorkflowName != null)
{
VersionedActivity subWorkflow = ActivityFactory.Instance.CreateActivity(wfVersion.WorkflowName, wfVersion.Version);
if (subWorkflow != null && subWorkflow.ActivityProp != null)
{
subWorkflowInternal = subWorkflow.ActivityProp;
metadata.AddImplementationChild(subWorkflowInternal);
}
}
}
}
}