• 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以回溯方做流程全路径测试的例子

  • 相关阅读:
    pfofinet和S7
    A1010 Radix [二分/******]
    A1005 Spell It Right
    最大回文子串长度 [dp]
    HDU 1159 Common Subsequence [最长公共子序列]
    1045 Favorite Color Stripe [动态规划/最长不下降子序列]
    1007 Maximum Subsequence Sum [动态规划]
    数塔问题(递归/递推)
    hdu 畅通工程 [Kruskal/Prime]
    1087 All Roads Lead to Rome [dj]
  • 原文地址:https://www.cnblogs.com/foundation/p/1510971.html
Copyright © 2020-2023  润新知