protected internal override NSFEventStatus processEvent(NSFEvent nsfEvent)
        {
            NSFTransition elseTransition = null;

            // Check transitions out of state
            foreach (NSFTransition transition in outgoingTransitions)
            {
                if (!transition.Guards.isEmpty())
                {
                    if (transition.processEvent(nsfEvent) == NSFEventStatus.NSFEventHandled)
                    {
                        return(NSFEventStatus.NSFEventHandled);
                    }
                }
                else
                {
                    if (elseTransition != null)
                    {
                        // A choice is ill formed if it has more than one "else" transition
                        throw new Exception(Name + " invalid choice state with multiple else transitions");
                    }

                    elseTransition = transition;
                }
            }

            if ((elseTransition != null) && (elseTransition.processEvent(nsfEvent) == NSFEventStatus.NSFEventHandled))
            {
                return(NSFEventStatus.NSFEventHandled);
            }

            // If no transition is taken, then the model is ill formed and an exception is thrown.
            throw new Exception(Name + " invalid model with no transition taken from a choice state");
        }
Пример #2
0
 /// <summary>
 /// Re-routes a transition between a specified source and destination
 /// </summary>
 /// <param name="transition">The transition to re-route.</param>
 /// <param name="source">The new source for the transition.</param>
 /// <param name="target">The new target for the transition.</param>
 /// <remarks>
 /// This method can be used when extending state machines.
 /// Careful design consideration should be made before using this method.
 /// Never change a state machines structure while it is running.
 /// </remarks>
 protected void rerouteTransition(NSFTransition transition, NSFState source, NSFState target)
 {
     transition.Source.removeOutgoingTransition(transition);
     transition.Target.removeIncomingTransition(transition);
     transition.Source = source;
     transition.Target = target;
 }
 /// <summary>
 /// Creates a state machine context.
 /// </summary>
 /// <param name="source">The state machine.</param>
 /// <param name="enteringState">The state being entered.</param>
 /// <param name="exitingState">The state being exited.</param>
 /// <param name="transition">The associated transition.</param>
 /// <param name="trigger">The triggering event.</param>
 public NSFStateMachineContext(NSFStateMachine source, NSFState enteringState, NSFState exitingState, NSFTransition transition, NSFEvent trigger)
     : base(source)
 {
     EnteringState = enteringState;
     ExitingState  = exitingState;
     Transition    = transition;
     Trigger       = trigger;
 }
 /// <summary>
 /// Removes an outgoing transition.
 /// </summary>
 /// <param name="transition">The outgoing transition to remove.</param>
 /// <remarks>
 /// It is called when re-routing a transition.
 /// </remarks>
 internal void removeOutgoingTransition(NSFTransition transition)
 {
     outgoingTransitions.Remove(transition);
 }
 /// <summary>
 /// Removes an incoming transition.
 /// </summary>
 /// <param name="transition">The incoming transition to remove.</param>
 /// <remarks>
 /// It is called when re-routing a transition.
 /// </remarks>
 internal void removeIncomingTransition(NSFTransition transition)
 {
     incomingTransitions.Remove(transition);
 }
 /// <summary>
 /// Adds an incoming transition.
 /// </summary>
 /// <param name="transition">The incoming transition to add.</param>
 /// <remarks>
 /// This method is called from the base transition class constructor.
 /// </remarks>
 internal void addIncomingTransition(NSFTransition transition)
 {
     incomingTransitions.Add(transition);
 }
 /// <summary>
 /// Re-routes a transition between a specified source and destination
 /// </summary>
 /// <param name="transition">The transition to re-route.</param>
 /// <param name="source">The new source for the transition.</param>
 /// <param name="target">The new target for the transition.</param>
 /// <remarks>
 /// This method can be used when extending state machines.
 /// Careful design consideration should be made before using this method.
 /// Never change a state machines structure while it is running.
 /// </remarks>
 protected void rerouteTransition(NSFTransition transition, NSFState source, NSFState target)
 {
     transition.Source.removeOutgoingTransition(transition);
     transition.Target.removeIncomingTransition(transition);
     transition.Source = source;
     transition.Target = target;
 }
 /// <summary>
 /// Creates a state machine context.
 /// </summary>
 /// <param name="source">The state machine.</param>
 /// <param name="enteringState">The state being entered.</param>
 /// <param name="exitingState">The state being exited.</param>
 /// <param name="transition">The associated transition.</param>
 /// <param name="trigger">The triggering event.</param>
 public NSFStateMachineContext(NSFStateMachine source, NSFState enteringState, NSFState exitingState, NSFTransition transition, NSFEvent trigger)
     : base(source)
 {
     EnteringState = enteringState;
     ExitingState = exitingState;
     Transition = transition;
     Trigger = trigger;
 }
 /// <summary>
 /// Removes an outgoing transition.
 /// </summary>
 /// <param name="transition">The outgoing transition to remove.</param>
 /// <remarks>
 /// It is called when re-routing a transition.
 /// </remarks>
 internal void removeOutgoingTransition(NSFTransition transition)
 {
     outgoingTransitions.Remove(transition);
 }
 /// <summary>
 /// Removes an incoming transition.
 /// </summary>
 /// <param name="transition">The incoming transition to remove.</param>
 /// <remarks>
 /// It is called when re-routing a transition.
 /// </remarks>
 internal void removeIncomingTransition(NSFTransition transition)
 {
     incomingTransitions.Remove(transition);
 }
 /// <summary>
 /// Adds an incoming transition.
 /// </summary>
 /// <param name="transition">The incoming transition to add.</param>
 /// <remarks>
 /// This method is called from the base transition class constructor.
 /// </remarks>
 internal void addIncomingTransition(NSFTransition transition)
 {
     incomingTransitions.Add(transition);
 }