Ejemplo n.º 1
0
        public async Task Parallel()
        {
            var root = new Parallel()
            {
                Id       = "Ref0",
                Branches = new List <IActivity> {
                    new Code()
                    {
                        Id = "Ref1", Script = "console.log('ref1')"
                    },
                    new Code()
                    {
                        Id = "Ref2", Script = "console.log('ref2')"
                    },
                    new Code()
                    {
                        Id = "Ref3", Script = "console.log('ref3')"
                    },
                }
            };

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

            await wfe.RunAsync(inst.Id);
        }
Ejemplo n.º 2
0
        public async Task NestedContext()
        {
            var root = new Sequence()
            {
                Id        = "Ref0",
                Variables = new List <IVariable> {
                    new Variable()
                    {
                        Name = "X", Dir = VariableDirection.In, Type = VariableType.Number
                    },
                    new Variable()
                    {
                        Name = "R", Dir = VariableDirection.Out, Type = VariableType.Number
                    },
                },
                Activities = new List <IActivity> {
                    new Code()
                    {
                        Id = "Ref1", Script = "X = X + 1"
                    },
                    new Code()
                    {
                        Id = "Ref2", Script = "X = X + 1"
                    },
                    new Sequence()
                    {
                        Id         = "Ref3",
                        Activities = new List <IActivity> {
                            new Code()
                            {
                                Id = "Ref4", Script = "X = X + 1"
                            },
                            new Code()
                            {
                                Id = "Ref5", Script = "X = X + 1"
                            },
                        }
                    },
                    new Code()
                    {
                        Id = "Ref7", Script = "R = X"
                    },
                }
            };

            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(9, result.Get <Int32>("R"));
        }
Ejemplo n.º 3
0
        public async Task Simple()
        {
            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 Code()
                        {
                            Id = "Ref4", 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(0, result.Get <Int32>("X"));

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

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

            result = inst.Result;
            Assert.AreEqual(0, result.Get <Int32>("X"));
        }
Ejemplo n.º 4
0
        public async Task Counter()
        {
            var root = new StateMachine()
            {
                Id        = "Ref0",
                Variables = new List <IVariable>
                {
                    new Variable()
                    {
                        Name = "X", Dir = VariableDirection.InOut, Type = VariableType.Number
                    },
                },
                States = new List <StateBase>()
                {
                    new StartState()
                    {
                        Id = "Ref1", Next = "Ref2"
                    },
                    new State()
                    {
                        Id    = "Ref2", Next = "Ref3",
                        Entry = new Code()
                        {
                            Id = "Ref21", Script = "X -=1"
                        },
                        Transitions = new List <Transition>()
                        {
                            new Transition()
                            {
                                Id = "Ref211", Condition = "X > 0", Destination = "Ref2"
                            }
                        }
                    },
                    new FinalState {
                        Id = "Ref3"
                    }
                }
            };

            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(0, result.Get <Int32>("X"));
        }
Ejemplo n.º 5
0
        public async Task If()
        {
            var root = new Sequence()
            {
                Id        = "Ref0",
                Variables = new List <IVariable> {
                    new Variable()
                    {
                        Name = "X", Dir = VariableDirection.In, Type = VariableType.Number
                    },
                    new Variable()
                    {
                        Name = "R", Dir = VariableDirection.Out, Type = VariableType.String
                    }
                },
                Activities = new List <IActivity> {
                    new If()
                    {
                        Id        = "Ref1",
                        Condition = "X > 5",
                        Then      = new Code()
                        {
                            Id = "Ref2", Script = "R = 'X > 5'"
                        },
                        Else = new Code()
                        {
                            Id = "Ref3", Script = "R = 'X <= 5'"
                        }
                    }
                }
            };

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

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

            Assert.AreEqual("X <= 5", inst.Result.Get <String>("R"));

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

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

            Assert.AreEqual("X > 5", inst.Result.Get <String>("R"));
        }
Ejemplo n.º 6
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.º 7
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);
        }