WF4.0 Beta1 WorkflowInvoker

Source: Internet
Author: User
WorkflowInvoker
Use WorkflowInvoker. Invoke static method

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 );


 

 

Example 1: input the parameter and obtain the result.

Process

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 );

}

}

Call

 

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 ();

}

 

Use WorkflowInvoker instance

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 );

 

Example 1: InvokeAsync method and invokeCompleted event

 

Process

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 );

}

}

Call

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"]);

}

 

Example 2: BeginInvoke method and EndInvoke Method

Process

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 );

}

}

Call

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 ");

}

 

I will write a group later

Example of using WorkflowInvoker to call a sub-process

And

Example of using WorkflowInvoker to test the full-path process with backtracing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.