Setting internal properties in a composite WF4. Activities during development

I want to create a compound Windows workflow operation (in .NET.NET) that contains a predefined ReceiveAndSendReply operation. Some of the properties are predefined, but others must be set in the designer (in particular, ServiceContractName).

I could implement this as an Activity Pattern (just like ReceiveAndSendReply is implemented), but it probably won't. If you later change the template, I will have to update all previously created workflows manually. The template will also allow other developers to change the properties that need to be fixed.

Is there a way to do this from Xaml Activity? I have not found a way to assign an Argument value to an inline activity property. If not, what method would you suggest?

+3
source share
1 answer

I did not do this using composite XAML activity, and I get some errors when I try, but doing it through NativeActivity is not a problem. See the sample code below.

public class MyReceiveAndSendReply : NativeActivity
{
    private Receive _receive;
    private SendReply _sendReply;

    public string ServiceContractName { get; set; }
    public string OperationName { get; set; }

    protected override bool CanInduceIdle
    {
        get { return true; }
    }

    protected override void CacheMetadata(NativeActivityMetadata metadata)
    {
        _receive = _receive ?? new Receive();
        _sendReply = _sendReply ?? new SendReply();
        _receive.CanCreateInstance = true;
        metadata.AddImplementationChild(_receive);
        metadata.AddImplementationChild(_sendReply);

        _receive.ServiceContractName = ServiceContractName;
        _receive.OperationName = OperationName;

        var args = new ReceiveParametersContent();
        args.Parameters["firstName"] = new OutArgument<string>();
        _receive.Content = args;

        _sendReply.Request = _receive;

        var results = new SendParametersContent();
        results.Parameters["greeting"] = new InArgument<string>("Hello there");
        _sendReply.Content = results;

        base.CacheMetadata(metadata);
    }

    protected override void Execute(NativeActivityContext context)
    {
        context.ScheduleActivity(_receive, ReceiveCompleted);

    }

    private void ReceiveCompleted(NativeActivityContext context, ActivityInstance completedInstance)
    {
        context.ScheduleActivity(_sendReply);
    }
}
+6
source

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


All Articles