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