Пример #1
0
        public void ExecuteTransistion(Transistion transition)
        {
            if (CurrenState.StateName != transition.SourceStateName)
            {
                string message = String.Format("Transisition has wrong source state {0}, when system is in {1}",
                                               transition.SourceStateName, CurrenState.StateName);
                RaiseStateMachineSystemEvent("State machine: default guard execute transistion", message);
                return;
            }

            if (!StateList.ContainsKey(transition.TargetStateName))
            {
                string message = String.Format("Transisition has wrong target state {0},when system is in {1}. State not in global", transition.SourceStateName, CurrenState.StateName);
                RaiseStateMachineSystemEvent("State machine: Default guard execute transition ", message);
                return;
            }


            CurrenState.ExitActions.ForEach(a => a.Execute());

            transition.GuardList.ForEach(g => g.Execute());
            string info = transition.GuardList.Count + " guard actions executed";

            RaiseStateMachineSystemEvent("State machine: ExecuteTransistion", info);

            //Run all transistion action list
            transition.TransistionActionList.ForEach(t => t.Execute());

            //State change
            info = transition.TransistionActionList.Count + " transistion actions executed";
            RaiseStateMachineSystemEvent("State machine: Begin state change", info);

            var targetState = GetStateFromStateList(transition.TargetStateName);

            PreviouState = CurrenState;
            CurrenState  = targetState;

            foreach (var entryActions in CurrenState.EntryActions)
            {
                entryActions.Execute();
            }

            RaiseStateMachineSystemEvent("State machine: State change completed succesfully", "Previous State" + PreviouState.StateName + " New State= " + CurrenState.StateName);
        }
Пример #2
0
        public void ExecuteTransistion(Transistion transition)
        {
            if (CurrenState.StateName != transition.SourceStateName)
            {
                string message = String.Format("Transisition has wrong source state {0}, when system is in {1}",
                    transition.SourceStateName, CurrenState.StateName);
                RaiseStateMachineSystemEvent("State machine: default guard execute transistion", message);
                return;
            }

            if (!StateList.ContainsKey(transition.TargetStateName))
            {
                string message = String.Format("Transisition has wrong target state {0},when system is in {1}. State not in global", transition.SourceStateName, CurrenState.StateName);
                RaiseStateMachineSystemEvent("State machine: Default guard execute transition ", message);
                return;
            }

            CurrenState.ExitActions.ForEach(a => a.Execute());

            transition.GuardList.ForEach(g => g.Execute());
            string info = transition.GuardList.Count + " guard actions executed";
            RaiseStateMachineSystemEvent("State machine: ExecuteTransistion", info);

            //Run all transistion action list
            transition.TransistionActionList.ForEach(t => t.Execute());

            //State change
            info = transition.TransistionActionList.Count + " transistion actions executed";
            RaiseStateMachineSystemEvent("State machine: Begin state change", info);

            var targetState = GetStateFromStateList(transition.TargetStateName);

            PreviouState = CurrenState;
            CurrenState = targetState;

            foreach (var entryActions in CurrenState.EntryActions)
            {
                entryActions.Execute();
            }

            RaiseStateMachineSystemEvent("State machine: State change completed succesfully", "Previous State" + PreviouState.StateName + " New State= " + CurrenState.StateName);
        }