Esempio n. 1
0
        public void Test08()
        {
            var code = @"
                new Stage
                    ID = 'MyStage'
                    Name = 'MySweetStage'
                    Procs
                        add p1 = new Process
                            ID = 'PROCP1'
                            Name = 'MyPROCP1'
                        add p2 = new Process
                        add p3 = new Process
            ";
            var jac  = new JacInterpreter();

            jac.Exec(code);
            //--------------------------------------------------------
            code = $@"
                MyStage               // To find Stage object named 'MyStage'
                    Procs
                        remove PROCP1   // find JitProcess instance by ID (not by ID as string)
                        remove p2       // find JitProcess instance by variable
            ";
            jac.Exec(code);
            var MyStage      = jac.GetStage("MyStage");
            var MySweetStage = jac.GetStage("MySweetStage");

            Assert.IsNotNull(MyStage);
            Assert.IsNotNull(MySweetStage);
            Assert.AreEqual(MyStage, MySweetStage);
            Assert.AreEqual(MyStage.GetChildProcesses().Count(), 1);
        }
Esempio n. 2
0
        public void Test06_2()
        {
            var code = @"
                st = new Stage
                    Procs
                        add new Process
                            ID = 'IgnoreProcess'
            ";
            var jac  = new JacInterpreter();

            jac.Exec(code);
            Assert.IsNotNull(jac.GetProcess("IgnoreProcess"));

            code = @"
                st
                    Procs
                        remove IgnoreProcess
            ";
            jac.Exec(code);
            Assert.IsNull(jac.GetProcess("IgnoreProcess"));

            code = @"
                st
                    Procs
                        add IgnoreProcess   // Expected cannot add removed process.
            ";
            jac.Exec(code);
            Assert.IsNull(jac.GetProcess("IgnoreProcess"));   // CANNOT ADD After Removed
        }
Esempio n. 3
0
        public void Test06_3()
        {
            var code = @"
                st = new Stage
                p1 = new Process
                    ID = 'IgnoreProcess'
            ";
            var jac  = new JacInterpreter();

            jac.Exec(code);
            Assert.IsNotNull(jac.GetProcess("IgnoreProcess"));

            code = @"
                st
                    Procs
                        add IgnoreProcess
            ";
            jac.Exec(code);
            Assert.IsNotNull(jac.GetProcess("IgnoreProcess"));

            code = @"
                st
                    Procs
                        remove IgnoreProcess
            ";
            jac.Exec(code);
            Assert.IsNull(jac.GetProcess("IgnoreProcess"));
        }
Esempio n. 4
0
        public void Test06_1()
        {
            var code = @"
                st = new Stage
                    Procs
                        add new Process
                        add new Process
                            ID = 'IgnoreProcess'
            ";
            var jac  = new JacInterpreter();

            jac.Exec(code);
            Assert.IsNotNull(jac.GetProcess("IgnoreProcess"));
            var name = jac.GetProcess("IgnoreProcess").Name;

            Assert.IsNotNull(jac.GetProcess(name));
            //--------------------------------------------------------
            code = $@"
                st
                    Procs
                        remove    IgnoreProcess  // Can specify ID (Cannot specify 'IgnoreProcess' as string)
            ";
            jac.Exec(code);
            Assert.AreEqual(jac.GetStage("st")?.GetChildProcesses().Count(), 1);
            Assert.AreNotEqual(jac.GetStage("st")?.GetChildProcess(0).Name, "IgnoreProcess");
            Assert.IsNull(jac.GetProcess("IgnoreProcess")); // removed from VarBuffer
            Assert.IsNull(jac.GetProcess(name));            // removed from InstanceBuffer
        }
