Example #1
0
        public LevelMainSs(MyDataClass dataClass)
            : base(MyStateID.Main, dataClass)
        {
            MySuperState level2   = new Level2Ss(this, dataClass);
            MySuperState recovery = new RecoverySs(this, dataClass);

            this.AddSubState(level2);
            this.AddSubState(recovery);

            // Register Started state transitions
            //notStarted.RegisterOnEventTransition(MyEventType.Start, new SpStateTransition(SpStateTransitionType.NextState, recovery, null));
            //notStarted.RegisterOnEventTransition(MyEventType.Abort, new SpStateTransition(SpStateTransitionType.ExitState, null, null));


            // Register OnResult so that the Superstate can handle its state's ExitState transitions
//            level2.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.NextState, recovery, null));

            level2.RegisterOnResultTransition(MyMsgId.Abort, new SpStateTransition <MyMsgId>(SpStateTransitionType.NextState, recovery, new MyTickMsg()));


            //// Register active state transitions
            //active.RegisterOnEventTransition(MyEventType.Stop, new SpStateTransition(SpStateTransitionType.NextState, idle, null));
            //active.RegisterOnEventTransition(MyEventType.Abort, new SpStateTransition(SpStateTransitionType.ExitState, null, null));


            //// Only on events registered.  On abor goes exit state


            this.SetEntryState(level2);
        }
Example #2
0
        public Level2Ss(ISpState <MyMsgId> parent, MyDataClass dataClass)
            : base(parent, MyStateID.Level2, dataClass)
        {
            MySuperState level3Ss = new Level3Ss(this, dataClass);

            //MyState active = new ActiveSt(this, dataClass);

            this.AddSubState(level3Ss);
            //this.AddSubState(active);


            //// Register Idle state transitions
            //idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Start), new SpStateTransition(SpStateTransitionType.NextState, active, null));
            ////idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            // results - this idle class just returns whatever msg we send in. So send Start and it will return it as its return value and provok this transition

            // Register as the result event from previous state comming from abort to it
            //level3Ss.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            //level3Ss.RegisterOnResultTransition(MyMsgId.Abort, new SpStateTransition<MyMsgId>(SpStateTransitionType.ExitState, null, new MyTickMsg()));
            level3Ss.RegisterOnResultTransition(MyMsgId.Abort, new SpStateTransition <MyMsgId>(SpStateTransitionType.ExitState, null, null));


            //// Register active state transitions
            //active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition(SpStateTransitionType.NextState, idle, null));
            //active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            //// results - this class just returns whatever msg we send in. So send Stop and it will return it as its return value and provok this transition
            //active.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition(SpStateTransitionType.NextState, idle, null));

            this.SetEntryState(level3Ss);
        }
Example #3
0
        public Level3Ss(ISpState <MyMsgId> parent, MyDataClass dataClass)
            : base(parent, MyStateID.Level3, dataClass)
        {
            MyState idle   = new IdleSt(this, dataClass);
            MyState active = new ActiveSt(this, dataClass);

            this.AddSubState(idle);
            this.AddSubState(active);

            // Register Idle state transitions
            //idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Start), new SpStateTransition<MyEventType>(SpStateTransitionType.NextState, active, null));
            idle.RegisterOnEventTransition(MyMsgId.Start, new SpStateTransition <MyMsgId>(SpStateTransitionType.NextState, active, null));
            //idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            // results - this idle class just returns whatever msg we send in. So send Start and it will return it as its return value and provok this transition
            //idle.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Start), new SpStateTransition<MyEventType>(SpStateTransitionType.NextState, active, null));
            idle.RegisterOnResultTransition(MyMsgId.Start, new SpStateTransition <MyMsgId>(SpStateTransitionType.NextState, active, null));


            // Register active state transitions
            //active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition<MyEventType>(SpStateTransitionType.NextState, idle, null));
            active.RegisterOnEventTransition(MyMsgId.Stop, new SpStateTransition <MyMsgId>(SpStateTransitionType.NextState, idle, null));
            //active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            // results - this class just returns whatever msg we send in. So send Stop and it will return it as its return value and provok this transition
            //active.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition<MyEventType>(SpStateTransitionType.NextState, idle, null));
            //active.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition<MyEventType>(SpStateTransitionType.ExitState, null, null));
            active.RegisterOnResultTransition(MyMsgId.Stop, new SpStateTransition <MyMsgId>(SpStateTransitionType.NextState, idle, null));
            active.RegisterOnResultTransition(MyMsgId.Abort, new SpStateTransition <MyMsgId>(SpStateTransitionType.ExitState, null, null));

            this.SetEntryState(idle);
        }
