Example #1
0
 public void DuplicatesNotAllowed()
 {
     var sc = new StateCollection();
       var s = new State();
       sc.Add(s);
       sc.Add(s);
 }
        public void CompositeStateTestWithInitialState()
        {
            var sm = new StateMachine();

            var s0       = CreateState("0");
            var s0States = new StateCollection();

            s0.ParallelSubStates.Add(s0States);
            sm.States.Add(s0);

            var s00 = CreateState("00");

            s0States.Add(s00);
            var s01 = CreateState("01");

            s0States.Add(s01);

            var t0 = new Transition
            {
                SourceState = s0,
                TargetState = s0,
            };

            t0.Action += (s, e) => _events = _events + "A0";

            s0States.InitialState = s01;

            sm.Update(TimeSpan.FromSeconds(1));
            sm.Update(TimeSpan.FromSeconds(1));
            t0.Fire();
            sm.Update(TimeSpan.FromSeconds(1));
            sm.Update(TimeSpan.FromSeconds(1));

            Assert.AreEqual("E0E01U01U0U01U0X01X0A0E0E01U01U0U01U0", _events);
        }
        public void Test_Count()
        {
            string group = "TestGroup";

            StateCollection <string> collection = new StateCollection <string>(StateScope.Application, group);

            string zero = "Zero";
            string one  = "One";


            collection.Add(zero);

            string key = collection.GetStateKey();

            StateAccess.State.SetApplication(key, collection);

            StateCollection <string> foundCollection0 = (StateCollection <string>)StateAccess.State.GetApplication(key);

            Assert.AreEqual(1, foundCollection0.Count);



            collection.Add(one);


            StateAccess.State.SetApplication(key, collection);

            StateCollection <string> foundCollection2 = (StateCollection <string>)StateAccess.State.GetApplication(key);

            Assert.AreEqual(2, foundCollection2.Count);



            Assert.AreEqual(2, collection.Count);
        }
Example #4
0
        public void CompositeStateTest()
        {
            var sm = new StateMachine();

              var s0 = CreateState("0");
              var s0States = new StateCollection();
              s0.ParallelSubStates.Add(s0States);
              sm.States.Add(s0);

              var s00 = CreateState("00");
              s0States.Add(s00);
              var s01 = CreateState("01");
              s0States.Add(s01);

              var t0 = new Transition
              {
            SourceState = s0,
            TargetState = s0,
              };
              t0.Action += (s, e) => _events = _events + "A0";

              sm.Update(TimeSpan.FromSeconds(1));
              sm.Update(TimeSpan.FromSeconds(1));
              t0.Fire();
              sm.Update(TimeSpan.FromSeconds(1));
              sm.Update(TimeSpan.FromSeconds(1));

              Assert.AreEqual("E0E00U00U0U00U0X00X0A0E0E00U00U0U00U0", _events);
        }
        public void Test_GetEnumerator()
        {
            string group = "TestGroup";

            StateCollection <string> collection = new StateCollection <string>(StateScope.Application, group);

            string one = "One";
            string two = "Two";

            string[] values = new String[] { one, two };

            collection.Add(one);
            collection.Add(two);


            int i = 0;

            foreach (string value in collection)
            {
                Assert.IsNotNull(value, "Value is null at index position " + i + ".");

                Assert.AreEqual(values[i], value, "Only value doesn't match what is expected.");

                i++;
            }
        }
        public void DuplicatesNotAllowed()
        {
            var sc = new StateCollection();
            var s  = new State();

            sc.Add(s);
            sc.Add(s);
        }
Example #7
0
        private StateCollection CreateParserStates(CGTContent content)
        {
            rules = CreateRules(content);

            StateCollection states = new StateCollection();
            foreach (LALRStateRecord record in content.LALRStateTable)
            {
                State state = new State(record.Index);
                states.Add(state);
            }

            foreach (LALRStateRecord record in content.LALRStateTable)
            {
                State state = states[record.Index];
                foreach (ActionSubRecord subRecord in record.ActionSubRecords)
                {
                    Action action =
                        ActionFactory.CreateAction(subRecord,
                                                   states,
                                                   symbols,
                                                   rules);
                    state.Actions.Add(action);
                }

            }
            return states;
        }
        public void CompositeState()
        {
            var sm = new StateMachine();

            var s0       = CreateState("0");
            var s0States = new StateCollection();

            s0.ParallelSubStates.Add(s0States);
            sm.States.Add(s0);

            var s00 = CreateState("00");

            s0States.Add(s00);

            var t = new Transition
            {
                SourceState = s00,
                TargetState = s0,
            };

            t.Action += (s, e) => _events = _events + "A";

            sm.Update(TimeSpan.FromSeconds(1));
            t.Fire();
            sm.Update(TimeSpan.FromSeconds(1));

            Assert.AreEqual("E0E00U00U0X00X0AE0E00U00U0", _events);
        }