Esempio n. 5
0
        public void Test34()
        {
            var code = @"
                st = new Stage
                    Works
                        add datetime('2020/7/31 9:00:00'):new Work
                            Name = 'Work1'
            ";
            var jac  = new JacInterpreter();

            jac.Exec(code);
            var st  = jac.GetStage("st");
            var dat = st.Events.Peeks(99).ToList();

            Assert.IsTrue(CMP(dat[0], "Work1", EventTypes.Out, $"9:00"));

            code = @"
                st
                    Works
                        remove Work1    // remove command is for GUI(undo) only.
            ";
            jac.Exec(code);
            dat = st.Events.Peeks(99).ToList();
            Assert.AreEqual(0, dat.Count);
        }
Esempio n. 6
0
        public void Test26()
        {
            var code = @"
                p1 = new Process
                    ID = 'AAA123'
                AAA123
                    Cio
                        add o1 = new CoSpan
                            ID = 'SPANCONSTRAINTID'
                            Span = 0.1H
                            PorlingSpan = 1S
            ";
            var jac  = new JacInterpreter();

            jac.Exec(code);
            var p1 = jac["p1"] as JitProcess;
            var o1 = p1.Cios.FirstOrDefault() as CoSpan;

            Assert.IsNotNull(o1);
            Assert.AreEqual(o1.Span, TimeSpan.FromHours(0.1));
            Assert.AreEqual(o1.PorlingSpan, TimeSpan.FromSeconds(1.0));

            code = @"
                SPANCONSTRAINTID
                    Span = 0.2H
                    PorlingSpan = 1.2S
            ";
            jac.Exec(code);
            o1 = p1.Cios.FirstOrDefault() as CoSpan;
            Assert.IsNotNull(o1);
            Assert.AreEqual(o1.Span, TimeSpan.FromHours(0.2));
            Assert.AreEqual(o1.PorlingSpan, TimeSpan.FromSeconds(1.2));
        }
Esempio n. 7
0
        public void Test17()
        {
            var code = @"
                new Stage
                    Procs
                        add sink = new Process
                            Name = 'SinkProc'
                        add p1 = new Process
                            Name = 'MyProc'
                            Cio
                                add o1 = new CoJoinFrom
                                    PullFromProcessKey = 'SinkProc'
                                    ChildWorkKey = 'TEPA'
                                    PorlingSpan = 0.5M                                    
            ";
            var jac  = new JacInterpreter();

            jac.Exec(code);
            var o1 = jac["o1"] as CoJoinFrom;

            Assert.IsNotNull(o1);
            Assert.AreEqual(o1.PullFromProcessKey, jac.GetProcess("SinkProc").Name);
            Assert.AreEqual(o1.ChildWorkKey, "TEPA");
            Assert.AreEqual(o1.PorlingSpan, TimeSpan.FromSeconds(30));
        }
Esempio n. 8
0
        public void Test02()
        {
            var code = @"
                st = new Stage
                    Procs
                        add b  = new Process
                            Name = 'AAA'
                            Name = 'aaa'
                        add c=new Process
                            ID = 'IDFINDB'  // Try to find by ID
                            Name = 'BBB'
                            Name = 'bbb'
            ";
            var jac  = new JacInterpreter();

            jac.Exec(code);
            Assert.AreEqual(jac["st"].GetType(), typeof(JitStage));

            Assert.AreEqual(jac["b"].GetType(), typeof(JitProcess));
            var b = jac["b"] as JitProcess;

            Assert.AreEqual(b.Name, "aaa");
            Assert.AreEqual(jac["c"].GetType(), typeof(JitProcess));
            var c = jac["c"] as JitProcess;         // get instance by variable

            Assert.AreEqual(c.Name, "bbb");

            var bbb = jac["IDFINDB"] as JitProcess;   // get instance by name

            Assert.AreEqual(c, bbb);
        }
