Ejemplo n.º 1
0
            public Transition Exit(Transition transition)
            {
                if (transition.IsReentry)
                {
                    ExecuteExitActions(transition);
                }
                else if (!Includes(transition.Destination))
                {
                    ExecuteExitActions(transition);

                    // Must check if there is a superstate, and if we are leaving that superstate
                    if (_superstate != null)
                    {
                        // Check if destination is within the state list
                        if (IsIncludedIn(transition.Destination))
                        {
                            // Destination state is within the list, exit first superstate only if it is NOT the the first
                            if (!_superstate.UnderlyingState.Equals(transition.Destination))
                            {
                                return(_superstate.Exit(transition));
                            }
                        }
                        else
                        {
                            // Exit the superstate as well
                            return(_superstate.Exit(transition));
                        }
                    }
                }
                return(transition);
            }
Ejemplo n.º 2
0
        private void HandleTransitioningTrigger(object[] args, StateRepresentation representativeState, Transition transition)
        {
            transition = representativeState.Exit(transition);

            State = transition.Destination;
            var newRepresentation = GetRepresentation(transition.Destination);

            // Check if there is an intital transition configured
            if (newRepresentation.HasInitialTransition)
            {
                // Verify that the target state is a substate
                if (!newRepresentation.GetSubstates().Any(s => s.UnderlyingState.Equals(newRepresentation.InitialTransitionTarget)))
                {
                    throw new InvalidOperationException($"The target ({newRepresentation.InitialTransitionTarget}) for the initial transition is not a substate.");
                }

                // Check if state has substate(s), and if an initial transition(s) has been set up.
                while (newRepresentation.GetSubstates().Any() && newRepresentation.HasInitialTransition)
                {
                    var initialTransition = new Transition(transition.Source, newRepresentation.InitialTransitionTarget, transition.Trigger);
                    newRepresentation = GetRepresentation(newRepresentation.InitialTransitionTarget);
                    newRepresentation.Enter(initialTransition, args);
                    State = newRepresentation.UnderlyingState;
                }
                //Alert all listeners of state transition
                _onTransitionedEvent.Invoke(transition);
            }
            else
            {
                //Alert all listeners of state transition
                _onTransitionedEvent.Invoke(transition);
                newRepresentation.Enter(transition, args);
            }
        }
Ejemplo n.º 3
0
        private void HandleReentryTrigger(object[] args, StateRepresentation representativeState, Transition transition)
        {
            StateRepresentation representation;

            transition = representativeState.Exit(transition);
            var newRepresentation = GetRepresentation(transition.Destination);

            if (!transition.Source.Equals(transition.Destination))
            {
                // Then Exit the final superstate
                transition = new Transition(transition.Destination, transition.Destination, transition.Trigger, args);
                newRepresentation.Exit(transition);

                _onTransitionedEvent.Invoke(transition);
                representation = EnterState(newRepresentation, transition, args);
                _onTransitionCompletedEvent.Invoke(transition);
            }
            else
            {
                _onTransitionedEvent.Invoke(transition);
                representation = EnterState(newRepresentation, transition, args);
                _onTransitionCompletedEvent.Invoke(transition);
            }
            State = representation.UnderlyingState;
        }
Ejemplo n.º 4
0
        private void HandleTransitioningTrigger(object[] args, StateRepresentation representativeState, Transition transition)
        {
            transition = representativeState.Exit(transition);

            State = transition.Destination;
            var newRepresentation = GetRepresentation(transition.Destination);

            //Alert all listeners of state transition
            _onTransitionedEvent.Invoke(transition);
            var representation = EnterState(newRepresentation, transition, args);

            State = representation.UnderlyingState;
        }
Ejemplo n.º 5
0
            public void Exit(Transition transition)
            {
                Enforce.ArgumentNotNull(transition, nameof(transition));

                if (transition.IsReentry)
                {
                    ExecuteExitActions(transition);
                }
                else if (!Includes(transition.Destination))
                {
                    ExecuteExitActions(transition);
                    if (_superstate != null)
                        _superstate.Exit(transition);
                }
            }
Ejemplo n.º 6
0
        private void HandleReentryTrigger(object[] args, StateRepresentation representativeState, Transition transition)
        {
            transition = representativeState.Exit(transition);
            State      = transition.Destination;
            var newRepresentation = GetRepresentation(transition.Destination);

            if (!transition.Source.Equals(transition.Destination))
            {
                // Then Exit the final superstate
                transition = new Transition(transition.Destination, transition.Destination, transition.Trigger);
                newRepresentation.Exit(transition);
            }

            _onTransitionedEvent.Invoke(transition);

            newRepresentation.Enter(transition, args);
        }
Ejemplo n.º 7
0
            public void Exit(Transition transition)
            {
                if (transition.IsReentry)
                {
                    ExecuteDeactivationActions();
                    ExecuteExitActions(transition);
                }
                else if (!Includes(transition.Destination))
                {
                    ExecuteDeactivationActions();
                    ExecuteExitActions(transition);

                    if (_superstate != null)
                    {
                        _superstate.Exit(transition);
                    }
                }
            }
Ejemplo n.º 8
0
 public void Exit(Transition transition)
 {
     if (transition != null)
     {
         if (transition.IsReentry)
         {
             ExecuteExitActions(transition);
         }
         else if (!IncludeState(transition.Destination))
         {
             ExecuteExitActions(transition);
             if (mSuperState != null)
             {
                 mSuperState.Exit(transition);
             }
         }
     }
 }
Ejemplo n.º 9
0
        private void HandleTransitioningTrigger(object[] args, StateRepresentation representativeState, Transition transition)
        {
            transition = representativeState.Exit(transition);

            State = transition.Destination;
            var newRepresentation = GetRepresentation(transition.Destination);

            //Alert all listeners of state transition
            _onTransitionedEvent.Invoke(transition);
            var representation = EnterState(newRepresentation, transition, args);

            // Check if state has changed by entering new state (by fireing triggers in OnEntry or such)
            if (!representation.UnderlyingState.Equals(State))
            {
                // The state has been changed after entering the state, must update current state to new one
                State = representation.UnderlyingState;
            }

            _onTransitionCompletedEvent.Invoke(transition);
        }
Ejemplo n.º 10
0
            public Transition Exit(Transition transition)
            {
                if (transition.IsReentry)
                {
                    ExecuteDeactivationActions();
                    ExecuteExitActions(transition);
                }
                else if (!Includes(transition.Destination))
                {
                    ExecuteDeactivationActions();
                    ExecuteExitActions(transition);

                    if (_superstate != null)
                    {
                        transition = new Transition(_superstate.UnderlyingState, transition.Destination, transition.Trigger);
                        return(_superstate.Exit(transition));
                    }
                }
                return(transition);
            }