Example #4
0
        public Level2Ss(ISpState parent, MyDataClass dataClass)
            : base(parent, MyStateID.Level2, dataClass)
        {
            MySuperState level3Ss = new Level3Ss(this, dataClass);
            MyState active = new ActiveSt(this, dataClass);

            this.AddSubState(level3Ss);
            //this.AddSubState(active);

            //// Register Idle state transitions
            //idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Start), new SpStateTransition(SpStateTransitionType.NextState, active, null));
            ////idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            // results - this idle class just returns whatever msg we send in. So send Start and it will return it as its return value and provok this transition

            // Register as the result event from previous state comming from abort to it
            //level3Ss.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            level3Ss.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, new MyTickMsg()));

            //// Register active state transitions
            //active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition(SpStateTransitionType.NextState, idle, null));
            //active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            //// results - this class just returns whatever msg we send in. So send Stop and it will return it as its return value and provok this transition
            //active.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition(SpStateTransitionType.NextState, idle, null));

            this.SetEntryState(level3Ss);
        }
Example #5
0
    // Use this for initialization
    void Start()
    {
        MyData md = new MyData();

        md.x = 10;
        md.y = 20;

        ChangeData cd = new ChangeData();

        cd.change(md);
        print(md.x);
        print(md.y);

        cd.change(ref md);
        print(md.x);
        print(md.y);

        MyData m;

        m.x = 10;
        m.y = 20;
        cd.change(ref m);
        print(m.x);
        print(m.y);

        MyDataClass mdc = new MyDataClass();

        mdc.x = 10;
        mdc.y = 20;
        cd.change(mdc);
        print(mdc.x);
        print(mdc.y);
    }
Example #6
0
        public RecoverySs(ISpState <MyMsgId> parent, MyDataClass dataClass)
            : base(parent, MyStateID.Recovery, dataClass)
        {
            this.idle   = new IdleSt(this, dataClass);
            this.active = new ActiveSt(this, dataClass);

            this.AddSubState(this.idle);
            this.AddSubState(this.active);

            // Register Idle state transitions
            //idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Start), new SpStateTransition<MyEventType>(SpStateTransitionType.NextState, active, null));
            //idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition<MyEventType>(SpStateTransitionType.ExitState, null, null));

            //idle.RegisterOnEventTransition(MyEventType.Start, new SpStateTransition<MyEventType>(SpStateTransitionType.NextState, active, null));
            //idle.RegisterOnEventTransition(MyEventType.Abort, new SpStateTransition<MyEventType>(SpStateTransitionType.ExitState, null, null));
            this.idle.ToNextOnEvent(MyMsgId.Start, this.active);
            this.idle.ToExitOnEvent(MyMsgId.Abort);

            // Register active state transitions
            //active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition<MyEventType>(SpStateTransitionType.NextState, idle, null));
            //active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition<MyEventType>(SpStateTransitionType.ExitState, null, null));
            //active.RegisterOnEventTransition(MyEventType.Stop, new SpStateTransition<MyEventType>(SpStateTransitionType.NextState, idle, null));
            //active.RegisterOnEventTransition(MyEventType.Abort, new SpStateTransition<MyEventType>(SpStateTransitionType.ExitState, null, null));

            this.active.ToNextOnEvent(MyMsgId.Stop, this.idle);
            this.active.ToExitOnEvent(MyMsgId.Abort);

            // Only on events registered.  On abor goes exit state


            this.SetEntryState(idle);
        }
        public LevelMainSs(MyDataClass dataClass)
            : base(MyStateID.Main, dataClass)
        {
            MySuperState level2 = new Level2Ss(this, dataClass);
            MySuperState recovery = new RecoverySs(this, dataClass);

            this.AddSubState(level2);
            this.AddSubState(recovery);

            // Register Started state transitions
            //notStarted.RegisterOnEventTransition(MyEventType.Start, new SpStateTransition(SpStateTransitionType.NextState, recovery, null));
            //notStarted.RegisterOnEventTransition(MyEventType.Abort, new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            // Register OnResult so that the Superstate can handle its state's ExitState transitions
            //            level2.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.NextState, recovery, null));

            level2.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.NextState, recovery, new MyTickMsg()));

            //// Register active state transitions
            //active.RegisterOnEventTransition(MyEventType.Stop, new SpStateTransition(SpStateTransitionType.NextState, idle, null));
            //active.RegisterOnEventTransition(MyEventType.Abort, new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            //// Only on events registered.  On abor goes exit state

            this.SetEntryState(level2);
        }
        //[Test, Explicit]
        public void TestDeferedTransitionsInSuperState()
        {
            TestHelpers.CatchUnexpected(() => {
                // Setting flip count will cause back and fourth between active and idle
                MyDataClass dataClass     = new MyDataClass();
                MySuperState notStartedSs = new NotStartedSs(null, dataClass);
                ISpEventListner listner;
                SpStateMachineEngine engine = this.GetEngine(out listner, dataClass, notStartedSs);
                listner.MsgReceived        += this.helpers.ListnerMsgDumpDelegate;
                listner.ResponseReceived   += this.helpers.ListnerResponseDumpDelegate;

                engine.Start();
                Thread.Sleep(600);

                Assert.AreEqual("NotStarted.Idle", notStartedSs.CurrentStateName);

                listner.PostMessage(new MyBaseMsg(MyMsgType.SimpleMsg, MyMsgId.Start));
                Thread.Sleep(700);
                Assert.AreEqual("NotStarted.Active", notStartedSs.CurrentStateName);

                listner.PostMessage(new MyBaseMsg(MyMsgType.SimpleMsg, MyMsgId.Abort));
                Thread.Sleep(700);
                Assert.AreEqual("NotStarted.Idle", notStartedSs.CurrentStateName);

                listner.MsgReceived      -= this.helpers.ListnerMsgDumpDelegate;
                listner.ResponseReceived -= this.helpers.ListnerResponseDumpDelegate;


                Thread.Sleep(200);
                engine.Stop();
                engine.Dispose();
                Console.WriteLine("Engine Disposed");
            });
        }
        //[Test, Explicit]
        public void TestResultExitTickStateTransitionsInSuperState()
        {
            TestHelpers.CatchUnexpected(() => {
                MyDataClass dataClass = new MyDataClass();
                SS_M m = new SS_M(dataClass);
                ISpEventListner listner;
                SpStateMachineEngine engine = this.GetEngine(out listner, dataClass, m);

                listner.MsgReceived      += this.helpers.ListnerMsgDumpDelegate;
                listner.ResponseReceived += this.helpers.ListnerResponseDumpDelegate;

                engine.Start();

                this.DoTick(listner, m, "SS_M.SS_A1.SS_A1");
                this.DoTick(listner, m, "SS_M.SS_A1.SS_A1");
                this.DoTick(listner, m, "SS_M.SS_A1.SS_A1");
                // After third it should have transitioned and stays the same
                this.DoTick(listner, m, "SS_M.SS_B1.S_B1");
                this.DoTick(listner, m, "SS_M.SS_B1.S_B1");
                this.DoTick(listner, m, "SS_M.SS_B1.S_B1");

                engine.Stop();
                engine.Dispose();
                Console.WriteLine("Engine Disposed");
            });
        }
