Ejemplo n.º 1
0
        private void btnCreateSequentialWorkflow_Click(Object sender, EventArgs e)
        {
            ConnectionStringSettings persistenceConnectionString = cboPersistenceService.SelectedItem as ConnectionStringSettings;
            ConnectionStringSettings trackingConnectionString    = cboTrackingService.SelectedItem as ConnectionStringSettings;

            if (persistenceConnectionString == null)
            {
                MessageBox.Show("No connection string selected for persistence service.", "WFTools Samples",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);

                return;
            }

            String workflowRuntimeKey = String.Format("{0}_{1}_{2}",
                                                      persistenceConnectionString.Name,
                                                      trackingConnectionString == null ? "None" : trackingConnectionString.Name,
                                                      chkUseLocalTransactions.Checked);

            SampleWorkFlowRuntime workflowRuntime;

            if (!this.loadedWorkflowRuntimes.TryGetValue(workflowRuntimeKey, out workflowRuntime))
            {
                workflowRuntime = new SampleWorkFlowRuntime(persistenceConnectionString,
                                                            trackingConnectionString, chkUseLocalTransactions.Checked);

                workflowRuntime.WorkflowTerminated          += workflowRuntime_WorkflowTerminated;
                workflowRuntime.ServicesExceptionNotHandled += workflowRuntime_ServicesExceptionNotHandled;

                this.loadedWorkflowRuntimes.Add(workflowRuntimeKey, workflowRuntime);
            }

            // create a new sequential workflow
            WorkflowInstance workflowInstance = workflowRuntime.CreateSequentialWorkflow();

            if (chkModifyWorkflow.Checked)
            {
                Activity        rootActivity    = workflowInstance.GetWorkflowDefinition();
                WorkflowChanges workflowChanges = new WorkflowChanges(rootActivity);

                // modify the workflow
                Activity          activityToRemove = workflowChanges.TransientWorkflow.GetActivityByName("codeActivity3");
                CompositeActivity parentActivity   = activityToRemove.Parent;

                parentActivity.Activities.Remove(activityToRemove);

                CodeActivity codeActivity = new CodeActivity("TestChangeActivity");
                codeActivity.ExecuteCode +=
                    delegate { Trace.WriteLine("Test Change Activity executed..."); };

                parentActivity.Activities.Add(codeActivity);

                workflowInstance.ApplyWorkflowChanges(workflowChanges);
            }

            workflowInstance.Start();

            ManualWorkflowSchedulerService schedulerService = workflowRuntime.GetService <ManualWorkflowSchedulerService>();

            schedulerService.RunWorkflow(workflowInstance.InstanceId);
        }
Ejemplo n.º 2
0
        private void btnCreateSequentialWorkflow_Click(object sender, EventArgs e)
        {
            ConnectionStringSettings connectionStringSettings = cboConnectionString.SelectedItem as ConnectionStringSettings;

            if (connectionStringSettings == null)
            {
                MessageBox.Show("No connection string selected.", "WFTools Samples",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);

                return;
            }

            SampleWorkFlowRuntime workflowRuntime;

            if (this.loadedWorkflowRuntimes.ContainsKey(connectionStringSettings.Name))
            {
                workflowRuntime = this.loadedWorkflowRuntimes[connectionStringSettings.Name];
            }
            else
            {
                workflowRuntime = new SampleWorkFlowRuntime(connectionStringSettings);
                workflowRuntime.WorkflowTerminated          += new EventHandler <WorkflowTerminatedEventArgs>(workflowRuntime_WorkflowTerminated);
                workflowRuntime.ServicesExceptionNotHandled += new EventHandler <ServicesExceptionNotHandledEventArgs>(workflowRuntime_ServicesExceptionNotHandled);
                this.loadedWorkflowRuntimes.Add(connectionStringSettings.Name, workflowRuntime);
            }

            // create a new sequential workflow
            WorkflowInstance workflowInstance = workflowRuntime.CreateSequentialWorkflow();

            workflowInstance.Start();

            ManualWorkflowSchedulerService schedulerService = workflowRuntime.GetService <ManualWorkflowSchedulerService>();

            schedulerService.RunWorkflow(workflowInstance.InstanceId);
        }