Exemple #1
0
        public static void Run()
        {
            using (WorkflowRuntimeManager manager
                       = new WorkflowRuntimeManager(new WorkflowRuntime()))
            {
                //start the runtime
                manager.WorkflowRuntime.StartRuntime();

                Console.WriteLine("Executing Workflow");
                //pass a number to test
                Dictionary <String, Object> wfArguments
                    = new Dictionary <string, object>();
                wfArguments.Add("TheNumber", 1);

                try
                {
                    //start the workflow
#if MARKUP_ONLY_RULES
                    WorkflowInstanceWrapper instance =
                        manager.StartWorkflow(
                            "MarkupOnlyRulesWorkflow.xoml",
                            "MarkupOnlyRulesWorkflow.rules",
                            wfArguments);
#else
                    WorkflowInstanceWrapper instance =
                        manager.StartWorkflow(
                            "MarkupOnlyWorkflow.xoml", null, wfArguments);
#endif
                }
                catch (WorkflowValidationFailedException e)
                {
                    foreach (ValidationError error in e.Errors)
                    {
                        Console.WriteLine(error.ErrorText);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                //wait for the workflow to complete
                manager.WaitAll(2000);
                Console.WriteLine("Completed Workflow\n\r");
            }
        }
Exemple #2
0
        /// <summary>
        /// Execute the SellItemWorkflow
        /// </summary>
        /// <param name="item"></param>
        private static void ExecuteWorkflow(
            WorkflowRuntimeManager manager, SalesItem item)
        {
            DisplaySalesItem(item, "Before");

            //create a dictionary with input arguments
            Dictionary <String, Object> wfArguments
                = new Dictionary <string, object>();

            wfArguments.Add("SalesItem", item);

            //execute the workflow
#if PRIORITY_TEST
            WorkflowInstanceWrapper instance = manager.StartWorkflow(
                typeof(SharedWorkflows.SellItemPriorityWorkflow), wfArguments);
#elif METHODS_TEST
            WorkflowInstanceWrapper instance = manager.StartWorkflow(
                typeof(SharedWorkflows.SellItemMethodsWorkflow), wfArguments);
#elif INVOKE_METHOD_TEST
            WorkflowInstanceWrapper instance = manager.StartWorkflow(
                typeof(SharedWorkflows.SellItemMethods2Workflow), wfArguments);
#elif UPDATE_TEST
            WorkflowInstanceWrapper instance = manager.StartWorkflow(
                typeof(SharedWorkflows.SellItemUpdateWorkflow), wfArguments);
#elif RULESET_IN_CODE_TEST
            WorkflowInstanceWrapper instance = manager.StartWorkflow(
                typeof(SharedWorkflows.SellItemInCodeWorkflow), wfArguments);
#elif SERIALIZED_RULESET_TEST
            WorkflowInstanceWrapper instance = manager.StartWorkflow(
                typeof(SharedWorkflows.SellItemSerializedWorkflow), wfArguments);
#else
            WorkflowInstanceWrapper instance = manager.StartWorkflow(
                typeof(SharedWorkflows.SellItemWorkflow), wfArguments);
#endif
            manager.WaitAll(5000);

            if (instance.Exception != null)
            {
                Console.WriteLine("EXCEPTION: {0}",
                                  instance.Exception.Message);
            }
            else
            {
                DisplaySalesItem(item, "After");
            }
        }
Exemple #3
0
        private void btnNewCar_Click(object sender, EventArgs e)
        {
#if CARWORKFLOWRECURSIVE
            _instanceWrapper
                = _workflowManager.StartWorkflow(
                      typeof(CarWorkflowRecursive), null);
#else
            _instanceWrapper
                = _workflowManager.StartWorkflow(
                      typeof(CarWorkflow), null);
#endif

            _instanceId = _instanceWrapper.WorkflowInstance.InstanceId;

            //enable the buttons
            EnableEventButtons(true);
            btnNewCar.Enabled = false;
        }
        public static void Run()
        {
            using (WorkflowRuntimeManager manager
                       = new WorkflowRuntimeManager(
                             new WorkflowRuntime("WorkflowRuntime")))
            {
                //add services to the workflow runtime
                AddServices(manager.WorkflowRuntime);
                manager.WorkflowRuntime.StartRuntime();

                //create a dictionary with input arguments
                Dictionary <String, Object> wfArguments
                    = new Dictionary <string, object>();

                //run the first workflow
                Console.WriteLine("Executing BalanceAdjustmentWorkflow");
                wfArguments.Add("Id", 101);
                wfArguments.Add("Adjustment", -25.00);
                WorkflowInstanceWrapper instance = manager.StartWorkflow(
                    typeof(SharedWorkflows.BalanceAdjustmentWorkflow),
                    wfArguments);
                manager.WaitAll(2000);

                Account account
                    = instance.OutputParameters["Account"] as Account;
                if (account != null)
                {
                    Console.WriteLine(
                        "Revised Account: {0}, Name={1}, Bal={2:C}",
                        account.Id, account.Name, account.Balance);
                }
                else
                {
                    Console.WriteLine("Invalid Account Id\n\r");
                }

                Console.WriteLine("Completed BalanceAdjustmentWorkflow\n\r");
            }
        }
Exemple #5
0
        public static void Run()
        {
            //create a workflow in code
            Activity workflow = CreateWorkflowInCode();

            //serialize the new workflow to a markup file
            SerializeToMarkup(workflow, "SerializedCodedWorkflow.xoml");

#if COMPILE_WORKFLOW
            //create a new assembly containing the workflow
            CompileWorkflow("SerializedCodedWorkflow.xoml",
                            "MyNewAssembly.dll");
#endif

            using (WorkflowRuntimeManager manager
                       = new WorkflowRuntimeManager(new WorkflowRuntime()))
            {
                //start the runtime
                manager.WorkflowRuntime.StartRuntime();

                Console.WriteLine("Executing Workflow");
                Dictionary <String, Object> wfArguments
                    = new Dictionary <string, object>();
                wfArguments.Add("TheNumber", 1);

                try
                {
#if COMPILE_WORKFLOW
                    //get a Type object for the newly compiled workflow
                    Type workflowType = Type.GetType(
                        "ProWF.MyNewWorkflowClass,MyNewAssembly");
                    //start the workflow using the Type
                    WorkflowInstanceWrapper instance =
                        manager.StartWorkflow(workflowType, wfArguments);
#else
                    //start the workflow
                    WorkflowInstanceWrapper instance =
                        manager.StartWorkflow(
                            "SerializedCodedWorkflow.xoml",
                            null, wfArguments);
#endif
                }
#if !COMPILE_WORKFLOW
                catch (WorkflowValidationFailedException e)
                {
                    foreach (ValidationError error in e.Errors)
                    {
                        Console.WriteLine(error.ErrorText);
                    }
                }
#endif
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                //wait for the workflow to complete
                manager.WaitAll(2000);
                Console.WriteLine("Completed Workflow\n\r");
            }
        }
Exemple #6
0
        public static void Run()
        {
            Console.WriteLine("Running test of WorkflowInstance methods");

            using (WorkflowRuntimeManager manager
                       = new WorkflowRuntimeManager(
                             new WorkflowRuntime("WorkflowRuntime")))
            {
                //add event handler to log messages from the manager
                manager.MessageEvent += delegate(
                    Object sender, WorkflowLogEventArgs e)
                {
                    Console.WriteLine(e.Message);
                };

                //start the workflow runtime. It will also autostart if
                //we don't do it here.
                manager.WorkflowRuntime.StartRuntime();

                //create a dictionary with input arguments
                Dictionary <String, Object> wfArguments
                    = new Dictionary <string, object>();
                wfArguments.Add("InputString", "one");
                //run the workflow
                WorkflowInstanceWrapper instance = manager.StartWorkflow(
                    typeof(SharedWorkflows.Workflow1), wfArguments);

                //manually terminate the workflow instance
                instance.WorkflowInstance.Terminate("Manually terminated");
                //wait for this instance to end
                instance.WaitHandle.WaitOne(10000, false);

                //run another instance with different parameters
                wfArguments.Clear();
                wfArguments.Add("InputString", "two");
                instance = manager.StartWorkflow(
                    typeof(SharedWorkflows.Workflow1), wfArguments);
                //give the workflow time to start execution
                System.Threading.Thread.Sleep(1000);

                //suspend the workflow
                instance.WorkflowInstance.Suspend("Manually suspended");
                //now resume the workflow we just suspended
                instance.WorkflowInstance.Resume();
                //wait for the instance to end
                instance.WaitHandle.WaitOne(10000, false);

                //display the results from all workflow instances
                foreach (WorkflowInstanceWrapper wrapper
                         in manager.Workflows.Values)
                {
                    if (wrapper.OutputParameters.ContainsKey("Result"))
                    {
                        Console.WriteLine(wrapper.OutputParameters["Result"]);
                    }
                    //must be a problem - see if there is an exception
                    if (wrapper.Exception != null)
                    {
                        Console.WriteLine("{0} - Exception: {1}",
                                          wrapper.Id, wrapper.Exception.Message);
                    }
                    //was it suspended?
                    if (wrapper.ReasonSuspended.Length > 0)
                    {
                        Console.WriteLine("{0} - Suspended: {1}",
                                          wrapper.Id, wrapper.ReasonSuspended);
                    }
                }
                manager.ClearAllWorkflows();
            }
        }