Example #10
0
    public void change(MyDataClass md)
    {
        int temp;

        temp = md.x;
        md.x = md.y;
        md.y = temp;
    }
Example #11
0
        public void AddData(string JSonPostDataStr)
        {
            Dictionary <string, string> dic = JSonUtility.GetJSonDic(JSonPostDataStr);

            MyDataClass DataClassObj = new MyDataClass(DateTime.Now.ToString("yyyyMMddHHmmss"), Convert.ToInt32(dic["para1"]), dic["para2"], Convert.ToSingle(dic["para3"]), DateTime.Now);

            DataCollection.Add(DataClassObj);
        }
Example #12
0
    public void Change(MyDataClass m)
    {
        int temp;

        temp = m.x;
        m.x  = m.y;
        m.y  = temp;
    }
Example #13
0
        public SS_A2(ISpState <MyMsgId> parent, MyStateID id, MyDataClass dataClass)
            : base(parent, id, dataClass)
        {
            // This super state will exit on entry of first state
            this.stDone = this.AddSubState(new S_ExitDoneOnEntry(this, MyStateID.S_A1_ExitEntry, dataClass));
            this.stDone.ToExitOnResult(MyMsgId.RespDone);

            this.SetEntryState(this.stDone);
        }
Example #14
0
        private static void PassingDataSample(IWorkflowRegistry registry, IWorkflowRuntime runtime)
        {
            MyDataClass initialData = new MyDataClass();

            initialData.Value1 = 2;
            initialData.Value2 = 3;
            runtime.StartWorkflow("PassingDataWorkflow", 1, initialData);
            Console.ReadLine();
        }
Example #15
0
        public SS_M(MyDataClass dataClass)
            : base(MyStateID.SS_M, dataClass)
        {
            this.ssA = this.AddSubState(new SS_A(this, dataClass));
            this.ssB = this.AddSubState(new SS_B(this, dataClass));

            this.ssA.ToNextOnResult(MyMsgId.RespDone, this.ssB);

            this.SetEntryState(this.ssA);
        }
