Esempio n. 1
0
        public void Run()
        {
            wfHostTypeName = XName.Get("Version" + Guid.NewGuid().ToString(),
                                       typeof(Workflow1).FullName);
            this.instanceStore  = SetupSqlpersistenceStore();
            this.instanceHandle = CreateInstanceStoreOwnerHandle(
                instanceStore, wfHostTypeName);
            WorkflowApplication wfApp = CreateWorkflowApp();

            wfApp.Run();
            while (true)
            {
                this.waitHandler.WaitOne();
                if (completed)
                {
                    break;
                }
                WaitForRunnableInstance(this.instanceHandle);
                wfApp = CreateWorkflowApp();
                try
                {
                    wfApp.LoadRunnableInstance();
                    waitHandler.Reset();
                    wfApp.Run();
                }
                catch (InstanceNotReadyException)
                {
                    Console.WriteLine("Handled expected InstanceNotReadyException, retrying...");
                }
            }
            Console.WriteLine("workflow completed.");
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            SqlWorkflowInstanceStore store = new SqlWorkflowInstanceStore(persistenceConn);

            // Create a unique name that is used to associate instances in the instance store hosts that can load them. This is needed to prevent a Workflow host from loading
            // instances that have different implementations. The unique name should change whenever the implementation of the workflow changes to prevent workflow load exceptions.
            // For the purposes of the demo we create a unique name every time the program is run.
            XName wfHostTypeName = XName.Get("Version" + Guid.NewGuid().ToString(), typeof(Workflow1).FullName);

            // Create an InstanceStore owner that is associated with the workflow type
            InstanceHandle ownerHandle = CreateInstanceStoreOwner(store, wfHostTypeName);

            // Create a WorkflowApplication instance to start a new workflow
            WorkflowApplication wfApp = CreateWorkflowApplication(new Workflow1(), store, wfHostTypeName);

            // This will create the workflow and execute it until the delay is executed, the workflow goes idle, and is unloaded
            wfApp.Run();

            // This loop handles re-loading workflows that have been unloaded due to durable timers
            while (true)
            {
                // Wait for workflow to unload
                workflowUnloadedEvent.WaitOne();

                // Break the loop once the workflow has completed
                if (workflowCompleted)
                {
                    break;
                }

                // Wait for a timer registered by the delay to expire and the workflow instance to become "runnable" again
                WaitForRunnableInstance(store, ownerHandle);

                // Create a new WorkflowApplication instance to host the re-loaded workflow
                wfApp = CreateWorkflowApplication(new Workflow1(), store, wfHostTypeName);

                try
                {
                    // Re-load the runnable workflow instance and run it
                    wfApp.LoadRunnableInstance();

                    workflowUnloadedEvent.Reset();

                    wfApp.Run();
                }
                catch (InstanceNotReadyException)
                {
                    Console.WriteLine("Handled expected InstanceNotReadyException, retrying...");
                }
            }

            Console.WriteLine("Sample finished, hit enter to close");
            Console.ReadLine();
        }