Ejemplo n.º 1
0
        public async Task Bookmarks()
        {
            var root = new Flowchart()
            {
                Id        = "Ref0",
                Variables = new List <IVariable>
                {
                    new Variable()
                    {
                        Name = "X", Dir = VariableDirection.InOut, Type = VariableType.Number
                    },
                },
                Nodes = new List <FlowNode>()
                {
                    new FlowStart()
                    {
                        Id = "Ref1", Next = "Ref2"
                    },
                    new FlowDecision()
                    {
                        Id = "Ref2", Condition = "X > 0", Then = "Ref3"
                    },
                    new FlowActivity()
                    {
                        Id       = "Ref3", Next = "Ref2",
                        Activity = new Sequence()
                        {
                            Id         = "Ref4",
                            Activities = new List <IActivity>()
                            {
                                new Wait()
                                {
                                    Id = "Ref5", Bookmark = "BM1"
                                },
                                new Code()
                                {
                                    Id = "Ref6", Script = "X -= 1"
                                }
                            }
                        }
                    }
                }
            };

            var wfe  = TestEngine.CreateInMemoryEngine();
            var inst = await wfe.CreateAsync(root, null);

            inst = await wfe.RunAsync(inst.Id, new { X = 5 });

            var result = inst.Result;

            Assert.AreEqual(5, result.Get <Int32>("X"));
            //var id = inst.Id;

            int x = result.Get <Int32>("X");

            while (x > 0)
            {
                var resInst = await wfe.ResumeAsync(inst.Id, "BM1");

                x = resInst.Result.Get <Int32>("X");
            }
            Assert.AreEqual(0, x);
        }
Ejemplo n.º 2
0
        public async Task ParallelGateway()
        {
            var process = new Process()
            {
                Id           = "process",
                IsExecutable = true,
                Children     = new List <BaseElement>()
                {
                    new StartEvent()
                    {
                        Id       = "start",
                        Children = new List <BaseElement>()
                        {
                            new Outgoing()
                            {
                                Text = "start->gate1"
                            }
                        }
                    },
                    new ParallelGateway()
                    {
                        Id       = "gate1",
                        Children = new List <BaseElement>()
                        {
                            new Incoming()
                            {
                                Text = "start->gate1"
                            },
                            new Outgoing()
                            {
                                Text = "gate1->task1"
                            },
                            new Outgoing()
                            {
                                Text = "gate1->task2"
                            },
                            new Script()
                            {
                                Text = ""
                            }
                        }
                    },
                    new ScriptTask()
                    {
                        Id       = "task1",
                        Children = new List <BaseElement>()
                        {
                            new Incoming()
                            {
                                Text = "gate1->task1"
                            },
                            new Outgoing()
                            {
                                Text = "task1->gate2"
                            }
                        }
                    },
                    new ScriptTask()
                    {
                        Id       = "task2",
                        Children = new List <BaseElement>()
                        {
                            new Incoming()
                            {
                                Text = "gate1->task2"
                            },
                            new Outgoing()
                            {
                                Text = "task2->gate2"
                            }
                        }
                    },
                    new ParallelGateway()
                    {
                        Id       = "gate2",
                        Children = new List <BaseElement>()
                        {
                            new Incoming()
                            {
                                Text = "task1->gate2"
                            },
                            new Incoming()
                            {
                                Text = "task2->gate2"
                            },
                            new Outgoing()
                            {
                                Text = "gate2->end",
                            }
                        },
                    },
                    new EndEvent()
                    {
                        Id       = "end",
                        Children = new List <BaseElement>()
                        {
                            new Incoming()
                            {
                                Text = "script->end"
                            }
                        }
                    },
                    new SequenceFlow()
                    {
                        Id = "start->gate1", SourceRef = "start", TargetRef = "gate1"
                    },
                    new SequenceFlow()
                    {
                        Id = "gate1->task1", SourceRef = "gate1", TargetRef = "task1"
                    },
                    new SequenceFlow()
                    {
                        Id = "gate1->task2", SourceRef = "gate1", TargetRef = "task2"
                    },
                    new SequenceFlow()
                    {
                        Id = "task1->gate2", SourceRef = "task1", TargetRef = "gate2"
                    },
                    new SequenceFlow()
                    {
                        Id = "task2->gate2", SourceRef = "task2", TargetRef = "gate2"
                    },
                    new SequenceFlow()
                    {
                        Id = "gate2->end", SourceRef = "gate2", TargetRef = "end"
                    }
                }
            };

            var wfe  = TestEngine.CreateInMemoryEngine();
            var inst = await wfe.CreateAsync(process, null);

            await wfe.RunAsync(inst.Id);
        }