Exemple #1
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!");
                }
            }
        }
Exemple #2
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!");
            }
        }