/// <summary> /// Called when [transition]. /// </summary> /// <param name="TO"> The TO. </param> /// <param name="FROM"> The FROM. </param> /// <param name="transition"> The transition. </param> // ReSharper disable InconsistentNaming private void OnTransition(List <IState> TO, IState FROM, IStateTransition transition) // ReSharper restore InconsistentNaming { try { if (FROM.Leave != null) { foreach (IState toState in ActiveStates) { if (_logging.IsDebugEnabled) { _logging.DebugFormat("StateMachine Transition Activated From {0} to {1}", FROM.Name, toState.Name); } } FROM.Leave.CallOnEach(x => x.Execute(StateContainer, _stateMap)); } } catch (Exception ex) { throw new StateMachineException(ex.Message); } try { if (TO != null) { ActiveStates.AddRange(TO); foreach (IState toState in ActiveStates) { if (toState.Enter != null) { toState.Enter.CallOnEach(x => x.Execute(StateContainer, _stateMap)); } if (_logging.IsDebugEnabled) { _logging.DebugFormat("StateMachine Transition Completed From {0} to {1}", FROM.Name, toState.Name); } } } else { if (_logging.IsDebugEnabled) { _logging.DebugFormat("StateMachine has Transitioned To A Final State From {0}", FROM.Name); } } } catch (Exception ex) { throw new StateMachineException(ex.Message); } }