Example #9
0
        public static StateCollection GetCollection()
        {
            StateCollection tempList = null;

            using (SqlConnection myConnection = new SqlConnection(AppConfiguration.ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("usp_GetState", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

                    myCommand.Parameters.AddWithValue("@QueryId", SelectTypeEnum.GetCollection);

                    myConnection.Open();
                    using (SqlDataReader myReader = myCommand.ExecuteReader())
                    {
                        if (myReader.HasRows)
                        {
                            tempList = new StateCollection();
                            while (myReader.Read())
                            {
                                tempList.Add(FillDataRecord(myReader));
                            }
                        }
                        myReader.Close();
                    }
                }
            }
            return(tempList);
        }
        public void Test_Current()
        {
            string group = "TestGroup";

            StateCollection <string> collection = StateCollection <string> .Current(StateScope.Application, group);

            string one = "One";
            string two = "Two";

            collection.Add(one);
            collection.Add(two);



            StateCollection <string> foundCollection = StateCollection <string> .Current(StateScope.Application, group);

            Assert.AreEqual(collection.Count, foundCollection.Count);
        }
        public void Test_this()
        {
            StateCollection <string> collection = new StateCollection <string>(StateScope.Application, "TestGroup");

            string zero = "Zero";
            string one  = "One";
            string two  = "Two";

            collection.Add(zero);
            collection.Add(one);
            collection.Add(two);

            Assert.AreEqual(3, collection.Count);

            Assert.AreEqual(zero, collection[0]);
            Assert.AreEqual(one, collection[1]);
            Assert.AreEqual(two, collection[2]);
        }
Example #12
0
        public void TestNoFinalState()
        {
            var sm = new StateMachine();

            var s0       = CreateState("0");
            var s0States = new StateCollection();

            s0.ParallelSubStates.Add(s0States);
            sm.States.Add(s0);

            var s1 = CreateState("1");

            sm.States.Add(s1);

            var s00 = CreateState("00");

            s0States.Add(s00);
            var s01 = CreateState("01");

            s0States.Add(s01);
            var s02 = CreateState("02");

            s0States.Add(s02);

            Assert.AreEqual(null, s0States.FinalState);

            var t0 = new Transition
            {
                SourceState = s0,
                TargetState = s1,
                FireAlways  = true,
            };

            t0.Action += (s, e) => _events = _events + "A0";

            sm.Update(TimeSpan.FromSeconds(1));
            sm.Update(TimeSpan.FromSeconds(1));

            Assert.AreEqual("E0E00U00U0X00X0A0E1U1", _events);
        }
        public void Test_Add_Separate()
        {
            StateCollection <string> collection = new StateCollection <string>(StateScope.Application, "TestGroup1");

            string zero  = "Zero";
            string one   = "One";
            string two   = "Two";
            string three = "Three";

            collection.Add(zero);
            collection.Add(one);
            collection.Add(two);
            collection.Add(three);

            StateCollection <string> collection2 = new StateCollection <string>(StateScope.Application, "TestGroup2");

            collection2.Add(zero + "2");
            collection2.Add(one + "2");
            collection2.Add(two + "2");
            collection2.Add(three + "2");



            Assert.AreEqual(4, collection.Count);

            Assert.AreEqual(zero, collection[0]);
            Assert.AreEqual(one, collection[1]);
            Assert.AreEqual(two, collection[2]);
            Assert.AreEqual(three, collection[3]);

            Assert.AreEqual(4, collection2.Count);

            Assert.AreEqual(zero + "2", collection2[0]);
            Assert.AreEqual(one + "2", collection2[1]);
            Assert.AreEqual(two + "2", collection2[2]);
            Assert.AreEqual(three + "2", collection2[3]);
        }
Example #14
0
            public void RegisterDefaultState(GUIElementBase definition, bool full = false)
            {
                var key   = GetElementHash(definition);
                var value = new StateCollection();

                var props = definition.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);

                foreach (var prop in props)
                {
                    value.Add(prop.Name, prop.GetValue(definition));
                }

                if (full)
                {
                    var objs = definition.Render();

                    foreach (var obj in objs)
                    {
                        var name = obj.Name;
                    }
                }

                _defaultStates.Add(key, value);
            }
