コード例 #1
0
        /// <summary>
        /// Force a transition to the given state, even though there may not be a valid configured transition to that state from the current state
        /// </summary>
        /// <remarks>Exit and entry handlers will be fired, but no transition handler will be fired</remarks>
        /// <param name="toState">State to transition to</param>
        /// <param name="event">Event pass to the exit/entry handlers</param>
        /// <param name="eventData">Event data to pass to the state exit/entry handlers</param>
        public void ForceTransition <TEventData>(TState toState, Event <TEventData> @event, TEventData eventData)
        {
            if (toState == null)
            {
                throw new ArgumentNullException(nameof(toState));
            }
            if (@event == null)
            {
                throw new ArgumentNullException(nameof(@event));
            }

            var transitionInvoker = new ForcedTransitionInvoker <TState>(toState, @event, eventData, this);

            if (this.Synchronizer != null)
            {
                this.Synchronizer.ForceTransition(() => this.InvokeTransition(this.ForceTransitionImpl, transitionInvoker));
            }
            else
            {
                this.InvokeTransition(this.ForceTransitionImpl, transitionInvoker);
            }
        }
コード例 #2
0
        /// <summary>
        /// Force a transition to the given state, even though there may not be a valid configured transition to that state from the current state
        /// </summary>
        /// <remarks>Exit and entry handlers will be fired, but no transition handler will be fired</remarks>
        /// <param name="toState">State to transition to</param>
        /// <param name="event">Event pass to the exit/entry handlers</param>
        public void ForceTransition(State toState, IEvent @event)
        {
            if (toState == null)
            {
                throw new ArgumentNullException(nameof(toState));
            }
            if (@event == null)
            {
                throw new ArgumentNullException(nameof(@event));
            }

            if (toState.ParentStateMachine != this)
            {
                throw new InvalidStateTransitionException(this.CurrentState, toState);
            }
            if (@event.ParentStateMachine != this && !this.IsChildOf(@event.ParentStateMachine))
            {
                throw new InvalidEventTransitionException(this.CurrentState, @event);
            }

            var transitionInvoker = new ForcedTransitionInvoker <State>(toState, @event, this.InnerStateMachine.Kernel);

            this.InnerStateMachine.ForceTransitionFromUser(transitionInvoker);
        }