Exemplo n.º 1
0
        // Recursively goes up the the state hierarchy until a state is found
        // that will handle the event.
        private TransitionResult Dispatch(State origin, int eventID, object[] args)
        {
            TransitionResult transResult = notFiredResult;

            // If there are any Transitions for this event.
            if (transitions[eventID] != null)
            {
                // Iterate through the Transitions until one of them fires.
                foreach (Transition trans in transitions[eventID])
                {
                    transResult = trans.Fire(origin, args);

                    if (transResult.HasFired)
                    {
                        // Break out of loop. We're finished.
                        break;
                    }
                }
            }
            // Else if there are no Transitions for this event and there is a
            // superstate.
            else if (Superstate != null)
            {
                // Dispatch the event to the superstate.
                transResult = Superstate.Dispatch(origin, eventID, args);
            }

            return(transResult);
        }
Exemplo n.º 2
0
            // Enters the state in via its history in shallow mode.
            private TransitionResult dispatch(EventContext context)
            {
                var transResult = s_notFiredResult;

                // If there are any Transitions for this event.
                if (m_transitions[context.CurrentEvent] != null)
                {
                    // Iterate through the Transitions until one of them fires.
                    foreach (var trans in m_transitions[context.CurrentEvent])
                    {
                        transResult = trans.fire(context);
                        if (transResult.HasFired)
                        {
                            // Break out of loop. We're finished.
                            return(transResult);
                        }
                    }
                }
                // Else if there are no Transitions for this event and there is a
                // superstate.
                if (Superstate != null)
                {
                    // Dispatch the event to the superstate.
                    transResult = Superstate.dispatch(context);
                }

                return(transResult);
            }
Exemplo n.º 3
0
            public bool TryFindHandler(TTrigger trigger, object[] args, out TriggerBehaviourResult handler)
            {
                TriggerBehaviourResult superStateHandler = null;

                bool handlerFound = (TryFindLocalHandler(trigger, args, out TriggerBehaviourResult localHandler) ||
                                     (Superstate != null && Superstate.TryFindHandler(trigger, args, out superStateHandler)));

                // If no handler for super state, replace by local handler (see issue #398)
                handler = superStateHandler ?? localHandler;

                return(handlerFound);
            }
Exemplo n.º 4
0
            public IEnumerable <TTrigger> GetPermittedTriggers(params object[] args)
            {
                var result = TriggerBehaviours
                             .Where(t => t.Value.Any(a => !a.UnmetGuardConditions(args).Any()))
                             .Select(t => t.Key);

                if (Superstate != null)
                {
                    result = result.Union(Superstate.GetPermittedTriggers(args));
                }

                return(result);
            }
Exemplo 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);
                    Superstate?.Exit(transition);
                }
            }
Exemplo n.º 6
0
            public void Enter(Transition transition, params object[] entryArgs)
            {
                Enforce.ArgumentNotNull(transition, nameof(transition));

                if (transition.IsReentry)
                {
                    ExecuteEntryActions(transition, entryArgs);
                }
                else if (!Includes(transition.Source))
                {
                    Superstate?.Enter(transition, entryArgs);

                    ExecuteEntryActions(transition, entryArgs);
                }
            }
Exemplo n.º 7
0
            public void Exit(Transition transition)
            {
                Enforce.ArgumentNotNull(transition, "transtion");

                if (transition.IsReentry)
                {
                    ExecuteExitActions(transition);
                }
                else if (!Includes(transition.Destination))
                {
                    ExecuteExitActions(transition);
                    if (Superstate != null)
                    {
                        Superstate.Exit(transition);
                    }
                }
            }
Exemplo n.º 8
0
            public void Enter(Transition transition, params object[] entryArgs)
            {
                Enforce.ArgumentNotNull(transition, "transtion");

                if (transition.IsReentry)
                {
                    ExecuteEntryActions(transition, entryArgs);
                }
                else if (!Includes(transition.Source))
                {
                    if (Superstate != null)
                    {
                        Superstate.Enter(transition, entryArgs);
                    }

                    ExecuteEntryActions(transition, entryArgs);
                }
            }
Exemplo n.º 9
0
 public bool TryFindHandlerWithUnmetGuardCondition(TTrigger trigger, out TriggerBehaviour handler)
 {
     return(TryFindLocalHandler(trigger, out handler, t => !t.IsGuardConditionMet) ||
            (Superstate != null && Superstate.TryFindHandlerWithUnmetGuardCondition(trigger, out handler)));
 }
Exemplo n.º 10
0
 public bool TryFindHandler(TTrigger trigger, out TriggerBehaviour handler)
 {
     return(TryFindLocalHandler(trigger, out handler) ||
            Superstate != null && Superstate.TryFindHandler(trigger, out handler));
 }
Exemplo n.º 11
0
 public bool IsIncludedIn(TState state)
 {
     return
         (UnderlyingState.Equals(state) ||
          Superstate != null && Superstate.IsIncludedIn(state));
 }
Exemplo n.º 12
0
 public bool TryFindHandler(TTrigger trigger, object[] args, out TriggerBehaviourResult handler)
 {
     return(TryFindLocalHandler(trigger, args, out handler) ||
            (Superstate != null && Superstate.TryFindHandler(trigger, args, out handler)));
 }
Exemplo n.º 13
0
 public bool HasHandlerFor(TTriggerType trigger, out TriggerStrategy handler)
 {
     return(HasLocalHandlerFor(trigger, out handler) ||
            (Superstate != null && Superstate.HasHandlerFor(trigger, out handler)));
 }