Exemple #1
1
        static void Main()
        {
            CreateRoles();

            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                workflowRuntime.StartRuntime();

                // Load the workflow type.
                Type type = typeof(PurchaseOrderWorkflow);

                ExternalDataExchangeService dataService = new ExternalDataExchangeService();
                workflowRuntime.AddService(dataService);

                poImpl = new StartPurchaseOrder();
                dataService.AddService(poImpl);

                workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
                workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;

                WorkflowInstance instance = workflowRuntime.CreateWorkflow(type);
                workflowInstanceId = instance.InstanceId;
                instance.Start();

                SendPORequestMessage();

                waitHandle.WaitOne();

                workflowRuntime.StopRuntime();
            }
        }
        public void ValidAccountTest()
        {
            Dictionary <String, Object> wfArguments
                = new Dictionary <string, object>();

            wfArguments.Add("AccountId", 1001);

            WorkflowInstance instance = _workflowRuntime.CreateWorkflow(
                typeof(OrderEntryActivities.ValidateAccountActivity),
                wfArguments);

            Assert.IsNotNull(instance,
                             "Could not create workflow instance");
            instance.Start();

            _waitHandle.WaitOne(5000, false);

            Assert.IsNotNull(_completedArgs,
                             "Completed workflow event args should not be null");

            Decimal credit
                = (Decimal)_completedArgs.OutputParameters["AvailableCredit"];

            Assert.AreEqual((Decimal)100.00, credit,
                            "AvailableCredit value is incorrect");

            Boolean accountVerified
                = (Boolean)_completedArgs.OutputParameters["IsAccountVerified"];

            Assert.IsTrue(accountVerified,
                          "IsAccountVerified value is incorrect");
        }
Exemple #3
0
        /// <summary>
        /// Asynchronously starts executing workflow.
        /// </summary>
        /// <param name="workflowType">
        /// Type object referencing the workflow.
        /// </param>
        /// <param name="parameters">
        /// Name/value list of parameters to be passed
        /// to the workflow instance.
        /// </param>
        public void BeginWorkflow(Type workflowType, Dictionary <string, object> parameters)
        {
            InitializeRuntime();

            if (!_workflowRuntime.IsStarted)
            {
                _workflowRuntime.StartRuntime();
            }

            // create workflow instance
            if (parameters != null)
            {
                _instance = _workflowRuntime.CreateWorkflow(
                    workflowType,
                    parameters);
            }
            else
            {
                _instance = _workflowRuntime.CreateWorkflow(
                    workflowType);
            }

            // execute workflow
            _instance.Start();
            _status = WorkflowStatus.Executing;
        }
        /// <summary>
        /// Create and start a workflow
        /// </summary>
        /// <param name="workflowType"></param>
        /// <param name="parameters"></param>
        /// <returns>A wrapped workflow instance</returns>
        public WorkflowInstanceWrapper StartWorkflow(Type workflowType,
                                                     Dictionary <String, Object> parameters)
        {
            WorkflowInstance instance = _workflowRuntime.CreateWorkflow(
                workflowType, parameters);
            WorkflowInstanceWrapper wrapper
                = AddWorkflowInstance(instance);

            instance.Start();
            return(wrapper);
        }
Exemple #5
0
        /// <summary>
        /// 克隆一个实例
        /// </summary>
        /// <param name="WfRuntimeClone"></param>
        /// <param name="instanceClone"></param>
        /// <param name="WfRuntime"></param>
        /// <returns></returns>
        public static WorkflowInstance CloneWorkflowInstance(WorkflowRuntime WfRuntimeClone, WorkflowInstance instanceClone, WorkflowRuntime WfRuntime)
        {
            try
            {
                if (!WfRuntimeClone.IsStarted)
                {
                    WfRuntimeClone.StartRuntime();
                }
                StateMachineWorkflowInstance workflowinstance = new StateMachineWorkflowInstance(WfRuntimeClone, instanceClone.InstanceId);

                System.Workflow.Activities.StateMachineWorkflowActivity smworkflow = new StateMachineWorkflowActivity();
                smworkflow = workflowinstance.StateMachineWorkflow;
                RuleDefinitions          ruleDefinitions  = smworkflow.GetValue(RuleDefinitions.RuleDefinitionsProperty) as RuleDefinitions;
                WorkflowMarkupSerializer markupSerializer = new WorkflowMarkupSerializer();

                StringBuilder xoml       = new StringBuilder();
                StringBuilder rule       = new StringBuilder();
                XmlWriter     xmlWriter  = XmlWriter.Create(xoml);
                XmlWriter     ruleWriter = XmlWriter.Create(rule);
                markupSerializer.Serialize(xmlWriter, smworkflow);

                if (ruleDefinitions != null)
                {
                    markupSerializer.Serialize(ruleWriter, ruleDefinitions);
                }

                xmlWriter.Close();
                ruleWriter.Close();

                StringReader     readxoml   = new StringReader(xoml.ToString());
                XmlReader        readerxoml = XmlReader.Create(readxoml);
                WorkflowInstance instance;
                if (ruleDefinitions == null)
                {
                    instance = WfRuntime.CreateWorkflow(readerxoml);
                }
                else
                {
                    StringReader readrule   = new StringReader(rule.ToString());
                    XmlReader    readerrule = XmlReader.Create(readrule);
                    instance = WfRuntime.CreateWorkflow(readerxoml, readerrule, null);
                }

                instance.Start();
                return(instance);
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("CloneWorkflowInstance异常信息 :" + ex.ToString());
                throw new Exception(ex.Message);
            }
        }
Exemple #6
0
        /// <summary>
        /// Runs a flow based on a xoml file.
        /// </summary>
        /// <param name="xomlFile">Xoml file name containing the flow. Please note that the .rules file containing the rules
        /// must be located at the same folder as the xoml file.</param>
        /// <param name="parameters">The parameters to pass to the workflow</param>
        /// <param name="conditionValues">The condition values to use in the workflow</param>
        public void RunXomlFlow(string xomlFile, Hashtable parameters, Hashtable conditionValues)
        {
            if (!File.Exists(xomlFile) ||
                xomlFile == null ||
                xomlFile == String.Empty)
            {
                throw new ArgumentException("Invalid workflow parameter. Cannot be null/empty, or xoml file does not exist.");
            }

            Console.WriteLine("Running XOML Flow (" + xomlFile + ")");
            using (WorkflowRuntime runtime = new WorkflowRuntime())
            {
                AutoResetEvent waitHandle = new AutoResetEvent(false);
                runtime.WorkflowCompleted  += delegate(object sender, WorkflowCompletedEventArgs e) { waitHandle.Set(); };
                runtime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
                {
                    Console.WriteLine(e.Exception.Message);
                    waitHandle.Set();
                };


                SqlWorkflowPersistenceService persistanceService =
                    new SqlWorkflowPersistenceService(_connectionString);

                runtime.AddService(persistanceService);
                runtime.StartRuntime();

                //Fill the parameters .
                Dictionary <string, object> paramsD = new Dictionary <string, object>();
                paramsD.Add("Parameters", parameters);
                paramsD.Add("ConditionValues", conditionValues);

                WorkflowInstance instance = null;
                using (XmlTextReader reader = new XmlTextReader(xomlFile))
                {
                    string rulesFileName = xomlFile.Replace(".xoml", ".rules");
                    if (File.Exists(rulesFileName))
                    {
                        XmlTextReader rulesFileReader = new XmlTextReader(rulesFileName);
                        instance = runtime.CreateWorkflow(reader, rulesFileReader, paramsD);
                    }
                    else
                    {
                        instance = runtime.CreateWorkflow(reader, null, paramsD);
                    }
                }

                instance.Start();

                waitHandle.WaitOne();
            }
        }
