private void ExitState(StateHandlerInfo <TState> info)
        {
            try
            {
                info.From.FireExitHandler(info);
            }
            catch (Exception e)
            {
                throw new InternalTransitionFaultException(info.From, info.To, info.Event, FaultedComponent.ExitHandler, e);
            }

            foreach (var group in info.From.Groups.Reverse())
            {
                // We could use .Except, but that uses a HashSet which is complete overkill here
                if (info.To.Groups.Contains(group))
                {
                    continue;
                }

                try
                {
                    group.FireExitHandler(info);
                }
                catch (Exception e)
                {
                    throw new InternalTransitionFaultException(info.From, info.To, info.Event, FaultedComponent.GroupExitHandler, e, group);
                }
            }
        }
示例#2
0
        public void FireExitHandler(StateHandlerInfo <TState> info)
        {
            var handler = this.ExitHandler;

            if (handler != null)
            {
                handler(info);
            }
        }
        void ITransitionDelegate <TState> .CoordinateTransition <TTransitionInfo>(TTransitionInfo transitionInfo, Action <TTransitionInfo> handler)
        {
            // We require that from.ParentStateMachine.TopmostStateMachine == to.ParentStateMachine.TopmostStateMachine == this

            this.OnTransition(transitionInfo.From.ParentStateMachine, transitionInfo);

            var stateHandlerInfo = new StateHandlerInfo <TState>(transitionInfo.From, transitionInfo.To, transitionInfo.Event, transitionInfo.IsInnerTransition, transitionInfo.EventData, transitionInfo.EventFireMethod);

            if (!transitionInfo.IsInnerTransition)
            {
                if (transitionInfo.From.ChildStateMachine != null)
                {
                    this.ExitChildStateMachine(transitionInfo.From.ChildStateMachine, transitionInfo.To, transitionInfo.Event, transitionInfo.IsInnerTransition, transitionInfo.EventData, transitionInfo.EventFireMethod);
                }

                this.ExitState(stateHandlerInfo);
            }

            if (handler != null)
            {
                try
                {
                    handler(transitionInfo);
                }
                catch (Exception e)
                {
                    throw new InternalTransitionFaultException(transitionInfo.From, transitionInfo.To, transitionInfo.Event, FaultedComponent.TransitionHandler, e);
                }
            }

            transitionInfo.From.ParentStateMachine.SetCurrentState(transitionInfo.To);

            if (!transitionInfo.IsInnerTransition)
            {
                this.EnterState(stateHandlerInfo);

                if (transitionInfo.To.ChildStateMachine != null)
                {
                    this.EnterChildStateMachine(transitionInfo.To.ChildStateMachine, transitionInfo.From, transitionInfo.Event, transitionInfo.IsInnerTransition, transitionInfo.EventData, transitionInfo.EventFireMethod);
                }
            }

            this.OnTransitionFinished(transitionInfo.From.ParentStateMachine, transitionInfo);
        }
        public void CoordinateTransition <TTransitionInfo>(TState from, TState to, IEvent @event, bool isInnerTransition, Action <TTransitionInfo> handler, TTransitionInfo transitionInfo)
        {
            // We require that from.ParentStateMachine.Kernel == to.ParentStateMachine.Kernel == this

            var stateHandlerInfo = new StateHandlerInfo <TState>(from, to, @event);

            if (!isInnerTransition)
            {
                if (from.ChildStateMachine != null)
                {
                    this.ExitChildStateMachine(from.ChildStateMachine, to, @event);
                }

                this.ExitState(stateHandlerInfo);
            }

            if (handler != null)
            {
                try
                {
                    handler(transitionInfo);
                }
                catch (Exception e)
                {
                    throw new InternalTransitionFaultException(from, to, @event, FaultedComponent.TransitionHandler, e);
                }
            }

            from.ParentStateMachine.SetCurrentState(to);

            if (!isInnerTransition)
            {
                this.EnterState(stateHandlerInfo);

                if (to.ChildStateMachine != null)
                {
                    this.EnterChildStateMachine(to.ChildStateMachine, from, @event);
                }
            }

            this.OnTransition(from, to, @event, from.ParentStateMachine, isInnerTransition);
        }
示例#5
0
 public void FireEntryHandler(StateHandlerInfo <TState> info)
 {
     this.EntryHandler?.Invoke(info);
 }
示例#6
0
 void IState <State> .FireExitHandler(StateHandlerInfo <State> info)
 {
     this.innerState.FireExitHandler(info);
 }
示例#7
0
 /// <summary>
 /// Invoke the exit handler - override for custom behaviour
 /// </summary>
 /// <param name="info">Information associated with this transition</param>
 protected internal virtual void OnExit(StateHandlerInfo <TState> info)
 {
     this.ExitHandler?.Invoke(info);
 }
示例#8
0
 void IStateGroup <State> .FireEntryHandler(StateHandlerInfo <State> info)
 {
     this.innerStateGroup.FireEntryHandler(info);
 }
示例#9
0
 void IState <State <TStateData> > .FireEntryHandler(StateHandlerInfo <State <TStateData> > info)
 {
     this.innerState.FireEntryHandler(info);
 }
示例#10
0
 void IStateGroup <State <TStateData> > .FireExitHandler(StateHandlerInfo <State <TStateData> > info)
 {
     this.innerStateGroup.FireExitHandler(info);
 }