Example #15
0
        public void IgnoredHistory()
        {
            var sm = new StateMachine();

            var s0 = CreateState("0");

            sm.States.Add(s0);

            var s1       = CreateState("1");
            var s1States = new StateCollection();

            s1States.SaveHistory = true;
            s1.ParallelSubStates.Add(s1States);
            sm.States.Add(s1);

            var s10 = CreateState("10");

            s1States.Add(s10);
            var s11 = CreateState("11");

            s1States.Add(s11);
            var s12 = CreateState("12");

            s1States.Add(s12);

            s1States.InitialState = s11;

            var t0 = new Transition
            {
                SourceState = s0,
                TargetState = s12,
            };

            t0.Action += (s, e) => _events = _events + "A0";

            var t1211 = new Transition
            {
                SourceState = s12,
                TargetState = s11,
            };

            t1211.Action += (s, e) => _events = _events + "A1211";

            var t1 = new Transition
            {
                SourceState = s1,
                TargetState = s0,
            };

            t1.Action += (s, e) => _events = _events + "A1";

            var t010 = new Transition
            {
                SourceState = s0,
                TargetState = s10,
            };

            t010.Action += (s, e) => _events = _events + "A010";

            sm.Update(TimeSpan.FromSeconds(1));
            t0.Fire();
            sm.Update(TimeSpan.FromSeconds(1));
            t1211.Fire();
            sm.Update(TimeSpan.FromSeconds(1));
            t1.Fire();
            sm.Update(TimeSpan.FromSeconds(1));
            t010.Fire();
            sm.Update(TimeSpan.FromSeconds(1));

            Assert.AreEqual("E0U0X0A0E1E12U12U1X12A1211E11U11U1X11X1A1E0U0X0A010E1E10U10U1", _events);
        }
        private void SetupReferenceData()
        {
            var countries = new Country { CountryId = "1", Name = "USA", Code = "USA" };

            var states = new State { StateId = "2", CountryId = "1", Name = "Florida" };

            var ports = new Port { PortId = "1", City = "Florida", Name = "Miami", State = "Florida", StateId = "2", CountryId = "1" };

            var brands = new Brand { BrandId = "1", Name = "Carnival" };

            var personTypes = new PersonTypeEntity { PersonTypeId = "1001", Name = "Daniel" };

            var loyaltyLevelTypes = new LoyaltyLevelType { LoyaltyLevelTypeId = "1001", Name = "abc", BrandId = "1", NoOfCruiseNights = 3, LogoImageAddress = "abc" };

            var documentType = new DocumentType { CountryId = "232", Code = "USA", DocumentTypeId = "1", Name = "Passport" };

            var brand = new BrandCollection();

            var country = new CountryCollection();
            country.Add(countries);

            var state = new StateCollection();
            state.Add(states);

            var documentTypes = new DocumentTypeCollection();
            documentTypes.Add(documentType);

            var port = new PortCollection();
            port.Add(ports);

            var personTypeEntity = new PersonTypeEntityCollection();
            personTypeEntity.Add(personTypes);

            var loyaltyLevelType = new LoyaltyLevelTypeCollection();
            loyaltyLevelType.Add(loyaltyLevelTypes);

            this.referenceData.AssignBrands(brand);
            this.referenceData.AssignCountries(country);
            this.referenceData.AssignStates(state);
            this.referenceData.AssignDocumentTypes(documentTypes);
            this.referenceData.AssignLoyaltyLevelTypes(loyaltyLevelType);
            this.referenceData.AssignPersonTypes(personTypeEntity);
            this.referenceData.AssignPorts(port);
        }