Exemple #7
0
        static void Main()
        {
            try
            {
                // Create WorkflowRuntime
                using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
                {
                    // Add SimpleFileTrackingService
                    workflowRuntime.AddService(new SimpleFileTrackingService());

                    // Subscribe to Workflow Completed, Suspended, and Terminated WorkflowRuntime Event
                    workflowRuntime.WorkflowCompleted  += OnWorkflowCompleted;
                    workflowRuntime.WorkflowSuspended  += OnWorkflowSuspended;
                    workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;

                    // Start WorkflowRuntime
                    workflowRuntime.StartRuntime();

                    // Execute the SimpleWorkflow Workflow
                    Console.WriteLine("Executing the SimpleWorkflow...");
                    workflowRuntime.StartRuntime();
                    WorkflowInstance simpleWorkflowInstance = workflowRuntime.CreateWorkflow(typeof(SimpleWorkflow));
                    simpleWorkflowInstance.Start();
                    // Wait for the Workflow Completion
                    waitHandle.WaitOne();

                    // Execute the SuspendedWorkflow Workflow
                    Console.WriteLine("Executing the SuspendedWorkflow...");
                    workflowRuntime.StartRuntime();
                    WorkflowInstance suspendedWorkflowInstance = workflowRuntime.CreateWorkflow(typeof(SuspendedWorkflow));
                    suspendedWorkflowInstance.Start();
                    // Wait for the Workflow Suspension
                    waitHandle.WaitOne();

                    // Execute the ExceptionWorkflow Workflow
                    Console.WriteLine("Executing the ExceptionWorkflow...");
                    workflowRuntime.StartRuntime();
                    WorkflowInstance exceptionWorkflowInstance = workflowRuntime.CreateWorkflow(typeof(ExceptionWorkflow));
                    exceptionWorkflowInstance.Start();
                    // Wait for the Workflow Termination
                    waitHandle.WaitOne();

                    // Stop Runtime
                    workflowRuntime.StopRuntime();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nException:\n\tMessage: {0}\n\tSource: {1}", ex.Message, ex.Source);
            }
        }
Exemple #8
0
        static void Main()
        {
            try
            {
                // Create WorkflowRuntime
                using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
                {
                    // Add SimpleFileTrackingService
                    workflowRuntime.AddService(new SimpleFileTrackingService());

                    // Subscribe to Workflow Completed, Suspended, and Terminated WorkflowRuntime Event
                    workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
                    workflowRuntime.WorkflowSuspended += OnWorkflowSuspended;
                    workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;

                    // Start WorkflowRuntime
                    workflowRuntime.StartRuntime();

                    // Execute the SimpleWorkflow Workflow
                    Console.WriteLine("Executing the SimpleWorkflow...");
                    workflowRuntime.StartRuntime();
                    WorkflowInstance simpleWorkflowInstance = workflowRuntime.CreateWorkflow(typeof(SimpleWorkflow));
                    simpleWorkflowInstance.Start();
                    // Wait for the Workflow Completion
                    waitHandle.WaitOne();

                    // Execute the SuspendedWorkflow Workflow
                    Console.WriteLine("Executing the SuspendedWorkflow...");
                    workflowRuntime.StartRuntime();
                    WorkflowInstance suspendedWorkflowInstance = workflowRuntime.CreateWorkflow(typeof(SuspendedWorkflow));
                    suspendedWorkflowInstance.Start();
                    // Wait for the Workflow Suspension
                    waitHandle.WaitOne();

                    // Execute the ExceptionWorkflow Workflow
                    Console.WriteLine("Executing the ExceptionWorkflow...");
                    workflowRuntime.StartRuntime();
                    WorkflowInstance exceptionWorkflowInstance = workflowRuntime.CreateWorkflow(typeof(ExceptionWorkflow));
                    exceptionWorkflowInstance.Start();
                    // Wait for the Workflow Termination
                    waitHandle.WaitOne();

                    // Stop Runtime
                    workflowRuntime.StopRuntime();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nException:\n\tMessage: {0}\n\tSource: {1}", ex.Message, ex.Source);
            }
        }
        public bool CreateWorkflowIfNotExists(WorkflowRuntime runtime, Guid instanceId, WorkflowType workflowType, Dictionary <string, object> parameters)
        {
            try
            {
                var workflow = runtime.GetWorkflow(instanceId);
                return(true);
            }
            catch (Exception)
            {
            }

            WorkflowInstance instance = null;

            var wfparameters = new Dictionary <string, object>();

            if (parameters != null)
            {
                wfparameters = new Dictionary <string, object>(1)
                {
                    { "WorkflowPersistanceParameters", parameters }
                }
            }
            ;

            if (workflowType == WorkflowType.BillDemandWorkfow)
            {
                instance = runtime.CreateWorkflow(typeof(BillDemand), wfparameters,
                                                  instanceId);
            }
            else if (workflowType == WorkflowType.DemandAdjustmentWorkflow)
            {
                instance = runtime.CreateWorkflow(typeof(DemandAdjustment), wfparameters,
                                                  instanceId);
            }
            else if (workflowType == WorkflowType.DemandWorkflow)
            {
                instance = runtime.CreateWorkflow(typeof(Demand), wfparameters,
                                                  instanceId);
            }
            else
            {
                throw new InvalidOperationException("Невозможно определить тип маршрута");
            }

            instance.Start();

            return(false);

            //TODO Синхронизация и класс синхронизатор
        }
Exemple #10
0
        static void Main()
        {
            // Instanciate and configure workflow runtime
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                workflowRuntime.AddService(
                    new SqlWorkflowPersistenceService(
                        ConfigurationManager.AppSettings["ConnectionString"], true, new TimeSpan(0, 10, 0), new TimeSpan(0, 0, 5)));

                // Subscribe to workflow events
                workflowRuntime.WorkflowCompleted           += OnWorkflowCompleted;
                workflowRuntime.WorkflowIdled               += OnWorkflowIdle;
                workflowRuntime.ServicesExceptionNotHandled += OnExceptionNotHandled;
                workflowRuntime.WorkflowTerminated          += OnWorkflowTerminated;
                workflowRuntime.WorkflowAborted             += OnWorkflowAborted;

                // Start Workflow Runtime
                workflowRuntime.StartRuntime();

                //
                // start PO approval workflow with purchase order amount less than $1000
                //
                Console.WriteLine("Workflow 1:");

                Int32 poAmount     = 750;
                Type  workflowType = typeof(DynamicUpdateWorkflow);
                Dictionary <string, object> workflow1Parameters = new Dictionary <string, object>();
                workflow1Parameters.Add(amountParameter, poAmount);
                workflowRuntime.CreateWorkflow(workflowType, workflow1Parameters).Start();
                waitHandle.WaitOne();

                //
                // start PO approval workflow with purchase order amount greater than $1000
                //
                Console.WriteLine("Workflow 2:");

                poAmount = 1200;
                Dictionary <string, object> workflow2Parameters = new Dictionary <string, object>();
                workflow2Parameters.Add(amountParameter, poAmount);
                workflowRuntime.CreateWorkflow(workflowType, workflow2Parameters).Start();
                waitHandle.WaitOne();

                //Wait for dynamically created workflow to finish
                waitHandle.WaitOne();

                // After workflows have completed, stop runtime and report to command line
                workflowRuntime.StopRuntime();
                Console.WriteLine("Workflow runtime stopped, program exiting... \n");
            }
        }
Exemple #11
0
        static void Main()
        {
            // Instanciate and configure workflow runtime
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                workflowRuntime.AddService(
                    new SqlWorkflowPersistenceService(
                        ConfigurationManager.AppSettings["ConnectionString"], true, new TimeSpan(0, 10, 0), new TimeSpan(0, 0, 5)));

                // Subscribe to workflow events
                workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
                workflowRuntime.WorkflowIdled += OnWorkflowIdle;
                workflowRuntime.ServicesExceptionNotHandled += OnExceptionNotHandled;
                workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
                workflowRuntime.WorkflowAborted += OnWorkflowAborted;

                // Start Workflow Runtime
                workflowRuntime.StartRuntime();

                //
                // start PO approval workflow with purchase order amount less than $1000
                //
                Console.WriteLine("Workflow 1:");

                Int32 poAmount = 750;
                Type workflowType = typeof(DynamicUpdateWorkflow);
                Dictionary<string, object> workflow1Parameters = new Dictionary<string, object>();
                workflow1Parameters.Add(amountParameter, poAmount);
                workflowRuntime.CreateWorkflow(workflowType, workflow1Parameters).Start();
                waitHandle.WaitOne();

                //
                // start PO approval workflow with purchase order amount greater than $1000
                //
                Console.WriteLine("Workflow 2:");

                poAmount = 1200;
                Dictionary<string, object> workflow2Parameters = new Dictionary<string, object>();
                workflow2Parameters.Add(amountParameter, poAmount);
                workflowRuntime.CreateWorkflow(workflowType, workflow2Parameters).Start();
                waitHandle.WaitOne();

                //Wait for dynamically created workflow to finish
                waitHandle.WaitOne();

                // After workflows have completed, stop runtime and report to command line
                workflowRuntime.StopRuntime();
                Console.WriteLine("Workflow runtime stopped, program exiting... \n");
            }
        }
