Create and start a workflow in xoml mode <Article 10>

Source: Internet
Author: User
I. Benefits of using workflows in xoml

The advantage of using a workflow through xoml is that it can change the workflow by configuring xoml without restarting the program.

  

Create a winform program as follows:

  

The Code is as follows:

Namespace winform {public partial class form1: FORM {// defines the runtime container workflowruntime = new workflowruntime (); Public form1 () {initializecomponent (); workflowruntime. startruntime ();} private void button#click (Object sender, eventargs e) {// create a workflow sequenceactivity workflow = new sequenceactivity (); workflow. activities. add (New myactivity () {message = "I have executed it! "}); Workflowmarkupserializer serializer = new workflowmarkupserializer (); // Save the workflow in the XML file using (xmlwriter xr = xmlwriter. create ("myworkflow. xoml ", new xmlwritersettings () {closeoutput = true}) {serializer. serialize (XR, workflow);} MessageBox. show ("workflow created successfully! ");} Private void button2_click (Object sender, eventargs e) {// execute a workflow from an XML file. If you want to, you can save XML data anywhere, even saved in the database // read the workflow from the database, and then execute workflowinstance winstance = workflowruntime. createworkflow (xmlreader. create ("myworkflow. xoml "); winstance. start () ;}} public partial class myactivity: Activity {Public String message {Get; set;} protected override activityexecutionstatus execute (activityexecutioncontext executioncontext) {MessageBox. show (Message); Return base. execute (executioncontext );}}}

The effect is as follows:

  

Based on this method, you can create an easy-to-operate UI that allows you to configure the process and save the Generated Process in XML, string, and database. Then the read-out process is implemented and then executed.

Combined with the xmlreader overload, you can start the process with only one string:

VaR xmlstr = "<? XML version = \ "1.0 \" encoding = \ "UTF-8 \"?> <Sequenceactivity X: Name = \ "sequenceactivity \" xmlns: ns0 = \ "CLR-namespace: winform; Assembly = winform, version = 1.0.0.0, culture = neutral, publickeytoken = NULL \ "xmlns: x = \" http://schemas.microsoft.com/winfx/2006/xaml\ "xmlns = \" success "> <ns0: myactivity message = \" I have executed it! \ "X: Name = \" myactivity1 \ "/> </sequenceactivity>"; workflowinstance winstance = workflowruntime. createworkflow (xmlreader. create (New stringreader (xmlstr); winstance. start ();

 

Create and start a workflow in xoml mode <Article 10>

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.