Exemplo 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;
                }
            }
        }
Exemplo n.º 2
0
        protected void OnBeforeStarting()
        {
            OnBeforeStart?.Invoke();
            if (BeforeStarting == null)
            {
                return;
            }
            var exceptions = InvokeServerEventHandlers(BeforeStarting.GetInvocationList().Reverse().Cast <ServerEventHandler>());

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