Example #17
0
        public void TestWithFinalState()
        {
            var sm = new StateMachine();

              var s0 = CreateState("0");
              var s0States = new StateCollection();
              s0.ParallelSubStates.Add(s0States);
              sm.States.Add(s0);

              var s1 = CreateState("1");
              sm.States.Add(s1);

              var s00 = CreateState("00");
              s0States.Add(s00);
              var s01 = CreateState("01");
              s0States.Add(s01);
              var s02 = CreateState("02");
              s0States.Add(s02);

              // Set final state
              s0States.FinalState = s02;

              var t0 = new Transition
              {
            SourceState = s0,
            TargetState = s1,
            FireAlways = true,
              };
              t0.Action += (s, e) => _events = _events + "A0";

              var t0001 = new Transition
              {
            SourceState = s00,
            TargetState = s01,
              };
              t0001.Action += (s, e) => _events = _events + "A0001";

              var t0102 = new Transition
              {
            SourceState = s01,
            TargetState = s02,
              };
              t0102.Action += (s, e) => _events = _events + "A0102";

              sm.Update(TimeSpan.FromSeconds(1));
              sm.Update(TimeSpan.FromSeconds(1));
              t0001.Fire();
              sm.Update(TimeSpan.FromSeconds(1));
              sm.Update(TimeSpan.FromSeconds(1));
              t0102.Fire();
              sm.Update(TimeSpan.FromSeconds(1));
              sm.Update(TimeSpan.FromSeconds(1));

              Assert.AreEqual("E0E00U00U0U00U0X00A0001E01U01U0U01U0X01A0102E02U02U0X02X0A0E1U1", _events);
        }
Example #18
0
        public void TwoCompositeStates()
        {
            var sm = new StateMachine();

              var s0 = CreateState("0");
              var s0States = new StateCollection();
              s0.ParallelSubStates.Add(s0States);
              sm.States.Add(s0);

              var s1 = CreateState("1");
              var s1States = new StateCollection();
              s1.ParallelSubStates.Add(s1States);
              sm.States.Add(s1);

              var s00 = CreateState("00");
              s0States.Add(s00);
              var s01 = CreateState("01");
              s0States.Add(s01);
              var s10 = CreateState("10");
              s1States.Add(s10);
              var s11 = CreateState("11");
              s1States.Add(s11);

              var t0001 = new Transition
              {
            SourceState = s00,
            TargetState = s01,
              };
              t0001.Action += (s, e) => _events = _events + "A0001";

              var t0111 = new Transition
              {
            SourceState = s01,
            TargetState = s11,
              };
              t0111.Action += (s, e) => _events = _events + "A0111";

              var t101 = new Transition
              {
            SourceState = s1,
            TargetState = s10,
              };
              t101.Action += (s, e) => _events = _events + "A101";

              sm.Update(TimeSpan.FromSeconds(1));
              t0001.Fire();
              sm.Update(TimeSpan.FromSeconds(1));
              t0111.Fire();
              sm.Update(TimeSpan.FromSeconds(1));
              t101.Fire(null, null);
              sm.Update(TimeSpan.FromSeconds(1));

              Assert.AreEqual("E0E00U00U0X00A0001E01U01U0X01X0A0111E1E11U11U1X11X1A101E1E10U10U1", _events);
        }
Example #19
0
        private StateCollection CreateParserStates(CGTContent content)
        {
            rules = CreateRules(content);

            StateCollection states = new StateCollection();
            foreach (LALRStateRecord record in content.LALRStateTable)
            {
                State state = new State(record.Index);
                states.Add(state);
            }

            foreach (LALRStateRecord record in content.LALRStateTable)
            {
                State state = states[record.Index];
                foreach (ActionSubRecord subRecord in record.ActionSubRecords)
                {
                    Action action =
                        ActionFactory.CreateAction(subRecord,
                                                   states,
                                                   symbols,
                                                   rules);
                    state.Actions.Add(action);
                }

            }
            return states;
        }
