Exemple #1
0
        public void UnloadFlowchartWhileExecutingFlowStep()
        {
            TestFlowchart flowchart = new TestFlowchart();

            TestBlockingActivity blocking = new TestBlockingActivity("Block");

            flowchart.AddStartLink(blocking);

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

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(flowchart, null, jsonStore, PersistableIdleAction.Unload))
            {
                testWorkflowRuntime.ExecuteWorkflow();

                testWorkflowRuntime.WaitForActivityStatusChange(blocking.DisplayName, TestActivityInstanceState.Executing);

                testWorkflowRuntime.UnloadWorkflow();

                testWorkflowRuntime.LoadWorkflow();


                testWorkflowRuntime.ResumeBookMark("Block", null);

                testWorkflowRuntime.WaitForCompletion();
            }
        }
Exemple #2
0
 public static void PersistAndUpdate(this TestWorkflowRuntime twRuntime, WorkflowIdentity updatedIdentity)
 {
     twRuntime.PersistWorkflow();
     twRuntime.UnloadWorkflow();
     if (null != updatedIdentity)
     {
         twRuntime.LoadAndUpdateWorkflow(updatedIdentity.ToString());
     }
     else
     {
         twRuntime.LoadWorkflow();
     }
     twRuntime.ResumeWorkflow();
 }
Exemple #3
0
        public void UnloadFlowchartWhileExecutingFlowSwitchExpression()
        {
            TestFlowchart flowchart = new TestFlowchart();

            TestWriteLine writeHello = new TestWriteLine("Hello", "Hello");

            TestWriteLine writeStart = new TestWriteLine("Start", "Start");

            TestExpressionEvaluatorWithBody <object> expressionActivity = new TestExpressionEvaluatorWithBody <object>
            {
                ExpressionResultExpression = context => "One",
                Body            = new TestBlockingActivity("Block"),
                WillBodyExecute = true
            };

            Dictionary <object, TestActivity> cases = new Dictionary <object, TestActivity>();

            cases.Add("One", writeHello);
            cases.Add("Two", new TestWriteLine("Two", "Two will not execute"));

            List <int> hints = new List <int>()
            {
                0
            };

            flowchart.AddStartLink(writeStart);

            flowchart.AddSwitchLink(writeStart, cases, hints, expressionActivity, new TestWriteLine("Default", "Will not execute"));

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

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(flowchart, null, jsonStore, PersistableIdleAction.Unload))
            {
                testWorkflowRuntime.ExecuteWorkflow();

                testWorkflowRuntime.WaitForActivityStatusChange(expressionActivity.DisplayName, TestActivityInstanceState.Executing);

                testWorkflowRuntime.UnloadWorkflow();

                testWorkflowRuntime.LoadWorkflow();

                testWorkflowRuntime.ResumeBookMark("Block", null);

                testWorkflowRuntime.WaitForCompletion();
            }
        }
Exemple #4
0
        public void TestAbortLoad()
        {
            Variable <int> value    = VariableHelper.Create <int>("value");
            TestSequence   sequence = new TestSequence()
            {
                Variables  = { value },
                Activities =
                {
                    new TestAssign <int>()
                    {
                        ToVariable = value,
                        Value      = 100
                    },
                    new TestPersist(),
                    new TestReadLine <int>("Read", "Read")
                    {
                        BookmarkValue = value
                    },
                    new TestWriteLine("AfterAbort")
                    {
                        MessageExpression = (env) => value.Get(env).ToString(),
                        HintMessage       = "9999"
                    }
                }
            };

            JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~");
            TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(sequence, null, jsonStore, PersistableIdleAction.Persist);

            runtime.ExecuteWorkflow();
            runtime.WaitForActivityStatusChange("Read", TestActivityInstanceState.Executing);
            runtime.PersistWorkflow();
            runtime.AbortWorkflow("Abort Workflow");
            //Wait Sometime to Handle to free
            Thread.CurrentThread.Join((int)TimeSpan.FromSeconds(4).TotalMilliseconds);
            //Load Workflow from Last Persistence Point
            runtime.LoadWorkflow();
            runtime.ResumeBookMark("Read", 9999);
            runtime.WaitForActivityStatusChange("AfterAbort", TestActivityInstanceState.Closed);

            //Wait for the second completion trace
            TestTraceManager.Instance.WaitForTrace(runtime.CurrentWorkflowInstanceId, new SynchronizeTrace(RemoteWorkflowRuntime.CompletedOrAbortedHandlerCalled), 1);

            //Call Abort on Completed Workflow, this should not throw exception
            runtime.AbortWorkflow("Abort on Completed Workflow");
        }
