Пример #1
0
        /// <summary>
        /// Fires the trigger towards this <see cref="IState"/>.
        /// </summary>
        /// <param name="trigger">The trigger as an instance of <see cref="EventMessage"/>.</param>
        /// <returns>
        /// The reference to the <see cref="IState"/> which has been reached after the transition.
        /// </returns>
        /// <exception cref="ArgumentNullException">Is thrown when <paramref name="trigger"/> is a <see langword="null"/> reference.</exception>
        protected internal virtual IState ProcessTrigger(EventMessage trigger)
        {
            if (trigger == null)
            {
                throw new ArgumentNullException("trigger");
            }

            this.transitions[trigger.Name].PerformTransition(trigger);
            return this.transitions[trigger.Name].ToState;
        }
Пример #2
0
        /// <summary>
        /// Triggers the <see cref="IStateMachine"/> to handle the given <see cref="EventMessage"/> according to the actual <see cref="IState"/>.
        /// </summary>
        /// <param name="eventToHandle">The <see cref="EventMessage"/> to handle.</param>
        /// <exception cref="ArgumentNullException">Is thrown when <paramref name="eventToHandle"/> is a <see langword="null"/> reference.</exception>
        public void HandleEvent(EventMessage eventToHandle)
        {
            if (eventToHandle == null)
            {
                throw new ArgumentNullException("eventToHandle");
            }

            logger.DebugFormat("Handling event named {0} on state {1}", eventToHandle.Name, this.actualState.Name);

            if (this.actualState.HasTransitionForTrigger(eventToHandle.Name))
            {
                IState target = this.actualState.ProcessTrigger(eventToHandle);
                if (target.Name != this.actualState.Name)
                {
                    this.actualState = (State)target;
                }
            }
            else
            {
                logger.Info("No transitions defined for this trigger.");
            }
        }