Example #20
0
        public void TestParallelStates2()
        {
            var sm = new StateMachine();

              var s0 = CreateState("0");
              sm.States.Add(s0);

              var s0A = new StateCollection();
              s0.ParallelSubStates.Add(s0A);
              var s0B = new StateCollection();
              s0.ParallelSubStates.Add(s0B);
              var s0C = new StateCollection();
              s0.ParallelSubStates.Add(s0C);

              var s1 = CreateState("1");
              sm.States.Add(s1);

              var sa0 = CreateState("a0");
              s0A.Add(sa0);
              var sa1 = CreateState("a1");
              s0A.Add(sa1);

              var sb0 = CreateState("b0");
              s0B.Add(sb0);
              var sb1 = CreateState("b1");
              s0B.Add(sb1);
              var sb2 = CreateState("b2");
              s0B.Add(sb2);

              var sc0 = CreateState("c0");
              s0C.Add(sc0);
              var sc1 = CreateState("c1");
              s0C.Add(sc1);

              s0C.InitialState = sc1;

              // Set final state
              s0A.FinalState = sa1;
              s0B.FinalState = sb2;
              s0C.FinalState = null;

              var t0 = new Transition
              {
            SourceState = s0,
            TargetState = s1,
            FireAlways = true,
              };
              t0.Action += (s, e) => _events = _events + "A0";

              var ta0a1 = new Transition
              {
            SourceState = sa0,
            TargetState = sa1,
            FireAlways = true,
              };
              ta0a1.Action += (s, e) => _events = _events + "Aa0a1";

              var tb0b1 = new Transition
              {
            SourceState = sb0,
            TargetState = sb1,
            FireAlways = true,
              };
              tb0b1.Action += (s, e) => _events = _events + "Ab0b1";

              var tb1b2 = new Transition
              {
            SourceState = sb1,
            TargetState = sb2,
            FireAlways = true,
              };
              tb1b2.Action += (s, e) => _events = _events + "Ab1b2";

              var tc0c1 = new Transition
              {
            SourceState = sc0,
            TargetState = sc1,
            FireAlways = true,
              };
              tc0c1.Action += (s, e) => _events = _events + "Ac0c1";

              var tc1c0 = new Transition
              {
            SourceState = sc1,
            TargetState = sc0,
              };
              tc1c0.Action += (s, e) => _events = _events + "Ac1c0";

              tc1c0.Fire();
              sm.Update(TimeSpan.FromSeconds(1));
              tc1c0.Fire();
              sm.Update(TimeSpan.FromSeconds(1));
              tc1c0.Fire();
              sm.Update(TimeSpan.FromSeconds(1));
              tc1c0.Fire(); // tc1c0 fires --> t0 must not fire.
              sm.Update(TimeSpan.FromSeconds(1));

              Assert.AreEqual("E0Ea0Eb0Ec1Ua0Ub0Uc1U0Xa0Aa0a1Ea1Xb0Ab0b1Eb1Xc1Ac1c0Ec0Ua1Ub1Uc0U0Xb1Ab1b2Eb2Xc0Ac0c1Ec1Ua1Ub2Uc1U0Xc1Ac1c0Ec0Ua1Ub2Uc0U0", _events);
        }
Example #21
0
        public void IgnoredHistory()
        {
            var sm = new StateMachine();

              var s0 = CreateState("0");
              sm.States.Add(s0);

              var s1 = CreateState("1");
              var s1States = new StateCollection();
              s1States.SaveHistory = true;
              s1.ParallelSubStates.Add(s1States);
              sm.States.Add(s1);

              var s10 = CreateState("10");
              s1States.Add(s10);
              var s11 = CreateState("11");
              s1States.Add(s11);
              var s12 = CreateState("12");
              s1States.Add(s12);

              s1States.InitialState = s11;

              var t0 = new Transition
              {
            SourceState = s0,
            TargetState = s12,
              };
              t0.Action += (s, e) => _events = _events + "A0";

              var t1211 = new Transition
              {
            SourceState = s12,
            TargetState = s11,
              };
              t1211.Action += (s, e) => _events = _events + "A1211";

              var t1 = new Transition
              {
            SourceState = s1,
            TargetState = s0,
              };
              t1.Action += (s, e) => _events = _events + "A1";

              var t010 = new Transition
              {
            SourceState = s0,
            TargetState = s10,
              };
              t010.Action += (s, e) => _events = _events + "A010";

              sm.Update(TimeSpan.FromSeconds(1));
              t0.Fire();
              sm.Update(TimeSpan.FromSeconds(1));
              t1211.Fire();
              sm.Update(TimeSpan.FromSeconds(1));
              t1.Fire();
              sm.Update(TimeSpan.FromSeconds(1));
              t010.Fire();
              sm.Update(TimeSpan.FromSeconds(1));

              Assert.AreEqual("E0U0X0A0E1E12U12U1X12A1211E11U11U1X11X1A1E0U0X0A010E1E10U10U1", _events);
        }
