Exemplo n.º 1
0
        public void AddTransitionCallback(TState target, TransitionCallback <TState> method)
        {
            if (!_transitionsMap.ContainsKey(target))
            {
                throw new StateMachineException <TState>(ErrorCodes.UnknownArc, StateMachineException <TState> .MakeArcName(Name, target));
            }

            var transition = _transitionsMap[target];

            transition.AddTransitionCallback(method);
        }
Exemplo n.º 2
0
        public void AddTransition(State <T> state)
        {
            if (_transitionsMap.ContainsKey(state.Name))
            {
                throw new StateMachineException <T>(ErrorCodes.AlreadyPresentArc, StateMachineException <T> .MakeArcName(Name, state.Name));
            }

            Transition <T> transition = new Transition <T>(this, state);

            _transitionsMap[state.Name] = transition;
        }
Exemplo n.º 3
0
        public void AddTransitArcCallback(string target, ArcCallback method)
        {
            if (!_arcsMap.ContainsKey(target))
            {
                throw new StateMachineException(ErrorCodes.UnknownArc, StateMachineException.MakeArcName(Name, target));
            }

            Arc a = _arcsMap[target];

            a.AddTransitionCallback(method);
        }
Exemplo n.º 4
0
        public void AddArc(State s)
        {
            if (_arcsMap.ContainsKey(s.Name))
            {
                throw new StateMachineException(ErrorCodes.AlreadyPresentArc, StateMachineException.MakeArcName(Name, s.Name));
            }

            Arc a = new Arc(this, s);

            _arcsMap[s.Name] = a;
        }
Exemplo n.º 5
0
        public Arc(State source, State target)
        {
            Source = source;
            Target = target;

            _transitCallbacks = new List <ArcCallbackInvoker>();

            if (IsUnlinked)
            {
                throw new StateMachineException(ErrorCodes.InvalidArc, StateMachineException.MakeArcName(source.Name, target.Name));
            }
        }
Exemplo n.º 6
0
        public Transition(StateContainer <TState> source, StateContainer <TState> target)
        {
            Source = source;
            Target = target;

            _transitCallbacks = new List <TransitionCallbackInvoker <TState> >();

            if (IsUnlinked)
            {
                throw new StateMachineException <TState>(ErrorCodes.InvalidArc, StateMachineException <TState> .MakeArcName(source.Name, target.Name));
            }
        }
        public Transition(State <T> source, State <T> target)
        {
            Source = source;
            Target = target;

            _callbacks = new List <Action <State <T>, State <T> > >();

            if (IsUnlinked)
            {
                throw new StateMachineException <T>(ErrorCodes.InvalidArc, StateMachineException <T> .MakeArcName(source.Name, target.Name));
            }
        }
Exemplo n.º 8
0
        public void GoToState(TState stateName)
        {
            try
            {
                if (IsTransiting)
                {
                    throw new StateMachineException <TState>(ErrorCodes.AlreadyTransiting, stateName);
                }

                IsTransiting = true;
                OnTransiting(new TransitingEventArgs <TState>(stateName));
                var target = this[stateName];

                if (target == null)
                {
                    throw new StateMachineException <TState>(ErrorCodes.UnknownState, stateName);
                }

                if (CurrentState != null)
                {
                    var transition = CurrentState[target];

                    if (transition == null)
                    {
                        throw new StateMachineException <TState>(ErrorCodes.InvalidTransition, StateMachineException <TState> .MakeArcName(CurrentState.Name, target.Name));
                    }

                    CurrentState.CallExitCallbacks();
                    transition.CallTransitionCallbacks();
                }

                CurrentState = target;
                target.CallEnterCallbacks();
                IsTransiting = false;
                OnTransited(new TransitedEventArgs <TState>(CurrentState.Name));
            }
            catch
            {
                IsTransiting = false;
                throw;
            }
        }