Frage

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.

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.?

Thanks in advance!

Marcus.

War es hilfreich?

Lösung

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 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>();
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top