Exemple #1
0
        /// <summary>
        /// Constructs a state to a state machine.
        /// </summary>
        public SMState(string name, StateMachineController.StateHandler handler, StateMachine sm)
        {
            if (name == null || name.Length == 0)
            {
                throw new ArgumentNullException("name");
            }
            if (sm == null)
            {
                throw new ArgumentNullException("sm");
            }

            this.name         = name;
            this.handler      = handler;
            this.stateMachine = sm;
        }
        /// <see cref="IStateMachine.AddState"/>
        public ISMState AddState(string name, StateMachineController.StateHandler handler)
        {
            if (this.commissioned)
            {
                throw new SMException("Unable to add state to a commissioned state machine!");
            }
            if (name == null || name.Length == 0)
            {
                throw new ArgumentNullException("name");
            }

            if (!this.states.ContainsKey(name))
            {
                SMState newState = new SMState(name, handler, this);
                this.states.Add(name, newState);
                this.stateObjectMap.RegisterState(newState);
                return(newState);
            }
            else
            {
                throw new SMException("State '" + name + "' already exists in state machine '" + this.name + "'!");
            }
        }