Exemple #12
0
        static void Main()
        {
            // Create WorkflowRuntime
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                try
                {
                    // Add SqlTrackingService
                    SqlTrackingService sqlTrackingService = new SqlTrackingService(connectionString);
                    sqlTrackingService.IsTransactional = false;
                    workflowRuntime.AddService(sqlTrackingService);

                    // Subscribe to Workflow Suspended WorkflowRuntime Event
                    workflowRuntime.WorkflowSuspended += OnWorkflowSuspended;
                    // Subscribe to Workflow Terminated WorkflowRuntime Event
                    workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;

                    // Start WorkflowRuntime
                    workflowRuntime.StartRuntime();

                    // Execute the ExceptionWorkflow Workflow
                    WriteTitle("Executing the exception workflow");
                    WorkflowInstance exceptionWorkflowInstance = workflowRuntime.CreateWorkflow(typeof(ExceptionWorkflow));
                    exceptionWorkflowInstance.Start();
                    waitHandle.WaitOne();
                    QueryAndWriteTrackingInformationToConsole(exceptionWorkflowInstance.InstanceId, TrackingWorkflowEvent.Exception);
                    QueryAndWriteTrackingInformationToConsole(exceptionWorkflowInstance.InstanceId, TrackingWorkflowEvent.Terminated);

                    // Execute the SuspendedWorkflow Workflow
                    WriteTitle("Executing the suspended workflow");
                    WorkflowInstance suspendedWorkflowInstance = workflowRuntime.CreateWorkflow(typeof(SuspendedWorkflow));
                    suspendedWorkflowInstance.Start();
                    waitHandle.WaitOne();
                    QueryAndWriteTrackingInformationToConsole(suspendedWorkflowInstance.InstanceId, TrackingWorkflowEvent.Suspended);

                    // Stop Runtime
                    workflowRuntime.StopRuntime();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Encountered an exception. Exception Source: {0}, Exception Message: {1} ", e.Source, e.Message);
                }
                finally
                {
                    workflowRuntime.StopRuntime();
                }
            }
        }
Exemple #13
0
        static void Main()
        {
            // Create WorkflowRuntime
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                try
                {
                    // Add SqlTrackingService
                    SqlTrackingService sqlTrackingService = new SqlTrackingService(connectionString);
                    sqlTrackingService.IsTransactional = false;
                    workflowRuntime.AddService(sqlTrackingService);

                    // Subscribe to Workflow Suspended WorkflowRuntime Event
                    workflowRuntime.WorkflowSuspended += OnWorkflowSuspended;
                    // Subscribe to Workflow Terminated WorkflowRuntime Event
                    workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;

                    // Start WorkflowRuntime
                    workflowRuntime.StartRuntime();

                    // Execute the ExceptionWorkflow Workflow
                    WriteTitle("Executing the exception workflow");
                    WorkflowInstance exceptionWorkflowInstance = workflowRuntime.CreateWorkflow(typeof(ExceptionWorkflow));
                    exceptionWorkflowInstance.Start();
                    waitHandle.WaitOne();
                    QueryAndWriteTrackingInformationToConsole(exceptionWorkflowInstance.InstanceId, TrackingWorkflowEvent.Exception);
                    QueryAndWriteTrackingInformationToConsole(exceptionWorkflowInstance.InstanceId, TrackingWorkflowEvent.Terminated);

                    // Execute the SuspendedWorkflow Workflow
                    WriteTitle("Executing the suspended workflow");
                    WorkflowInstance suspendedWorkflowInstance = workflowRuntime.CreateWorkflow(typeof(SuspendedWorkflow));
                    suspendedWorkflowInstance.Start();
                    waitHandle.WaitOne();
                    QueryAndWriteTrackingInformationToConsole(suspendedWorkflowInstance.InstanceId, TrackingWorkflowEvent.Suspended);

                    // Stop Runtime
                    workflowRuntime.StopRuntime();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Encountered an exception. Exception Source: {0}, Exception Message: {1} ", e.Source, e.Message);
                }
                finally
                {
                    workflowRuntime.StopRuntime();
                }
            }
        }
Exemple #14
0
        public void StartWorkflow(Type workflowType, Dictionary <string, object> inparms, Guid caller, IComparable qn, ActivityExecutionContext context)
        {
            this.ParentId = caller;

            WorkflowRuntime wr = this.Runtime;

            CallContext.SetData(CallingWorkflowIDProperty.Name, caller);
            CallContext.SetData(CallingWorkflowQueueNameProperty.Name, qn);


            //wr.WorkflowCreated += new EventHandler<WorkflowEventArgs>(wr_WorkflowCreated);
            WorkflowInstance wi = wr.CreateWorkflow(workflowType, inparms);

            // wr.WorkflowCompleted += new EventHandler<WorkflowCompletedEventArgs>(wr_WorkflowCompleted);
            _childWorkflows.Add(wi.InstanceId, new ChildData(caller, qn));

            //SubWorkflowArgs arg = new SubWorkflowArgs(wi.InstanceId, wi.InstanceId, caller, null);
            //this.OnStartSubWorkflow(arg);

            wi.Start();


            //// Call Workflow Service when the SubWorkflow Started
            //WorkflowServices workflowServicde = context.GetService<WorkflowServices>();
            SubWorkflowArgs arg = new SubWorkflowArgs(wi.InstanceId, wi.InstanceId, caller, null);

            this.OnSubWorkflowInstanceStart(arg);
            //////////////////////
            ManualWorkflowSchedulerService ss = wr.GetService <ManualWorkflowSchedulerService>();

            if (ss != null)
            {
                ss.RunWorkflow(wi.InstanceId);
            }
        }
Exemple #15
0
        static void Main()
        {
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                try
                {
                    // Start the engine
                    workflowRuntime.StartRuntime();

                    // Subscribe to events
                    workflowRuntime.WorkflowCompleted  += OnWorkflowCompleted;
                    workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;

                    workflowRuntime.WorkflowIdled += OnWorkflowIdled;
                    workflowRuntime.ServicesExceptionNotHandled += OnServicesExceptionNotHandled;

                    // Start PO approval workflow with purchase less than $1000
                    System.Int32 poAmount     = 750;
                    Type         workflowType = typeof(Microsoft.Samples.Workflow.DynamicUpdateFromHost.DynamicUpdateWorkflow);
                    Dictionary <string, object> inputParameters = new Dictionary <string, object>();
                    inputParameters.Add("Amount", poAmount);
                    workflowRuntime.CreateWorkflow(workflowType, inputParameters).Start();
                    waitHandle.WaitOne();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception \n\t Source: {0} \n\t Message: {1}", e.Source, e.Message);
                }
                finally
                {
                    workflowRuntime.StopRuntime();
                    Console.WriteLine("Workflow runtime stopped, program exiting... \n");
                }
            }
        }
Exemple #16
0
        static void Main()
        {
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                try
                {
                    // Start the engine
                    workflowRuntime.StartRuntime();

                    // Subscribe to events
                    workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
                    workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;

                    workflowRuntime.WorkflowIdled += OnWorkflowIdled;
                    workflowRuntime.ServicesExceptionNotHandled += OnServicesExceptionNotHandled;

                    // Start PO approval workflow with purchase less than $1000
                    System.Int32 poAmount = 750;
                    Type workflowType = typeof(Microsoft.Samples.Workflow.DynamicUpdateFromHost.DynamicUpdateWorkflow);
                    Dictionary<string, object> inputParameters = new Dictionary<string, object>();
                    inputParameters.Add("Amount", poAmount);
                    workflowRuntime.CreateWorkflow(workflowType, inputParameters).Start();
                    waitHandle.WaitOne();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception \n\t Source: {0} \n\t Message: {1}", e.Source, e.Message);
                }
                finally
                {
                    workflowRuntime.StopRuntime();
                    Console.WriteLine("Workflow runtime stopped, program exiting... \n");
                }
            }
        }
