获取子活动子树 [英] Get Child Activity Subtree

查看:98
本文介绍了获取子活动子树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将旧版工作流程系统转换为WF4,因此我必须跳过几个步骤以使其与我们应用程序的api相匹配.因此,我将尝试使问题的解释尽可能简单. :)

I'm converting a legacy workflow system to WF4 so I have to jump through a couple hoops to make it match up with the api of our application. So I'll try to keep the problem explination as simple as possible. :)

我有一个自定义活动,该活动将一个序列作为参数,然后执行它.在执行该活动之前,自定义活动需要遍历序列(及其分支等),以查找特定类型的子活动-然后对这些特定的子活动进行一些报告.

I have a custom activity that takes a sequence as an argument and then executes it. Prior to executing it, the custom activity needs to traverse the sequence (and it's branches etc) looking for specific types of child activities - then it does some reporting on these specific child activities.

我知道约束可以使用GetChildSubtree活动时,可以在验证期间遍历活动的子树,但这不能使我在运行时访问列表.我也知道也可以使用宿主应用程序中的ActivityValidationServices执行类似的调用,但这对我的情况也不起作用.

I know it is possible to traverse the child sub tree of an activity during Validation time when a Constraint can use a GetChildSubtree activiy, but this doesn't give me access to the list at runtime. I also know it's also possible to execute a similar call using ActivityValidationServices from the host application, but that won't work for my scenario either.

那么从自定义活动的执行方法中获取子子树中活动列表的最佳方法是什么?

So what's the best way to get a list of the activities in the child subtree from within the execution method of a custom activity.?

提前谢谢!

马库斯.

推荐答案

您可能想看看 GetActivities 方法.

You might want to take a look at WorkflowInspectionServices class which provides methods for working with the runtime metadata for an activity tree. In particular the GetActivities method.

GetActivities返回活动的所有直接子级,包括活动,委托处理程序,变量默认值和参数表达式.现在,您可以编写扩展方法以返回所有活动,包括内部分支:

GetActivities returns all the direct children of an activity, including activities, delegate handlers, variable defaults, and argument expressions. You can now write an extension method to return all activities including the inner branches:

public static IEnumerable<Activity> GetInnerActivities(this Activity activity)
{
    var children = WorkflowInspectionServices.GetActivities(activity);

    foreach (var child in children)
    {
        children = children.Concat(child.GetChildren());
    }

    return children;
}

现在获取指定类型的所有活动的内部活动:

Now get all activity's inner activities of a specified type:

activity.GetInnerActivities().OfType<MySpecificType>();

这篇关于获取子活动子树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