WF4.0 Beta1 WorkflowInvoker
WorkflowInvoker
使用 WorkflowInvoker.Invoke静态方法
public static IDictionary<string, object> Invoke(WorkflowElement workflow);
public static IDictionary<string, object> Invoke(WorkflowElement workflow, IDictionary<string, object> inputs);
public static IDictionary<string, object> Invoke(WorkflowElement workflow, TimeSpan timeout);
public static IDictionary<string, object> Invoke(WorkflowElement workflow, IDictionary<string, object> inputs, TimeSpan timeout);
|
例1:传入参数,并得到结果
流程 | public sealed class Add : CodeActivity<int> { public InArgument<int> X { get; set; } public InArgument<int> Y { get; set; }
protected override void Execute(CodeActivityContext context) { int x = X.Get(context); int y = Y.Get(context);
context.SetValue(base.Result, x + y); } } | |
调用 |
static void Main(string[] args) {
var p= new Dictionary<string, object> { { "X", 1 }, { "Y", 2 }};
IDictionary<string, object> results = WorkflowInvoker.Invoke(new Add(), p); Console.WriteLine( results["Result"]);
Console.ReadLine(); } |
使用 WorkflowInvoker实例
public WorkflowInvoker(WorkflowElement workflow);
public Collection<object> Extensions { get; }
public event EventHandler<InvokeCompletedEventArgs> InvokeCompleted;
public IAsyncResult BeginInvoke(AsyncCallback callback, object state);
public IAsyncResult BeginInvoke(IDictionary<string, object> inputs, AsyncCallback callback, object state);
public IAsyncResult BeginInvoke(TimeSpan timeout, AsyncCallback callback, object state);
public IAsyncResult BeginInvoke(IDictionary<string, object> inputs, TimeSpan timeout, AsyncCallback callback, object state);
public IDictionary<string, object> EndInvoke(IAsyncResult result);
public IDictionary<string, object> Invoke();
public IDictionary<string, object> Invoke(IDictionary<string, object> inputs);
public IDictionary<string, object> Invoke(TimeSpan timeout);
public IDictionary<string, object> Invoke(IDictionary<string, object> inputs, TimeSpan timeout);
public void InvokeAsync();
public void InvokeAsync(IDictionary<string, object> inputs);
public void InvokeAsync(object userState);
public void InvokeAsync(TimeSpan timeout);
public void InvokeAsync(IDictionary<string, object> inputs, object userState);
public void InvokeAsync(IDictionary<string, object> inputs, TimeSpan timeout);
public void InvokeAsync(TimeSpan timeout, object userState);
public void InvokeAsync(IDictionary<string, object> inputs, TimeSpan timeout, object userState); |
例1:InvokeAsync方法与invokeCompleted事件
流程 | public sealed class Add : CodeActivity<int> { public InArgument<int> X { get; set; } public InArgument<int> Y { get; set; }
protected override void Execute(CodeActivityContext context) { int x = X.Get(context); int y = Y.Get(context);
context.SetValue(base.Result, x + y); } } |
调用 | static void Main(string[] args) {
WorkflowInvoker myInvoker = new WorkflowInvoker(new Add());
var p = new Dictionary<string, object> { { "X", 1 }, { "Y", 2 }};
myInvoker.InvokeCompleted += new EventHandler<InvokeCompletedEventArgs>(myInvoker_InvokeCompleted);
myInvoker.InvokeAsync(p);
Console.ReadLine(); }
static void myInvoker_InvokeCompleted(object sender, InvokeCompletedEventArgs e) { Console.WriteLine(e.Outputs["Result"]); } |
例2:BeginInvoke方法与EndInvoke方法
流程 | public sealed class Add : CodeActivity<int> { public InArgument<int> X { get; set; } public InArgument<int> Y { get; set; }
protected override void Execute(CodeActivityContext context) { int x = X.Get(context); int y = Y.Get(context);
context.SetValue(base.Result, x + y); } } |
调用 | static void Main(string[] args) {
WorkflowInvoker myInvoker = new WorkflowInvoker(new Add());
var p = new Dictionary<string, object> { { "X", 1 }, { "Y", 2 }};
IAsyncResult ir= myInvoker.BeginInvoke(p, new AsyncCallback(callback), myInvoker);
var r = myInvoker.EndInvoke(ir);
System.Console.WriteLine(r["Result"]);
Console.ReadLine(); }
static void callback(IAsyncResult asyncResult) { System.Threading.ManualResetEvent mr = asyncResult.AsyncWaitHandle as System.Threading.ManualResetEvent;
System.Console.WriteLine("callback"); } |
后面我会写一组
用WorkflowInvoker实现调用子流程的例
与
用WorkflowInvoker以回溯方做流程全路径测试的例子