Exemplo n.º 1
0
        public bool StartMachine(TState initialState)
        {
            uiDispatcher = System.Windows.Threading.Dispatcher.CurrentDispatcher;
            if (_currentState == null && States.ContainsKey(initialState))
            {
                _currentState = States[initialState];
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        void _acceptInputGoToState(TInput input)
        {
            StateMachineTransition <TState, TInput> trans        = null;
            StateMachineState <TState, TInput>      oldStateTemp = null;

            if (_stateMachineTrace.TraceVerbose)
            {
                PrintTraceMessage(DisplayName + " incoming input " + input + " in state " + _currentState.ToString(), _stateMachineTrace.DisplayName);
            }
            if (CanAcceptInput(input))
            {
                lock (_currentState)
                {
                    oldStateTemp = _currentState;
                    if (CurrentState != null)
                    {
                        trans = CurrentState.FindTransitionForInput(input);
                        if (trans != null)
                        {
                            if (trans.Run(input))
                            {
                                if (States.ContainsKey(trans.NextState))
                                {
                                    CurrentState = States[trans.NextState];
                                }
                                else
                                {
                                    Log.AddEventLog(0, DisplayName, "State: " + trans.NextState + " does not exist in the state list");
                                }
                            }
                            if (CurrentState != null)
                            {
                                OnChangedState(oldStateTemp.State, _currentState.State);
                            }
                            else
                            {
                                CurrentState = oldStateTemp;
                            }
                        }
                    }
                }
            }
            else
            {
                if (_stateMachineTrace.TraceInfo)
                {
                    PrintTraceMessage(DisplayName + " Failed to accept input " + input + " in state " + _currentState.ToString(), _stateMachineTrace.DisplayName);
                }
            }
        }
Exemplo n.º 3
0
 public void AddTransition(TState state, TInput input, TState nextState, DelegateStateMachineTransitionCustomFunction <TInput> function)
 {
     if (States.ContainsKey(state))
     {
         States[state].AddTransition(input, nextState, function);
     }
     else
     {
         StateMachineState <TState, TInput> newState = new StateMachineState <TState, TInput>(state, input, nextState, function);
         States.Add(state, newState);
     }
     if (!States.ContainsKey(nextState))
     {
         States.Add(nextState, new StateMachineState <TState, TInput>(nextState));
     }
 }