简体   繁体   English

Windows Workflow Foundation和Persistence中的子工作流

[英]Sub Workflow in Windows Workflow Foundation and Persistence

I have a custom Activity that should call a sub workflow according to a name passed in an InArgument. 我有一个自定义活动,该活动应根据InArgument中传递的名称调用子工作流程。

public class CallSubWorkflowActivtiy : NativeActivity { 公共类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) { } 

} }

My prefered solution would be to invoke the child activity with context.ScheduleActivity . 我更喜欢的解决方案是使用context.ScheduleActivity调用子活动。 That doesn't work because I can't add metadata.AddImplementationChild(subWorkflow) in CacheMeta(context) because i haven't access to the InArguments at this point. 那是行不通的,因为我无法添加CacheMeta(context) metadata.AddImplementationChild(subWorkflow) ,因为此时我无法访问InArguments。

A solution could be to hack around this an access the InArguments in the CacheMetadata. 解决方案可能是解决此问题,以访问CacheMetadata中的InArguments。 But this isn't a solution that should be implemented. 但这不是应实施的解决方案。

Another solution I came up with was to use the WorkflowInstance or WorkflowInvoker to execute the subWorkflow Activities. 我想到的另一个解决方案是使用WorkflowInstance或WorkflowInvoker执行subWorkflow活动。

public class CallSubWorkflowActivtiy : NativeActivity { public InArgument SelectedWorkflow { get; 公共类CallSubWorkflowActivtiy:NativeActivity {public InArgument SelectedWorkflow {get; set; 组; } }

 protected override void Execute(NativeActivityContext context) { Activity subWorkflow = ActivityFactory.CreateActivity(SelectedWorkflow.Get(context)); WorkflowApplication wfInstance = new WorkflowApplication(subWorkflow); } 

} }

This solution would practically work. 该解决方案实际上将起作用。 But I am not sure how the persistance is handled in this subworkflow an how the parent workflow continues when the child workflow finishes. 但是我不确定在此子工作流程中如何处理持久性以及在子工作流程完成时父工作流程如何继续。

My questions are now: 我的问题是:

  1. Is there any way to call SubWorkflow Activities with context.ScheduleActivity(...) if the activity wasn't added practically with metadata.AddImplementationChild(subWorkflow) 如果实际上没有使用metadata.AddImplementationChild(subWorkflow)添加活动,则有什么方法可以使用context.ScheduleActivity(...)来调用SubWorkflow活动metadata.AddImplementationChild(subWorkflow)
  2. If you use the WorkflowInstance class how is the persistance handled and how to continue the parent workflow if the child workflow finishes. 如果您使用WorkflowInstance类,那么在子工作流程完成时,如何处理持久性以及如何继续父工作流程。

I solved my problem as follows: 我解决了如下问题:

 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);
                        }
                    }
                }
            }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM