public TransitionLogic( IExtensionHost <TState, TEvent> extensionHost, IStateMachineInformation <TState, TEvent> stateMachineInformation) { this.extensionHost = extensionHost; this.stateMachineInformation = stateMachineInformation; }
public StateTest() { this.stateMachineInformation = A.Fake<IStateMachineInformation<States, Events>>(); this.extensionHost = A.Fake<IExtensionHost<States, Events>>(); this.testee = new State<States, Events>(States.A, this.stateMachineInformation, this.extensionHost); }
public override void ExecutedTransition( IStateMachineInformation <States, Events> stateMachine, ITransition <States, Events> transition, ITransitionContext <States, Events> transitionContext) { this.items.Add(new Item(stateMachine, transition.Source, transition.Target, transitionContext)); }
public InternalExtension( IExtension <TState, TEvent> apiExtension, IStateMachineInformation <TState, TEvent> stateMachineInformation) { this.apiExtension = apiExtension; this.stateMachineInformation = stateMachineInformation; }
public override void Loaded( IStateMachineInformation <State, Event> stateMachineInformation, Initializable <State> loadedCurrentState, IDictionary <State, State> loadedHistoryStates) { this.LoadedCurrentState.Add(loadedCurrentState.Value); }
public virtual Task EnteringState( IStateMachineInformation <TState, TEvent> stateMachine, IState <TState, TEvent> state, ITransitionContext <TState, TEvent> context) { return(TaskEx.Completed); }
public override void InitializingStateMachine(IStateMachineInformation <States, Events> stateMachine, ref States initialState) { if (this.OverriddenState.HasValue) { initialState = this.OverriddenState.Value; } }
public override void HandlingExitActionException(IStateMachineInformation <TState, TEvent> stateMachine, IState <TState, TEvent> state, ITransitionContext <TState, TEvent> context, ref Exception exception) { Ensure.ArgumentNotNull(stateMachine, "stateMachine"); Ensure.ArgumentNotNull(state, "state"); this.log.ErrorFormat("Exception in exit action of state {0} of state machine {1}: {2}", state.Id, stateMachine.Name, exception); }
public override void HandlingGuardException(IStateMachineInformation <States, Events> stateMachine, ITransitionDefinition <States, Events> transition, ITransitionContext <States, Events> transitionContext, ref Exception exception) { if (this.OverriddenException != null) { exception = this.OverriddenException; } }
public override void HandlingExitActionException(IStateMachineInformation <States, Events> stateMachine, IState <States, Events> state, ITransitionContext <States, Events> context, ref Exception exception) { if (this.OverriddenException != null) { exception = this.OverriddenException; } }
public override void SwitchedState( IStateMachineInformation <ToiletStates, ToiletEvents> stateMachine, IState <ToiletStates, ToiletEvents> oldState, IState <ToiletStates, ToiletEvents> newState) { this.CurrentState = newState.Id; }
/// <summary> /// Fires the specified event. /// </summary> /// <param name="eventId">The event.</param> /// <param name="eventArgument">The event argument.</param> /// <param name="stateContainer">Contains all mutable state of of the state machine.</param> /// <param name="stateMachineInformation">The state machine information.</param> /// <param name="stateDefinitions">The definitions for all states of this state Machine.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> public async Task Fire( TEvent eventId, object eventArgument, StateContainer <TState, TEvent> stateContainer, IStateMachineInformation <TState, TEvent> stateMachineInformation, IStateDefinitionDictionary <TState, TEvent> stateDefinitions) { CheckThatStateMachineHasEnteredInitialState(stateContainer); await stateContainer.ForEach(extension => extension.FiringEvent(stateMachineInformation, ref eventId, ref eventArgument)) .ConfigureAwait(false); var currentState = stateContainer.CurrentState.ExtractOrThrow(); var context = this.factory.CreateTransitionContext(currentState, new Missable <TEvent>(eventId), eventArgument, this); var result = await this.stateLogic.Fire(currentState, context, stateContainer) .ConfigureAwait(false); if (!result.Fired) { this.OnTransitionDeclined(context); return; } var newState = stateDefinitions[result.NewState]; await SwitchStateTo(newState, stateContainer, stateMachineInformation) .ConfigureAwait(false); await stateContainer.ForEach(extension => extension.FiredEvent(stateMachineInformation, context)) .ConfigureAwait(false); this.OnTransitionCompleted(context, stateMachineInformation); }
/// <summary> /// Initializes a new instance of the <see cref="Transition<TState, TEvent>"/> class. /// </summary> /// <param name="stateMachineInformation">The state machine information.</param> /// <param name="extensionHost">The extension host.</param> public Transition(IStateMachineInformation <TState, TEvent> stateMachineInformation, IExtensionHost <TState, TEvent> extensionHost) { this.stateMachineInformation = stateMachineInformation; this.extensionHost = extensionHost; this.actions = new List <ITransitionActionHolder>(); }
/// <summary> /// Called when a transition was executed. /// </summary> /// <param name="stateMachine">The state machine.</param> /// <param name="transition">The transition.</param> /// <param name="transitionContext">The transition context.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> public virtual Task ExecutedTransition( IStateMachineInformation <TState, TEvent> stateMachine, ITransition <TState, TEvent> transition, ITransitionContext <TState, TEvent> transitionContext) { return(TaskEx.Completed); }
public StateTest() { this.stateMachineInformation = A.Fake <IStateMachineInformation <States, Events> >(); this.extensionHost = A.Fake <IExtensionHost <States, Events> >(); this.testee = new State <States, Events>(States.A, this.stateMachineInformation, this.extensionHost); }
public void StoppedStateMachine(IStateMachineInformation <NodeState, GossipEvent> stateMachine) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine( "State machine {0} stopped.", stateMachine); Console.ResetColor(); }
/// <summary> /// Fires the specified event. /// </summary> /// <param name="eventId">The event.</param> /// <param name="stateContainer">Contains all mutable state of of the state machine.</param> /// <param name="stateMachineInformation">The state machine information.</param> /// <param name="stateDefinitions">The definitions for all states of this state Machine.</param> public void Fire( TEvent eventId, StateContainer <TState, TEvent> stateContainer, IStateMachineInformation <TState, TEvent> stateMachineInformation, IStateDefinitionDictionary <TState, TEvent> stateDefinitions) { this.Fire(eventId, Missing.Value, stateContainer, stateMachineInformation, stateDefinitions); }
/// <summary> /// Called after the state machine switched states. /// </summary> /// <param name="stateMachine">The state machine.</param> /// <param name="oldState">The old state.</param> /// <param name="newState">The new state.</param> public override void SwitchedState(IStateMachineInformation <TState, TEvent> stateMachine, IState <TState, TEvent> oldState, IState <TState, TEvent> newState) { this.log.InfoFormat( "State machine {0} switched from state {1} to state {2}.", stateMachine, oldState, newState); }
public override void Loaded( IStateMachineInformation <State, Event> stateMachineInformation, IInitializable <State> loadedCurrentState, IReadOnlyDictionary <State, State> loadedHistoryStates, IReadOnlyCollection <EventInformation <Event> > events) { this.LoadedCurrentState.Add(loadedCurrentState); }
public void FiredEvent(IStateMachineInformation <NodeState, GossipEvent> stateMachine, ITransitionContext <NodeState, GossipEvent> context) { EnsureArg.IsNotNull(stateMachine, "stateMachine"); EnsureArg.IsNotNull(context, "context"); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("State machine {0} performed {1}.", stateMachine.Name, context.GetRecords()); Console.ResetColor(); }
public override Task ExecutedTransition( IStateMachineInformation <States, Events> stateMachine, ITransitionDefinition <States, Events> transition, ITransitionContext <States, Events> transitionContext) { this.items.Add(new Item(stateMachine, transition.Source, transition.Target, transitionContext)); return(Task.CompletedTask); }
public virtual Task Loaded( IStateMachineInformation <TState, TEvent> stateMachineInformation, IInitializable <TState> loadedCurrentState, IReadOnlyDictionary <TState, TState> loadedHistoryStates, IReadOnlyCollection <EventInformation <TEvent> > events, IReadOnlyCollection <EventInformation <TEvent> > priorityEvents) { return(TaskEx.Completed); }
public StateLogic( ITransitionLogic <TState, TEvent> transitionLogic, IExtensionHost <TState, TEvent> extensionHost, IStateMachineInformation <TState, TEvent> stateMachineInformation) { this.extensionHost = extensionHost; this.stateMachineInformation = stateMachineInformation; this.transitionLogic = transitionLogic; }
public override Task Loaded( IStateMachineInformation <State, Event> stateMachineInformation, IInitializable <State> loadedCurrentState, IReadOnlyDictionary <State, State> loadedHistoryStates, IReadOnlyCollection <EventInformation <Event> > events, IReadOnlyCollection <EventInformation <Event> > priorityEvents) { this.LoadedCurrentState.Add(loadedCurrentState); return(Task.CompletedTask); }
/// <summary> /// Called when an event was fired on the state machine. /// </summary> /// <param name="stateMachine">The state machine.</param> /// <param name="context">The transition context.</param> public override void FiredEvent(IStateMachineInformation <TState, TEvent> stateMachine, ITransitionContext <TState, TEvent> context) { Ensure.ArgumentNotNull(stateMachine, "stateMachine"); Ensure.ArgumentNotNull(context, "context"); if (this.log.IsDebugEnabled) { this.log.DebugFormat("State machine {0} performed {1}.", stateMachine.Name, context.GetRecords()); } }
public void SwitchedState(IStateMachineInformation <NodeState, GossipEvent> stateMachine, IState <NodeState, GossipEvent> oldState, IState <NodeState, GossipEvent> newState) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine( "State machine {0} switched from state {1} to state {2}.", stateMachine, oldState, newState); Console.ResetColor(); }
public Item( IStateMachineInformation <States, Events> stateMachine, IStateDefinition <States, Events> source, IStateDefinition <States, Events> target, ITransitionContext <States, Events> transitionContext) { this.StateMachine = stateMachine; this.Source = source; this.Target = target; this.TransitionContext = transitionContext; }
/// <summary> /// Overrides the event and event arguments with <see cref="OverriddenEvent"/> and <see cref="OverriddenEventArguments"/> if they are not null. /// </summary> /// <param name="stateMachine">The state machine.</param> /// <param name="eventId">The event id. Can be replaced by the extension.</param> /// <param name="eventArguments">The event arguments. Can be replaced by the extension.</param> public override void FiringEvent(IStateMachineInformation <States, Events> stateMachine, ref Events eventId, ref object[] eventArguments) { if (this.OverriddenEvent.HasValue) { eventId = this.OverriddenEvent.Value; } if (this.OverriddenEventArguments != null) { eventArguments = this.OverriddenEventArguments; } }
public override void SwitchedState(IStateMachineInformation <TState, TEvent> stateMachine, IState <TState, TEvent> oldState, IState <TState, TEvent> newState) { base.SwitchedState(stateMachine, oldState, newState); if (oldState != null) { _logger.Debug("StateMachine " + stateMachine.Name + " switched from " + oldState.ToString() + " to " + newState.ToString()); } else { _logger.Debug("StateMachine " + stateMachine.Name + " switched to " + newState.ToString()); } }
/// <summary> /// Initializes a new instance of the <see cref="State<TState, TEvent>"/> class. /// </summary> /// <param name="id">The unique id of this state.</param> /// <param name="stateMachineInformation">The state machine information.</param> /// <param name="extensionHost">The extension host.</param> public State(TState id, IStateMachineInformation <TState, TEvent> stateMachineInformation, IExtensionHost <TState, TEvent> extensionHost) { this.Id = id; this.level = 1; this.stateMachineInformation = stateMachineInformation; this.extensionHost = extensionHost; this.subStates = new List <IState <TState, TEvent> >(); this.transitions = new TransitionDictionary <TState, TEvent>(this); this.EntryActions = new List <IActionHolder>(); this.ExitActions = new List <IActionHolder>(); }
/// <summary> /// Called when an event is firing on the state machine. /// </summary> /// <param name="stateMachine">The state machine.</param> /// <param name="eventId">The event id. Can be replaced by the extension.</param> /// <param name="eventArgument">The event argument. Can be replaced by the extension.</param> public void FiringEvent(IStateMachineInformation <NodeState, GossipEvent> stateMachine, ref GossipEvent eventId, ref object eventArgument) { EnsureArg.IsNotNull(stateMachine, "stateMachine"); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine( "Fire event {0} on state machine {1} with current state {2} and event argument {3}.", eventId, stateMachine.Name, stateMachine.CurrentStateId, eventArgument); Console.ResetColor(); }