예제 #1
0
		public void AddState(BaseState state)
		{
			if (!this.CheckIsRunning())
			{
				state.MachineName = this.MachineName;
				this.states.Add(state);
			}
		}
예제 #2
0
		public StateStatusTransition(BaseState next, string statusKey) : base(next)
		{
			this.statusKey = statusKey;
		}
예제 #3
0
		public LambdaTransition(Func<bool> predicate, BaseState state) : base(state)
		{
			this.predicate = predicate;
		}
		public TransitionFromErrorState(BaseState state)
		{
			base.DefaultTransition = new DefaultTransition(state);
		}
예제 #5
0
		private BaseState HandleTransitionException(BaseState state, Exception exception)
		{
			Error error = new Error(exception);
			BaseErrorState baseErrorState = this.NextErrorState(error);
			if (baseErrorState != null)
			{
				baseErrorState.Start(error);
				state = baseErrorState;
			}
			return state;
		}
예제 #6
0
		protected virtual void OnCurrentStateChanged(BaseState oldValue, BaseState newValue)
		{
		}
예제 #7
0
		protected BaseTransition(BaseState next)
		{
			this.Next = next;
		}
예제 #8
0
		private void RaiseCurrentStateChanged(BaseState previousState, BaseState newState)
		{
			Action<BaseState, BaseState> currentStateChanged = this.CurrentStateChanged;
			if (currentStateChanged != null)
			{
				currentStateChanged(previousState, newState);
			}
		}
예제 #9
0
		public void SetStartState(BaseState state)
		{
			this.states.Remove(state);
			this.states.Insert(0, state);
		}
예제 #10
0
		public BaseStateMachine()
		{
			this.CurrentState = BaseState.NullObject();
			this.states = new List<BaseState>();
			this.machineState = BaseStateMachine.StateMachineState.Stopped;
		}
예제 #11
0
		private void SetErrorState(Error error)
		{
			if (!this.CheckIsRunning())
			{
				return;
			}
			if (this.IsCurrentStateEndErrorState())
			{
				this.StopStateMachine();
				this.RaiseStateMachineErroredEvent(error);
				return;
			}
			BaseErrorState baseErrorState = this.CurrentState.NextErrorState(error);
			if (baseErrorState != this.CurrentState)
			{
				this.CurrentState.Stop();
				this.CurrentState.Finished -= new EventHandler<TransitionEventArgs>(this.CurrentStateFinished);
				this.CurrentState.Errored -= new EventHandler<Error>(this.CurrentStateErrored);
				this.CurrentState = baseErrorState;
				baseErrorState.Finished += new EventHandler<TransitionEventArgs>(this.CurrentStateFinished);
				baseErrorState.Errored += new EventHandler<Error>(this.CurrentStateErrored);
				baseErrorState.Start(error);
			}
		}
예제 #12
0
		private void SetNextState(TransitionEventArgs eventArgs)
		{
			if (!this.CheckIsRunning())
			{
				return;
			}
			BaseState baseState = this.CurrentState.NextState(eventArgs);
			this.CurrentState.Stop();
			this.CurrentState.Finished -= new EventHandler<TransitionEventArgs>(this.CurrentStateFinished);
			this.CurrentState.Errored -= new EventHandler<Error>(this.CurrentStateErrored);
			this.CurrentState = baseState;
			this.CurrentState.Finished += new EventHandler<TransitionEventArgs>(this.CurrentStateFinished);
			this.CurrentState.Errored += new EventHandler<Error>(this.CurrentStateErrored);
			try
			{
				this.CurrentState.Start();
			}
			catch (OutOfMemoryException ex)
			{
				Tracer<BaseStateMachine>.WriteError(ex, "Cannot start a state", new object[0]);
				this.CurrentStateErrored(this.CurrentState, new Error(ex));
			}
			catch (Exception ex2)
			{
				Tracer<BaseStateMachine>.WriteError(ex2, "Cannot start a state", new object[0]);
				this.CurrentStateErrored(this.CurrentState, new Error(new InternalException(string.Empty, ex2)));
			}
			if (this.IsCurrentStateEndState())
			{
				string status = this.StopStateMachine();
				EventHandler<TransitionEventArgs> machineEnded = this.MachineEnded;
				if (machineEnded != null)
				{
					machineEnded(this, new TransitionEventArgs(status));
				}
			}
		}
예제 #13
0
		private string StopStateMachine()
		{
			this.machineState = BaseStateMachine.StateMachineState.Stopped;
			string result = string.Empty;
			EndState endState = this.CurrentState as EndState;
			if (endState != null)
			{
				result = endState.Status;
			}
			this.CurrentState.Finished -= new EventHandler<TransitionEventArgs>(this.CurrentStateFinished);
			this.CurrentState.Errored -= new EventHandler<Error>(this.CurrentStateErrored);
			this.CurrentState.Stop();
			this.CurrentState = BaseState.NullObject();
			return result;
		}
예제 #14
0
		private void StartStateMachine()
		{
			if (this.states.Count == 0)
			{
				UnexpectedErrorException ex = new UnexpectedErrorException("No states to run state machine!");
				Tracer<BaseStateMachine>.WriteError(ex);
				throw ex;
			}
			this.machineState = BaseStateMachine.StateMachineState.Running;
			this.CurrentState = this.states[0];
			this.CurrentState.Finished += new EventHandler<TransitionEventArgs>(this.CurrentStateFinished);
			this.CurrentState.Errored += new EventHandler<Error>(this.CurrentStateErrored);
			this.CurrentState.Start();
		}
예제 #15
0
		public DefaultTransition(BaseState state) : base(state)
		{
		}