Exemple #17
0
        static void Main()
        {
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                try
                {
                    const string connectString = "Initial Catalog=SqlPersistenceService;Data Source=localhost;Integrated Security=SSPI;";

                    workflowRuntime.AddService(new SqlWorkflowPersistenceService(connectString));

                    workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
                    workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
                    workflowRuntime.WorkflowAborted += OnWorkflowAborted;

                    workflowRuntime.StartRuntime();
                    Type type = typeof(Compensation.PurchaseOrder);
                    workflowRuntime.CreateWorkflow(type).Start();

                    waitHandle.WaitOne();
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null)
                        Console.WriteLine(ex.InnerException.Message);
                    else
                        Console.WriteLine(ex.Message);
                }
                finally
                {
                    workflowRuntime.StopRuntime();
                }
            }
        }
Exemple #18
0
        static void Main()
        {
            string connectionString = "Initial Catalog=SqlPersistenceService;Data Source=localhost;Integrated Security=SSPI;";

            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                ExternalDataExchangeService dataService = new ExternalDataExchangeService();
                workflowRuntime.AddService(dataService);
                dataService.AddService(expenseService);

                workflowRuntime.AddService(new SqlWorkflowPersistenceService(connectionString));
                workflowRuntime.StartRuntime();

                workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
                workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
                workflowRuntime.WorkflowIdled += OnWorkflowIdled;
                workflowRuntime.WorkflowAborted += OnWorkflowAborted;

                Type type = typeof(Microsoft.Samples.Workflow.CancelWorkflow.SampleWorkflow);
                WorkflowInstance workflowInstance = workflowRuntime.CreateWorkflow(type);
                workflowInstance.Start();

                waitHandle.WaitOne();

                workflowRuntime.StopRuntime();
            }
        }
Exemple #19
0
        static void Main()
        {
            orderService = new OrderServiceImpl();

            // Start the workflow runtime engine.
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                ExternalDataExchangeService dataService = new ExternalDataExchangeService();
                workflowRuntime.AddService(dataService);
                dataService.AddService(orderService);

                workflowRuntime.StartRuntime();

                // Listen for the workflow events
                workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
                workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
                workflowRuntime.WorkflowIdled += OnWorkflowIdled;

                // Start the workflow and wait for it to complete
                Type type = typeof(PurchaseOrderWorkflow);
                workflowRuntime.CreateWorkflow(type).Start();

                waitHandle.WaitOne();

                // Stop the workflow runtime engine.
                workflowRuntime.StopRuntime();
            }
        }
Exemple #20
0
        static void Main()
        {
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                try
                {
                    // engine will unload workflow instance when it is idle
                    workflowRuntime.AddService(new FilePersistenceService(true));

                    workflowRuntime.WorkflowCreated += OnWorkflowCreated;
                    workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
                    workflowRuntime.WorkflowIdled += OnWorkflowIdle;
                    workflowRuntime.WorkflowUnloaded += OnWorkflowUnload;
                    workflowRuntime.WorkflowLoaded += OnWorkflowLoad;
                    workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
                    workflowRuntime.ServicesExceptionNotHandled += OnExceptionNotHandled;

                    workflowRuntime.CreateWorkflow(typeof(PersistenceServiceWorkflow)).Start();

                    waitHandle.WaitOne();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception \n\t Source: {0} \n\t Message: {1}", e.Source, e.Message);
                }
                finally
                {
                    workflowRuntime.StopRuntime();
                    Console.WriteLine("Workflow runtime stopped, program exiting... \n");
                }
            }
        }
Exemple #21
0
        static void Main()
        {
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {

                // Create our local service and add it to the workflow runtime's list of services
                ExternalDataExchangeService dataService = new ExternalDataExchangeService();
                workflowRuntime.AddService(dataService);
                VotingServiceImpl votingService = new VotingServiceImpl();
                dataService.AddService(votingService);

                // Start up the runtime and hook the creation and completion events
                workflowRuntime.StartRuntime();

                workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
                workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
                workflowRuntime.WorkflowStarted += OnWorkflowStarted;

                // Create the workflow's parameters collection
                Dictionary<string, object> parameters = new Dictionary<string, object>();
                parameters.Add("Alias", "Jim");
                // Create and start the workflow
                Type type = typeof(HostCommunication.VotingServiceWorkflow);
                workflowRuntime.CreateWorkflow(type, parameters).Start();

                waitHandle.WaitOne();

                // Cleanly stop the runtime and all services
                workflowRuntime.StopRuntime();
            }
        }
Exemple #22
0
        static void Main()
        {
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                try
                {
                    // A workflow is always run asychronously; the main thread waits on this event so the program
                    // doesn't exit before the workflow completes
                    workflowRuntime.AddService(new SqlWorkflowPersistenceService("Initial Catalog=SqlPersistenceService;Data Source=localhost;Integrated Security=SSPI;"));

                    // Listen for the workflow events
                    workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
                    workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
                    workflowRuntime.WorkflowAborted += OnWorkflowAborted;

                    // Create an instance of the workflow
                    Type type = typeof(NestedExceptionsWorkflow);
                    workflowRuntime.CreateWorkflow(type).Start();
                    Console.WriteLine("Workflow Started.\n");

                    // Wait for the event to be signaled
                    waitHandle.WaitOne();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Source: {0}\nMessage: {1}", ex.Source, ex.Message);
                }
                finally
                {
                    workflowRuntime.StopRuntime();
                    Console.WriteLine("\nWorkflow Complete.");
                }
            }
        }
Exemple #23
0
        static void Main(string[] args)
        {
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                AutoResetEvent waitHandle = new AutoResetEvent(false);
                workflowRuntime.WorkflowCompleted  += delegate(object sender, WorkflowCompletedEventArgs e) { waitHandle.Set(); };
                workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
                {
                    Console.WriteLine(e.Exception.Message);
                    waitHandle.Set();
                };

                // Define two parameters for use by our workflow.
                // Remember!  These must be mapped to identically named
                // properties in our workflow class type.
                Dictionary <string, object> parameters = new Dictionary <string, object>();
                parameters.Add("ErrorMessage", "Ack!  Your name is too long!");
                parameters.Add("NameLength", 5);

                // Now, create a WF instance that represents our type
                // and pass in parameters.
                WorkflowInstance instance =
                    workflowRuntime.CreateWorkflow(
                        typeof(UserDataWFApp.ProcessUsernameWorkflow), parameters
                        );
                instance.Start();
                waitHandle.WaitOne();
            }
        }
Exemple #24
0
        static void Main(string[] args)
        {
            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();
                };

                WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(StateInitialization.SampleWorkflow));
                Console.WriteLine("Starting workflow.");
                instance.Start();

                waitHandle.WaitOne();

                workflowRuntime.StopRuntime();
            }
        }
Exemple #25
0
        static void Main()
        {
            // Start the engine.
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                workflowRuntime.StartRuntime();

                // Load the workflow type.
                Type type = typeof(SuspendAndTerminateWorkflow);

                workflowRuntime.WorkflowCompleted += OnWorkflowCompletion;
                workflowRuntime.WorkflowSuspended += OnWorkflowSuspend;
                workflowRuntime.WorkflowResumed += OnWorkflowResume;
                workflowRuntime.WorkflowTerminated += OnWorkflowTerminate;

                WorkflowInstance workflowInstance = workflowRuntime.CreateWorkflow(type);
                workflowInstance.Start();

                waitHandle.WaitOne();

                if (workflowSuspended)
                {
                    Console.WriteLine("\r\nResuming Workflow Instance");
                    workflowInstance.Resume();
                    waitHandle.WaitOne();
                }

                workflowRuntime.StopRuntime();
            }

        }
