Ejemplo n.º 1
0
        public void CloneEventHandlers(IRestServer server)
        {
            if (BeforeStarting != null)
            {
                foreach (var action in BeforeStarting.GetInvocationList().Reverse().Cast <ServerEventHandler>())
                {
                    server.BeforeStarting += action;
                }
            }

            if (AfterStarting != null)
            {
                foreach (var action in AfterStarting.GetInvocationList().Reverse().Cast <ServerEventHandler>())
                {
                    server.AfterStarting += action;
                }
            }

            if (BeforeStopping != null)
            {
                foreach (var action in BeforeStopping.GetInvocationList().Reverse().Cast <ServerEventHandler>())
                {
                    server.BeforeStopping += action;
                }
            }

            if (AfterStopping != null)
            {
                foreach (var action in AfterStopping.GetInvocationList().Reverse().Cast <ServerEventHandler>())
                {
                    server.AfterStopping += action;
                }
            }
        }
Ejemplo n.º 2
0
        public override void Stop()
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }
            if (IsStopping || IsStarting)
            {
                return;
            }
            IsStopping = true;

            try
            {
                // 1. Execute BeforeStopping event handlers
                BeforeStopping?.Invoke(this);

                // 2. Stop the listener
                Listener?.Stop();

                // 3. Complete or cancel running routes
                TokenSource?.Cancel();

                // 4. Execute AfterStopping event handlers
                AfterStopping?.Invoke(this);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                IsStopping = false;
            }
        }
Ejemplo n.º 3
0
        protected void OnAfterStopping()
        {
            OnAfterStop?.Invoke();
            if (AfterStopping == null)
            {
                return;
            }
            var exceptions = InvokeServerEventHandlers(AfterStopping.GetInvocationList().Reverse().Cast <ServerEventHandler>());

            if (exceptions.Count > 0)
            {
                throw new AggregateException(exceptions);
            }
        }