Esempio n. 9
0
        public void Test27()
        {
            var code = @"
                p1 = new Process
                    ID = 'AAA123'
                AAA123
                    Cio
                        add o1 = new CoSpan
                            ID = 'SPANID'
                            Span = 0.1H
                            PorlingSpan = 1S
            ";
            var jac  = new JacInterpreter();

            jac.Exec(code);
            var p1 = jac["p1"] as JitProcess;
            var o1 = p1.Cios.FirstOrDefault() as CoSpan;

            Assert.IsNotNull(o1);
            Assert.AreEqual(o1.Span, TimeSpan.FromHours(0.1));
            Assert.AreEqual(o1.PorlingSpan, TimeSpan.FromSeconds(1.0));

            var code2 = @$ "
                AAA123
                    Cio
                        remove SPANID
            ";

            jac.Exec(code2);
            var ciosCount = p1.Cios.Count();

            Assert.AreEqual(ciosCount, 0);
        }
Esempio n. 10
0
        public void Test31_TupleObject()
        {
            var code = @"
                t1 = 'tono':'saki'
                t2 = t1:'mana'
                t3 = t1:t2
            ";
            var jac  = new JacInterpreter();

            jac.Exec(code);
            var xt1 = jac["t1"];
            var xt2 = jac["t2"];
            var xt3 = jac["t3"];

            Assert.AreEqual(xt1.GetType(), typeof(ValueTuple <object, object>));
            Assert.AreEqual(xt2.GetType(), typeof(ValueTuple <object, object>));
            Assert.AreEqual(xt3.GetType(), typeof(ValueTuple <object, object>));
            var t1 = (ValueTuple <object, object>)xt1;
            var t2 = (ValueTuple <object, object>)xt2;
            var t3 = (ValueTuple <object, object>)xt3;

            Assert.AreEqual(t1.Item1, "tono");
            Assert.AreEqual(t1.Item2, "saki");
            var t21 = (ValueTuple <object, object>)t2.Item1;

            Assert.AreEqual(t21.Item1, "tono");
            Assert.AreEqual(t21.Item2, "saki");
            Assert.AreEqual(t2.Item2, "mana");
            var t32 = (ValueTuple <object, object>)t3.Item2;

            Assert.AreEqual(t32.Item2, "mana");
        }
Esempio n. 11
0
        public void Test10()
        {
            var code = @"
                new Stage
                    Procs
                        add p1 = new Process
                            Name = 'PROCP1'
                            Cio
                                add new CoSpan
                                    Span = 11S
                                add new CiDelay
                                    Delay = 66M
            ";
            var jac  = new JacInterpreter();

            jac.Exec(code);
            var proc = jac.GetProcess("p1");

            Assert.IsNotNull(proc);

            var span = proc.Cios.Select(a => a as CoSpan).Where(a => a != null).FirstOrDefault();

            Assert.AreEqual(span.Span, TimeSpan.FromSeconds(11));
            var delay = proc.Cios.Select(a => a as CiDelay).Where(a => a != null).FirstOrDefault();

            Assert.AreEqual(delay.Delay, TimeSpan.FromMinutes(66));
        }
Esempio n. 12
0
 public void Test21()
 {
     try
     {
         var code = @"
             t1 = new TestJitClass
         ";
         var jac  = new JacInterpreter();
         jac.Exec(code);
     }
     catch (JacException ex)
     {
         Assert.AreEqual(ex.Code, JacException.Codes.TypeNotFound);
     }
     try
     {
         var code = @"
             t1 = new TestJitClass
         ";
         JacInterpreter.RegisterJacTarget(typeof(TestJitClass).Assembly);
         var jac = new JacInterpreter();
         jac.Exec(code);
     }
     catch (JacException)
     {
         Assert.Fail();
     }
 }
Esempio n. 13
0
        public void Test13_4()
        {
            var code = @"
                h = new Variable
                    Value = 1.23e-10
            ";
            var jac  = new JacInterpreter();

            jac.Exec(code);
            Assert.AreEqual(jac.GetVariable("h").Value, 1.23e-10);
        }