Exemple #26
0
        public void RaisingEventFromExternalDataExchange()
        {
            _container.AddComponent("testingexternaldata.service", typeof(ITestingExternalData), typeof(TestingExternalData));

            WorkflowRuntime runtime = _container.Resolve <WorkflowRuntime>();

            ManualResetEvent finished = new ManualResetEvent(false);

            runtime.WorkflowCompleted  += delegate(object sender, WorkflowCompletedEventArgs e) { finished.Set(); };
            runtime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e) { finished.Set(); };

            WorkflowInstance workflow = runtime.CreateWorkflow(typeof(PausingWorkflow));

            workflow.Start();
            bool isFinished = finished.WaitOne(TimeSpan.FromSeconds(.25), false);

            Assert.IsFalse(isFinished, "Workflow must not be finished yet");

            TestingExternalData testingExternalData = (TestingExternalData)_container.Resolve <ITestingExternalData>();

            testingExternalData.OnSurveyComplete(workflow.InstanceId, "a test name");

            isFinished = finished.WaitOne(TimeSpan.FromSeconds(1), false);
            Assert.IsTrue(isFinished, "Workflow must finish in less than a second");

            Assert.AreEqual("a test name called", testingExternalData.MostRecentFullName, "Workflow was supposed to call back with the value the test provided");
        }
Exemple #27
0
        private static void Main()
        {
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                poImpl = new StartPurchaseOrder();
                ExternalDataExchangeService dataService = new ExternalDataExchangeService();
                workflowRuntime.AddService(dataService);
                dataService.AddService(poImpl);

                workflowRuntime.WorkflowCompleted  += OnWorkflowCompleted;
                workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;

                // Load the workflow type.
                Type             type     = typeof(PurchaseOrderWorkflow);
                WorkflowInstance instance = workflowRuntime.CreateWorkflow(type);
                workflowInstanceId = instance.InstanceId;

                // Start the workflow runtime engine
                workflowRuntime.StartRuntime();

                instance.Start();

                SendPORequestMessage();

                waitHandle.WaitOne();

                workflowRuntime.StopRuntime();
            }
        }
Exemple #28
0
        static void Main()
        {
            try
            {
                waitHandle = new AutoResetEvent(false);
                CreateAndInsertTrackingProfile();
                using (WorkflowRuntime runtime = new WorkflowRuntime())
                {
                    SqlTrackingService trackingService = new SqlTrackingService(connectionString);
                    runtime.AddService(trackingService);
                    runtime.StartRuntime();
                    runtime.WorkflowCompleted += OnWorkflowCompleted;
                    runtime.WorkflowTerminated += OnWorkflowTerminated;
                    runtime.WorkflowAborted += OnWorkflowAborted;

                    WorkflowInstance instance = runtime.CreateWorkflow(typeof(BankMachineWorkflow));
                    instance.Start();
                    waitHandle.WaitOne();

                    runtime.StopRuntime();
                    OutputTrackedData(instance.InstanceId);
                    
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                    Console.WriteLine(ex.InnerException.Message);
                else
                    Console.WriteLine(ex.Message);
            }
        }
Exemple #29
0
        private void CheckRule(CodeBinaryOperatorExpression expression, bool executed, string error)
        {
            WorkflowInstance wi;
            WorkflowRuntime  workflowRuntime = new WorkflowRuntime();
            Type             type            = typeof(WorkFlowIfElseRule);

            workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;

            executed1       = false;
            executed2       = false;
            check_condition = expression;
            wi = workflowRuntime.CreateWorkflow(type);
            wi.Start();
            waitHandle.WaitOne();

            if (executed)
            {
                Assert.AreEqual(true, executed1, error);
                Assert.AreEqual(false, executed2, error);
            }
            else
            {
                Assert.AreEqual(false, executed1, error);
                Assert.AreEqual(true, executed2, error);
            }

            workflowRuntime.Dispose();
        }
Exemple #30
0
        static void Main()
        {
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {

                try
                {
                    // Start the engine.
                    workflowRuntime.StartRuntime();

                    // Load the workflow type.
                    Type type = typeof(Microsoft.Samples.Workflow.Synchronized.SynchronizedActivityWorkflow);

                    workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
                    workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
                    workflowRuntime.ServicesExceptionNotHandled += OnExceptionNotHandled;

                    workflowRuntime.CreateWorkflow(type).Start();

                    waitHandle.WaitOne();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception \n\t Source: {0} \n\t Message: {1}", e.Source, e.Message);
                }
                finally
                {
                    workflowRuntime.StopRuntime();
                    Console.WriteLine("\nWorkflow runtime stopped, program exiting... \n");
                }
            }
        }
Exemple #31
0
        public void CallingExternalDataExchangeFromWindsor()
        {
            _container.AddComponent("testingexternaldata.service", typeof(ITestingExternalData), typeof(TestingExternalData));

            WorkflowRuntime runtime = _container.Resolve <WorkflowRuntime>();

            ManualResetEvent finished = new ManualResetEvent(false);
            string           fullName = null;

            runtime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)
            {
                fullName = Convert.ToString(e.OutputParameters["FullName"]);
                finished.Set();
            };
            runtime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e) { finished.Set(); };

            WorkflowInstance workflow = runtime.CreateWorkflow(typeof(CreateNameWorkflow));

            workflow.Start();
            bool isFinished = finished.WaitOne(TimeSpan.FromSeconds(1), false);

            Assert.IsTrue(isFinished, "Workflow must finish in less than a second");

            Assert.AreEqual("hello world", fullName, "Full name must be set with default values");

            TestingExternalData testingExternalData = (TestingExternalData)_container.Resolve <ITestingExternalData>();

            Assert.AreEqual("hello world", testingExternalData.MostRecentFullName, "Container must return the singleton the workflow used to call method");
        }
Exemple #32
0
        /// <summary>
        /// The equals button was pressed. Invoke the workflow
        /// that performs the calculation
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Equals_Click(object sender, EventArgs e)
        {
            try
            {
                _number2 = Int32.Parse(txtNumber.Text);

                //create a dictionary with input arguments
                Dictionary <String, Object> wfArguments
                    = new Dictionary <string, object>();
                wfArguments.Add("Number1", _number1);
                wfArguments.Add("Number2", _number2);
                wfArguments.Add("Operation", _operation);

                WorkflowInstance instance
                    = _workflowRuntime.CreateWorkflow(
                          typeof(SimpleCalculatorWorkflow.Workflow1),
                          wfArguments);
                instance.Start();

                _waitHandle.WaitOne();

                //display the result
                Clear();
                txtNumber.Text = _result.ToString();
            }
            catch (Exception exception)
            {
                MessageBox.Show(String.Format(
                                    "Equals error: {0}", exception.Message));
            }
        }
Exemple #33
0
        static void Main()
        {
            // Create the WorkflowRuntime
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {

                // Set up the WorkflowRuntime events so that the host gets notified when the workflow
                // completes and terminates
                workflowRuntime.WorkflowCompleted += new EventHandler<WorkflowCompletedEventArgs>(OnWorkflowCompleted);
                workflowRuntime.WorkflowTerminated += new EventHandler<WorkflowTerminatedEventArgs>(OnWorkflowTerminated);

                // Load the workflow type
                Type type = typeof(ThrowWorkflow);

                //Start the workflow and wait for it to complete
                workflowRuntime.CreateWorkflow(type).Start();

                Console.WriteLine("Workflow Started.");
                waitHandle.WaitOne();

                Console.WriteLine("Workflow Completed.");

                workflowRuntime.StopRuntime();
            }
        }
Exemple #34
0
        /////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////////////
        public MainForm()
        {
            InitializeComponent();

            #region UI define
            GenerateButtons();
            GenerateAcctions();
            #endregion

            #region Bankomats Init

            currentAccountCulture = CultureInfo.CurrentCulture;

            #endregion

            #region IniT Workflow
            workflowRuntime = new WorkflowRuntime();
            ExternalDataExchangeService des = new ExternalDataExchangeService();
            workflowRuntime.AddService(des);
            des.AddService(this);

            workflowRuntime.StartRuntime();

            workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
            workflowRuntime.WorkflowTerminated += new EventHandler<WorkflowTerminatedEventArgs>(workflowRuntime_WorkflowTerminated);

            Type type = typeof(BankomatWorkflowLibrary.BankomatsWorkflow);
            workflowInstance = workflowRuntime.CreateWorkflow(type);
            workflowInstance.Start();
            #endregion
        }
