/// <summary> /// Fires the transition. /// </summary> /// <param name="context">The event context.</param> /// <returns>The result of the transition.</returns> public ITransitionResult <TState, TEvent> Fire(ITransitionContext <TState, TEvent> context) { Ensure.ArgumentNotNull(context, "context"); if (!this.ShouldFire(context.EventArgument, context)) { return(TransitionResult <TState, TEvent> .NotFired); } context.OnTransitionBegin(); IState <TState, TEvent> newState = context.State; if (!this.InternalTransition) { this.UnwindSubStates(context.State, context); this.Fire(this.Source, this.Target, context.EventArgument, context); newState = this.Target.EnterByHistory(context); } else { this.PerformActions(context.EventArgument, context); } return(new TransitionResult <TState, TEvent>(true, newState, context.Exceptions)); }
public async Task <ITransitionResult <TState> > Fire( ITransitionDefinition <TState, TEvent> transitionDefinition, ITransitionContext <TState, TEvent> context, ILastActiveStateModifier <TState, TEvent> lastActiveStateModifier) { Guard.AgainstNullArgument("context", context); var shouldFire = await this.ShouldFire(transitionDefinition, context).ConfigureAwait(false); if (!shouldFire) { await this.extensionHost .ForEach(extension => extension.SkippedTransition( this.stateMachineInformation, transitionDefinition, context)) .ConfigureAwait(false); return(TransitionResult <TState> .NotFired); } context.OnTransitionBegin(); await this.extensionHost .ForEach(extension => extension.ExecutingTransition( this.stateMachineInformation, transitionDefinition, context)) .ConfigureAwait(false); var newState = context.StateDefinition.Id; if (!transitionDefinition.IsInternalTransition) { await this.UnwindSubStates(transitionDefinition, context, lastActiveStateModifier).ConfigureAwait(false); await this.Fire(transitionDefinition, transitionDefinition.Source, transitionDefinition.Target, context, lastActiveStateModifier) .ConfigureAwait(false); newState = await this.stateLogic.EnterByHistory(transitionDefinition.Target, context, lastActiveStateModifier) .ConfigureAwait(false); } else { await this.PerformActions(transitionDefinition, context).ConfigureAwait(false); } await this.extensionHost .ForEach(extension => extension.ExecutedTransition( this.stateMachineInformation, transitionDefinition, context)) .ConfigureAwait(false); return(new TransitionResult <TState>(true, newState)); }
public async Task <ITransitionResult <TState, TEvent> > Fire(ITransitionContext <TState, TEvent> context) { LiteGuard.AgainstNullArgument("context", context); var shouldFire = await this.ShouldFire(context).ConfigureAwait(false); if (!shouldFire) { await this.extensionHost .ForEach(extension => extension.SkippedTransition( this.stateMachineInformation, this, context)) .ConfigureAwait(false); return(TransitionResult <TState, TEvent> .NotFired); } context.OnTransitionBegin(); await this.extensionHost .ForEach(extension => extension.ExecutingTransition( this.stateMachineInformation, this, context)) .ConfigureAwait(false); IState <TState, TEvent> newState = context.State; if (!this.IsInternalTransition) { await this.UnwindSubStates(context).ConfigureAwait(false); await this.Fire(this.Source, this.Target, context).ConfigureAwait(false); newState = await this.Target.EnterByHistory(context).ConfigureAwait(false); } else { await this.PerformActions(context).ConfigureAwait(false); } await this.extensionHost .ForEach(extension => extension.ExecutedTransition( this.stateMachineInformation, this, context)) .ConfigureAwait(false); return(new TransitionResult <TState, TEvent>(true, newState)); }
public ITransitionResult <TState, TEvent> Fire(ITransitionContext <TState, TEvent> context) { Ensure.ArgumentNotNull(context, "context"); if (!this.ShouldFire(context)) { this.extensionHost.ForEach(extension => extension.SkippedTransition( this.stateMachineInformation, this, context)); return(TransitionResult <TState, TEvent> .NotFired); } context.OnTransitionBegin(); this.extensionHost.ForEach(extension => extension.ExecutingTransition( this.stateMachineInformation, this, context)); IState <TState, TEvent> newState = context.State; if (!this.IsInternalTransition) { this.UnwindSubStates(context); this.Fire(this.Source, this.Target, context); newState = this.Target.EnterByHistory(context); } else { this.PerformActions(context); } this.extensionHost.ForEach(extension => extension.ExecutedTransition( this.stateMachineInformation, this, context)); return(new TransitionResult <TState, TEvent>(true, newState)); }
public ITransitionResult <TState> Fire( ITransitionDefinition <TState, TEvent> transitionDefinition, ITransitionContext <TState, TEvent> context, ILastActiveStateModifier <TState> lastActiveStateModifier, IStateDefinitionDictionary <TState, TEvent> stateDefinitions) { Guard.AgainstNullArgument("context", context); if (!this.ShouldFire(transitionDefinition, context)) { this.extensionHost.ForEach(extension => extension.SkippedTransition(transitionDefinition, context)); return(TransitionResult <TState> .NotFired); } context.OnTransitionBegin(); this.extensionHost.ForEach(extension => extension.ExecutingTransition(transitionDefinition, context)); var newState = context.StateDefinition.Id; if (!transitionDefinition.IsInternalTransition) { this.UnwindSubStates(transitionDefinition, context, lastActiveStateModifier); this.Fire(transitionDefinition, transitionDefinition.Source, transitionDefinition.Target, context, lastActiveStateModifier); newState = this.stateLogic.EnterByHistory(transitionDefinition.Target, context, lastActiveStateModifier, stateDefinitions); } else { this.PerformActions(transitionDefinition, context); } this.extensionHost.ForEach(extension => extension.ExecutedTransition(transitionDefinition, context)); return(new TransitionResult <TState>(true, newState)); }