Exemple #1
0
        private TransitionInfo TransitionTo(StateToken stateToken, object data)
        {
            if (stateToken == null)
            {
                throw new ArgumentNullException(nameof(stateToken));
            }

            StateBase state = states.FirstOrDefault(s => s.Token == stateToken);

            if (state == null)
            {
                throw new UnknownStateException(CurrentStateToken, stateToken);
            }

            RaiseOnExitEvent(stateToken, data);

            StateBase oldState = CurrentState;

            CurrentState = state;

            var stateEnterEventArgs = new StateEnterEventArgs(oldState?.Token, data);

            isPerformActionLocked = true;
            try
            {
                OnStateChanged(new StateChangedEventArgs(oldState, CurrentState));

                CurrentState.OnEnter(stateEnterEventArgs);
            }
            finally
            {
                isPerformActionLocked = false;
            }

            return(stateEnterEventArgs.Redirect);
        }
Exemple #2
0
 /// <summary>
 /// Called when the state machine enters the current state.
 /// </summary>
 /// <param name="e">Custem event arguments.</param>
 protected internal virtual void OnEnter(StateEnterEventArgs e)
 {
     Enter?.Invoke(this, e);
 }