コード例 #1
0
 public TransitionLogic(
     IExtensionHost <TState, TEvent> extensionHost,
     IStateMachineInformation <TState, TEvent> stateMachineInformation)
 {
     this.extensionHost           = extensionHost;
     this.stateMachineInformation = stateMachineInformation;
 }
コード例 #2
0
ファイル: StateTest.cs プロジェクト: WenningQiu/appccelerate
        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);
        }
コード例 #3
0
 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));
 }
コード例 #4
0
 public InternalExtension(
     IExtension <TState, TEvent> apiExtension,
     IStateMachineInformation <TState, TEvent> stateMachineInformation)
 {
     this.apiExtension            = apiExtension;
     this.stateMachineInformation = stateMachineInformation;
 }
コード例 #5
0
ファイル: Persisting.cs プロジェクト: tranpl/statemachine
 public override void Loaded(
     IStateMachineInformation <State, Event> stateMachineInformation,
     Initializable <State> loadedCurrentState,
     IDictionary <State, State> loadedHistoryStates)
 {
     this.LoadedCurrentState.Add(loadedCurrentState.Value);
 }
コード例 #6
0
 public virtual Task EnteringState(
     IStateMachineInformation <TState, TEvent> stateMachine,
     IState <TState, TEvent> state,
     ITransitionContext <TState, TEvent> context)
 {
     return(TaskEx.Completed);
 }
コード例 #7
0
 public override void InitializingStateMachine(IStateMachineInformation <States, Events> stateMachine, ref States initialState)
 {
     if (this.OverriddenState.HasValue)
     {
         initialState = this.OverriddenState.Value;
     }
 }
コード例 #8
0
        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);
        }
コード例 #9
0
ファイル: ExtensionTest.cs プロジェクト: wtjerry/statemachine
 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;
     }
 }
コード例 #10
0
 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;
     }
 }
コード例 #11
0
 public override void SwitchedState(
     IStateMachineInformation <ToiletStates, ToiletEvents> stateMachine,
     IState <ToiletStates, ToiletEvents> oldState,
     IState <ToiletStates, ToiletEvents> newState)
 {
     this.CurrentState = newState.Id;
 }
コード例 #12
0
ファイル: StateMachine.cs プロジェクト: wtjerry/statemachine
        /// <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);
        }
コード例 #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Transition&lt;TState, TEvent&gt;"/> 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>();
        }
コード例 #14
0
 /// <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);
 }
コード例 #15
0
        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);
        }
コード例 #16
0
 public void StoppedStateMachine(IStateMachineInformation <NodeState, GossipEvent> stateMachine)
 {
     Console.ForegroundColor = ConsoleColor.Yellow;
     Console.WriteLine(
         "State machine {0} stopped.",
         stateMachine);
     Console.ResetColor();
 }
コード例 #17
0
ファイル: StateMachine.cs プロジェクト: wtjerry/statemachine
 /// <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);
 }
コード例 #18
0
 /// <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);
 }
コード例 #19
0
 public override void Loaded(
     IStateMachineInformation <State, Event> stateMachineInformation,
     IInitializable <State> loadedCurrentState,
     IReadOnlyDictionary <State, State> loadedHistoryStates,
     IReadOnlyCollection <EventInformation <Event> > events)
 {
     this.LoadedCurrentState.Add(loadedCurrentState);
 }
コード例 #20
0
        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();
        }
コード例 #21
0
            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);
            }
コード例 #22
0
 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);
 }
コード例 #23
0
ファイル: StateLogic.cs プロジェクト: wtjerry/statemachine
 public StateLogic(
     ITransitionLogic <TState, TEvent> transitionLogic,
     IExtensionHost <TState, TEvent> extensionHost,
     IStateMachineInformation <TState, TEvent> stateMachineInformation)
 {
     this.extensionHost           = extensionHost;
     this.stateMachineInformation = stateMachineInformation;
     this.transitionLogic         = transitionLogic;
 }
コード例 #24
0
 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);
 }
コード例 #25
0
        /// <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());
            }
        }
コード例 #26
0
 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();
 }
コード例 #27
0
 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;
 }
コード例 #28
0
ファイル: ExtensionTest.cs プロジェクト: ursenzler/bbv.Common
            /// <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;
                }
            }
コード例 #29
0
        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());
            }
        }
コード例 #30
0
ファイル: State.cs プロジェクト: ikillforfood/Antykutasator
        /// <summary>
        /// Initializes a new instance of the <see cref="State&lt;TState, TEvent&gt;"/> 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>();
        }
コード例 #31
0
        /// <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();
        }