Example #16
0
        public SS_A(ISpState <MyMsgId> parent, MyDataClass dataClass)
            : base(parent, MyStateID.SS_A1, dataClass)
        {
            this.doneSt = this.AddSubState(new S_A1(this, dataClass));

            // The Done state will trigger the exit on 4th ticks. The first tick causes the entry
            this.doneSt.ToExitOnResult(MyMsgId.RespDone);

            this.SetEntryState(this.doneSt);
        }
        public void CustomActionData()
        {
            string dataString  = "Key1=Value1;Key2=;Key3;Key4=Value=4;Key5";
            string dataString2 = "Key1=;Key2=Value2;Key3;Key4;Key6=Value;;6=6;Key7=Value7";

            CustomActionData data = new CustomActionData(dataString);

            Assert.AreEqual <string>(dataString, data.ToString());

            data["Key1"] = String.Empty;
            data["Key2"] = "Value2";
            data["Key4"] = null;
            data.Remove("Key5");
            data["Key6"] = "Value;6=6";
            data["Key7"] = "Value7";

            Assert.AreEqual <string>(dataString2, data.ToString());

            MyDataClass myData = new MyDataClass();

            myData.Member1 = "test1";
            myData.Member2 = "test2";
            data.AddObject("MyData", myData);

            string           myDataString = data.ToString();
            CustomActionData data2        = new CustomActionData(myDataString);

            MyDataClass myData2 = data2.GetObject <MyDataClass>("MyData");

            Assert.AreEqual <MyDataClass>(myData, myData2);

            List <string> myComplexDataObject = new List <string>();

            myComplexDataObject.Add("CValue1");
            myComplexDataObject.Add("CValue2");
            myComplexDataObject.Add("CValue3");

            CustomActionData myComplexData = new CustomActionData();

            myComplexData.AddObject("MyComplexData", myComplexDataObject);
            myComplexData.AddObject("NestedData", data);
            string myComplexDataString = myComplexData.ToString();

            CustomActionData myComplexData2       = new CustomActionData(myComplexDataString);
            List <string>    myComplexDataObject2 = myComplexData2.GetObject <List <string> >("MyComplexData");

            Assert.AreEqual <int>(myComplexDataObject.Count, myComplexDataObject2.Count);
            for (int i = 0; i < myComplexDataObject.Count; i++)
            {
                Assert.AreEqual <string>(myComplexDataObject[i], myComplexDataObject2[i]);
            }

            data2 = myComplexData2.GetObject <CustomActionData>("NestedData");
            Assert.AreEqual <string>(data.ToString(), data2.ToString());
        }
Example #18
0
        public void CustomActionData()
        {
            string dataString = "Key1=Value1;Key2=;Key3;Key4=Value=4;Key5";
            string dataString2 = "Key1=;Key2=Value2;Key3;Key4;Key6=Value;;6=6;Key7=Value7";

            CustomActionData data = new CustomActionData(dataString);
            Assert.AreEqual<string>(dataString, data.ToString());

            data["Key1"] = String.Empty;
            data["Key2"] = "Value2";
            data["Key4"] = null;
            data.Remove("Key5");
            data["Key6"] = "Value;6=6";
            data["Key7"] = "Value7";

            Assert.AreEqual<string>(dataString2, data.ToString());

            MyDataClass myData = new MyDataClass();
            myData.Member1 = "test1";
            myData.Member2 = "test2";
            data.AddObject("MyData", myData);

            string myDataString = data.ToString();
            CustomActionData data2 = new CustomActionData(myDataString);

            MyDataClass myData2 = data2.GetObject<MyDataClass>("MyData");
            Assert.AreEqual<MyDataClass>(myData, myData2);

            List<string> myComplexDataObject = new List<string>();
            myComplexDataObject.Add("CValue1");
            myComplexDataObject.Add("CValue2");
            myComplexDataObject.Add("CValue3");

            CustomActionData myComplexData = new CustomActionData();
            myComplexData.AddObject("MyComplexData", myComplexDataObject);
            myComplexData.AddObject("NestedData", data);
            string myComplexDataString = myComplexData.ToString();

            CustomActionData myComplexData2 = new CustomActionData(myComplexDataString);
            List<string> myComplexDataObject2 = myComplexData2.GetObject<List<string>>("MyComplexData");

            Assert.AreEqual<int>(myComplexDataObject.Count, myComplexDataObject2.Count);
            for (int i = 0; i < myComplexDataObject.Count; i++)
            {
                Assert.AreEqual<string>(myComplexDataObject[i], myComplexDataObject2[i]);
            }

            data2 = myComplexData2.GetObject<CustomActionData>("NestedData");
            Assert.AreEqual<string>(data.ToString(), data2.ToString());
        }
Example #19
0
        public SS_M2(MyDataClass dataClass)
            : base(MyStateID.SS_M2, dataClass)
        {
            //this.firstState = this.AddSubState(new EntryState(this, MyStateID.Level3, dataClass));
            this.ssADoneOnEntry = this.AddSubState(new SS_A2(this, MyStateID.SS_A1, dataClass));
            this.ssB            = this.AddSubState(new SS_B(this, dataClass));

            // Add first state to just handle initial tick
            //this.firstState.ToNextOnResult(MyMsgId.RespDone, this.ssADoneOnEntry);

            this.ssADoneOnEntry.ToNextOnResult(MyMsgId.RespDone, this.ssB);

            //this.SetEntryState(this.firstState);
            this.SetEntryState(this.ssADoneOnEntry);
        }
        static void Main(string[] args)
        {
            MyDataClass <int, string> obj1 = new MyDataClass <int, string>(1, "abc");
            MyDataClass <int, int>    obj2 = new MyDataClass <int, int>(1, 2);
            MyDataClass <double, int> obj3 = new MyDataClass <double, int>(1.55, 2);

            int a = obj1.retT();

            int b = obj2.retT();

            double c = obj3.retT();


            Console.ReadKey();
        }