Exemple #5
0
        public void UnloadFlowchartWhileExecutingFlowConditionalCondition()
        {
            TestFlowchart flowchart = new TestFlowchart();

            TestExpressionEvaluatorWithBody <bool> expression = new TestExpressionEvaluatorWithBody <bool>(true)
            {
                Body            = new TestBlockingActivity("Block"),
                WillBodyExecute = true
            };

            TestFlowConditional conditional = new TestFlowConditional(HintTrueFalse.True)
            {
                ConditionValueExpression = expression
            };

            flowchart.AddConditionalLink(new TestWriteLine("Start", "Flowchart started"),
                                         conditional,
                                         new TestWriteLine("True", "True Action"),
                                         new TestWriteLine("False", "False Action"));


            JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(System.Environment.CurrentDirectory);

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(flowchart, null, jsonStore, PersistableIdleAction.Unload))
            {
                testWorkflowRuntime.ExecuteWorkflow();

                testWorkflowRuntime.WaitForActivityStatusChange(expression.DisplayName, TestActivityInstanceState.Executing);

                //testWorkflowRuntime.PersistWorkflow();
                testWorkflowRuntime.UnloadWorkflow();

                testWorkflowRuntime.LoadWorkflow();

                testWorkflowRuntime.ResumeBookMark("Block", null);

                testWorkflowRuntime.WaitForCompletion(true);
            }
        }
        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 #7
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 #8
0
        public static void TestOperationsResumeBookmarkCallback(int operationId)
        {
            Variable <int> value        = VariableHelper.Create <int>("value");
            const string   WaitMessage  = "WaitActivity will wait for this trace";
            TestSequence   testSequence = new TestSequence()
            {
                Variables  = { value },
                Activities =
                {
                    new TestWriteLine()
                    {
                        Message = "Workflow Started"
                    },
                    new TestWaitForTrace()
                    {
                        DisplayName = "WaitActivity",
                        TraceToWait = WaitMessage
                    },
                    new TestWaitReadLine <int>("Read", "Read")
                    {
                        BookmarkValue = value
                    },
                    new TestReadLine <int>("Read1", "Read1")
                    {
                        BookmarkValue = value
                    },
                    new TestWriteLine()
                    {
                        Message = "Workflow Completed"
                    }
                }
            };

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

            workflowRuntime.ExecuteWorkflow();
            workflowRuntime.WaitForActivityStatusChange("WaitActivity", TestActivityInstanceState.Executing);

            TestWorkflowRuntimeAsyncResult asyncResult = workflowRuntime.BeginResumeBookMark("Read", 10, new AsyncCallback(ResumeBookmarkCallback), operationId);

            //Continue the WaitActivity
            TestTraceManager.Instance.AddTrace(workflowRuntime.CurrentWorkflowInstanceId, new SynchronizeTrace(WaitMessage));
            SynchronizeTrace.Trace(workflowRuntime.CurrentWorkflowInstanceId, WaitMessage);
            workflowRuntime.EndResumeBookMark(asyncResult);
            workflowRuntime.WaitForTrace(new UserTrace("After ResumeBookmarkCallback"));

            if (operationId == 2)
            {
                //Do nothing
            }
            else if (operationId == 3)
            {
                workflowRuntime.UnloadWorkflow();
                workflowRuntime.LoadWorkflow();
                workflowRuntime.ExecuteWorkflow();
                workflowRuntime.ResumeBookMark("Read1", 99);
            }
            else if (operationId == 4)
            {
                workflowRuntime.LoadWorkflow();
                workflowRuntime.ExecuteWorkflow();
                workflowRuntime.ResumeBookMark("Read1", 99);
            }

            ExpectedTrace expectedTrace = testSequence.GetExpectedTrace();

            expectedTrace.AddIgnoreTypes(typeof(UserTrace));
            workflowRuntime.WaitForCompletion(expectedTrace);
        }