Exemple #35
0
        static void Main(string[] args)
        {
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                // Add ChannelManager.
                ChannelManagerService channelmgr = new ChannelManagerService();
                workflowRuntime.AddService(channelmgr);

                AutoResetEvent waitHandle = new AutoResetEvent(false);
                workflowRuntime.WorkflowCompleted  += delegate(object sender, WorkflowCompletedEventArgs e) { Console.WriteLine("WorkflowCompleted: " + e.WorkflowInstance.InstanceId.ToString()); waitHandle.Set(); };
                workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e) { Console.WriteLine("WorkflowTerminated: " + e.Exception.Message); waitHandle.Set(); };

                while (true)
                {
                    WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(Microsoft.WorkflowServices.Samples.SequentialCalculatorClient));
                    Console.WriteLine("Start SequentialCalculatorClient.");
                    instance.Start();
                    waitHandle.WaitOne();
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Do another calculation? (Y)");
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Press <enter> to exit.");
                    Console.ResetColor();
                    string input = Console.ReadLine();
                    if (input.Length == 0 || input[0] != 'Y')
                    {
                        break;
                    }
                    waitHandle.Reset();
                }
            }
        }
Exemple #36
0
        static void Main()
        {
            // Create WorkflowRuntime
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                // Add ConsoleTrackingService
                workflowRuntime.AddService(new ConsoleTrackingService());

                // Subscribe to Workflow Completed WorkflowRuntime Event
                workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;

                // Subscribe to Workflow Terminated WorkflowRuntime Event
                workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;

                // Start WorkflowRuntime
                workflowRuntime.StartRuntime();

                // Execute the SampleWorkflow Workflow
                Console.WriteLine("Executing the workflow...");
                workflowRuntime.CreateWorkflow(typeof(SimplePolicyWorkflow)).Start();

                // Wait for the Workflow Completion
                waitHandle.WaitOne();

                // Stop Runtime
                workflowRuntime.StopRuntime();
            }
        }
Exemple #37
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting Workflow");

            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                // Run SQL scripts:
                // C:\Windows\Microsoft.NET\Framework\v3.0\Windows Workflow Foundation\SQL\en\SqlPersistenceService_Schema.sql
                // C:\Windows\Microsoft.NET\Framework\v3.0\Windows Workflow Foundation\SQL\en\SqlPersistenceService_Logic.sql

                SqlWorkflowPersistenceService sqlPersistenceService = new SqlWorkflowPersistenceService("Server=localhost;Database=NetMeter;User Id=sa;Password=MetraTech1;");
                workflowRuntime.AddService(sqlPersistenceService);
                workflowRuntime.AddService(new ConsoleTrackingService());

                AutoResetEvent waitHandle = new AutoResetEvent(false);
                workflowRuntime.WorkflowCompleted  += delegate(object sender, WorkflowCompletedEventArgs e) { waitHandle.Set(); };
                workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
                {
                    Console.WriteLine(e.Exception.ToString());
                    waitHandle.Set();
                };

                WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(WorkflowConsoleApplication2.Workflow1));
                instance.Start();

                waitHandle.WaitOne();
            }

            Console.WriteLine("Workflow done");
            Console.ReadLine();
        }
Exemple #38
0
        static void Main()
        {
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                // Create our local service and add it to the workflow runtime's list of services
                ExternalDataExchangeService dataService = new ExternalDataExchangeService();
                workflowRuntime.AddService(dataService);
                VotingServiceImpl votingService = new VotingServiceImpl();
                dataService.AddService(votingService);

                // Start up the runtime and hook the creation and completion events
                workflowRuntime.StartRuntime();

                workflowRuntime.WorkflowCompleted  += OnWorkflowCompleted;
                workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
                workflowRuntime.WorkflowStarted    += OnWorkflowStarted;

                // Create the workflow's parameters collection
                Dictionary <string, object> parameters = new Dictionary <string, object>();
                parameters.Add("Alias", "Jim");
                // Create and start the workflow
                Type type = typeof(HostCommunication.VotingServiceWorkflow);
                workflowRuntime.CreateWorkflow(type, parameters).Start();

                waitHandle.WaitOne();

                // Cleanly stop the runtime and all services
                workflowRuntime.StopRuntime();
            }
        }
Exemple #39
0
        private void OnSubmitRegistration(object sender, EventArgs args)
        {
            Type workflowType = typeof(RegistrationWorkflow);

            // Start workflow runtime
            workflowRuntime.StartRuntime();

            foreach (ListBoxItem item in PendingRegistrations.Items)
            {
                // Define parameters
                Dictionary <string, object> parameters = new Dictionary <string, object>();
                parameters.Add("UserId", Application.Current.Properties["UserId"]);
                parameters.Add("SessionId", item.Tag as String);

                // Start workflow instance
                WorkflowInstance workflowInstance = workflowRuntime.CreateWorkflow(workflowType, parameters);
                workflowInstance.Start();
            }

            // Give workflows time to complete
            Thread.Sleep(5000);

            // Stop the runtime
            workflowRuntime.StopRuntime();

            // Display dialog confirming registion
            MessageBox.Show("Your registration has been submitted.");

            // Close registration window
            this.Close();
        }
        static void Main(string[] args)
        {
            try {
                // Create the WorkflowRuntime
                WorkflowRuntime workflowRuntime = new WorkflowRuntime();

                workflowRuntime.AddService(new SqlWorkflowPersistenceService("Initial Catalog=SqlPersistenceService;Data Source=localhost;Integrated Security=SSPI;"));

                // Set up the WorkflowRuntime event handlers
                workflowRuntime.WorkflowCompleted  += OnWorkflowCompleted;
                workflowRuntime.WorkflowIdled      += OnWorkflowIdled;
                workflowRuntime.WorkflowPersisted  += OnWorkflowPersisted;
                workflowRuntime.WorkflowUnloaded   += OnWorkflowUnloaded;
                workflowRuntime.WorkflowLoaded     += OnWorkflowLoaded;
                workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;

                // Load the workflow type
                Type type = typeof(Workflow1);

                // Create an instance of the workflow
                workflowRuntime.CreateWorkflow(type).Start();
                Console.WriteLine("Workflow Started.");

                // Wait for the event to be signaled
                waitHandle.WaitOne();

                // Stop the runtime
                workflowRuntime.StopRuntime();
                Console.WriteLine("Program Complete.");
            }
            catch (Exception exception)
            {
                Console.WriteLine("Application exception occured: " + exception.Message);
            }
        }
Exemple #41
0
        static void Main()
        {
            orderService = new OrderServiceImpl();

            // Start the workflow runtime engine.
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                ExternalDataExchangeService dataService = new ExternalDataExchangeService();
                workflowRuntime.AddService(dataService);
                dataService.AddService(orderService);

                workflowRuntime.StartRuntime();

                // Listen for the workflow events
                workflowRuntime.WorkflowCompleted  += OnWorkflowCompleted;
                workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
                workflowRuntime.WorkflowIdled      += OnWorkflowIdled;

                // Start the workflow and wait for it to complete
                Type type = typeof(PurchaseOrderWorkflow);
                workflowRuntime.CreateWorkflow(type).Start();

                waitHandle.WaitOne();

                // Stop the workflow runtime engine.
                workflowRuntime.StopRuntime();
            }
        }
Exemple #42
0
        static void Main(string[] args)
        {
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                // Add ChannelManager
                ChannelManagerService channelmgr = new ChannelManagerService();
                workflowRuntime.AddService(channelmgr);
                
                AutoResetEvent waitHandle = new AutoResetEvent(false);
                workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) { Console.WriteLine("WorkflowCompleted: " + e.WorkflowInstance.InstanceId.ToString()); waitHandle.Set(); };
                workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e) { Console.WriteLine("WorkflowTerminated: " + e.Exception.Message); waitHandle.Set(); };

                while (true)
                {
                    WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(Microsoft.WorkflowServices.Samples.SequentialCalculatorClient));
                    Console.WriteLine("Start SequentialCalculatorClient.");
                    instance.Start();
                    waitHandle.WaitOne();
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Do another calculation? (Y)");
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Press <enter> to exit.");
                    Console.ResetColor();
                    string input = Console.ReadLine();
                    if (input.Length == 0 || input[0] != 'Y')
                        break;
                    waitHandle.Reset();
                }
            }
        }