Esempio n. 14
0
        public void Test13_3()
        {
            var code = @"
                cmd2 = new Variable
                    Value = -1.234e-2S
            ";
            var jac  = new JacInterpreter();

            jac.Exec(code);
            Assert.AreEqual(jac.GetVariable("cmd2").Value, TimeSpan.FromSeconds(-1.234e-2));
        }
Esempio n. 15
0
        public void Test13_2()
        {
            var code = @"
                bm = new Variable
                    Value = -123
            ";
            var jac  = new JacInterpreter();

            jac.Exec(code);
            Assert.AreEqual(jac.GetVariable("bm").Value, -123);
        }
Esempio n. 16
0
        public void Test14_2()
        {
            var code = @"
                st = new Stage
                    Procs
                        add p1 = new Process
                            Name = 'PROCP1'
                            Cio
                                add i1 = new CiPickTo
                                    Delay = 1.5M
                                    TargetWorkClass = ':Car'
                                    DestProcessKey = 'SUPERLAZY'
            ";
            var jac  = new JacInterpreter();

            jac.Exec(code);
            var st = jac.GetStage("st");

            var i1 = jac["i1"] as CiPickTo;

            Assert.IsNotNull(i1);
            var i1dest = st.FindChildProcess("SUPERLAZY", isReturnNull: true);

            Assert.IsNull(i1dest);  // Expected Null because of no registered yet.

            var code2 = @"
                st
                    Procs
                        add p2 = new Process
                            Name = 'SUPERLAZY'
            ";

            jac.Exec(code2);
            i1dest = st.FindChildProcess("SUPERLAZY", isReturnNull: true);
            var p2 = jac.GetProcess("p2");

            Assert.AreEqual(i1dest, p2);                             // Then FindProcess can find p2 named SUPERLAZY

            i1dest = st.FindChildProcess(p2.ID, isReturnNull: true); // You can also find by ID
            Assert.AreEqual(i1dest, p2);
        }
Esempio n. 17
0
        public void Test06_4()
        {
            var code = @"
                st = new Stage
                    Procs
                        add new Process
                            ID = 'IgnoreProcess'
            ";
            var jac  = new JacInterpreter();

            jac.Exec(code);
            Assert.IsNotNull(jac.GetProcess("IgnoreProcess"));

            code = @"
                st
                    Procs
                        remove IgnoreProcess
                        add IgnoreProcess           // Expected success add because there is in the same jac code.
            ";
            jac.Exec(code);
            Assert.IsNotNull(jac.GetProcess("IgnoreProcess"));
        }
Esempio n. 18
0
        public void Test33_3()
        {
            var code = @"
                st = new Stage
                w1 = new Work
                    Name = 'Work1'
            ";
            var jac  = new JacInterpreter();

            jac.Exec(code);
            var st = jac.GetStage("st");

            code = @"
                st
                    Works
                        add datetime('2020/7/31 9:00:00'):Work1
            ";
            jac.Exec(code);
            var dat = st.Events.Peeks(99).ToList();

            Assert.IsTrue(CMP(dat[0], "Work1", EventTypes.Out, $"9:00"));
        }
Esempio n. 19
0
        public void Test07()
        {
            var code = @"
                st = new Stage
                    Procs
                        add p1 = new Process
                            ID = 'PROCP1'
                        add p2 = new Process
            ";
            var jac  = new JacInterpreter();

            jac.Exec(code);
            //--------------------------------------------------------
            code = $@"
                st
                    Procs
                        remove PROCP1   // Can specify ID (Cannot specify 'PROCP1' as string)
                        remove p2
            ";
            jac.Exec(code);
            Assert.AreEqual(jac.GetStage("st")?.GetChildProcesses().Count(), 0);
        }