Example #21
0
    public static void Main()
    {
        MyData md = new MyData();

        md.x = 10;
        md.y = 20;

        Console.WriteLine("最初の状態");
        Console.WriteLine("md.x = {0}, md.y = {1}", md.x, md.y);

        ChangeData cd = new ChangeData();

        cd.Change(md);
        Console.WriteLine("cd.Change(md)後");
        Console.WriteLine("md.x = {0}, md.y = {1}", md.x, md.y);

        cd.Change(ref md);
        Console.WriteLine("cd.Change(ref md)後");
        Console.WriteLine("md.x = {0}, md.y = {1}", md.x, md.y);


        MyData m;

        m.x = 10;
        m.y = 20;

        Console.WriteLine("最初の状態");
        Console.WriteLine("m.x = {0}, m.y = {1}", m.x, m.y);
        cd.Change(m);
        Console.WriteLine("cd.Change(md)後");
        Console.WriteLine("md.x = {0}, md.y = {1}", md.x, md.y);

        cd.Change(ref m);
        Console.WriteLine("cd.Change(ref m)後");
        Console.WriteLine("m.x = {0}, m.y = {1}", m.x, m.y);


        MyDataClass mdc = new MyDataClass();

        mdc.x = 10;
        mdc.y = 20;

        Console.WriteLine("最初の状態");
        Console.WriteLine("mdc.x = {0}, mdc.y = {1}", mdc.x, mdc.y);
        cd.Change(mdc);
        Console.WriteLine("cd.Change(mdc)後");
        Console.WriteLine("mdc.x = {0}, mdc.y = {1}", mdc.x, mdc.y);
    }
Example #22
0
        public void UpdateData(string JSonPostDataStr)
        {
            Dictionary <string, string> dic = JSonUtility.GetJSonDic(JSonPostDataStr);

            string RecordKey = dic["RecordKey"];

            MyDataClass DataClassObj = (from t in DataCollection where t.RecordKey == RecordKey select t).FirstOrDefault();

            if (DataClassObj != null)
            {
                DataClassObj.IntegerData  = Convert.ToInt32(dic["para1"]);
                DataClassObj.StringData   = dic["para2"];
                DataClassObj.FloatData    = Convert.ToSingle(dic["para3"]);
                DataClassObj.DateTimeData = Convert.ToDateTime(dic["para4"]);
            }
        }
        private SpStateMachineEngine GetEngine(out ISpEventListner listner, MyDataClass dataClass, ISpState <MyMsgId> firstState)
        {
            ISpStateMachine    sm       = new MyStateMachine(dataClass, firstState);
            ISpEventStore      store    = new SimpleDequeEventStore(new MyTickMsg());
            ISpBehaviorOnEvent behavior = new SpPeriodicWakeupOnly();
            ISpPeriodicTimer   timer    = new WinSimpleTimer(new TimeSpan(0, 0, 0, 0, 500));

            //ISpEventListner listner = new SimpleEventListner();
            listner = new SimpleEventListner();

            // To avoid log errors if no subscribers
            listner.ResponseReceived += new EventHandler((o, e) => { });

            // Simulates DI
            return(new SpStateMachineEngine(listner, store, behavior, sm, timer));
        }
Example #24
0
        public void TestDeferedTransitionsInSuperState()
        {
            TestHelpers.CatchUnexpected(() => {
                // Setting flip count will cause back and fourth between active and idle
                MyDataClass dataClass     = new MyDataClass();
                MySuperState notStartedSs = new NotStartedSs(null, dataClass);
                ISpStateMachine sm        = new MyStateMachine(dataClass, notStartedSs);

                //this.TickAndValidateState(new MyTickMsg(), sm, "NotStarted.Idle");
                //this.TickAndValidateState(new MyTickMsg(), sm, "NotStarted.Idle");

                this.TickAndValidateState(this.GetMsg(MyMsgId.Tick), sm, "NotStarted.Idle");
                this.TickAndValidateState(this.GetMsg(MyMsgId.Start), sm, "NotStarted.Active");
                this.TickAndValidateState(this.GetMsg(MyMsgId.Abort), sm, "NotStarted.Idle");
                this.TickAndValidateState(this.GetMsg(MyMsgId.Tick), sm, "NotStarted.Idle");
            });
        }
