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);
        }
예제 #2
0
        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();
        }
예제 #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 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;
        }
예제 #5
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();
            }
        }
예제 #6
0
 public void invoke_happy_path_will_put_the_current_chain_together()
 {
     theInvoker.Invoke(theArguments, theRouteData);
     theArguments.Get <ICurrentChain>().ShouldBeOfType <CurrentChain>()
     .ResourceHash().ShouldBe(new CurrentChain(theChain, theRouteData).ResourceHash());
 }