コード例 #1
0
 internal StateMachineTransition <TState, TInput> FindTransitionForInput(TInput input)
 {
     if (_allowedTransitions.ContainsKey(input))
     {
         StateMachineTransition <TState, TInput> transition = _allowedTransitions[input];
         return(transition);
     }
     return(null);
 }
コード例 #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);
                }
            }
        }
コード例 #3
0
        protected virtual bool CanAcceptInput(TInput input)
        {
            StateMachineTransition <TState, TInput> transition = null;

            if (CurrentState != null)
            {
                if (States.ContainsKey(CurrentState.State))
                {
                    transition = States[CurrentState.State].FindTransitionForInput(input);
                }
                if (transition != null)
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #4
0
        internal void AddTransition(TInput input, TState nextState, DelegateStateMachineTransitionCustomFunction <TInput> function)
        {
            StateMachineTransition <TState, TInput> newTransition = new StateMachineTransition <TState, TInput>(input, nextState, function);

            _allowedTransitions.Add(input, newTransition);
        }