Example #25
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime lifetime)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            #region Workflow simple
            var workflowHost = app.ApplicationServices.GetRequiredService <IWorkflowHost>();

            workflowHost.RegisterWorkflow <Workflow1, MyDataClass>();

            workflowHost.Start();

            var myDataClass = new MyDataClass
            {
                Value1 = 1,
                Value2 = 2
            };

            workflowHost.StartWorkflow("Workflow1", data: myDataClass).Wait();

            //lifetime.ApplicationStopping.Register(() =>
            //{
            //    workflowHost.Stop();
            //});
            workflowHost.Stop();
            #endregion

            #region ScheduleWorkflow simple
            var scheduleWorkflowHost = app.ApplicationServices.GetRequiredService <IScheduleWorkflowHost>();

            scheduleWorkflowHost.StartAsync().Wait();

            scheduleWorkflowHost.RegisterScheduleWorkflow <ScheduleWorkflow1>("ScheduleWorkflow1");

            scheduleWorkflowHost.StartScheduleWorkflowAsync("ScheduleWorkflow1", "0/5 * * * * ?").Wait();

            lifetime.ApplicationStopping.Register(() =>
            {
                scheduleWorkflowHost.StopAsync().Wait();
            });
            #endregion
        }
Example #26
0
        public MainSs(MyDataClass dataClass)
            : base(MyStateID.Main, dataClass)
        {
            // Create and add the sub-states of this super state
            this.notStarted = new NotStartedSs(this, dataClass);
            this.recovery   = new RecoverySs(this, dataClass);
            this.AddSubState(this.notStarted);
            this.AddSubState(this.recovery);

            // Register Started state transitions


            //notStarted.RegisterOnEventTransition(MyEventType.Start, new SpStateTransition(SpStateTransitionType.NextState, recovery, null));
            //notStarted.RegisterOnEventTransition(MyEventType.Abort, new SpStateTransition(SpStateTransitionType.ExitState, null, null));


            // Register OnResult so that the Superstate can handle its state's ExitState transitions
            //            notStarted.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.NextState, recovery, null));

            // Register a transition based on on internal processing
            //notStarted.RegisterOnResultTransition(
            //    new SpEnumToInt(MyEventType.Abort),
            //    new SpStateTransition<MyEventType>(SpStateTransitionType.NextState,
            //    this.recovery, new MyTickMsg()));

            //notStarted.RegisterOnResultTransition(
            //    MyEventType.Abort,
            //    new SpStateTransition<MyEventType>(SpStateTransitionType.NextState,
            //    this.recovery, new MyTickMsg()));

            notStarted.ToNextOnResult(MyMsgId.Abort, this.recovery, new MyTickMsg());


            //// Register active state transitions
            //active.RegisterOnEventTransition(MyEventType.Stop, new SpStateTransition(SpStateTransitionType.NextState, idle, null));
            //active.RegisterOnEventTransition(MyEventType.Abort, new SpStateTransition(SpStateTransitionType.ExitState, null, null));


            //// Only on events registered.  On abor goes exit state


            //this.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.NextState, recovery, new MyTickMsg()));

            // Set the entry state as the not Started SS
            this.SetEntryState(this.notStarted);
        }
        public void Serializer_RoundTrip_Succeeds()
        {
            // Arrange
            string testDir = TestUtils.CreateTestSpecificFolder(this.TestContext);
            string filePath = Path.Combine(testDir, "file1.txt");

            MyDataClass original = new MyDataClass() { Value1 = "val1", Value2 = 22 };

            // Act - save and reload
            Serializer.SaveModel(original, filePath);
            MyDataClass reloaded = Serializer.LoadModel<MyDataClass>(filePath);

            // Assert
            Assert.IsNotNull(reloaded);
            Assert.AreEqual(original.Value1, reloaded.Value1);
            Assert.AreEqual(original.Value2, reloaded.Value2);
        }
        public void Serializer_ToString_Succeeds()
        {
            // Arrange
            MyDataClass inputData = new MyDataClass() { Value1 = "val1", Value2 = 22 };

            // Act
            string actual = Serializer.ToString(inputData);

            // Assert
            string expected = @"<?xml version=""1.0"" encoding=""utf-16""?>
            <MyDataClass xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
              <Value1>val1</Value1>
              <Value2>22</Value2>
            </MyDataClass>";

            Assert.AreEqual(expected, actual);
        }
        //[Test, Explicit]
        public void TestExitStateTransitionsInSuperState()
        {
            TestHelpers.CatchUnexpected(() => {
                // Setting flip count will cause back and fourth between active and idle
                MyDataClass dataClass = new MyDataClass();


                MySuperState mainSs = new MainSs(dataClass);
                ISpEventListner listner;
                SpStateMachineEngine engine = this.GetEngine(out listner, dataClass, mainSs);

                engine.Start();

                // Just move the inner states around
                Thread.Sleep(600);
                Assert.AreEqual("Main.NotStarted.Idle", mainSs.CurrentStateName);
                listner.PostMessage(new MyBaseMsg(MyMsgType.SimpleMsg, MyMsgId.Start));
                Thread.Sleep(600);

                Assert.AreEqual("Main.NotStarted.Active", mainSs.CurrentStateName);

                listner.PostMessage(new MyBaseMsg(MyMsgType.SimpleMsg, MyMsgId.Stop));
                Thread.Sleep(600);
                Assert.AreEqual("Main.NotStarted.Idle", mainSs.CurrentStateName);

                listner.PostMessage(new MyBaseMsg(MyMsgType.SimpleMsg, MyMsgId.Start));
                Thread.Sleep(600);
                Assert.AreEqual("Main.NotStarted.Active", mainSs.CurrentStateName);

                listner.PostMessage(new MyBaseMsg(MyMsgType.SimpleMsg, MyMsgId.Stop));
                Thread.Sleep(800);
                Assert.AreEqual("Main.NotStarted.Idle", mainSs.CurrentStateName);

                // Should be back to Main.NotStarted.Idle by now - it has a ExitState transition registered to that state
                Console.WriteLine("Sending the Abort event to provoke a ExitState transition");
                listner.PostMessage(new MyBaseMsg(MyMsgType.SimpleMsg, MyMsgId.Abort));
                Thread.Sleep(800);
                Assert.AreEqual("Main.Recovery.Idle", mainSs.CurrentStateName);


                engine.Stop();
                engine.Dispose();
                Console.WriteLine("Engine Disposed");
            });
        }
