Esempio n. 1
0
        private void ChangeState(ListenerState newState)
        {
            // Check that only allowed state changes are made
            switch (State)
            {
            case ListenerState.uninitialized:
                if (!(newState == ListenerState.initializing || newState == ListenerState.faulted))
                {
                    throw new Exception("Invalid state change. Uninitialized->" + newState.ToString());
                }
                break;

            case ListenerState.initializing:
                if (!(newState == ListenerState.initialized || newState == ListenerState.faulted))
                {
                    throw new Exception("Invalid state change. Initializing->" + newState.ToString());
                }
                break;

            case ListenerState.initialized:
                if (!(newState == ListenerState.starting || newState == ListenerState.faulted))
                {
                    throw new Exception("Invalid state change. Initialized->" + newState.ToString());
                }
                break;

            case ListenerState.starting:
                if (!(newState == ListenerState.started || newState == ListenerState.stopping || newState == ListenerState.faulted))
                {
                    throw new Exception("Invalid state change. Starting->" + newState.ToString());
                }
                break;

            case ListenerState.started:
                if (!(newState == ListenerState.stopping || newState == ListenerState.faulted || newState == ListenerState.starting))
                {
                    throw new Exception("Invalid state change. Started->" + newState.ToString());
                }
                break;

            case ListenerState.stopping:
                if (!(newState == ListenerState.stopped || newState == ListenerState.faulted))
                {
                    throw new Exception("Invalid state change. Stopping->" + newState.ToString());
                }
                break;

            case ListenerState.stopped:
                if (!(newState == ListenerState.faulted))
                {
                    throw new Exception("Invalid state change. Stopped->" + newState.ToString());
                }
                break;

            default:
                throw new Exception("Invalid state change");
            }

            // Raise event
            switch (newState)
            {
            case ListenerState.initializing:
                if (OnInitializing != null)
                {
                    OnInitializing.Invoke();
                }
                break;

            case ListenerState.initialized:
                if (OnInitialized != null)
                {
                    OnInitialized.Invoke();
                }
                break;

            case ListenerState.starting:
                if (OnStarting != null)
                {
                    OnStarting.Invoke();
                }
                break;

            case ListenerState.started:
                if (OnStarted != null)
                {
                    OnStarted.Invoke();
                }
                break;

            case ListenerState.stopping:
                if (OnStopping != null)
                {
                    OnStopping.Invoke();
                }
                break;

            case ListenerState.stopped:
                if (OnStopped != null)
                {
                    OnStopped.Invoke();
                }
                break;

            case ListenerState.faulted:
                if (OnFaulted != null)
                {
                    OnFaulted.Invoke();
                }
                break;
            }

            State = newState;
        }
Esempio n. 2
0
 //Hook to be called at the end of Licenses.Init
 internal static void Init()
 {
     OnInitializing?.Invoke();
 }