复制器活动中有一个invokeworkflow活动。我尝试调用的工作流需要传递2个参数,一个整数和一个字符串参数,这些参数应该由复制器活动传递给工作流。任何想法如何做到这一点?复制器活动中的InvokeWorkflow活动
谢谢。
复制器活动中有一个invokeworkflow活动。我尝试调用的工作流需要传递2个参数,一个整数和一个字符串参数,这些参数应该由复制器活动传递给工作流。任何想法如何做到这一点?复制器活动中的InvokeWorkflow活动
谢谢。
可以声明目标的工作流程两个属性是这样的:
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
类别的两个属性。
http://i35.tinypic.com/2czssuf.png
您既可以提供恒定值,也可以将它们绑定到托管工作流的任何财产。
下面是一个完整的例子(注意,无论是包含在构造函数可以在设计师的属性面板中设置):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仅包含一个将TargetWorkflow设置为Workflow3的InvokeWorkflowActivity。该隐藏代码如下:
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
希望这会帮助你。
我知道这个职位是旧的,但对于那些有同样的问题在谷歌找到这一点,这是你需要做的:
的ReplicatorActivity公开叫ChildInitialized事件处理程序。为此事件创建您的处理程序,并在其中您将收到一个ReplicatorChildEventArgs。在这里面,你可以通过事件参数收到活动为这样:
InvokerActivity activity = (e.Activity as InvokerActivity);
if (activity != null)
{
activity.MyParam = e.InstanceData as MyParamType;
}
现在,当你运行它时,ReplicatorActivity将调用此方法一次为集合中的每一个项目,将沿参数传递对于每个InvokerActivities它都会产生。
e。InstanceData将成为Replicator迭代的集合中的下一个对象。