Example #22
0
        public void TestNoFinalState()
        {
            var sm = new StateMachine();

              var s0 = CreateState("0");
              var s0States = new StateCollection();
              s0.ParallelSubStates.Add(s0States);
              sm.States.Add(s0);

              var s1 = CreateState("1");
              sm.States.Add(s1);

              var s00 = CreateState("00");
              s0States.Add(s00);
              var s01 = CreateState("01");
              s0States.Add(s01);
              var s02 = CreateState("02");
              s0States.Add(s02);

              Assert.AreEqual(null, s0States.FinalState);

              var t0 = new Transition
              {
            SourceState = s0,
            TargetState = s1,
            FireAlways = true,
              };
              t0.Action += (s, e) => _events = _events + "A0";

              sm.Update(TimeSpan.FromSeconds(1));
              sm.Update(TimeSpan.FromSeconds(1));

              Assert.AreEqual("E0E00U00U0X00X0A0E1U1", _events);
        }
Example #23
0
        public void TestParallelStates2()
        {
            var sm = new StateMachine();

            var s0 = CreateState("0");

            sm.States.Add(s0);

            var s0A = new StateCollection();

            s0.ParallelSubStates.Add(s0A);
            var s0B = new StateCollection();

            s0.ParallelSubStates.Add(s0B);
            var s0C = new StateCollection();

            s0.ParallelSubStates.Add(s0C);

            var s1 = CreateState("1");

            sm.States.Add(s1);

            var sa0 = CreateState("a0");

            s0A.Add(sa0);
            var sa1 = CreateState("a1");

            s0A.Add(sa1);

            var sb0 = CreateState("b0");

            s0B.Add(sb0);
            var sb1 = CreateState("b1");

            s0B.Add(sb1);
            var sb2 = CreateState("b2");

            s0B.Add(sb2);

            var sc0 = CreateState("c0");

            s0C.Add(sc0);
            var sc1 = CreateState("c1");

            s0C.Add(sc1);

            s0C.InitialState = sc1;

            // Set final state
            s0A.FinalState = sa1;
            s0B.FinalState = sb2;
            s0C.FinalState = null;

            var t0 = new Transition
            {
                SourceState = s0,
                TargetState = s1,
                FireAlways  = true,
            };

            t0.Action += (s, e) => _events = _events + "A0";

            var ta0a1 = new Transition
            {
                SourceState = sa0,
                TargetState = sa1,
                FireAlways  = true,
            };

            ta0a1.Action += (s, e) => _events = _events + "Aa0a1";

            var tb0b1 = new Transition
            {
                SourceState = sb0,
                TargetState = sb1,
                FireAlways  = true,
            };

            tb0b1.Action += (s, e) => _events = _events + "Ab0b1";

            var tb1b2 = new Transition
            {
                SourceState = sb1,
                TargetState = sb2,
                FireAlways  = true,
            };

            tb1b2.Action += (s, e) => _events = _events + "Ab1b2";

            var tc0c1 = new Transition
            {
                SourceState = sc0,
                TargetState = sc1,
                FireAlways  = true,
            };

            tc0c1.Action += (s, e) => _events = _events + "Ac0c1";

            var tc1c0 = new Transition
            {
                SourceState = sc1,
                TargetState = sc0,
            };

            tc1c0.Action += (s, e) => _events = _events + "Ac1c0";

            tc1c0.Fire();
            sm.Update(TimeSpan.FromSeconds(1));
            tc1c0.Fire();
            sm.Update(TimeSpan.FromSeconds(1));
            tc1c0.Fire();
            sm.Update(TimeSpan.FromSeconds(1));
            tc1c0.Fire(); // tc1c0 fires --> t0 must not fire.
            sm.Update(TimeSpan.FromSeconds(1));

            Assert.AreEqual("E0Ea0Eb0Ec1Ua0Ub0Uc1U0Xa0Aa0a1Ea1Xb0Ab0b1Eb1Xc1Ac1c0Ec0Ua1Ub1Uc0U0Xb1Ab1b2Eb2Xc0Ac0c1Ec1Ua1Ub2Uc1U0Xc1Ac1c0Ec0Ua1Ub2Uc0U0", _events);
        }
