private static WorkflowApplicationInstance GetADummyWorkflowApplicationInstance()
        {
            WorkflowIdentity wfIdentity   = new WorkflowIdentity("GetAWorkflowApplicationInstanceParameter", new Version(1, 0), null);
            TestSequence     wfDefinition = new TestSequence()
            {
                Activities =
                {
                    new TestWriteLine("testWriteLine1",    "In TestWriteLine1"),
                    new TestReadLine <string>("ReadLine1", "testReadLine1"),
                    new TestWriteLine("testWriteLine2",    "In TestWriteLine2")
                },
            };

            WorkflowApplicationInstance waInstance;

            JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~");

            using (TestWorkflowRuntime workflowRuntime = TestRuntime.CreateTestWorkflowRuntime(wfDefinition, null, jsonStore, PersistableIdleAction.Unload))
            {
                //PersistenceProviderHelper pphelper = new PersistenceProviderHelper(workflowRuntime.PersistenceProviderFactoryType);
                //InstanceStore store = pphelper.CreateWorkflowInstanceStore();

                workflowRuntime.ExecuteWorkflow();
                workflowRuntime.WaitForIdle();
                workflowRuntime.UnloadWorkflow();
                workflowRuntime.WaitForUnloaded();

                Guid worklfowInstanceId = workflowRuntime.CurrentWorkflowInstanceId;
                waInstance = WorkflowApplication.GetInstance(worklfowInstanceId, jsonStore);
                waInstance.Abandon();
            }

            return(waInstance);
        }
        public static void TestResumeWithDelay()
        {
            var testSequence = new TestSequence()
            {
                Activities =
                {
                    new TestDelay()
                    {
                        Duration = TimeSpan.FromMilliseconds(100)
                    },
                }
            };

            JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~");
            TestWorkflowRuntime workflowRuntime = TestRuntime.CreateTestWorkflowRuntime(testSequence, null, jsonStore, PersistableIdleAction.Unload);

            workflowRuntime.ExecuteWorkflow();
            workflowRuntime.PersistWorkflow();
            workflowRuntime.WaitForUnloaded();
            workflowRuntime.LoadWorkflow();
            workflowRuntime.ResumeWorkflow();
            workflowRuntime.WaitForCompletion(false);
        }
Exemple #3
0
        public static void TestPersistDuringResumeBookmark()
        {
            bool              isSync      = true;
            Variable <int>    value       = VariableHelper.Create <int>("value");
            Variable <string> persist     = VariableHelper.Create <string>("persist");
            const string      WaitMessage = "Continue the WaitActivity";

            TestSequence testSequence = new TestSequence()
            {
                Variables  = { value, persist },
                Activities =
                {
                    new TestWriteLine()
                    {
                        Message = "Workflow Started"
                    },
                    new TestWaitForTrace()
                    {
                        DisplayName   = "WaitActivity",
                        TraceToWait   = WaitMessage,
                        DelayDuration = TimeSpan.FromMilliseconds(10)
                    },
                    new TestWaitReadLine <int>("Read", "Read")
                    {
                        BookmarkValue = value,
                        WaitTime      = TimeSpan.FromSeconds(1)
                    },
                    new TestReadLine <string>("PersistBookmark", "PersistBookmark")
                    {
                        BookmarkValue = persist
                    },
                    new TestWriteLine()
                    {
                        MessageExpression = ((env) => value.Get(env).ToString()),
                        HintMessage       = "9999"
                    }
                }
            };

            JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~");
            TestWorkflowRuntime workflowRuntime = TestRuntime.CreateTestWorkflowRuntime(testSequence, null, jsonStore, PersistableIdleAction.Unload);

            workflowRuntime.ExecuteWorkflow();
            workflowRuntime.WaitForActivityStatusChange("WaitActivity", TestActivityInstanceState.Executing);
            TestTraceManager.Instance.AddTrace(workflowRuntime.CurrentWorkflowInstanceId, new SynchronizeTrace(WaitMessage));
            SynchronizeTrace.Trace(workflowRuntime.CurrentWorkflowInstanceId, WaitMessage);

            if (isSync)
            {
                workflowRuntime.ResumeBookMark("Read", 9999);
                workflowRuntime.PersistWorkflow();
            }
            else
            {
                TestWorkflowRuntimeAsyncResult asyncResultResume  = workflowRuntime.BeginResumeBookMark("Read", 9999, null, null);
                TestWorkflowRuntimeAsyncResult asyncResultPersist = workflowRuntime.BeginPersistWorkflow(null, null);

                workflowRuntime.EndResumeBookMark(asyncResultResume);
                workflowRuntime.EndPersistWorkflow(asyncResultPersist);
            }

            workflowRuntime.WaitForActivityStatusChange("PersistBookmark", TestActivityInstanceState.Executing);
            workflowRuntime.WaitForUnloaded(1);
            workflowRuntime.LoadWorkflow();
            workflowRuntime.ResumeBookMark("PersistBookmark", "Yes");
            workflowRuntime.WaitForCompletion(false);
        }
Exemple #4
0
        public void DelayPersisted()
        {
            Variable <int>       counter  = new Variable <int>("Counter", 0);
            TestBlockingActivity blocking = new TestBlockingActivity("B");

            TestSequence seq = new TestSequence
            {
                Activities =
                {
                    new TestWriteLine("Before")
                    {
                        Message = "Before"
                    },
                    new TestDelay()
                    {
                        Duration = TimeSpan.FromSeconds(1)
                    },
                    new TestWriteLine("After")
                    {
                        Message = "After"
                    }
                }
            };

            TestSequence seq2 = new TestSequence
            {
                Activities =
                {
                    new TestWriteLine("Before")
                    {
                        Message = "Before"
                    },
                    new TestDelay()
                    {
                        Duration = TimeSpan.FromSeconds(1)
                    },
                    new TestWriteLine("After")
                    {
                        Message = "After"
                    }
                }
            };


            JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~");

            var instanceHandle = jsonStore.CreateInstanceHandle();
            var instanceView   = jsonStore.Execute(instanceHandle, new CreateWorkflowOwnerCommand(), TimeSpan.MaxValue);
            var instanceOwner  = instanceView.InstanceOwner;

            jsonStore.DefaultInstanceOwner = instanceOwner;

            //Guid id;
            using (TestWorkflowRuntime runtime =
                       TestRuntime.CreateTestWorkflowRuntime(seq, null, jsonStore, PersistableIdleAction.Unload))
            {
                runtime.ExecuteWorkflow();

                runtime.WaitForUnloaded();

                //id = runtime.CurrentWorkflowInstanceId;

                Thread.Sleep(TimeSpan.FromSeconds(2));

                //runtime.InitiateWorkflowForLoad();
                //runtime.LoadRunnableInitiatedWorkflowForInstance(/*TimeSpan.Zero, id*/);
                runtime.LoadRunnableWorkflow();

                runtime.ResumeWorkflow();

                runtime.WaitForCompletion();
            }
        }