Ejemplo n.º 1
0
            //-------------------------------------------------------------------------------------------------------------------------------------------------

            public void Enter(StateMachineFeedbackEventArgs <TState, TTrigger> args)
            {
                if (_onEntered != null)
                {
                    _onEntered(_ownerMachine, args);
                }
            }
Ejemplo n.º 2
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        private StateMachineFeedbackEventArgs <TState, TTrigger> PerformTrigger(TTrigger trigger, object context)
        {
            var currentState = _currentState;
            var transition   = currentState.ValidateTransition(trigger);

            if (transition == null)
            {
                throw _logger.TransitionNotDefined(_codeBehind.GetType(), currentState.Value, trigger);
            }

            var eventArgs = new StateMachineFeedbackEventArgs <TState, TTrigger>(_currentState.Value, transition.DestinationStateValue, trigger, context);

            _currentState.Leave(eventArgs);

            try
            {
                transition.RaiseTransitioning(eventArgs);
            }
            catch
            {
                _currentState.Enter(eventArgs);
                throw;
            }

            _currentState = _states[transition.DestinationStateValue];
            _currentState.Enter(eventArgs);

            return(eventArgs);
        }
Ejemplo n.º 3
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        /*public TransientStateMachine(IStateMachineCodeBehind<TState, TTrigger> codeBehind, IComponentContext components)
         *  : this(codeBehind, components.ResolveAuto<ILogger>())
         * {
         * }
         *
         * //-----------------------------------------------------------------------------------------------------------------------------------------------------
         *
         * public TransientStateMachine(IStateMachineCodeBehind<TState, TTrigger> codeBehind, Auto<ILogger> logger)
         *  : this(codeBehind, logger.Instance)
         * {
         * }*/

        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public TransientStateMachine(IStateMachineCodeBehind <TState, TTrigger> codeBehind, ILogger logger)
        {
            _logger     = logger;
            _codeBehind = codeBehind;
            _states     = new Dictionary <TState, MachineState>();

            _codeBehind.BuildStateMachine(this);

            if (_currentState == null)
            {
                throw _logger.InitialStateNotSet(_codeBehind.GetType());
            }

            var eventArgs = new StateMachineFeedbackEventArgs <TState, TTrigger>(_currentState.Value);

            _currentState.Enter(eventArgs);

            if (eventArgs.HasFeedback)
            {
                ReceiveTrigger(eventArgs.Feedback);
            }
        }