Example #24
0
        public void TestWithFinalState()
        {
            var sm = new StateMachine();

            var s0       = CreateState("0");
            var s0States = new StateCollection();

            s0.ParallelSubStates.Add(s0States);
            sm.States.Add(s0);

            var s1 = CreateState("1");

            sm.States.Add(s1);

            var s00 = CreateState("00");

            s0States.Add(s00);
            var s01 = CreateState("01");

            s0States.Add(s01);
            var s02 = CreateState("02");

            s0States.Add(s02);

            // Set final state
            s0States.FinalState = s02;

            var t0 = new Transition
            {
                SourceState = s0,
                TargetState = s1,
                FireAlways  = true,
            };

            t0.Action += (s, e) => _events = _events + "A0";

            var t0001 = new Transition
            {
                SourceState = s00,
                TargetState = s01,
            };

            t0001.Action += (s, e) => _events = _events + "A0001";

            var t0102 = new Transition
            {
                SourceState = s01,
                TargetState = s02,
            };

            t0102.Action += (s, e) => _events = _events + "A0102";

            sm.Update(TimeSpan.FromSeconds(1));
            sm.Update(TimeSpan.FromSeconds(1));
            t0001.Fire();
            sm.Update(TimeSpan.FromSeconds(1));
            sm.Update(TimeSpan.FromSeconds(1));
            t0102.Fire();
            sm.Update(TimeSpan.FromSeconds(1));
            sm.Update(TimeSpan.FromSeconds(1));

            Assert.AreEqual("E0E00U00U0U00U0X00A0001E01U01U0U01U0X01A0102E02U02U0X02X0A0E1U1", _events);
        }
        public void NullNotAllowed()
        {
            var sc = new StateCollection();

            sc.Add(null);
        }
        /// <summary>
        /// Function to retrieve state collection
        /// </summary>
        /// <param name="queryStates">states query</param>
        /// <returns>state collection</returns>
        private static StateCollection RetrieveStateCollection(IEnumerable<State> queryStates)
        {
            StateCollection stateCollection = new StateCollection();
            foreach (State state in queryStates)
            {
                stateCollection.Add(state);
            }

            return stateCollection;
        }
Example #27
0
        public void TwoCompositeStates()
        {
            var sm = new StateMachine();

            var s0       = CreateState("0");
            var s0States = new StateCollection();

            s0.ParallelSubStates.Add(s0States);
            sm.States.Add(s0);

            var s1       = CreateState("1");
            var s1States = new StateCollection();

            s1.ParallelSubStates.Add(s1States);
            sm.States.Add(s1);

            var s00 = CreateState("00");

            s0States.Add(s00);
            var s01 = CreateState("01");

            s0States.Add(s01);
            var s10 = CreateState("10");

            s1States.Add(s10);
            var s11 = CreateState("11");

            s1States.Add(s11);

            var t0001 = new Transition
            {
                SourceState = s00,
                TargetState = s01,
            };

            t0001.Action += (s, e) => _events = _events + "A0001";

            var t0111 = new Transition
            {
                SourceState = s01,
                TargetState = s11,
            };

            t0111.Action += (s, e) => _events = _events + "A0111";

            var t101 = new Transition
            {
                SourceState = s1,
                TargetState = s10,
            };

            t101.Action += (s, e) => _events = _events + "A101";

            sm.Update(TimeSpan.FromSeconds(1));
            t0001.Fire();
            sm.Update(TimeSpan.FromSeconds(1));
            t0111.Fire();
            sm.Update(TimeSpan.FromSeconds(1));
            t101.Fire(null, null);
            sm.Update(TimeSpan.FromSeconds(1));

            Assert.AreEqual("E0E00U00U0X00A0001E01U01U0X01X0A0111E1E11U11U1X11X1A101E1E10U10U1", _events);
        }
Example #28
0
 public void NullNotAllowed()
 {
     var sc = new StateCollection();
       sc.Add(null);
 }
        /// <summary>
        /// Maps the states.
        /// </summary>
        /// <param name="dataReader">The data reader.</param>
        /// <returns>State collection.</returns>
        private static async Task<StateCollection> MapStates(SqlDataReader dataReader)
        {
            var stateCollection = new StateCollection();
            if (dataReader != null)
            {
                while (await dataReader.ReadAsync())
                {
                    var state = new State
                    {
                        CountryId = dataReader.Int32Field(CountryId).ToString(),
                        StateId = dataReader.Int32Field(StateId).ToString(),
                        Name = dataReader.StringField(Name)
                    };

                    stateCollection.Add(state);
                }
            }

            return stateCollection;
        }