Esempio n. 1
0
        public async Task <IInvocationContext> ExecuteChain(Envelope envelope, HandlerChain chain)
        {
            if (envelope.Log != null)
            {
                envelope.Log.RootChain = chain;
                envelope.Log.StartSubject(chain);
            }

            using (new ChainExecutionWatcher(_logger, chain, envelope))
            {
                var context  = new InvocationContext(envelope, chain);
                var behavior = _factory.BuildBehavior(context, chain.UniqueId);

                try
                {
                    await behavior.Invoke().ConfigureAwait(false);
                }
                finally
                {
                    (behavior as IDisposable)?.SafeDispose();

                    envelope.Log?.FinishSubject();
                }

                return(context);
            }
        }
Esempio n. 2
0
        public IInvocationContext ExecuteChain(Envelope envelope, HandlerChain chain)
        {
            if (envelope.Log != null)
            {
                envelope.Log.RootChain = chain;
                envelope.Log.StartSubject(chain);
            }

            using (new ChainExecutionWatcher(_logger, chain, envelope))
            {
                var context  = new InvocationContext(envelope, chain);
                var behavior = _factory.BuildBehavior(context, chain.UniqueId);

                try
                {
                    behavior.Invoke();
                }
                finally
                {
                    (behavior as IDisposable).CallIfNotNull(x => x.SafeDispose());

                    if (envelope.Log != null)
                    {
                        envelope.Log.FinishSubject();
                    }
                }

                return(context);
            }
        }
Esempio n. 3
0
        public void Invoke(ServiceArguments arguments, IDictionary <string, object> routeValues, IRequestCompletion requestCompletion)
        {
            var currentChain = new CurrentChain(_chain, routeValues);

            arguments.Set(typeof(ICurrentChain), currentChain);
            arguments.Set(typeof(IRequestCompletion), requestCompletion);

            if (arguments.Has(typeof(IChainExecutionLog)))
            {
                arguments.Get <IChainExecutionLog>().RootChain = _chain;
            }

            if (_chain.Filters.Any(filter => filter.Filter(arguments) == DoNext.Stop))
            {
                return;
            }

            IActionBehavior behavior = null;

            if (arguments.Has(typeof(IChainExecutionLog)))
            {
                arguments.Get <IChainExecutionLog>().Trace("Building the Behaviors", () =>
                {
                    behavior = _factory.BuildBehavior(arguments, _chain.UniqueId);
                });
            }
            else
            {
                behavior = _factory.BuildBehavior(arguments, _chain.UniqueId);
            }


            requestCompletion.WhenCompleteDo(x =>
            {
                var disposable = behavior as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            });

            behavior.Invoke();
        }
Esempio n. 4
0
        public async Task Invoke(TypeArguments arguments, IDictionary <string, object> routeValues)
        {
            var currentChain = new CurrentChain(_chain, routeValues);

            arguments.Set(typeof(ICurrentChain), currentChain);

            if (arguments.Has(typeof(IChainExecutionLog)))
            {
                arguments.Get <IChainExecutionLog>().RootChain = _chain;
            }

            if (_chain.Filters.Any(filter => filter.Filter(arguments) == DoNext.Stop))
            {
                return;
            }

            IActionBehavior behavior = null;

            if (arguments.Has(typeof(IChainExecutionLog)))
            {
                arguments.Get <IChainExecutionLog>().Trace("Building the Behaviors", () =>
                {
                    behavior = _factory.BuildBehavior(arguments, _chain.UniqueId);
                });
            }
            else
            {
                behavior = _factory.BuildBehavior(arguments, _chain.UniqueId);
            }

            try
            {
                await behavior.Invoke().ConfigureAwait(false);
            }
            finally
            {
                var disposable = behavior as IDisposable;
                disposable?.Dispose();
            }
        }
        public void Invoke(ServiceArguments arguments, IDictionary <string, object> routeValues)
        {
            var currentChain = new CurrentChain(_chain, routeValues);

            arguments.Set(typeof(ICurrentChain), currentChain);

            if (_chain.Filters.Any(filter => filter.Filter(arguments) == DoNext.Stop))
            {
                return;
            }

            var behavior = _factory.BuildBehavior(arguments, _chain.UniqueId);

            Invoke(behavior);
        }
        public IInvocationContext ExecuteChain(Envelope envelope, HandlerChain chain)
        {
            using (new ChainExecutionWatcher(_logger, chain, envelope))
            {
                var context  = new InvocationContext(envelope, chain);
                var behavior = _factory.BuildBehavior(context, chain.UniqueId);

                try
                {
                    behavior.Invoke();
                }
                finally
                {
                    (behavior as IDisposable).CallIfNotNull(x => x.SafeDispose());
                }

                return(context);
            }
        }
Esempio n. 7
0
        public void Invoke(ServiceArguments arguments, IDictionary <string, object> routeValues, IRequestCompletion requestCompletion)
        {
            var currentChain = new CurrentChain(_chain, routeValues);

            arguments.Set(typeof(ICurrentChain), currentChain);
            arguments.Set(typeof(IRequestCompletion), requestCompletion);

            if (_chain.Filters.Any(filter => filter.Filter(arguments) == DoNext.Stop))
            {
                return;
            }
            var behavior = _factory.BuildBehavior(arguments, _chain.UniqueId);

            requestCompletion.WhenCompleteDo(x =>
            {
                var disposable = behavior as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            });
            behavior.Invoke();
        }