如何从自定义代码活动访问全局变量? [英] How to access global variables from a custom code activity?

查看:34
本文介绍了如何从自定义代码活动访问全局变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚开始使用 WF4.

将一些文本从本机代码活动(位于顺序工作流的中间)传递到序列中的下一个(基于 xaml 的)活动时遇到问题.

这是一个快速概要:自定义本机代码活动进行数据库调用并需要将结果传递给标准的​​SendReplyToRecive"活动(这是此工作流中的最后一个活动).在顶级序列级别定义了一个全局变量reportValue",但我正在努力从该自定义本机代码活动中获取它.

此工作流的设计界面不提供参数,仅提供变量和导入,因此,我什至不确定是否可以使用 OutArgument.

这是怎么做到的?

解决方案

如果你的自定义 NativeActivity 被定义为返回一个值,像这样:

public 密封类 MyCustomNativeActivity : NativeActivity{受保护的覆盖无效执行(NativeActivityContext 上下文){context.SetValue(base.Result, 10);}}

您现在应该能够通过设计器使用 Result 属性将返回值设置为变量.

检查此示例图像.在您的 MyCustomNativeActivity 中,您将拥有一个 Result 属性.要将返回的值分配给变量,只需初始化该变量并将其放入结果字段.

从那时起,您可以在任何地方使用该变量.

请注意,在示例 MyCustomNativeActivity 中,返回值是 Int32 但它可以是任何其他类型.

Just getting started with WF4.

Ran into a problem with passing some text from a native code activity (located in the middle of a sequential workflow) onto the next (xaml-based) activity in a sequence.

Here is a quick synopsis: a custom native code activity makes a DB call and needs to pass the result to a standard "SendReplyToRecive" activity (which is the last activity in this workflow). There is a global variable "reportValue" defined at the top-level sequence level, but I'm struggling to get to it from within that custom native code activity.

The design surface for this workflow does not offer Arguments, just Variables and Imports, so, I'm not even sure if I could use OutArgument.

How is this done?

解决方案

If your custom NativeActivity is defined to return a value, like this:

public sealed class MyCustomNativeActivity : NativeActivity<int>
{
    protected override void Execute(NativeActivityContext context)
    {
        context.SetValue<int>(base.Result, 10);
    }
}

You should now be able to set the returned value to a Variable using Result property through the designer.

EDIT:

Check this sample image. In your MyCustomNativeActivity you'll have available a Result property. To assign the value returned to a variable just initialize that variable and put it in the Result field.

From that point on you can use that variable wherever you want.

Notice that in the sample MyCustomNativeActivity the returned value is an Int32 but it can be any other type.

Image link here

这篇关于如何从自定义代码活动访问全局变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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