Esempio n. 1
0
        /// <summary>
        /// Registers a trigger to this state machine.
        /// </summary>
        /// <param name="trigger">The registered trigger.</param>
        public void RegisterTrigger(SMTrigger trigger)
        {
            if (this.commissioned)
            {
                throw new SMException("Unable to register a trigger to a commissioned state machine");
            }
            if (null == trigger)
            {
                throw new ArgumentNullException("trigger");
            }
            if (trigger.SourceState.SM != this)
            {
                throw new SMException("Unable to register a trigger with a source state that belongs to a different state machine!");
            }
            if (trigger.TargetState.SM != this)
            {
                throw new SMException("Unable to register a trigger with a target state that belongs to a different state machine!");
            }

            this.registeredTriggers.Add(trigger);
        }
Esempio n. 2
0
        /// <summary>
        /// This function is called by a trigger of this state machine when it is fired.
        /// </summary>
        public void TriggerHasBeenFired(SMTrigger trigger)
        {
            if (this.SmController.IsFiringForbidden)
            {
                throw new SMException("Firing triggers is currently forbidden by the SMC!");
            }
            if (null == trigger)
            {
                throw new ArgumentNullException("trigger");
            }
            if (!this.registeredTriggers.Contains(trigger))
            {
                throw new SMException("Unable to fire unregistered trigger!");
            }

            if (this.triggerHasBeenFired != null && this.triggerHasBeenFired != trigger)
            {
                throw new SMException("Another trigger has already been fired in state machine '" + this.name + "'!");
            }

            this.triggerHasBeenFired = trigger;
        }