public DoNext Filter(TypeArguments arguments)
        {
            if (arguments.Has(typeof(Latch)))
            {
                return(DoNext.Stop);
            }


            var request = arguments.Get <IHttpRequest>();

            if (!request.HasHeader(HttpRequestHeaders.AcceptEncoding))
            {
                return(DoNext.Continue);
            }

            var acceptEncoding = request
                                 .GetSingleHeader(HttpRequestHeaders.AcceptEncoding);


            var encoding = _encoders.MatchFor(acceptEncoding);
            var writer   = arguments.Get <IHttpResponse>();

            writer.AppendHeader(HttpRequestHeaders.ContentEncoding, encoding.MatchingEncoding.Value);

            writer.UseEncoding(encoding);

            arguments.Set(typeof(Latch), new Latch());

            return(DoNext.Continue);
        }
        public void Invoke(TypeArguments 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;
                disposable?.Dispose();
            });

            behavior.Invoke();
        }
Exemple #3
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 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 DoNext Filter(TypeArguments arguments)
        {
            if (arguments.Has(typeof (Latch))) return DoNext.Stop;


            var request = arguments.Get<IHttpRequest>();
            if (!request.HasHeader(HttpRequestHeaders.AcceptEncoding)) return DoNext.Continue;

            var acceptEncoding = request
                .GetSingleHeader(HttpRequestHeaders.AcceptEncoding);


            var encoding = _encoders.MatchFor(acceptEncoding);
            var writer = arguments.Get<IHttpResponse>();
            writer.AppendHeader(HttpRequestHeaders.ContentEncoding, encoding.MatchingEncoding.Value);

            writer.UseEncoding(encoding);

            arguments.Set(typeof (Latch), new Latch());

            return DoNext.Continue;
        }