Esempio n. 20
0
        public void Test09()
        {
            var code = @"
                new Stage
                    Procs
                        add p1 = new Process
                            ID = 'PROCP1'
                        add p2 = new Process
                    ID = 'MyStage'
            ";
            var jac  = new JacInterpreter();

            jac.Exec(code);
            //--------------------------------------------------------
            code = $@"
                MyStage                 // You can also to find with variable name 'MyStage'
                    Procs
                        remove PROCP1   // find JitProcess instance by ID
                        remove p2       // find JitProcess instance by variable
            ";
            jac.Exec(code);
            Assert.AreEqual(jac.GetStage("MyStage")?.GetChildProcesses().Count(), 0);
        }
Esempio n. 21
0
        public void Test15()
        {
            var code = @"
                s = new CiSwitchNextLink
                    NextLinkVarName = 'NextLinkNo2' // Try to auto cast from string to JitVariable
            ";
            var jac  = new JacInterpreter();

            jac.Exec(code);
            var s = jac["s"] as CiSwitchNextLink;

            Assert.IsNotNull(s);
            Assert.AreEqual(s.NextLinkVarName, JitVariable.From("NextLinkNo2"));
        }
Esempio n. 22
0
        public void Test02()
        {
            var c   = @"
                te = new Template
                    Block
                        add 'st = new Stage'
                        add 'p1 = new Process'
                        add 'w1 = new Work'
                        add 'k1 = new Kanban'
            ";
            var jac = new JacInterpreter();

            jac.Exec(c);
            var te = jac.GetTemplate("te");

            Assert.IsNotNull(te);
            Assert.AreEqual(te.Count, 4);

            c = @"
                te
                    Block
                        add 'w2 = new Work'
                        add 'w3 = new Work'
                        add 'w4 = new Work'
            ";
            jac.Exec(c);
            Assert.AreEqual(te.Count, 7);

            c = @"
                te
                    Block
                        remove '::LAST::'
            ";
            jac.Exec(c);
            Assert.AreEqual(te.Count, 6);
        }
Esempio n. 23
0
        public void Test25()
        {
            var code = @"
                    Piyo = new TestJitClass
                        ChildValueA = 'abc'
                ";

            JacInterpreter.RegisterJacTarget(typeof(TestJitClass).Assembly);
            var jac = new JacInterpreter();

            jac.Exec(code);
            var Piyo = jac["Piyo"] as TestJitClass;

            Assert.IsNotNull(Piyo);
            Assert.IsTrue(Piyo.Contains("ChildValueA"));
            Assert.AreEqual(Piyo["ChildValueA"], "abc");

            code = $@"
                Piyo.ChildValueB = 'def'
            ";
            jac.Exec(code);
            Assert.IsTrue(Piyo.Contains("ChildValueB"));
            Assert.AreEqual(Piyo["ChildValueB"], "def");
        }
Esempio n. 24
0
        public void Test05()
        {
            var code = @"
                st = new Stage
                    Procs
                        add new Process
                        add new Process
                            Name = 'IgnoreProcess'
            ";
            var jac  = new JacInterpreter();

            jac.Exec(code);
            //--------------------------------------------------------
            var st = jac["st"] as JitStage;

            code = $@"
                st
                    Procs
                        remove '{st.GetChildProcess(0).Name}'
            ";
            jac.Exec(code);
            Assert.AreEqual(st.GetChildProcesses().Count(), 1);
            Assert.AreEqual(st.GetChildProcess(0).Name, "IgnoreProcess");
        }
