Beispiel #1
0
        protected RegulatorState AddState(string name)
        {
            var state = new RegulatorState(name, this);

            States.Add(name, state);
            return(state);
        }
Beispiel #2
0
        public bool SyncTransition(string newState, object data)
        {
            if (!this.States.ContainsKey(newState))
            {
                return(false);
            }

            lock (this)
            {
                InTransition = true;

                var oldState = this.CurrentState;
                var state    = this.States[newState];

                //state to own state is valid. see LotConnectionRegulator.

                /*
                 * if (oldState == state)
                 * {
                 *  InTransition = false;
                 *  return false;
                 * }*/

                try
                {
                    foreach (var validator in Validators)
                    {
                        if (validator.CanTransition(oldState.Name, state.Name) == false)
                        {
                            InTransition = false;
                            return(false);
                        }
                    }

                    OnBeforeTransition(oldState, state, data);
                    this.CurrentState = state;
                    if (this.OnTransition != null)
                    {
                        this.OnTransition(newState, data);
                    }
                    this.OnAfterTransition(oldState, state, data);
                    return(true);
                }
                catch (Exception ex)
                {
                    this.ThrowError(ex);
                }
                finally
                {
                    InTransition = false;
                }
                return(false);
            }
        }
Beispiel #3
0
 public RegulatorEventHandler(AbstractRegulator regulator, RegulatorState state)
 {
     this.State     = state;
     this.Regulator = regulator;
 }
Beispiel #4
0
 protected abstract void OnAfterTransition(RegulatorState oldState, RegulatorState newState, object data);