Beispiel #1
0
		public void AddState(BaseState state)
		{
			if (!this.CheckIsRunning())
			{
				state.MachineName = this.MachineName;
				this.states.Add(state);
			}
		}
		public StateStatusTransition(BaseState next, string statusKey) : base(next)
		{
			this.statusKey = statusKey;
		}
Beispiel #3
0
		public LambdaTransition(Func<bool> predicate, BaseState state) : base(state)
		{
			this.predicate = predicate;
		}
		public TransitionFromErrorState(BaseState state)
		{
			base.DefaultTransition = new DefaultTransition(state);
		}
Beispiel #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;
		}
		protected virtual void OnCurrentStateChanged(BaseState oldValue, BaseState newValue)
		{
		}
Beispiel #7
0
		protected BaseTransition(BaseState next)
		{
			this.Next = next;
		}
Beispiel #8
0
		private void RaiseCurrentStateChanged(BaseState previousState, BaseState newState)
		{
			Action<BaseState, BaseState> currentStateChanged = this.CurrentStateChanged;
			if (currentStateChanged != null)
			{
				currentStateChanged(previousState, newState);
			}
		}
Beispiel #9
0
		public void SetStartState(BaseState state)
		{
			this.states.Remove(state);
			this.states.Insert(0, state);
		}
Beispiel #10
0
		public BaseStateMachine()
		{
			this.CurrentState = BaseState.NullObject();
			this.states = new List<BaseState>();
			this.machineState = BaseStateMachine.StateMachineState.Stopped;
		}
Beispiel #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);
			}
		}
Beispiel #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));
				}
			}
		}
Beispiel #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;
		}
Beispiel #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();
		}
Beispiel #15
0
		public DefaultTransition(BaseState state) : base(state)
		{
		}