static void Main(string[] args) { const string workflowFilename = "workflow.xoml"; // // Create and configure workflow runtime // using(WorkflowRuntime workflowRuntime = new WorkflowRuntime()) { AutoResetEvent waitHandle = new AutoResetEvent(false); workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) { Console.WriteLine("Workflow completed."); waitHandle.Set(); }; workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e) { Console.WriteLine(e.Exception.Message); waitHandle.Set(); }; // // Create workflow programmatically // Console.WriteLine("Creating workflow."); SequentialWorkflowActivity workflow = new SequentialWorkflowActivity(); workflow.Name = "Programmatically created workflow"; workflow.Description = "Programmatically created workflow for XAML activation"; ConsoleActivity activity = new ConsoleActivity(); activity.Name = "ConsoleActivity1"; activity.StringToWrite = "Sample String"; workflow.Activities.Add(activity); // // Serialize workflow to XAML file // Console.WriteLine("Serializing workflow to file."); WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer(); using (XmlWriter writer = XmlWriter.Create(workflowFilename)) { DesignerSerializationManager serializationManager = new DesignerSerializationManager(); using (serializationManager.CreateSession()) { serializer.Serialize(serializationManager, writer, workflow); if (serializationManager.Errors.Count > 0) { Console.WriteLine(String.Format("There were {0} errors during serialization", serializationManager.Errors.Count)); return; } } } // // Deserialize workflow from file // WorkflowInstance deserializedWorkflow = null; Console.WriteLine("Deserializing workflow from file."); try { using (XmlReader reader = XmlReader.Create(workflowFilename)) { deserializedWorkflow = workflowRuntime.CreateWorkflow(reader); } } catch (WorkflowValidationFailedException exp) { ValidationErrorCollection list = exp.Errors; foreach (ValidationError err in list) { Console.WriteLine(err.ErrorText); } return; } // // Start workflow // Console.WriteLine("Starting workflow."); deserializedWorkflow.Start(); waitHandle.WaitOne(); workflowRuntime.StopRuntime(); } }
static void Main(string[] args) { const string workflowFilename = "workflow.xoml"; // // Create and configure workflow runtime // using (WorkflowRuntime workflowRuntime = new WorkflowRuntime()) { AutoResetEvent waitHandle = new AutoResetEvent(false); workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) { Console.WriteLine("Workflow completed."); waitHandle.Set(); }; workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e) { Console.WriteLine(e.Exception.Message); waitHandle.Set(); }; // // Create workflow programmatically // Console.WriteLine("Creating workflow."); SequentialWorkflowActivity workflow = new SequentialWorkflowActivity(); workflow.Name = "Programmatically created workflow"; workflow.Description = "Programmatically created workflow for XAML activation"; ConsoleActivity activity = new ConsoleActivity(); activity.Name = "ConsoleActivity1"; activity.StringToWrite = "Sample String"; workflow.Activities.Add(activity); // // Serialize workflow to XAML file // Console.WriteLine("Serializing workflow to file."); WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer(); using (XmlWriter writer = XmlWriter.Create(workflowFilename)) { DesignerSerializationManager serializationManager = new DesignerSerializationManager(); using (serializationManager.CreateSession()) { serializer.Serialize(serializationManager, writer, workflow); if (serializationManager.Errors.Count > 0) { Console.WriteLine(String.Format("There were {0} errors during serialization", serializationManager.Errors.Count)); return; } } } // // Deserialize workflow from file // WorkflowInstance deserializedWorkflow = null; Console.WriteLine("Deserializing workflow from file."); try { using (XmlReader reader = XmlReader.Create(workflowFilename)) { deserializedWorkflow = workflowRuntime.CreateWorkflow(reader); } } catch (WorkflowValidationFailedException exp) { ValidationErrorCollection list = exp.Errors; foreach (ValidationError err in list) { Console.WriteLine(err.ErrorText); } return; } // // Start workflow // Console.WriteLine("Starting workflow."); deserializedWorkflow.Start(); waitHandle.WaitOne(); workflowRuntime.StopRuntime(); } }