Exemple #43
0
        static void Main()
        {
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                try
                {
                    // A workflow is always run asychronously; the main thread waits on this event so the program
                    // doesn't exit before the workflow completes
                    workflowRuntime.AddService(new SqlWorkflowPersistenceService("Initial Catalog=SqlPersistenceService;Data Source=localhost;Integrated Security=SSPI;"));

                    // Listen for the workflow events
                    workflowRuntime.WorkflowCompleted  += OnWorkflowCompleted;
                    workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
                    workflowRuntime.WorkflowAborted    += OnWorkflowAborted;

                    // Create an instance of the workflow
                    Type type = typeof(NestedExceptionsWorkflow);
                    workflowRuntime.CreateWorkflow(type).Start();
                    Console.WriteLine("Workflow Started.\n");

                    // Wait for the event to be signaled
                    waitHandle.WaitOne();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Source: {0}\nMessage: {1}", ex.Source, ex.Message);
                }
                finally
                {
                    workflowRuntime.StopRuntime();
                    Console.WriteLine("\nWorkflow Complete.");
                }
            }
        }
Exemple #44
0
        static void Main()
        {
            string connectionString = "Initial Catalog=SqlPersistenceService;Data Source=localhost;Integrated Security=SSPI;";

            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                ExternalDataExchangeService dataService = new ExternalDataExchangeService();
                workflowRuntime.AddService(dataService);
                dataService.AddService(expenseService);

                workflowRuntime.AddService(new SqlWorkflowPersistenceService(connectionString));
                workflowRuntime.StartRuntime();

                workflowRuntime.WorkflowCompleted  += OnWorkflowCompleted;
                workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
                workflowRuntime.WorkflowIdled      += OnWorkflowIdled;
                workflowRuntime.WorkflowAborted    += OnWorkflowAborted;

                Type             type             = typeof(Microsoft.Samples.Workflow.CancelWorkflow.SampleWorkflow);
                WorkflowInstance workflowInstance = workflowRuntime.CreateWorkflow(type);
                workflowInstance.Start();

                waitHandle.WaitOne();

                workflowRuntime.StopRuntime();
            }
        }
Exemple #45
0
        public void Echo(string theString)
        {
            //Aquire the callback from the current OperationContext
            callback = OperationContext.Current.GetCallbackChannel <IEchoableCallback>();
            //grab the version of the incoming message in case we need to create a fault later
            version = OperationContext.Current.IncomingMessageVersion;

            Console.WriteLine("WCF: Got {0}", theString);

            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("ReceivedData", theString);

            WorkflowRuntime workflowRuntime          = new WorkflowRuntime();
            ManualWorkflowSchedulerService scheduler = new ManualWorkflowSchedulerService();

            workflowRuntime.AddService(scheduler);
            workflowRuntime.StartRuntime();

            workflowRuntime.WorkflowCompleted  += this.OnWorkflowCompleted;
            workflowRuntime.WorkflowTerminated += this.OnWorkflowTerminated;

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

            instance.Start();

            scheduler.RunWorkflow(instance.InstanceId);
        }
Exemple #46
0
        public VersaCell()
        {
            try
            {
                _clsHRecord     = new VersaCellHeaderRecord();
                _clsPRecord     = new VersaCellPatientRecord();
                _clsORecord     = new VersaCellOrderRecord();
                _clsQRecord     = new VersaCellQueryRecord();
                _clsRRecord     = new VersaCellResultRecord();
                _clsTRecord     = new VersaCellTerminationRecord();
                PrvRequestArray = new Queue <List <string> >();
                objService      = new ExternalDataExchangeService();

                InstanceId = Guid.NewGuid();
                objWorkFlowRuntime.AddService(objService);
                objASTM = new clsASTM();
                objService.AddService(objASTM);
                objASTM.SendACKEvent += objASTM_SendACKEvent;
                objASTM.SendNAKEvent += objASTM_SendNAKEvent;
                objASTM.SendENQEvent += objASTM_SendENQEvent;
                objASTM.SendEOTEvent += objASTM_SendEOTEvent;
                objWorkFlowInstance   = objWorkFlowRuntime.CreateWorkflow(typeof(ASTMWorkflow), null, InstanceId);
                objWorkFlowInstance.Start();
                Console.WriteLine(@"Work flow started");

                objDataEventArgs             = new ExternalDataEventArgs(InstanceId);
                objDataEventArgs.WaitForIdle = true;
                DumpStateMachine(objWorkFlowRuntime, InstanceId);
            }
            catch (Exception ex)
            {
                Log.FatalException("Fatal Error: ", ex);
            }
        }
Exemple #47
0
        static void Main()
        {
            // Create WorkflowRuntime
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                // Add ConsoleTrackingService
                workflowRuntime.AddService(new ConsoleTrackingService());

                // Subscribe to Workflow Completed WorkflowRuntime Event
                workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;

                // Subscribe to Workflow Terminated WorkflowRuntime Event
                workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;

                // Start WorkflowRuntime
                workflowRuntime.StartRuntime();

                // Execute the SampleWorkflow Workflow
                Console.WriteLine("Executing the workflow...");
                workflowRuntime.CreateWorkflow(typeof(SimplePolicyWorkflow)).Start();

                // Wait for the Workflow Completion
                waitHandle.WaitOne();

                // Stop Runtime
                workflowRuntime.StopRuntime();
            }
        }
        public TcpIpASTMManager()
        {
            try
            {
                _prvRequestArray         = new Queue <List <string> >();
                _currentOrder            = new List <string>();
                _failSending             = 0;
                _timeoutManager          = new Timer(60000);
                _timeoutManager.Elapsed += _timeoutManager_Elapsed;
                objService = new ExternalDataExchangeService();

                InstanceId = Guid.NewGuid();
                objWorkFlowRuntime.AddService(objService);
                objASTM = new ClsAstm();
                objService.AddService(objASTM);
                objASTM.SendACKEvent += objASTM_SendACKEvent;
                objASTM.SendNAKEvent += objASTM_SendNAKEvent;
                objASTM.SendENQEvent += objASTM_SendENQEvent;
                objASTM.SendEOTEvent += objASTM_SendEOTEvent;
                //objASTM.ACKTimeoutEvent += new EventHandler(objASTM_ACKTimeoutEvent);
                objWorkFlowInstance = objWorkFlowRuntime.CreateWorkflow(typeof(ASTMWorkflow), null, InstanceId);
                objWorkFlowInstance.Start();
                Console.WriteLine(string.Format(@"Work flow started"));

                objDataEventArgs = new ExternalDataEventArgs(InstanceId)
                {
                    WaitForIdle = true
                };
                DumpStateMachine(objWorkFlowRuntime, InstanceId);
            }
            catch (Exception ex)
            {
                Log.Error(string.Format("Error: {0}", ex));
            }
        }
Exemple #49
0
        static void Main()
        {
            // Start the engine.
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                workflowRuntime.StartRuntime();

                // Load the workflow type.
                Type type = typeof(IfElseWorkflow);

                workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
                workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;

                // The "OrderValueParameter" parameter is used to determine which branch of the IfElse should be executed
                // a value less than 10,000 will execute branch 1 - Get Manager Approval; any other value will execute branch 2 - Get VP Approval
                Dictionary<string, object> parameters = new Dictionary<string, object>();
                parameters.Add("OrderValue", 14000);
                WorkflowInstance workflow = workflowRuntime.CreateWorkflow(type, parameters);
                workflow.Start();

                waitHandle.WaitOne();

                workflowRuntime.StopRuntime();
            }
        }
Exemple #50
0
        static void Main(string[] args)
        {
            WorkflowRuntime workflowRuntime = new WorkflowRuntime();

            AutoResetEvent waitHandle = new AutoResetEvent(false);

            workflowRuntime.WorkflowCompleted
                += delegate(object sender, WorkflowCompletedEventArgs e)
                {
                waitHandle.Set();
                };
            workflowRuntime.WorkflowTerminated
                += delegate(object sender, WorkflowTerminatedEventArgs e)
                {
                Console.WriteLine(e.Exception.Message);
                waitHandle.Set();
                };

            WorkflowInstance instance
                = workflowRuntime.CreateWorkflow(typeof(HelloWorkflow.Workflow1));

            instance.Start();

            waitHandle.WaitOne();

            Console.WriteLine("Press any key to exit");
            Console.ReadLine();
        }
