public void SetFault(StateMachineFaultInfo faultInfo)
        {
            this.Fault = faultInfo;
            this.transitionQueue.Clear();

            this.Faulted?.Invoke(this, new StateMachineFaultedEventArgs(faultInfo));
        }
        private bool InvokeTransition <TTransitionInvoker>(Func <TTransitionInvoker, bool> method, TTransitionInvoker transitionInvoker)
            where TTransitionInvoker : ITransitionInvoker <TState>
        {
            this.EnsureNoFault();

            if (this.executingTransition)
            {
                this.transitionQueue.Enqueue(new TransitionQueueItem <TTransitionInvoker>(method, transitionInvoker));
                return(true);
            }

            bool success;

            try
            {
                try
                {
                    this.executingTransition = true;
                    success = method(transitionInvoker);
                }
                catch (InternalTransitionFaultException e)
                {
                    var faultInfo = new StateMachineFaultInfo(this, e.FaultedComponent, e.InnerException, e.From, e.To, e.Event, e.Group);
                    this.SetFault(faultInfo);
                    throw new TransitionFailedException(faultInfo);
                }
                finally
                {
                    this.executingTransition = false;
                }

                this.FireQueuedTransitions();
            }
            finally
            {
                // Whatever happens, when we've either failed or executed everything in the transition queue,
                // the queue should end up empty.
                this.transitionQueue.Clear();
            }

            return(success);
        }
        private bool InvokeTransition(Func <ITransitionInvoker <TState>, bool> method, ITransitionInvoker <TState> transitionInvoker)
        {
            if (this.Kernel.Fault != null)
            {
                throw new StateMachineFaultedException(this.Kernel.Fault);
            }

            if (this.Kernel.ExecutingTransition)
            {
                this.Kernel.EnqueueTransition(method, transitionInvoker);
                return(true);
            }

            bool success;

            try
            {
                this.Kernel.ExecutingTransition = true;
                success = method(transitionInvoker);
            }
            catch (InternalTransitionFaultException e)
            {
                var faultInfo = new StateMachineFaultInfo(this.outerStateMachine, e.FaultedComponent, e.InnerException, e.From, e.To, e.Event, e.Group);
                this.Kernel.SetFault(faultInfo);
                throw new TransitionFailedException(faultInfo);
            }
            finally
            {
                this.Kernel.ExecutingTransition = false;
            }


            this.Kernel.FireQueuedTransitions();

            return(success);
        }
 internal StateMachineFaultedEventArgs(StateMachineFaultInfo faultInfo)
 {
     this.FaultInfo = faultInfo;
 }
 internal StateMachineFaultedException(StateMachineFaultInfo faultInfo)
     : base(String.Format("The state machine {0} is currently faulted because a previous transition threw an exception. See FaultInfo for details", faultInfo.StateMachine.Name))
 {
     this.FaultInfo = faultInfo;
 }
Beispiel #6
0
 internal TransitionFailedException(StateMachineFaultInfo faultInfo)
     : base(String.Format("The transition from {0} to {1} (on event {2}) failed at stage {3} with exception '{4}'",
                          faultInfo.From.Name, faultInfo.To.Name, faultInfo.Event.Name, faultInfo.FaultedComponent, faultInfo.Exception.Message), faultInfo.Exception)
 {
     this.FaultInfo = faultInfo;
 }
Beispiel #7
0
 internal StateMachineFaultedException(StateMachineFaultInfo faultInfo)
     : base(String.Format("The state machine {0} is currently faulted because a previous transition threw an exception. See FaultInfo for details", faultInfo.StateMachine.Name))
 {
     this.FaultInfo = faultInfo;
 }
 private void SetFault(StateMachineFaultInfo faultInfo)
 {
     this.Fault = faultInfo;
     this.Faulted?.Invoke(this, new StateMachineFaultedEventArgs(faultInfo));
 }
 internal TransitionFailedException(StateMachineFaultInfo faultInfo)
     : base(String.Format("The transition from {0} to {1} (on event {2}) failed at stage {3} with exception '{4}'",
     faultInfo.From.Name, faultInfo.To.Name, faultInfo.Event.Name, faultInfo.FaultedComponent, faultInfo.Exception.Message), faultInfo.Exception)
 {
     this.FaultInfo = faultInfo;
 }
 internal StateMachineFaultedEventArgs(StateMachineFaultInfo faultInfo)
 {
     this.FaultInfo = faultInfo;
 }