从自定义活动访问参数、工作流变量 [英] Accessing Arguments, Workflow Variables from custom activities

查看:23
本文介绍了从自定义活动访问参数、工作流变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由许多自定义活动组成的工作流.所有这些活动都需要访问工作流本身的启动参数.我可以在所有这些自定义活动中定义 InArgument 并将工作流参数绑定到自定义活动参数,但我对这个解决方案不满意.从自定义活动访问工作流级别参数和变量声明的最佳方法是什么.我可以从 ActivityContext 获取它们吗?

I have a workflow composed of many custom activities. All these activities need to access startup arguments of the workflow itself. I can define InArgument inside all these custom activities and bind the workflow arguments to custom activity arguments but I am not comfortable with this solution. What is the best way to access workflow level argument and variable declarations from custom activities. Can I get them from ActivityContext?

谢谢.

推荐答案

我们通过自定义活动查看此问题的一种方法是使用 ActivityContext 中可用的 Properties 属性.我们有一个带有 InArgument 的活动,它在 execute 方法中添加了一个 ExecutionProperty,所​​以你最终得到:

One way we've looked at this with our custom activities is using the Properties property available in the ActivityContext. We have an activity with an InArgument which adds an ExecutionProperty in the execute method, so you end up with:

public InArgument<Custom> MyObject {get;set;}

...

context.Properties.Add("Contact",MyObject.Get(context));

然后在您的其他活动中您可以检查是否已设置

Then in your other activities you can check to see if this has been set

context.Properties.Find("Contact")

显然,如果您经常这样做,我建议您在某处使用常量而不是魔术字符串,但这应该可以避免您在设计时一遍又一遍地添加相同的参数.

Obviously if you're doing this a lot I'd recommend using a constant somewhere rather than magic strings, but it should save you having to add the same argument over and over when designing.

这篇关于从自定义活动访问参数、工作流变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