如何在 Workflow Foundation 4.0 中为变量分配参数?

发布于 2024-09-08 19:19:29 字数 1836 浏览 6 评论 0原文

这个简单的代码失败并出现以下错误:

处理工作流树时遇到以下错误:

“ArgumentValue”:在拥有这些私有的活动上找不到名为“Parameter”的参数孩子们。 ArgumentReference 和 ArgumentValue 只能在 Activity 定义的主体中使用。

我还尝试使用 VisualBasivValue("Parameter") 而不是 ArgumentValue,错误是:

处理工作流树时遇到以下错误:

“VisualBasicValue”:处理表达式“参数”时遇到编译器错误。 未声明“参数”。由于其保护级别,它可能无法访问。

如何正确操作?

我尝试在 Xaml 中构建类似的东西,并且它有效,这是代码:

<Assign sap:VirtualizedContainerService.HintSize="242,58">
    <Assign.To>
        <OutArgument x:TypeArguments="x:String">[variable]</OutArgument>
    </Assign.To>
    <Assign.Value>
        <InArgument x:TypeArguments="x:String">[Parameter]</InArgument>
    </Assign.Value>
</Assign>

看起来它以某种方式引用了参数,但是如何......

我如何在代码中做到这一点? 这是我的简单场景:

public class RootActivity : NativeActivity
{
    public InArgument<string> Parameter { get; set; }

    public Activity Activity { get; set; }

    public RootActivity()
    {
        var variable = new Variable<string>("V1", "This is my variable!");
        var activity = new Sequence
            {
                Variables = {variable},
                Activities =
                {
                    new Assign<string>
                    {
                        To = new OutArgument<string>(variable),
                        Value = new InArgument<string>(
                            new ArgumentValue<string>("Parameter"));
                    },
                }
            };

        this.Activity = activity;
    }

    protected override void Execute(NativeActivityContext context)
    {
        context.ScheduleActivity(this.Activity);
    }
}

非常感谢您的帮助!

This simple code fails with the following error:

The following errors were encountered while processing the workflow tree:

'ArgumentValue': The argument named 'Parameter' could not be found on the activity owning these private children. ArgumentReference and ArgumentValue should only be used in the body of an Activity definition.

I also tried VisualBasivValue("Parameter") instead of ArgumentValue, and the error was:

The following errors were encountered while processing the workflow tree:

'VisualBasicValue': Compiler error(s) encountered processing expression "Parameter".
'Parameter' is not declared. It may be inaccessible due to its protection level.

How to do it properly?

I tried to build something similar in Xaml, and it works, here is the code:

<Assign sap:VirtualizedContainerService.HintSize="242,58">
    <Assign.To>
        <OutArgument x:TypeArguments="x:String">[variable]</OutArgument>
    </Assign.To>
    <Assign.Value>
        <InArgument x:TypeArguments="x:String">[Parameter]</InArgument>
    </Assign.Value>
</Assign>

Looks like it references the parameter somehow, but how...

How can I do it in code?
Here is my simple scenario:

public class RootActivity : NativeActivity
{
    public InArgument<string> Parameter { get; set; }

    public Activity Activity { get; set; }

    public RootActivity()
    {
        var variable = new Variable<string>("V1", "This is my variable!");
        var activity = new Sequence
            {
                Variables = {variable},
                Activities =
                {
                    new Assign<string>
                    {
                        To = new OutArgument<string>(variable),
                        Value = new InArgument<string>(
                            new ArgumentValue<string>("Parameter"));
                    },
                }
            };

        this.Activity = activity;
    }

    protected override void Execute(NativeActivityContext context)
    {
        context.ScheduleActivity(this.Activity);
    }
}

Thanks a lot for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

把时间冻结 2024-09-15 19:19:29

您在 To 和 Value 中设置的表达式实际上是 VisualBasicReference 和 VisualBasicValue。 XAML 的等效代码是:

new Assign<string>
        {
            To = new VisualBasicReference<string>("V1"),
            Value = new VisualBasicValue<string>("Parameter")
        };

The expression that you set in the To and Value are actually VisualBasicReference and VisualBasicValue. The equivalent code for your XAML is:

new Assign<string>
        {
            To = new VisualBasicReference<string>("V1"),
            Value = new VisualBasicValue<string>("Parameter")
        };
只是一片海 2024-09-15 19:19:29

我不太确定,但我注意到一件事。

我发现尝试在构造函数中配置活动通常不起作用。建议在 IActivityTemplateFactory 的 Create 方法中执行此操作

更改代码以便实现此方法,然后将代码从构造函数移动到 Create 方法。这可能不是您的全部问题,但可能是其中之一。

I'm not exactly sure, but there is one thing I've noticed.

I've found that trying to configure an activity within a constructor often does not work. It is advisable to do this within the Create method of IActivityTemplateFactory.

Change your code so that you implement this method, then move the code from the constructor to the Create method. This may not be your whole issue, but it could be one of them.

瑶笙 2024-09-15 19:19:29

试试这个:

new Assign<string>
{
    To = new OutArgument<string>(variable),
    Value = new InArgument<string>(
        env => Parameter.Get(env));
},

Try this:

new Assign<string>
{
    To = new OutArgument<string>(variable),
    Value = new InArgument<string>(
        env => Parameter.Get(env));
},
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文