예제 #1
0
        /// <see cref="ISMState.AddInternalTrigger"/>
        public void AddInternalTrigger(ISMState targetState, StateMachineController.TransitionHandler handler, SMOperator stateOperator)
        {
            if (this.stateMachine.Commissioned)
            {
                throw new SMException("Unable to add trigger to a commissioned state machine");
            }
            if (targetState == null)
            {
                throw new ArgumentNullException("targetState");
            }
            if (stateOperator == null)
            {
                throw new ArgumentNullException("stateOperator");
            }

            SMState target = this.stateMachine.GetState(targetState.Name);

            if (target != null)
            {
                SMInternalTrigger intTrigger = new SMInternalTrigger(this, target, handler, stateOperator);
                this.stateMachine.RegisterTrigger(intTrigger);
            }
            else
            {
                throw new SMException("State '" + targetState.Name + "' doesn't exist!");
            }
        }
예제 #2
0
        /// <see cref="ISMState.AddInternalTrigger"/>
        public void AddInternalTrigger(ISMState targetState, StateMachineController.TransitionHandler handler, RCSet <ISMState> neededStates)
        {
            if (this.stateMachine.Commissioned)
            {
                throw new SMException("Unable to add trigger to a commissioned state machine");
            }
            if (targetState == null)
            {
                throw new ArgumentNullException("targetState");
            }
            if (neededStates == null || neededStates.Count == 0)
            {
                throw new ArgumentNullException("neededStates");
            }

            SMState target = this.stateMachine.GetState(targetState.Name);

            if (target != null)
            {
                ISMState[] neededStatesArray = new ISMState[neededStates.Count];
                int        i = 0;
                foreach (ISMState st in neededStates)
                {
                    neededStatesArray[i] = st;
                    i++;
                }
                //RCSet<SMState> neededStateObjects = new RCSet<SMState>();
                //foreach (ISMState s in neededStates)
                //{
                //    SMState sObj = this.stateMachine.StateObjectMap.GetStateObject(s);
                //    if (null != sObj)
                //    {
                //        neededStateObjects.Add(sObj);
                //    }
                //    else { throw new SMException("State '" + s.Name + "' was not found in the object map!"); }
                //}
                SMInternalTrigger intTrigger =
                    new SMInternalTrigger(this, target, handler, new SMOperator(SMOperatorType.AND, neededStatesArray));
                this.stateMachine.RegisterTrigger(intTrigger);
            }
            else
            {
                throw new SMException("State '" + targetState.Name + "' doesn't exist!");
            }
        }
예제 #3
0
        /// <summary>
        /// Constructs a trigger object.
        /// </summary>
        public SMTrigger(SMState source, SMState target, StateMachineController.TransitionHandler handler)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }
            if (source.SM != target.SM)
            {
                throw new SMException("Transition between states in different state machines not allowed!");
            }

            this.sourceState       = source;
            this.targetState       = target;
            this.transitionHandler = handler;
            this.sourceState.SM.CurrentStateChangedEvt += this.CurrentStateChanged;
        }
예제 #4
0
        public SMInternalTrigger(SMState source, SMState target, StateMachineController.TransitionHandler handler, SMOperator op)
            : base(source, target, handler)
        {
            //if (neededStates == null || neededStates.Count == 0) { throw new ArgumentNullException("neededStates"); }
            if (op == null)
            {
                throw new ArgumentNullException("op");
            }

            //this.sourceStateIsCurrent = false;
            RCSet <ISMState> neededStatesSet = new RCSet <ISMState>();

            op.CollectAllStates(ref neededStatesSet);
            this.operatorToCheck = op;

            this.neededStates = new Dictionary <ISMState, bool>();

            //RCSet<StateMachine> sms = new RCSet<StateMachine>();
            foreach (ISMState s in neededStatesSet)
            {
                SMState state = this.sourceState.SM.StateObjectMap.GetStateObject(s);
                if (state == null)
                {
                    throw new SMException("The state '" + s.Name + "' was not found in the object map!");
                }

                if (this.sourceState.SM != state.SM && this.sourceState.SM.SmController == state.SM.SmController)// && !sms.Contains(state.SM))
                {
                    //sms.Add(state.SM);
                    this.neededStates.Add(state, false);
                    state.SM.CurrentStateChangedEvt += this.CurrentStateChanged;
                    state.SM.CommissionedEvt        += this.StateMachineCommissioned;
                }
                else
                {
                    throw new SMException("Internal trigger operator error!");
                }
            }
        }
예제 #5
0
        /// <see cref="ISMState.AddExternalTrigger"/>
        public ISMTrigger AddExternalTrigger(ISMState targetState, StateMachineController.TransitionHandler handler)
        {
            if (this.stateMachine.Commissioned)
            {
                throw new SMException("Unable to add trigger to a commissioned state machine");
            }
            if (targetState == null)
            {
                throw new ArgumentNullException("targetState");
            }

            SMState target = this.stateMachine.GetState(targetState.Name);

            if (target != null)
            {
                SMExternalTrigger extTrigger = new SMExternalTrigger(this, target, handler);
                this.stateMachine.RegisterTrigger(extTrigger);
                return(extTrigger);
            }
            else
            {
                throw new SMException("State '" + targetState.Name + "' doesn't exist!");
            }
        }
예제 #6
0
 public SMExternalTrigger(SMState source, SMState target, StateMachineController.TransitionHandler handler)
     : base(source, target, handler)
 {
     //this.triggerActive = false;
 }