/// <summary>
		/// Initializes a new instance of the <see cref="StateInUseException"/> class.
		/// </summary>
		/// <param name="state">The state.</param>
		/// <param name="innerException">The inner exception.</param>
		public StateInUseException(IFiniteState state, Exception innerException)
			: base(
				string.Format(
					CultureInfo.CurrentCulture, "The {0} state is currently in use.", state.Name),
				innerException)
		{
		}
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StateInUseException"/> class.
 /// </summary>
 /// <param name="state">The state.</param>
 /// <param name="innerException">The inner exception.</param>
 public StateInUseException(IFiniteState state, Exception innerException)
     : base(
         string.Format(
             CultureInfo.CurrentCulture, "The {0} state is currently in use.", state.Name),
         innerException)
 {
 }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DuplicateStateCodeException"/> class.
 /// </summary>
 /// <param name="state">The state.</param>
 /// <param name="innerException">The inner exception.</param>
 public DuplicateStateCodeException(IFiniteState state, Exception innerException)
     : base(
         string.Format(
             CultureInfo.CurrentCulture, "The {0} state's Code value is already in use.", state.Name),
         innerException)
 {
 }
		/// <summary>
		/// Initializes a new instance of the <see cref="StateAlreadyRegisteredException"/> class.
		/// </summary>
		/// <param name="state">The state.</param>
		/// <param name="innerException">The inner exception.</param>
		public StateAlreadyRegisteredException(IFiniteState state, Exception innerException)
			: base(
				string.Format(
					CultureInfo.CurrentCulture, "The {0} state is already registered with this finite state machine.", state.Name),
				innerException)
		{
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="TransitionAlreadyRegisteredException"/> class.
		/// </summary>
		/// <param name="state">The state.</param>
		/// <param name="transition">The transition.</param>
		/// <param name="innerException">The inner exception.</param>
		public TransitionAlreadyRegisteredException(IFiniteState state, IFiniteStateTransition transition, Exception innerException)
			: base(
				string.Format(
					CultureInfo.CurrentCulture, "The {0} state is already registered with the {1} transition.", state.Name, transition.Name),
				innerException)
		{
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="DuplicateStateCodeException"/> class.
		/// </summary>
		/// <param name="state">The state.</param>
		/// <param name="innerException">The inner exception.</param>
		public DuplicateStateCodeException(IFiniteState state, Exception innerException)
			: base(
				string.Format(
					CultureInfo.CurrentCulture, "The {0} state's Code value is already in use.", state.Name),
				innerException)
		{
		}
 /// <summary>
 /// Initializes a new instance of the <see cref="TransitionAlreadyRegisteredException"/> class.
 /// </summary>
 /// <param name="state">The state.</param>
 /// <param name="transition">The transition.</param>
 /// <param name="innerException">The inner exception.</param>
 public TransitionAlreadyRegisteredException(IFiniteState state, IFiniteStateTransition transition, Exception innerException)
     : base(
         string.Format(
             CultureInfo.CurrentCulture, "The {0} state is already registered with the {1} transition.", state.Name, transition.Name),
         innerException)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="StateAlreadyRegisteredException"/> class.
 /// </summary>
 /// <param name="state">The state.</param>
 /// <param name="innerException">The inner exception.</param>
 public StateAlreadyRegisteredException(IFiniteState state, Exception innerException)
     : base(
         string.Format(
             CultureInfo.CurrentCulture, "The {0} state is already registered with this finite state machine.", state.Name),
         innerException)
 {
 }
		/// <summary>
		/// Initializes a new instance of the <see cref="StateNotRegisteredException"/> class.
		/// </summary>
		/// <param name="transition">
		/// The transition.
		/// </param>
		/// <param name="state">
		/// The state.
		/// </param>
		/// <param name="innerException">
		/// The inner exception.
		/// </param>
		public StateNotRegisteredException(
			IFiniteStateTransition transition, IFiniteState state, Exception innerException)
			: base(
				string.Format(
					CultureInfo.CurrentCulture, "The {0} transition returned an unregistered {1} state.", transition.Name, state.Name),
				innerException)
		{
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="TransitionNotAvailableException"/> class.
		/// </summary>
		/// <param name="transition">
		/// The transition.
		/// </param>
		/// <param name="state">
		/// The state.
		/// </param>
		/// <param name="innerException">
		/// The inner exception.
		/// </param>
		public TransitionNotAvailableException(
			IFiniteStateTransition transition, IFiniteState state, Exception innerException)
			: base(
				string.Format(
					CultureInfo.CurrentCulture, "The {0} transition is not available in the {1} state.", transition.Name, state.Name),
				innerException)
		{
		}
Beispiel #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TransitionNotAvailableException"/> class.
 /// </summary>
 /// <param name="transition">
 /// The transition.
 /// </param>
 /// <param name="state">
 /// The state.
 /// </param>
 /// <param name="innerException">
 /// The inner exception.
 /// </param>
 public TransitionNotAvailableException(
     IFiniteStateTransition transition, IFiniteState state, Exception innerException)
     : base(
         string.Format(
             CultureInfo.CurrentCulture, "The {0} transition is not available in the {1} state.", transition.Name, state.Name),
         innerException)
 {
 }
        public FiniteSingleStateMachine(IFiniteState StartState)
        {
            states.CollectionChanged += OnStateCollectionChanged;

            States.Add(StartState);
            CurrentState = StartState;
            CurrentStateIdentifier = StartState.Identifier;
        }
        public void TransitionTo(IFiniteState finiteState)
        {
            this.CurrentFiniteState?.TryExit();

            this.CurrentFiniteState = finiteState;

            this.CurrentFiniteState?.TryEnter();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="StateNotRegisteredException"/> class.
 /// </summary>
 /// <param name="transition">
 /// The transition.
 /// </param>
 /// <param name="state">
 /// The state.
 /// </param>
 /// <param name="innerException">
 /// The inner exception.
 /// </param>
 public StateNotRegisteredException(
     IFiniteStateTransition transition, IFiniteState state, Exception innerException)
     : base(
         string.Format(
             CultureInfo.CurrentCulture, "The {0} transition returned an unregistered {1} state.", transition.Name, state.Name),
         innerException)
 {
 }
Beispiel #15
0
        /// <summary>
        /// Creates buffered token.
        /// </summary>
        private void CreateBuffered()
        {
            string tokenName = buffer.ToString();

            ParsedToken token = new ParsedToken
            {
                Name             = tokenName,
                InRowPosition    = inRowPosition - buffer.Length,
                RowIndex         = rowIndex,
                InStringPosition = inStringPosition - buffer.Length,
            };

            // If the state doesn't have a link for the char
            // but has token name then the state
            // returns token of defined in the state type.

            // Otherwise if buffer was not empty
            // but there is no token name then
            // the automaton was interrupted where it was not meant
            // to be so we create an undefined token
            // and return to start state.
            if (currentState.TokenName != null)
            {
                IDefinedToken definedToken;

                if (currentState.TokenName == classTable.UnclassifiedTokenClassName ||
                    nodes.Terminals.Any(n => n.Name == tokenName))
                {
                    definedToken = (IDefinedToken)nodes.Terminals.Single(n => n.Name == tokenName);
                }
                else
                {
                    definedToken = nodes.Tokens.Single(n => n.Name == currentState.TokenName && n.TokenClass == currentState.TokenClass);
                }

                token.Id           = definedToken.Id;
                token.TokenClassId = definedToken.TokenClassId;
            }
            else
            {
                token.Id           = UndefinedTokenClassId;
                token.TokenClassId = UndefinedTokenClassId;
            }



            buffer.Clear();
            currentState = StartState;

            tokens.Add(token);

            Logger.Add("tokenParser", new TokenLog
            {
                TokenClass = token.TokenClassId.ToString(),
                TokenName  = token.Name, Message = "created token",
            });
        }
Beispiel #16
0
        public static bool TryExit(this IFiniteState finiteState)
        {
            if (finiteState.IsActive == false)
            {
                return(false);
            }

            finiteState.Exit();
            return(true);
        }
Beispiel #17
0
        public static bool TryEnter(this IFiniteState finiteState)
        {
            if (finiteState.IsActive)
            {
                return(false);
            }

            finiteState.Enter();
            return(true);
        }
Beispiel #18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FiniteStateMachine{THistoryEntry}" /> class.
        /// Initializes a new instance of the <see cref="FiniteStateMachine&lt;THistoryEntry&gt;" /> class.
        /// </summary>
        /// <param name="startingState">State of the starting.</param>
        protected FiniteStateMachine(IFiniteState startingState)
        {
            this.History = new FiniteStateMachineHistory <THistoryEntry>();

            this.StartingState = startingState;

            // Create our start transition...
            this.StartingTransition = new FiniteStateTransition(0, "New", new FiniteStateMachineTransitionReason("New", "New"), this.StartingState);

            this.Initialize();
        }
 public void AddState(IFiniteState state, bool isDefaultState = false)
 {
     if (state == null || state.GetName() == null)
     {
         return;
     }
     m_States[state.GetName()] = state;
     if (isDefaultState || string.IsNullOrEmpty(m_DefaultState))
     {
         m_DefaultState = state.GetName();
     }
     m_StateCount = m_States.Count;
 }
Beispiel #20
0
        /// <summary>
        /// Removes a state.
        /// </summary>
        /// <param name="state">The state to remove.</param>
        public virtual void RemoveState(IFiniteState state)
        {
            if (!this.registeredStates.Contains(state))
            {
                return;
            }

            if (this.CurrentState == state)
            {
                throw new StateInUseException(state);
            }

            this.registeredStates.Remove(state);
        }
        // 开始状态机
        public void OnBegin()
        {
#if  UNITY_EDITOR
            RTLog.Log(LogCat.AI, "Begin StateMachine: " + m_Name + " @ " + m_TickCount);
#endif
            m_Active           = true;
            m_Runtime          = 0;
            m_StateRuntime     = 0;
            m_TickCount        = 0;
            m_StateTickCount   = 0;
            m_PrevState        = null;
            m_CurrentState     = null;
            m_CurrentStateName = m_DefaultState;
            UpdateTransitions();
        }
Beispiel #22
0
        /// <summary>
        /// Registers a state.
        /// </summary>
        /// <param name="state">The state to register.</param>
        public virtual void RegisterState(IFiniteState state)
        {
            // If that state has already been registered then throw...
            if (this.registeredStates.Contains(state))
            {
                throw new StateAlreadyRegisteredException(state);
            }

            // If it's not the same state, but the Code value is already in use then throw...
            if (this.registeredStates.Any(x => x.Code == state.Code))
            {
                throw new DuplicateStateCodeException(state);
            }

            this.registeredStates.Add(state);
        }
        public void OnEnd()
        {
            if (m_CurrentState != null)
            {
                m_CurrentState.OnEnd();
            }
#if DEBUG_AI && UNITY_EDITOR
            Debug.Log("End StateMachine: " + m_Name + " @ " + m_TickCount);
#endif
            m_TickCount        = 0;
            m_CurrentState     = null;
            m_PrevState        = null;
            m_CurrentStateName = null;
            m_CurrentTransitions.Clear();
            m_Active = false;
        }
        // 开始状态机
        public void OnBegin()
        {
#if DEBUG_AI && UNITY_EDITOR
            Debug.Log("Begin StateMachine: " + m_Name + " @ " + m_TickCount);
#endif
            m_Active           = true;
            m_StartTime        = m_UseRealTime ? Time.realtimeSinceStartup : Time.time;
            m_StateStartTime   = m_StartTime;
            m_Runtime          = 0;
            m_StateStartTime   = 0;
            m_TickCount        = 0;
            m_StateTickCount   = 0;
            m_PrevState        = null;
            m_CurrentState     = null;
            m_CurrentStateName = m_DefaultState;
            UpdateTransitions();
        }
Beispiel #25
0
        /// <summary>
        /// Initializes the garage door state machine.
        /// </summary>
        private void InitializeStateMachine()
        {
            // Create the garage door states...
            this.openState   = new FiniteState((int)GarageDoorState.Open, "Open");
            this.closedState = new FiniteState((int)GarageDoorState.Closed, "Closed");

            // Create the garage door transitions...
            this.openTransition = new FiniteStateTransition(
                (int)GarageDoorTransition.Open,
                "Open",
                new FiniteStateMachineTransitionReason("Opened"),
                this.openState,
                () => this.openState,
                () => this.CanOpen);

            this.lockTransition = new FiniteStateTransition(
                (int)GarageDoorTransition.Lock,
                "Lock",
                new FiniteStateMachineTransitionReason("Closed and Locked"),
                this.closedState,
                () => this.closedState,
                () => this.CanLock);

            this.closeTransition = new FiniteStateTransition(
                (int)GarageDoorTransition.Close,
                "Close",
                new FiniteStateMachineTransitionReason("Closed"),
                this.closedState,
                () => this.closedState,
                () => this.CanClose);

            // Register the garage door transitions with their respective garage door states...
            this.openState.RegisterTransition(this.closeTransition);
            this.openState.RegisterTransition(this.lockTransition);
            this.closedState.RegisterTransition(this.openTransition);
            this.closedState.RegisterTransition(this.lockTransition);

            // Create the garage door state machine...
            this.stateMachine = new FiniteStateMachine.FiniteStateMachine(this.openState);

            // Register the garage door states with the garage door state machine...
            this.stateMachine.RegisterState(this.openState);
            this.stateMachine.RegisterState(this.closedState);
        }
Beispiel #26
0
        /// <summary>
        /// Determines whether should move on to the next state
        /// or create new token and then return.
        /// Also fills respective tables with newly created tokens.
        /// </summary>
        /// <param name="ch">Current symbol to process.</param>
        /// <param name="symbolCategory">Category of current symbol.</param>
        /// <param name="symbolClass">Class of current symbol.</param>
        /// <param name="isBufferedTokenCreated">Whether token was created from buffer or not.</param>
        private void ProcessSymbol(char ch, SymbolCategory symbolCategory, string symbolClass, out bool isBufferedTokenCreated)
        {
            isBufferedTokenCreated = false;

            // If current state has link for this symbol
            // then move to the next state and fill buffer with the character.
            if (symbolClass != null &&
                currentState.Links != null &&
                currentState.Links.ContainsKey(symbolClass))
            {
                buffer.Append(ch);
                currentState = GetState(currentState.Links[symbolClass]);

                return;
            }

            // if the buffer is empty and symbol is undefined
            // then an undefined token will be created.
            if (string.IsNullOrWhiteSpace(buffer.ToString()))
            {
                if (symbolCategory == SymbolCategory.Undefined)
                {
                    ParsedToken undefinedToken = new ParsedToken
                    {
                        Id               = -1,
                        TokenClassId     = -1,
                        Name             = ch.ToString(),
                        InRowPosition    = inRowPosition,
                        RowIndex         = rowIndex,
                        InStringPosition = inStringPosition,
                    };

                    tokens.Add(undefinedToken);
                }

                return;
            }


            CreateBuffered();

            isBufferedTokenCreated = true;
        }
		public void TestSetup()
		{
			// Create our states...
			this.openState = new FiniteState(0, "Open");
			this.closedState = new FiniteState(1, "Closed");

			// Create our transitions...
			this.startTransition = new FiniteStateTransition(0, "New", new FiniteStateMachineTransitionReason("0", "New"), this.openState);

			this.openTransition = new FiniteStateTransition(1, "Open", new FiniteStateMachineTransitionReason("1", "Opened"), this.closedState, this.openState);
			this.closeTransition = new FiniteStateTransition(2, "Close", new FiniteStateMachineTransitionReason("2", "Closed"), this.openState, this.closedState);

			// Add our transitions to our states...
			this.openState.RegisterTransition(this.closeTransition);
			this.closedState.RegisterTransition(this.openTransition);

			// Create our machine...
			this.machine = new FiniteStateMachine.FiniteStateMachine(this.startTransition);
		}
        public void TestSetup()
        {
            // Create our states...
            this.openState   = new FiniteState(0, "Open");
            this.closedState = new FiniteState(1, "Closed");

            // Create our transitions...
            this.startTransition = new FiniteStateTransition(0, "New", new FiniteStateMachineTransitionReason("0", "New"), this.openState);

            this.openTransition  = new FiniteStateTransition(1, "Open", new FiniteStateMachineTransitionReason("1", "Opened"), this.closedState, this.openState);
            this.closeTransition = new FiniteStateTransition(2, "Close", new FiniteStateMachineTransitionReason("2", "Closed"), this.openState, this.closedState);

            // Add our transitions to our states...
            this.openState.RegisterTransition(this.closeTransition);
            this.closedState.RegisterTransition(this.openTransition);

            // Create our machine...
            this.machine = new FiniteStateMachine.FiniteStateMachine(this.startTransition);
        }
        void ChangeState(Transition trans)
        {
            string toState = trans.m_ToState;
            bool   push    = true;

            if (string.IsNullOrEmpty(toState))
            {
                if (m_StateStack.Count > 0)
                {
                    toState = m_StateStack[m_StateStack.Count - 1];
                    m_StateStack.RemoveAt(m_StateStack.Count - 1);
                    push = false;
                }
                else
                {
                    return;
                }
            }
            if (toState == m_CurrentStateName)
            {
                return;
            }
            m_PrevState        = m_CurrentState;
            m_CurrentState     = null;
            m_CurrentStateName = toState;
            if (m_PrevState != null)
            {
                m_PrevState.OnEnd();
                // 入栈
                if (m_StackSize > 0 && push && m_PrevState.KeepInStack() && StateStackPeek != m_PrevState.GetName())
                {
                    int del = m_StateStack.Count + 1 - m_StackSize;
                    if (del > 0)
                    {
                        m_StateStack.RemoveRange(0, del);
                    }
                    m_StateStack.Add(m_PrevState.GetName());
                }
            }
            UpdateTransitions();
        }
        private void OnTransitionRequested(IFiniteState Sender, String Label)
        {
            var count = transitions.Count(Tr => Tr.SourceState == Sender.Identifier && Tr.Label == Label);
            if (count == 0) return;

            var adequateTransition = transitions.Single(Tr => Tr.SourceState == Sender.Identifier && Tr.Label == Label);
            currentStateId = adequateTransition.DestinationState;
            currentState = States.Single(St => St.Identifier == adequateTransition.DestinationState);
        }
Beispiel #31
0
 /// <summary>
 /// Tries the state of the get transition in.
 /// </summary>
 /// <typeparam name="T">The type of transition to find</typeparam>
 /// <param name="state">The state.</param>
 /// <param name="transition">The transition.</param>
 /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
 protected virtual bool TryGetTransitionInState <T>(IFiniteState state, out IFiniteStateTransition transition) where T : IFiniteStateTransition
 {
     transition = state.Transitions.OfType <T>().FirstOrDefault();
     return(transition != null);
 }
Beispiel #32
0
 /// <summary>
 /// Adds the history entry.
 /// </summary>
 /// <param name="transition">The transition.</param>
 /// <param name="transitionResult">The transition result.</param>
 /// <param name="comments">The comments.</param>
 /// <returns>A built-up history entry.</returns>
 protected abstract THistoryEntry BuildHistoryEntry(IFiniteStateTransition transition, IFiniteState transitionResult, string comments);
 public FiniteStateMachine(IFiniteState initialFiniteState) => this.TransitionTo(initialFiniteState);
Beispiel #34
0
        public ITokenParserResult Parse()
        {
            Logger.Clear("tokenParser");
            Logger.Clear("parsed-nodes");
            Logger.Clear("identifiers");
            Logger.Clear("constants");
            Logger.Clear("labels");

            if (string.IsNullOrWhiteSpace(Script))
            {
                Logger.Add("tokenParser", new TokenLog()
                {
                    Message = "Token parser recieved an empty script."
                });

                return(new TokenParserResult
                {
                    Errors = new List <IParserError>
                    {
                        new TokenParserError
                        {
                            Message = "Token parser recieved an empty script.",

                            Tag = "lexical",
                        }
                    },
                });
            }

            // Reset start values;
            inStringPosition = 0;
            rowIndex         = 0;
            inRowPosition    = 0;

            buffer       = new StringBuilder();
            currentState = StartState;

            tokens = new List <IParsedToken>();


            foreach (char ch in Script + classTable.PotentialWhiteDelimiter)
            {
                (SymbolCategory symbolCategory, string symbolClass) = classTable.GetSymbolInfo(ch);

                Logger.Add("tokenParser", new TokenLog
                {
                    SymbolCategory = symbolCategory,
                    SymbolClass    = symbolClass,
                    Character      = ch,
                    State          = finiteAutomaton.States.First(n => n.Value == currentState).Key
                });

                // If a buffered token was created then the state had been returned to start state
                // and buffer cleared so the symbol has to be processed second time.

                // We need two symbols to determine what token is to be returned;
                // Second process can create only undefined tokens
                // which are created in one go.
                // Therefore we don't need any value returned from the second go.

                ProcessSymbol(ch, symbolCategory, symbolClass, out bool isBufferedTokenCreated);

                if (isBufferedTokenCreated)
                {
                    ProcessSymbol(ch, symbolCategory, symbolClass, out _);
                }

                // Moves inStringPosition, row, inRowPosition
                // so that each token's location can be later found.
                SetNextPosition(ch);
            }



            // Show tables

            ParsedNodesTable parsedNodesTable = new ParsedNodesTable(tokens);

            Logger.AddRange("parsed-nodes", parsedNodesTable.GetTableEntities(null));
            Logger.AddRange("identifiers", parsedNodesTable.GetTableEntities(1));
            Logger.AddRange("constants", parsedNodesTable.GetTableEntities(3));
            Logger.AddRange("labels", parsedNodesTable.GetTableEntities(2));

            return(new TokenParserResult
            {
                ParsedTokens = tokens,
            });
        }
Beispiel #35
0
		/// <summary>
		/// Initializes the garage door state machine.
		/// </summary>
		private void InitializeStateMachine()
		{
			// Create the garage door states...
			this.openState = new FiniteState((int)GarageDoorState.Open, "Open");
			this.closedState = new FiniteState((int)GarageDoorState.Closed, "Closed");

			// Create the garage door transitions...
			this.openTransition = new FiniteStateTransition(
				(int)GarageDoorTransition.Open,
				"Open",
				new FiniteStateMachineTransitionReason("Opened"),
				this.openState,
				() => this.openState,
				() => this.CanOpen);

			this.lockTransition = new FiniteStateTransition(
				(int)GarageDoorTransition.Lock,
				"Lock",
				new FiniteStateMachineTransitionReason("Closed and Locked"),
				this.closedState,
				() => this.closedState,
				() => this.CanLock);

			this.closeTransition = new FiniteStateTransition(
				(int)GarageDoorTransition.Close,
				"Close",
				new FiniteStateMachineTransitionReason("Closed"),
				this.closedState,
				() => this.closedState,
				() => this.CanClose);

			// Register the garage door transitions with their respective garage door states...
			this.openState.RegisterTransition(this.closeTransition);
			this.openState.RegisterTransition(this.lockTransition);
			this.closedState.RegisterTransition(this.openTransition);
			this.closedState.RegisterTransition(this.lockTransition);

			// Create the garage door state machine...
			this.stateMachine = new FiniteStateMachine.FiniteStateMachine(this.openState);

			// Register the garage door states with the garage door state machine...
			this.stateMachine.RegisterState(this.openState);
			this.stateMachine.RegisterState(this.closedState);
		}
Beispiel #36
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StateChangedEventArgs"/> class.
 /// </summary>
 /// <param name="transition">The transition.</param>
 /// <param name="transitionResult">The transition result.</param>
 /// <param name="comment">The comment.</param>
 public StateChangedEventArgs(IFiniteStateTransition transition, IFiniteState transitionResult, string comment = null)
 {
     this.Transition       = transition;
     this.TransitionResult = transitionResult;
     this.Comment          = comment;
 }
 private void OnTransitionRequested(IFiniteState Sender, String Label)
 {
     var adequateTransitions = transitions.Where(Tr => Tr.SourceState == Sender.Identifier && Tr.Label == Label);
     CurrentStates.Remove(Sender);
     var added = adequateTransitions.Select(St => St.DestinationState).ToArray();
     CurrentStatesIdentifier.AddRange(added);
     CurrentStates.AddRange(States.Where(St => added.Contains(St.Identifier)));
 }
		/// <summary>
		/// Initializes a new instance of the <see cref="StateChangedEventArgs"/> class.
		/// </summary>
		/// <param name="transition">The transition.</param>
		/// <param name="transitionResult">The transition result.</param>
		/// <param name="comment">The comment.</param>
		public StateChangedEventArgs(IFiniteStateTransition transition, IFiniteState transitionResult, string comment = null)
		{
			this.Transition = transition;
			this.TransitionResult = transitionResult;
			this.Comment = comment;
		}
 /// <summary>
 /// Initializes a new instance of the <see cref="FiniteStateTransition" /> class.
 /// </summary>
 /// <param name="code">The code.</param>
 /// <param name="name">The name.</param>
 /// <param name="reason">The reason.</param>
 /// <param name="endState">The end state.</param>
 /// <param name="transition">The transition.</param>
 public FiniteStateTransition(int code, string name, IFiniteStateMachineTransitionReason reason, IFiniteState endState, Func <IFiniteState> transition)
     : this(code, name, reason, endState)
 {
     this.TransitionDelegate = transition;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="FiniteStateTransition" /> class.
        /// </summary>
        /// <param name="code">The code.</param>
        /// <param name="name">The name.</param>
        /// <param name="reason">The reason.</param>
        /// <param name="endState">The end state.</param>
        /// <remarks>Use this constructor when building a transition intended for use as a starting transition.</remarks>
        public FiniteStateTransition(int code, string name, IFiniteStateMachineTransitionReason reason, IFiniteState endState)
        {
            this.Code       = code;
            this.Name       = name;
            this.Reason     = reason;
            this.StartState = null;

            this.EndState = endState;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="FiniteStateTransition" /> class.
 /// </summary>
 /// <param name="code">The code.</param>
 /// <param name="name">The name.</param>
 /// <param name="reason">The reason.</param>
 /// <param name="startState">The start state.</param>
 /// <param name="endState">The end state.</param>
 /// <param name="transition">The transition delegate.</param>
 /// <param name="canTransition">The can transition delegate.</param>
 public FiniteStateTransition(int code, string name, IFiniteStateMachineTransitionReason reason, IFiniteState startState, IFiniteState endState, Func <IFiniteState> transition, Func <bool> canTransition)
     : this(code, name, reason, startState, endState, transition)
 {
     this.CanTransitionDelegate = canTransition;
 }
Beispiel #42
0
 /// <summary>
 /// Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
 /// </summary>
 /// <param name="state">A state to compare with this instance.</param>
 /// <returns>A value that indicates the relative order of the objects being compared. The return value has these meanings: Value Meaning Less than zero This instance is less than <paramref name="state" />. Zero This instance is equal to <paramref name="state" />. Greater than zero This instance is greater than <paramref name="state" />.</returns>
 public int CompareTo(IFiniteState state)
 {
     return(this.Code.CompareTo(state.Code));
 }