How can I write a custom WorkFlow 4 Code Activity that includes "Body Block"?

Is it possible? I know this is for MS, since they have WF activity packages, but I'm not sure how to do it. It would be nice to have actions with Body blocks to insert other actions, buttons, etc. If there are not too many problems and / or time, that is.

+3
source share
3 answers

Its easy enough if you follow a few rules. Here is an example of a NativeActivity that has a child:

[Designer(typeof(MyActivityDesigner)), ContentProperty("Child")]
public sealed class MyActivity : 
    NativeActivity, IActivityTemplateFactory
{
    // this "activity delegate" holds our child activity
    public ActivityAction Child { get; set; }

    // may be necessary to do this
    protected override void 
        CacheMetadata(NativeActivityMetadata metadata)
    {
        metadata.AddDelegate(Child);
    }

    protected override void 
        Execute(NativeActivityContext context)
    {
        // do some work here, then
        context.ScheduleAction(Child);
    }

    // better to use a template factory than a constructor to do this!
    Activity IActivityTemplateFactory
        .Create(System.Windows.DependencyObject target)
    {
        return new MyActivity
        {
            // HAVE to have this set, or it fails in the designer!
            Child = new ActivityAction()
        };
    }
}

. Activity Delegate . -, IActivityTemplateFactory . /, . , ; .

, , , - , , . , .

Child :

<sap:WorkflowItemPresenter
    HintText="Add children here!"
    Item="{Binding Path=ModelItem.Child.Handler}" />
+3

Pro WF: Windows Workflow .Net 4 . .

+2

You need to start with NativeActivity, not CodeActivity. The NativeActivity function allows you to plan child activities through the execution context. There is no template for NativeActivity; instead, you simply create a class and extract it from NativeActivity.

0
source

Source: https://habr.com/ru/post/1751455/


All Articles