/// <summary> /// Dispatches events to the current state. /// </summary> /// <param name="eventID"> /// The event ID. /// </param> /// <param name="args"> /// The data accompanying the event. /// </param> private void Dispatch(int eventID, object[] args) { // Reset action result. ActionResult = null; TransitionResult result; // Dispatch event to the current state. result = currentState.Dispatch(eventID, args); // If a transition was fired as a result of this event. if (result.HasFired) { currentState = result.NewState; TransitionCompletedEventArgs e = new TransitionCompletedEventArgs(currentState.ID, eventID, ActionResult, result.Error); if (context != null) { context.Post(delegate(object state) { OnTransitionCompleted(e); }, null); } else { OnTransitionCompleted(e); } } }
protected virtual void OnTransitionCompleted(TransitionCompletedEventArgs e) { TransitionCompletedEventHandler handler = TransitionCompleted; if (handler != null) { handler(this, e); } }
/// <summary> /// Dispatches events to the current state. /// </summary> /// <param name="eventId"> /// The event ID. /// </param> /// <param name="args"> /// The data accompanying the event. /// </param> protected virtual void Dispatch(TEvent eventId, TArgs args) { // Reset action result. ActionResult = null; var currentState = CurrentState; var eventContext = new EventContext(currentState.ID, eventId, args); CurrentEventContext = eventContext; s_currentStateMachine = this; try { OnBeginDispatch(eventContext); // Dispatch event to the current state. var result = currentState.Dispatch(eventContext); /* * // report errors * if (result.Error != null) * OnExceptionThrown( * new TransitionErrorEventArgs( * m_currentEventContext, result.Error)); */ // If a transition was fired as a result of this event. if (!result.HasFired) { OnTransitionDeclined(eventContext); return; } CurrentStateID = result.NewState; var eventArgs = new TransitionCompletedEventArgs <TState, TEvent, TArgs>( result.NewState, eventContext, ActionResult, result.Error); OnTransitionCompleted(eventArgs); } catch (Exception ex) { HandleDispatchException(ex); } finally { CurrentEventContext = null; s_currentStateMachine = null; } }
/// <summary> /// Raises the <see cref="StateMachine{TState,TEvent,TArgs}.TransitionCompleted"/> event. /// </summary> /// <param name="args">The <see cref="TransitionCompletedEventArgs{TState,TEvent,TArgs}"/> instance /// containing the event data.</param> protected virtual void OnTransitionCompleted(TransitionCompletedEventArgs <TState, TEvent, TArgs> args) { RaiseSafeEvent(TransitionCompleted, args, ExceptionPolicy.RaiseExceptionEvent); }
/// <summary> /// Raises the <see cref="StateMachine{TState,TEvent,TArgs}.TransitionCompleted"/> event. /// </summary> /// <param name="args">The <see cref="TransitionCompletedEventArgs{TState,TEvent,TArgs}"/> instance /// containing the event data.</param> protected override void OnTransitionCompleted(TransitionCompletedEventArgs <TState, TEvent, TArgs> args) { synchronizedPost(base.OnTransitionCompleted, args); }