Exemple #51
0
        static void Main()
        {
            try
            {
                waitHandle = new AutoResetEvent(false);
                
                DataAccess.CreateAndInsertTrackingProfile();
                using (WorkflowRuntime runtime = new WorkflowRuntime())
                {
                    SqlTrackingService trackingService = new SqlTrackingService(DataAccess.connectionString);

                    /*
                     *  Set partitioning settings on Sql Tracking Service and database
                     */

                    //Turn on PartitionOnCompletion setting-- Default is false
                    trackingService.PartitionOnCompletion = true;

                    //Set partition interval-- Default is 'm' (monthly)
                    DataAccess.SetPartitionInterval('d');

                    runtime.AddService(trackingService);
                    runtime.StartRuntime();

                    runtime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)
                    {
                       waitHandle.Set();
                    };
                    
                    runtime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
                    {
                        Console.WriteLine(e.Exception.Message);
                        waitHandle.Set();
                    };

                    WorkflowInstance instance = runtime.CreateWorkflow(typeof(SimpleWorkflow));
                    instance.Start();
                    waitHandle.WaitOne();

                    runtime.StopRuntime();
                    DataAccess.GetWorkflowTrackingEvents(instance.InstanceId);
                    Console.WriteLine("\nDone running the workflow.");

                    /*
                     *  Show tracking partition information and tables
                     */

                    DataAccess.ShowTrackingPartitionInformation();
                    DataAccess.ShowPartitionTableInformation();
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                    Console.WriteLine(ex.InnerException.Message);
                else
                    Console.WriteLine(ex.Message);
            }
        }
Exemple #52
0
 static void Main(string[] args)
 {
     WorkflowRuntime workflowRuntime = new WorkflowRuntime();
     workflowRuntime.WorkflowCompleted += workflowRuntime_WorkflowCompleted;
     workflowRuntime.WorkflowTerminated += workflowRuntime_WorkflowTerminated;
     WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(WorkflowMain));
     instance.Start();
     waitHandle.WaitOne();
 }
Exemple #53
0
 public PressGui()
 {
     InitializeComponent();
     _workflowRuntime = new WorkflowRuntime();
     _instance = _workflowRuntime.CreateWorkflow(typeof(PressFlow));
     _flow = _instance.GetWorkflowDefinition() as PressFlow;
     InitFlow();
     InitUI();
     RunUI();
 }
		public void WorkFlowTest ()
		{
			WorkflowRuntime workflowRuntime = new WorkflowRuntime ();

			Type type = typeof (SequentialWorkflow);
			workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;

			workflowRuntime.CreateWorkflow (type).Start ();
            		waitHandle.WaitOne ();
            		workflowRuntime.Dispose ();

			Assert.AreEqual (true, code_execute, "C1#1");
		}
Exemple #55
0
        static void Main(string[] args)
        {
            using(WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                AutoResetEvent waitHandle = new AutoResetEvent(false);

                WorkflowCompiler compiler = new WorkflowCompiler();
                WorkflowCompilerParameters compilerParameters = new WorkflowCompilerParameters();
                compilerParameters.GenerateInMemory = true;

                String[] workflowFilenames = GetWorkflowFilenames();
                
                WorkflowCompilerResults results = compiler.Compile(compilerParameters, workflowFilenames);
                if (results.Errors.Count > 0)
                {
                    Console.WriteLine("Errors occurred while building the workflow:");
                    foreach (WorkflowCompilerError compilerError in results.Errors)
                    {
                        Console.WriteLine(compilerError.Line.ToString() + "," + compilerError.Column.ToString() + " : " + compilerError.ErrorText);
                    }

                    return;
                }

                Type workflowType = results.CompiledAssembly.GetType("Microsoft.Samples.Workflow.SimpleInMemorySample.SequentialWorkflow");

                workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) 
                {
                    string orderStatus = e.OutputParameters["Status"].ToString();
                    Console.WriteLine("Order was " + orderStatus);
                    waitHandle.Set();
                };
                workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
                {
                    Console.WriteLine(e.Exception.Message);
                    waitHandle.Set();
                };

                Dictionary<string, object> parameters = new Dictionary<string, object>();
                parameters.Add("Amount", 300);

                WorkflowInstance instance = workflowRuntime.CreateWorkflow(workflowType, parameters);
                instance.Start();

                waitHandle.WaitOne();

                workflowRuntime.StopRuntime();
            }
            
        }
Exemple #56
0
        static void Main()
        {
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                workflowRuntime.StartRuntime();

                workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
                workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;

                Type type = typeof(SendEmailWorkflow);
                workflowRuntime.CreateWorkflow(type).Start();

                waitHandle.WaitOne();

                workflowRuntime.StopRuntime();
            }
        }
Exemple #57
0
        static void Main()
        {
            try
            {
                // Create the WorkflowRuntime
                using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
                {
                    // Add the SqlWorkflowPersistenceService service
                    WorkflowPersistenceService persistenceService =
                        new SqlWorkflowPersistenceService(
                        "Initial Catalog=SqlPersistenceService;Data Source=localhost;Integrated Security=SSPI;",
                        false, 
                        new TimeSpan(1, 0, 0), 
                        new TimeSpan(0, 0, 5));
                    workflowRuntime.AddService(persistenceService);

                    // Set up the WorkflowRuntime event handlers
                    workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
                    workflowRuntime.WorkflowIdled += OnWorkflowIdled;
                    workflowRuntime.WorkflowPersisted += OnWorkflowPersisted;
                    workflowRuntime.WorkflowUnloaded += OnWorkflowUnloaded;
                    workflowRuntime.WorkflowLoaded += OnWorkflowLoaded;
                    workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
                    workflowRuntime.WorkflowAborted += OnWorkflowAborted;


                    // Load the workflow type
                    Type type = typeof(PersistenceServicesWorkflow);

                    // Create an instance of the workflow
                    Console.WriteLine("Workflow Started.");
                    workflowRuntime.CreateWorkflow(type).Start();                    

                    // Wait for the event to be signaled
                    waitHandle.WaitOne();

                    // Stop the runtime
                    workflowRuntime.StopRuntime();
                    Console.WriteLine("Program Complete.");
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("Application exception occurred: " + exception.Message);
            }
        }
Exemple #58
0
        static void Main(string[] args)
        {
            try
            {
                // The program passes the one and only argument into the workflow
                //  as the order amount.
                if (args.Length < 1)
                {
                    Console.WriteLine("Usage: SequentialWorkflowWithParameters [amount]");
                    return;
                }

                // Create the WorkflowRuntime
                using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
                {
                    Console.WriteLine("Runtime Started.");

                    // Listen for the workflow events
                    workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
                    workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;

                    // Set up the parameters
                    // "amount" is an "in" parameter and specifies the order amount.
                    //  If the amount is < 500 the status is "approved"; "rejected" otherwise.
                    Dictionary<string, object> parameters = new Dictionary<string, object>();
                    parameters.Add("Amount", Convert.ToInt32(args[0], CultureInfo.InvariantCulture));

                    // Get the workflow type
                    Type type = typeof(SequentialWorkflow);

                    // Create and start an instance of the workflow
                    workflowRuntime.CreateWorkflow(type, parameters).Start();
                    Console.WriteLine("Workflow Started.");

                    // Wait for the event to be signaled
                    waitHandle.WaitOne();

                    workflowRuntime.StopRuntime();
                    Console.WriteLine("Program Complete.");
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("Exception occurred: " + exception.Message);
            }
        }
        static void Main(string[] args)
        {
            using(WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                AutoResetEvent waitHandle = new AutoResetEvent(false);
                workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) {waitHandle.Set();};
                workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
                {
                    Console.WriteLine(e.Exception.Message);
                    waitHandle.Set();
                };

                WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(WFOrderStatus.Workflow1));
                instance.Start();

                waitHandle.WaitOne();
            }
        }
Exemple #60
0
        static void Main(string[] args)
        {
            WorkflowRuntime workflowRuntime = new WorkflowRuntime();
            workflowRuntime.AddService(new Microsoft.Samples.Rules.ExternalRuleSetService.ExternalRuleSetService());

            AutoResetEvent waitHandle = new AutoResetEvent(false);
            workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) {waitHandle.Set();};
            workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
            {
                Console.WriteLine(e.Exception.Message);
                waitHandle.Set();
            };

            WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(GuestPassWorkflow));
            instance.Start();

            waitHandle.WaitOne();
        }