Showing posts with label WF. Show all posts
Showing posts with label WF. Show all posts

Friday, December 4, 2009

Code to create .xoml file from WF workflow using C#

Here is the simple code to create .xoml file from WF workflow;


using (XmlWriter writer = XmlWriter.Create(@"D:\Temp\MyWorkflow.xoml"))
            {
                WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
                SimpleWorkFlow sm = new SimpleWorkFlow();

                serializer.Serialize(writer, sm);
            }

Invoking WF with Input & Output parameters using C#

Here is the simple code for invoking the WF with Input and Output parameters using C#


Dictionary<string, object>  parameters = new Dictionary<string, object>();
            Employer emp = new Employer();
            emp.FirstName = txtFirstName.Text;
            emp.LastName = txtLastName.Text;
            emp.DOB = txtDOB.SelectedDate;
            emp.Email = txtEmail.Text;
            parameters["Emp"] = emp;
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                AutoResetEvent waitHandle = new AutoResetEvent(false);
                workflowRuntime.WorkflowCompleted += delegate(object sender1,
                    WorkflowCompletedEventArgs e1)
                {
                    lblResult.Text = e1.OutputParameters["Result"].ToString();
                    waitHandle.Set();
                };

                workflowRuntime.WorkflowTerminated += delegate(object sender2,
                    WorkflowTerminatedEventArgs e2)
                {
                    lblResult.Text = e2.Exception.Message;
                    waitHandle.Set();
                };

                WorkflowInstance instance =
                    workflowRuntime.CreateWorkflow(typeof(EmployerWorkFlow), parameters);

                instance.Start();

                waitHandle.WaitOne();
            }