Beispiel #1
0
        public bool SendEvent(IEvent ev)
        {
            var activeHierarchyPath = _stateHierarchyBehaviourScheduler.GetActiveHierarchyPath();

            foreach (var stateIdWithObject in activeHierarchyPath)
            {
                var eventHandlers = _eventHandlers.GetEventHandlersOf(stateIdWithObject.Key);

                foreach (var eventHandler in eventHandlers)
                {
                    if (eventHandler.HandleEvent(ev))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        private void ProcessPendingTriggers()
        {
            while (_pendingTriggers.Count > 0)
            {
                var activeHierarchyPath = _stateHierarchyBehaviourScheduler.GetActiveHierarchyPath();
                var trigger             = _pendingTriggers.Dequeue();
                Transition <TState, TTrigger> validTransition = default;

                bool hasOneValid = false;

                for (int i = activeHierarchyPath.Count - 1; i >= 0; i--)
                {
                    var stateFrom = activeHierarchyPath[i].Key;

                    foreach (var transition in _transitions)
                    {
                        if (Matches(transition, stateFrom, trigger))
                        {
                            if (_transitionValidator.IsValid(transition))
                            {
                                if (hasOneValid)
                                {
                                    _pendingTriggers.Clear();
                                    throw new MultipleValidTransitionsFromSameStateException(stateFrom.ToString(), trigger.ToString());
                                }
                                else
                                {
                                    hasOneValid     = true;
                                    validTransition = transition;
                                }
                            }
                        }
                    }
                }

                if (hasOneValid)
                {
                    OnTransitionValidated?.Invoke(validTransition);
                    _stateHierarchyBehaviourScheduler.SwitchTo(validTransition.StateTo);
                }
            }
        }
Beispiel #3
0
        public bool SendEvent(IEvent ev)
        {
            var activeHierarchyPath = _stateHierarchyBehaviourScheduler.GetActiveHierarchyPath();

            for (int i = activeHierarchyPath.Count - 1; i >= 0; i--)
            {
                if (_eventHandlers.ContainsKey(activeHierarchyPath[i].Key))
                {
                    var eventHandlers = _eventHandlers[activeHierarchyPath[i].Key];

                    for (int j = 0; j < eventHandlers.Count; j++)
                    {
                        if (eventHandlers[j].HandleEvent(ev))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }