Пример #1
0
        public void Fire(TTrigger trigger)
        {
            foreach (var permit in Permits)
            {
                if ((permit.FromAny || permit.Original.Equals(CurrentState)) && permit.Trigger.Equals(trigger))
                {
                    //Check if we are allowed to change state
                    bool?cont = permit.Execute?.Invoke();

                    //If not, break out
                    if (cont == false)
                    {
                        break;
                    }

                    //Fire the configuration's exit method
                    if (OnExit.TryGetValue(CurrentState, out var onExit))
                    {
                        onExit();
                    }

                    //Fire the exit event
                    ExitedState?.Invoke(CurrentState);

                    this.CurrentState = permit.NextState;

                    //Fire the configuration's enter method
                    if (OnEnter.TryGetValue(CurrentState, out var onEnter))
                    {
                        onEnter();
                    }

                    //Fire the enter event
                    EnteredState?.Invoke(CurrentState);

                    break;
                }
            }
        }
Пример #2
0
 public virtual void Process()
 {
     EnteredState.Invoke(this);
 }