WF:工作流设计器:动态添加的 InArgument 列表:如何在工作流执行期间获取价值 [英] WF: Workflow Designer: List of InArgument added dynamically : How to get value during workflow execution

查看:23
本文介绍了WF:工作流设计器:动态添加的 InArgument 列表:如何在工作流执行期间获取价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了一个工作流设计器,允许输入电子邮件地址列表.列表中的每封电子邮件都需要是一个 InArgument(Of String),以便可以使用变量单独编辑/添加它们.

I have built a workflow designer that allows to enter a list of email addresses.Each email in the list needs to be an InArgument(Of String) so they can be individually edited/added using variables.

在我的活动中,我有一个如下声明的属性:

On my Activity, I have a property that is declared like so:

Public Property [To] As ObservableCollection(Of InArgument(Of String))

我的设计师已经连接好并正确填充了这个集合.

My designer is wired up and populating this collection properly.

但是在执行过程中,我不知道如何获取添加的每个 InArgument 的运行时值.

However during the execution, I do not know how to get the run-time value for each InArgument that was added.

当我们执行工作流程并对添加到列表的每个 InArgument 进行迭代时,我尝试获取如下所示的值,但失败了:

When we are executing the workflow and iterating for each InArgument added to the list, I attempted to get the value as shown below but that fails:

For Each toAddress As InArgument(Of String) In Me.To.ToList()
            Dim emailToAddress As String = toAddress.Get(_Context)          
Next

我们得到的错误是类型为''的参数"不能使用.确保它是在一个活动中声明的",在我的例子中,type 是一个字符串......

The error we get is "The argument of type '<type>' cannot be used. Make sure that it is declared on an activity" and type is a string in my case...

我们得到的错误是有道理的,因为我们没有在活动上声明属性,因为它是动态添加到列表中的,因此无法使用如下所示的语法获取值:

The error we get sort of make sense because we haven’t declared a property on the activity since it was added dynamically to the list and therefore cannot get the value using the syntax shown below:

The_Property_Name.Get(_Context)

有人可以帮忙吗?我似乎找不到任何东西.我应该采取不同的方法吗?

Can someone help? I can't seem to find anything. Should I be doing a different approach?

推荐答案

我想通了,所以我来回答我自己的问题!我们需要做的就是通过覆盖活动上的 CacheMetadata() 方法将集合项显式添加到元数据中.然后,这使其可用于工作流上下文.

I figured it out so I will answer my own question! All we need to do is explicitly add the collection items to the metadata by overriding CacheMetadata() method on the activity. This then makes it available to the workflow context.

首先我们将它们添加到上下文中:

First we add them to the context:

   Protected Overrides Sub CacheMetadata(ByVal metadata As CodeActivityMetadata)
        MyBase.CacheMetadata(metadata)

        Dim i As Integer = 0
        For Each item As InArgument(Of String) In Me.To
            Dim runTimeArg As RuntimeArgument = New RuntimeArgument("TO" & i.ToString(), item.ArgumentType, item.Direction, False)
            metadata.Bind(item, runTimeArg)
            metadata.AddArgument(runTimeArg)
            i = i + 1
        Next

    End Sub

然后在执行时,我们得到这样的值

Then when executing, we get the values like this

   For Each item As InArgument(Of String) In Me.To
            Dim email As String = _Context.GetValue(item)
        Next

这篇关于WF:工作流设计器:动态添加的 InArgument 列表:如何在工作流执行期间获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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