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>