Esempio n. 25
0
        public void Test28()
        {
            var code = @"
                st = new Stage
                    Procs
                        add sink = new Process
                        add p1 = new Process
                            Name = 'PROCP1'
                            Cio
                                add pt = new CiPickTo
                                    Delay = 0MS
                                    TargetWorkClass = ':Car'
                                    DestProcessKey = sink.ID // To confirm Objct.Property style string set
            ";
            var jac  = new JacInterpreter();

            jac.Exec(code);
            var pt = jac["pt"] as CiPickTo;

            Assert.IsNotNull(pt);
            var p1 = jac.GetProcess("p1");

            Assert.IsNotNull(p1);
            var sink = jac.GetProcess("sink");

            Assert.IsNotNull(p1);
            var redo = $"{pt.ID}\r\n" +
                       $"    DestProcessKey = 'REDO_PROC'r\n";
            var undo = $"{pt.ID}\r\n" +
                       $"    DestProcessKey = '{sink.ID}'\r\n";

            Assert.AreEqual(pt.DestProcessKey, sink.ID);
            jac.Exec(redo);
            jac.Exec(undo);
            Assert.AreEqual(pt.DestProcessKey, sink.ID);
        }
Esempio n. 26
0
        public void Test01()
        {
            var c   = @"
                te = new Template
                    Block
                        add 'st = new Stage'
                    Name = 'MyTemp'
            ";
            var jac = new JacInterpreter();

            jac.Exec(c);
            Assert.AreEqual(jac["te"].GetType(), typeof(JitTemplate));
            Assert.IsNotNull(jac.GetTemplate("te"));
            Assert.AreEqual(jac.GetTemplate("te").Name, "MyTemp");
        }
Esempio n. 27
0
        public void Test11()
        {
            var code = @"
                a = 1MS
                b = 2S
                c = 3M
                d = 4H
                e = 5D
                f = 6W
            ";
            var jac  = new JacInterpreter();

            jac.Exec(code);
            Assert.AreEqual(jac["a"], TimeSpan.FromMilliseconds(1));
            Assert.AreEqual(jac["b"], TimeSpan.FromSeconds(2));
            Assert.AreEqual(jac["c"], TimeSpan.FromMinutes(3));
            Assert.AreEqual(jac["d"], TimeSpan.FromHours(4));
            Assert.AreEqual(jac["e"], TimeSpan.FromDays(5));
            Assert.AreEqual(jac["f"], TimeSpan.FromDays(6 * 7));
        }
Esempio n. 28
0
        public void Test01()
        {
            var c   = $@"
                st = new Stage
                    Procs
                        add b  = new Process
                            Name = 'AAA'
                            Name = 'aaa'
                        add new Process
                            Name = 'bbb'
            ";
            var jac = new JacInterpreter();

            jac.Exec(c);
            Assert.AreEqual(jac["st"].GetType(), typeof(JitStage));
            Assert.AreEqual(jac["b"].GetType(), typeof(JitProcess));
            var b = jac["b"] as JitProcess;

            Assert.AreEqual(b.Name, "aaa");
        }
Esempio n. 29
0
        public void Test12()
        {
            var code = @"
                a = 1.1MS
                b = 2.1S
                c = 3.1M
                d = 4.1H
                e = 5.1D
                f = 6.1W
            ";
            var jac  = new JacInterpreter();

            jac.Exec(code);
            Assert.AreEqual(jac["a"], TimeSpan.FromMilliseconds(1.1));
            Assert.AreEqual(jac["b"], TimeSpan.FromSeconds(2.1));
            Assert.AreEqual(jac["c"], TimeSpan.FromMinutes(3.1));
            Assert.AreEqual(jac["d"], TimeSpan.FromHours(4.1));
            Assert.AreEqual(jac["e"], TimeSpan.FromDays(5.1));
            Assert.AreEqual(jac["f"], TimeSpan.FromDays(6.1 * 7));
        }
Esempio n. 30
0
        public void Test04()
        {
            var code = @"
                st = new Stage
                    Procs
                        add new Process
                            BadName = 'ShouldBeError'
            ";

            try
            {
                var jac = new JacInterpreter();
                jac.Exec(code);
                var st = jac["st"] as JitStage;
            }
            catch (JacException ex)
            {
                Assert.AreEqual(ex.Code, JacException.Codes.NotImplementedProperty);
                Assert.IsTrue(ex.Message.Contains("BadName"));
            }
        }