/// <summary> /// Execute the inter-transition interceptor. /// </summary> /// <param name="stateMachineContext">The state machine context.</param> /// <returns>An async task.</returns> internal async Task Execute(StateMachineContextBase <TState, TTransition, TPayload> stateMachineContext) { if (true == this.onTransitionDelegate.Any()) { var context = StateMachineTransitionContext.Create(this.startState, this.endState.State, this.Message, this.stateMachine, stateMachineContext.Payload); await Task.WhenAll(this.onTransitionDelegate.Select(d => this.HandlerExecutor(d, context))); } if (StateMachineLifetime.Error == stateMachineContext.CurrentLifecycle) { return; } // We can continue on the same thread for the executing the next state. stateMachineContext.SetState(this.endState); // Fire of the state entrance. this.endState.InvokeEnter(stateMachineContext); }
/// <summary> /// The method handler exector. /// </summary> /// <param name="action">The action to execute.</param> /// <param name="context">The transition context.</param> /// <returns>An async task.</returns> private async Task HandlerExecutor(StateMachineTransitionDel <TState, TTransition, TPayload> action, StateMachineTransitionContext <TState, TTransition, TPayload> context) { try { if (StateMachineLifetime.Error == context.CurrentLifecycle) { return; } await action(context); } catch (Exception ex) { if (StateMachineLifetime.Error == context.CurrentLifecycle) { return; } this.stateMachine.HandleFault(context, ex); } }