Example #30
0
        public void TestExitStateTransitionsInSuperState()
        {
            TestHelpers.CatchUnexpected(() => {
                // Setting flip count will cause back and fourth between active and idle
                MyDataClass dataClass = new MyDataClass();
                MySuperState mainSs   = new MainSs(dataClass);
                ISpStateMachine sm    = new MyStateMachine(dataClass, mainSs);

                //this.TickAndValidateState(new MyTickMsg(), sm, "Main.NotStarted");
                //this.TickAndValidateState(new MyTickMsg(), sm, "Main.NotStarted.Idle");
                this.TickAndValidateState(this.GetMsg(MyMsgId.Tick), sm, "Main.NotStarted.Idle");
                this.TickAndValidateState(this.GetMsg(MyMsgId.Start), sm, "Main.NotStarted.Active");
                this.TickAndValidateState(this.GetMsg(MyMsgId.Stop), sm, "Main.NotStarted.Idle");
                this.TickAndValidateState(this.GetMsg(MyMsgId.Abort), sm, "Main.Recovery.Idle");
                //this.TickAndValidateState(this.GetMsg(MyEventType.Tick), sm, "Main.Recovery.Idle");

                //Thread.Sleep(500);
            });
        }
Example #31
0
        public void DeleteData(string JSonPostDataStr)
        {
            Dictionary <string, string> dic = JSonUtility.GetJSonDic(JSonPostDataStr);
            string RecordKey = dic["RecordKey"];

            MyDataClass DataClassObj = null;

            foreach (MyDataClass t in DataCollection)
            {
                if (t.RecordKey == RecordKey)
                {
                    DataClassObj = t;
                }
            }

            if (DataClassObj != null)
            {
                DataCollection.Remove(DataClassObj);
            }
        }
        //[Test, Explicit]
        public void TestResultExitEntryStateTransitionsInSuperState()
        {
            TestHelpers.CatchUnexpected(() => {
                MyDataClass dataClass = new MyDataClass();
                SS_M2 m = new SS_M2(dataClass);
                ISpEventListner listner;
                SpStateMachineEngine engine = this.GetEngine(out listner, dataClass, m);

                engine.Start();
                // First tick will drive cascade of state changes because the first SS aborts on entry of first sub state entry
                this.DoTick(listner, m, "SS_M2.SS_B1.S_B1", true);

                Thread.Sleep(1000);
                Log.Warning(0, () => string.Format(" -*-*- Current state: {0} -*-*-", m.CurrentStateName));
                Thread.Sleep(1000);
                engine.Stop();
                engine.Dispose();
                Console.WriteLine("Engine Disposed");
            });
        }
Example #33
0
        public void Serializer_RoundTrip_Succeeds()
        {
            // Arrange
            var testDir  = TestUtils.CreateTestSpecificFolderWithSubPaths(TestContext);
            var filePath = Path.Combine(testDir, "file1.txt");

            var original = new MyDataClass()
            {
                Value1 = "val1", Value2 = 22
            };

            // Act - save and reload
            Serializer.SaveModel(original, filePath);
            var reloaded = Serializer.LoadModel <MyDataClass>(filePath);

            // Assert
            reloaded.Should().NotBeNull();
            reloaded.Value1.Should().Be(original.Value1);
            reloaded.Value2.Should().Be(original.Value2);
        }
