WF4 User Activity with OutArgument and Assign

I am trying to write a custom action by composing standard actions, one of which is the Assignment operation, which is responsible for assigning the OutArgument string value called β€œTextOut”, which I defined in my custom Activity. The idea is that the author of the workflow that uses this custom activity identifies the variable in the workflow and maps it to the TextOut OutArgument of my user activity. I would like to achieve this with an iterative approach, since I have a requirement to dynamically create select branches at runtime. I abandoned this code to simplify my question.

Below is the action code. This is probably not how it should be done, because it does not work :) A workflow that uses this action causes a validation error: "The value for the required activity argument has not been provided to".

I would like to get some tips on how to get my OutArgument to work with the Assign child activity (so without calling .Set on my OutArgument).

public sealed class OutArgActivity : Activity
{
    public OutArgument<string> TextOut { get; set; }

    public OutArgActivity()
    {
        Assign assign = new Assign {
            To = this.TextOut,
            Value = new InArgument<string>(
                env => "this is my custom return value")
        };

        Sequence sequence = new Sequence();
        sequence.Activities.Add(assign);

        this.Implementation = () => sequence;
    }
}
+3
source share
2 answers

Try using the ArgumentReference in your Assign operation as follows:

public sealed class OutArgActivity : Activity
{
    public OutArgument<string> TextOut { get; set; }

    public OutArgActivity()
    {
        Assign<string> assign = new Assign<string>
        {
            To = new ArgumentReference<string>("TextOut"),
            Value = new InArgument<string>(
                env => "this is my custom return value")
        };

        Sequence sequence = new Sequence();
        sequence.Activities.Add(assign);

        this.Implementation = () => sequence;
    }
}
+8
source

If you do not want to use magic strings, you can do it as follows.

public sealed class OutArgActivity : Activity
{
    public OutArgument<string> TextOut { get; set; }

    public OutArgActivity()
    {
        Assign<string> assign = new Assign<string>
        {
            To = new OutArgument<string>(ctx => TextOut.Get(ctx)),
            Value = new InArgument<string>(
                env => "this is my custom return value")
        };

        Sequence sequence = new Sequence();
        sequence.Activities.Add(assign);

        this.Implementation = () => sequence;
    }
}

, OutArgument<> Expression, . , .

0

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


All Articles