复制器活动内的 InvokeWorkflow 活动

发布于 2024-07-09 00:34:00 字数 117 浏览 4 评论 0原文

我在复制器活动中有一个调用工作流活动。 我尝试调用的工作流需要向其传递 2 个参数,一个整数和一个字符串参数,并且这些参数应由复制器活动传递给工作流。 关于如何做到这一点有什么想法吗?

谢谢。

I have an invokeworkflow activity inside a replicator activity. The workflow that I'm trying to invoke requires 2 parameters to be passed to it, an integer and a string parameters, and these should be passed to the workflow by the replicator activity. Any ideas on how this could be done?

Thanks.

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

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

发布评论

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

评论(3

巡山小妖精 2024-07-16 00:34:00

这是一个完整的示例(请注意,构造函数中包含的任何内容都可以在设计器的属性窗格中设置): Workflow3 是仅包含 CodeActivity 的目标工作流,后面的代码如下:

public sealed partial class Workflow3 : SequentialWorkflowActivity
{
    public static readonly DependencyProperty MyIntProperty =
        DependencyProperty.Register("MyInt", typeof(int), typeof(Workflow3));
    public static readonly DependencyProperty MyStringProperty =
        DependencyProperty.Register("MyString", typeof(string), typeof(Workflow3));

    public Workflow3()
    {
        InitializeComponent();

        this.codeActivity1.ExecuteCode += new System.EventHandler(this.codeActivity1_ExecuteCode);
    }

    public int MyInt
    {
        get { return (int)GetValue(MyIntProperty); }
        set { SetValue(MyIntProperty, value); }
    }

    public string MyString
    {
        get { return (string)GetValue(MyStringProperty); }
        set { SetValue(MyStringProperty, value); }
    }

    private void codeActivity1_ExecuteCode(object sender, EventArgs e)
    {
        Console.WriteLine("Invoke WF: Int = {0}, String = {1}", this.MyInt, this.MyString);
    }
}

Workflow2 是托管工作流仅包含 ReplicatorActivity。 ReplicatorActivity 仅包含 InvokeWorkflowActivity,其 TargetWorkflow 设置为 Workflow3。 隐藏代码如下:

public sealed partial class Workflow2 : SequentialWorkflowActivity
{
    // Variables used in bindings
    public int InvokeWorkflowActivity1_MyInt = default(int);
    public string InvokeWorkflowActivity1_MyString = string.Empty;

    public Workflow2()
    {
        InitializeComponent();

        // Bind MyInt parameter of target workflow to my InvokeWorkflowActivity1_MyInt
        WorkflowParameterBinding wpb1 = new WorkflowParameterBinding("MyInt");
        wpb1.SetBinding(WorkflowParameterBinding.ValueProperty, new ActivityBind(this.GetType().Name, "InvokeWorkflowActivity1_MyInt"));
        this.invokeWorkflowActivity1.ParameterBindings.Add(wpb1);

        // Bind MyString parameter of target workflow to my InvokeWorkflowActivity1_MyString
        WorkflowParameterBinding wpb2 = new WorkflowParameterBinding("MyString");
        wpb2.SetBinding(WorkflowParameterBinding.ValueProperty, new ActivityBind(this.GetType().Name, "InvokeWorkflowActivity1_MyString"));
        this.invokeWorkflowActivity1.ParameterBindings.Add(wpb2);

        // Add event handler for Replicator's Initialized event
        this.replicatorActivity1.Initialized += new EventHandler(ReplicatorInitialized);

        // Add event handler for Replicator's ChildInitialized event
        this.replicatorActivity1.ChildInitialized += new EventHandler<ReplicatorChildEventArgs>(this.ChildInitialized);
    }

    private void ReplicatorInitialized(object sender, EventArgs e)
    {
        // Find how many workflows I want
        List<MyClass> list = new List<MyClass>();
        list.Add(new MyClass() { MyInt = 1, MyString = "Str1" });
        list.Add(new MyClass() { MyInt = 2, MyString = "Str2" });
        list.Add(new MyClass() { MyInt = 3, MyString = "Str3" });

        // Assign list to replicator
        replicatorActivity1.InitialChildData = list;
    }

    private void ChildInitialized(object sender, ReplicatorChildEventArgs e)
    {
        // This is the activity that is initialized
        InvokeWorkflowActivity currentActivity = (InvokeWorkflowActivity)e.Activity;

        // This is the initial data
        MyClass initialData = (MyClass)e.InstanceData;

        // Setting the initial data to the activity
        InvokeWorkflowActivity1_MyInt = initialData.MyInt;
        InvokeWorkflowActivity1_MyString = initialData.MyString;
    }

    public class MyClass
    {
        public int MyInt { get; set; }
        public string MyString { get; set; }
    }
}

预期结果如下:

Invoke WF: Int = 1, String = Str1
Invoke WF: Int = 2, String = Str2
Invoke WF: Int = 3, String = Str3

希望这会对您有所帮助。

Here is a full example (note that whatever is included in the constructors can be set in the properties pane of the designer): Workflow3 is the target workflow that contains only a CodeActivity and the behind code is the following:

public sealed partial class Workflow3 : SequentialWorkflowActivity
{
    public static readonly DependencyProperty MyIntProperty =
        DependencyProperty.Register("MyInt", typeof(int), typeof(Workflow3));
    public static readonly DependencyProperty MyStringProperty =
        DependencyProperty.Register("MyString", typeof(string), typeof(Workflow3));

    public Workflow3()
    {
        InitializeComponent();

        this.codeActivity1.ExecuteCode += new System.EventHandler(this.codeActivity1_ExecuteCode);
    }

    public int MyInt
    {
        get { return (int)GetValue(MyIntProperty); }
        set { SetValue(MyIntProperty, value); }
    }

    public string MyString
    {
        get { return (string)GetValue(MyStringProperty); }
        set { SetValue(MyStringProperty, value); }
    }

    private void codeActivity1_ExecuteCode(object sender, EventArgs e)
    {
        Console.WriteLine("Invoke WF: Int = {0}, String = {1}", this.MyInt, this.MyString);
    }
}

Workflow2 is the hosting workflow that contains only a ReplicatorActivity. The ReplicatorActivity contains only a InvokeWorkflowActivity which has the TargetWorkflow set to Workflow3. The code-behind is the following:

public sealed partial class Workflow2 : SequentialWorkflowActivity
{
    // Variables used in bindings
    public int InvokeWorkflowActivity1_MyInt = default(int);
    public string InvokeWorkflowActivity1_MyString = string.Empty;

    public Workflow2()
    {
        InitializeComponent();

        // Bind MyInt parameter of target workflow to my InvokeWorkflowActivity1_MyInt
        WorkflowParameterBinding wpb1 = new WorkflowParameterBinding("MyInt");
        wpb1.SetBinding(WorkflowParameterBinding.ValueProperty, new ActivityBind(this.GetType().Name, "InvokeWorkflowActivity1_MyInt"));
        this.invokeWorkflowActivity1.ParameterBindings.Add(wpb1);

        // Bind MyString parameter of target workflow to my InvokeWorkflowActivity1_MyString
        WorkflowParameterBinding wpb2 = new WorkflowParameterBinding("MyString");
        wpb2.SetBinding(WorkflowParameterBinding.ValueProperty, new ActivityBind(this.GetType().Name, "InvokeWorkflowActivity1_MyString"));
        this.invokeWorkflowActivity1.ParameterBindings.Add(wpb2);

        // Add event handler for Replicator's Initialized event
        this.replicatorActivity1.Initialized += new EventHandler(ReplicatorInitialized);

        // Add event handler for Replicator's ChildInitialized event
        this.replicatorActivity1.ChildInitialized += new EventHandler<ReplicatorChildEventArgs>(this.ChildInitialized);
    }

    private void ReplicatorInitialized(object sender, EventArgs e)
    {
        // Find how many workflows I want
        List<MyClass> list = new List<MyClass>();
        list.Add(new MyClass() { MyInt = 1, MyString = "Str1" });
        list.Add(new MyClass() { MyInt = 2, MyString = "Str2" });
        list.Add(new MyClass() { MyInt = 3, MyString = "Str3" });

        // Assign list to replicator
        replicatorActivity1.InitialChildData = list;
    }

    private void ChildInitialized(object sender, ReplicatorChildEventArgs e)
    {
        // This is the activity that is initialized
        InvokeWorkflowActivity currentActivity = (InvokeWorkflowActivity)e.Activity;

        // This is the initial data
        MyClass initialData = (MyClass)e.InstanceData;

        // Setting the initial data to the activity
        InvokeWorkflowActivity1_MyInt = initialData.MyInt;
        InvokeWorkflowActivity1_MyString = initialData.MyString;
    }

    public class MyClass
    {
        public int MyInt { get; set; }
        public string MyString { get; set; }
    }
}

The expected outcome is the following:

Invoke WF: Int = 1, String = Str1
Invoke WF: Int = 2, String = Str2
Invoke WF: Int = 3, String = Str3

Hope that this will help you.

末骤雨初歇 2024-07-16 00:34:00

我意识到这篇文章已经过时了,但对于那些在 Google 上发现同样问题的人来说,这就是您需要做的:

  1. 将对 InvokeWorkflow 的调用包装在自定义 Activity 中 - 这将简化参数映射。 在此活动中,为要传递到调用的工作流的每个属性创建一个 DependencyProperty。 现在我们将其称为“InvokerActivity”。
    然后,在 InvokeWorkflowActivity 中,将 TargetWorkflow 的属性映射到 InvokerActivity 上的依赖项属性,如 Panos 上面建议的那样。 注意:为了显示省略号,对象必须是具体类型。 如果您的对象是接口,您将无法映射它。 工作流不知道如何实例化接口对象。
  2. 使用设计器将 InvokerActivity 放置在 ReplicatorActivity 中。
  3. ReplicatorActivity 公开了一个名为 ChildInitialized 的事件处理程序。 为此事件创建您的处理程序,您将在其中收到一个 ReplicatorChildEventArgs。 在其中,您可以通过事件参数接收 Activity,如下所示:

     InvokerActivity 活动 = (e.Activity as InvokerActivity); 
          如果(活动!= null) 
          { 
              Activity.MyParam = e.InstanceData 作为 MyParamType; 
          } 
      

现在,当您运行它时,ReplicatorActivity 将为集合中的每个项目调用此方法一次,并将传递它将生成的每个 InvokerActivity 的参数。

e.InstanceData 将是 Replicator 迭代的集合中的下一个对象。

I realize this post is old, but for those finding this on Google with the same question, this is what you need to do:

  1. Wrap the call to InvokeWorkflow in a custom Activity - this will simplify mapping the parameters. In this Activity create a DependencyProperty for each of the properties you want to pass to the invoked workflow. Let's call this our "InvokerActivity" for now.
    Then in the InvokeWorkflowActivity, map the properties of the TargetWorkflow to the dependency properties on the InvokerActivity, as Panos suggests above. NOTE: in order for the ellipsis to show up the objects MUST be concrete types. If your object is an Interface you will not be able to map it. The workflow will not know how to instantiate an interface object.
  2. Place the InvokerActivity inside the ReplicatorActivity, using the designer.
  3. The ReplicatorActivity exposes an event handler called ChildInitialized. Create your handler for this event and in it you will receive a ReplicatorChildEventArgs. In it, you can receive the Activity through the event args as such:

        InvokerActivity activity = (e.Activity as InvokerActivity);
        if (activity != null)
        {
            activity.MyParam = e.InstanceData as MyParamType;
        }
    

Now when you run it, the ReplicatorActivity will call this method once for every item in the collection and will pass along the parameters for each of the InvokerActivities it will spawn.

e.InstanceData will be the next object in the collection that the Replicator is iterating through.

徒留西风 2024-07-16 00:34:00

您可以在目标工作流中声明两个属性,如下所示:

    public static readonly DependencyProperty MyIntProperty =
        DependencyProperty.Register("MyInt", typeof(int), typeof(Workflow3));
    public static readonly DependencyProperty MyStringProperty =
        DependencyProperty.Register("MyString", typeof(string), typeof(Workflow3));

    public int MyInt
    {
        get { return (int)GetValue(MyIntProperty); }
        set { SetValue(MyIntProperty, value); }
    }

    public string MyString
    {
        get { return (string)GetValue(MyStringProperty); }
        set { SetValue(MyStringProperty, value); }
    }

之后,如果您检查 InvokeWorkflowActivity 的“属性”选项卡,您将在 Parameters 类别中看到这两个属性。

您可以提供常量值,也可以将它们绑定到托管工作流程的任何属性。

You can declare two properties in the target workflow like this:

    public static readonly DependencyProperty MyIntProperty =
        DependencyProperty.Register("MyInt", typeof(int), typeof(Workflow3));
    public static readonly DependencyProperty MyStringProperty =
        DependencyProperty.Register("MyString", typeof(string), typeof(Workflow3));

    public int MyInt
    {
        get { return (int)GetValue(MyIntProperty); }
        set { SetValue(MyIntProperty, value); }
    }

    public string MyString
    {
        get { return (string)GetValue(MyStringProperty); }
        set { SetValue(MyStringProperty, value); }
    }

After that, if you check the Properties tab of the InvokeWorkflowActivity you will see the two properties in the Parameters category.

You can either provide constant values or you can bind them to any property of the hosting workflow.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文