Example #34
0
        public void Serializer_ToString_Succeeds()
        {
            // Arrange
            var inputData = new MyDataClass()
            {
                Value1 = "val1", Value2 = 22
            };

            // Act
            var actual = Serializer.ToString(inputData);

            // Assert
            var expected = @"<?xml version=""1.0"" encoding=""utf-16""?>
<MyDataClass xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
  <Value1>val1</Value1>
  <Value2>22</Value2>
</MyDataClass>";

            actual.Should().Be(expected);
        }
Example #35
0
        public void Serializer_RoundTrip_Succeeds()
        {
            // Arrange
            var testDir  = TestUtils.CreateTestSpecificFolder(TestContext);
            var filePath = Path.Combine(testDir, "file1.txt");

            var original = new MyDataClass()
            {
                Value1 = "val1", Value2 = 22
            };

            // Act - save and reload
            Serializer.SaveModel(original, filePath);
            var reloaded = Serializer.LoadModel <MyDataClass>(filePath);

            // Assert
            Assert.IsNotNull(reloaded);
            Assert.AreEqual(original.Value1, reloaded.Value1);
            Assert.AreEqual(original.Value2, reloaded.Value2);
        }
Example #36
0
        public RecoverySs(ISpState parent, MyDataClass dataClass)
            : base(parent, MyStateID.Recovery, dataClass)
        {
            MyState idle = new IdleSt(this, dataClass);
            MyState active = new ActiveSt(this, dataClass);

            this.AddSubState(idle);
            this.AddSubState(active);

            // Register Idle state transitions
            idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Start), new SpStateTransition(SpStateTransitionType.NextState, active, null));
            idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            // Register active state transitions
            active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition(SpStateTransitionType.NextState, idle, null));
            active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            // Only on events registered.  On abor goes exit state

            this.SetEntryState(idle);
        }
        public NotStartedSs(ISpState parent, MyDataClass dataClass)
            : base(parent, MyStateID.NotStarted, dataClass)
        {
            MyState idle = new IdleSt(this, dataClass);
            MyState active = new ActiveSt(this, dataClass);

            this.AddSubState(idle);
            this.AddSubState(active);

            // Register Idle state transitions
            idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Start), new SpStateTransition(SpStateTransitionType.NextState, active, null));
            idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));
            //idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, new MyTickMsg()));

            // results
            idle.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Start), new SpStateTransition(SpStateTransitionType.NextState, active, null));
            //idle.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, new MyTickMsg()));

            // Register active state transitions
            //active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition(SpStateTransitionType.NextState, idle, null));
            active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition(SpStateTransitionType.NextState, idle, new MyTickMsg()));

            //active.RegisterOnEventTransition(MyEventType.Abort, new SpStateTransition(SpStateTransitionType.ExitState, null, null));
            active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.Defered, null, null));

            //            active.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition(SpStateTransitionType.NextState, idle, null));
            active.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition(SpStateTransitionType.NextState, idle, new MyTickMsg()));

            // Register my defered
            // If I get an abort handed to me by a state I will push the internal transition to idle

            // TODO - use this to provoque a check error
            //this.RegisterOnResultTransition(MyEventType.Abort, new SpStateTransition(SpStateTransitionType.NextState, idle, null));

            this.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition(SpStateTransitionType.NextState, idle, null));

            this.SetEntryState(idle);
        }
Example #38
0
 //        private int triggerCount = 0;
 public IdleSt(ISpState parent, MyDataClass dataClass)
     : base(parent, MyStateID.Idle, dataClass)
 {
 }
 public WaitOnInput(ISpState parent, MyDataClass dataClass)
     : base(parent, MyStateID.Idle, dataClass)
 {
 }
Example #40
0
 //        private int triggerCount = 0;
 public ActiveSt(ISpState parent, MyDataClass dataClass)
     : base(parent, MyStateID.Active, dataClass)
 {
 }
Example #41
0
        public Level3Ss(ISpState parent, MyDataClass dataClass)
            : base(parent, MyStateID.Level3, dataClass)
        {
            MyState idle = new IdleSt(this, dataClass);
            MyState active = new ActiveSt(this, dataClass);

            this.AddSubState(idle);
            this.AddSubState(active);

            // Register Idle state transitions
            idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Start), new SpStateTransition(SpStateTransitionType.NextState, active, null));
            //idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            // results - this idle class just returns whatever msg we send in. So send Start and it will return it as its return value and provok this transition
            idle.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Start), new SpStateTransition(SpStateTransitionType.NextState, active, null));

            // Register active state transitions
            active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition(SpStateTransitionType.NextState, idle, null));
            //active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            // results - this class just returns whatever msg we send in. So send Stop and it will return it as its return value and provok this transition
            active.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition(SpStateTransitionType.NextState, idle, null));
            active.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            this.SetEntryState(idle);
        }
Example #42
0
 //        private int triggerCount = 0;
 public Level2Idle(ISpState parent, MyDataClass dataClass)
     : base(parent, MyStateID.Idle, dataClass)
 {
 }