Example #1
0
        public void Apply(RouteChain chain)
        {
            try
            {
                if (chain.InputType != null)
                {
                    foreach (var reader in _readers)
                    {
                        if (reader.TryToApply(chain))
                        {
                            break;
                        }
                    }
                }

                if (chain.ResourceType != null)
                {
                    foreach (var writer in _writers)
                    {
                        if (writer.TryToApply(chain))
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw new InvalidOperationException($"Error trying to apply conneg rules to {chain}", e);
            }
        }
Example #2
0
        bool IWriterRule.TryToApply(RouteChain chain)
        {
            var customWriters = _serializers.CustomWritersFor(chain.ResourceType);

            if (customWriters.Length == 1)
            {
                chain.Writer = customWriters.Single();
                chain.Postprocessors.Add(new UseWriter(chain, true));
            }
            else if (customWriters.Length > 1)
            {
                chain.ConnegWriter = _serializers.WriterFor(chain.ResourceType);
                var selectWriter = new SelectWriter();
                chain.Middleware.Add(selectWriter);
                chain.Middleware.Add(new CheckForMissing(406, selectWriter.ReturnVariable));
                chain.Middleware.Add(new UseWriter(chain, false));
            }
            else
            {
                chain.Writer = _serializers.JsonWriterFor(chain.ResourceType);
                chain.Postprocessors.Add(new UseWriter(chain, true));
            }

            return(true);
        }
Example #3
0
        bool IReaderRule.TryToApply(RouteChain chain)
        {
            var customReaders = _serializers.CustomReadersFor(chain.InputType);

            if (customReaders.Length == 1)
            {
                chain.Reader = customReaders.Single();
                chain.Middleware.Add(new UseReader(chain, true));
            }
            else if (customReaders.Length > 1)
            {
                chain.ConnegReader = _serializers.ReaderFor(chain.InputType);
                var selectReader = new SelectReader();
                chain.Middleware.Add(selectReader);
                chain.Middleware.Add(new CheckForMissing(415, selectReader.ReturnVariable));
                chain.Middleware.Add(new UseReader(chain, false));
            }
            else
            {
                var reader = _serializers.ReaderFor(chain.InputType);


                chain.Reader = _serializers.JsonReaderFor(chain.InputType);
                chain.Middleware.Add(new UseReader(chain, true));
            }

            return(true);
        }
Example #4
0
        public void applies_attributes_against_the_IChain()
        {
            var chain = RouteChain.For <ConfiguredEndpoint>(x => x.get_wrapper3());

            var frames = chain.DetermineFrames();

            frames.OfType <FakeWrapper3>().Any().ShouldBeTrue();
        }
Example #5
0
        public void applies_the_Configure_RoutedChain_method()
        {
            var chain = RouteChain.For <ConfiguredEndpoint>(x => x.get_configured());

            var frames = chain.DetermineFrames(ConnegRules.Empty());

            frames.OfType <FakeTransaction>().Any().ShouldBeTrue();
        }
        public void applies_attributes_against_the_RouteChain()
        {
            var chain = RouteChain.For <ConfiguredEndpoint>(x => x.get_wrapper2());

            var frames = chain.DetermineFrames(ConnegRules.Empty(), JasperGenerationRules.Empty());

            frames.OfType <FakeWrapper2>().Any().ShouldBeTrue();
        }
Example #7
0
        public void applies_the_Configure_IChain_method()
        {
            var chain = RouteChain.For <ConfiguredEndpoint>(x => x.get_configured());

            var frames = chain.DetermineFrames();

            frames.OfType <FakeWrapper>().Any().ShouldBeTrue();
        }
Example #8
0
        public UseWriter(RouteChain chain, bool isLocal) : base(typeof(IMessageSerializer), _method)
        {
            Arguments[0] = chain.Action.ReturnVariable;

            if (isLocal)
            {
                Target = new Variable(typeof(IMessageSerializer), nameof(RouteHandler.Writer));
            }
        }
Example #9
0
        public UseReader(RouteChain chain, bool isLocal) : base(typeof(IMessageDeserializer), selectMethod(chain.InputType))
        {
            if (isLocal)
            {
                Target = new Variable(typeof(IMessageDeserializer), nameof(RouteHandler.Reader));
            }

            creates.Add(ReturnVariable);
        }
Example #10
0
        public bool TryToApply(RouteChain chain)
        {
            if (chain.ResourceType != typeof(int))
            {
                return(false);
            }


            chain.Postprocessors.Add(new SetStatusCode(chain));
            return(true);
        }
Example #11
0
        public bool TryToApply(RouteChain chain)
        {
            if (chain.ResourceType != typeof(string))
            {
                return(false);
            }

            chain.Postprocessors.Add(new CallWriteText(chain.Action.ReturnVariable));

            return(true);
        }
Example #12
0
        public bool TryToApply(RouteChain chain)
        {
            if (chain.ResourceType.CanBeCastTo <IActionResult>())
            {
                chain.Postprocessors.Add(new BuildActionContext());
                chain.Postprocessors.Add(new CallActionResultFrame(chain.ResourceType));

                return(true);
            }

            return(false);
        }
Example #13
0
        public void Apply(RouteChain chain)
        {
            if (chain.InputType != null)
            {
                foreach (var reader in _readers)
                {
                    if (reader.TryToApply(chain))
                    {
                        break;
                    }
                }
            }

            if (chain.ResourceType != null)
            {
                foreach (var writer in _writers)
                {
                    if (writer.TryToApply(chain))
                    {
                        break;
                    }
                }
            }
        }
 public bool TryToApply(RouteChain chain)
 {
     return(false);
 }
Example #15
0
 public SetStatusCode(RouteChain chain) : base(false)
 {
     _return = chain.Action.ReturnVariable;
     _usage  = _return.Usage;
 }
Example #16
0
        public UseWriter(RouteChain chain) : base(typeof(IMessageSerializer), _method)
        {
            Arguments[0] = chain.Action.ReturnVariable;

            IsLocal = true;
        }
Example #17
0
        public UseChosenWriter(RouteChain chain) : base(typeof(IResponseWriter), _method)
        {
            Arguments[0] = chain.Action.ReturnVariable;

            IsLocal = true;
        }
Example #18
0
 public override void Modify(RouteChain chain)
 {
     chain.Middleware.Add(new FakeTransaction());
 }
 public void do_not_flush_if_no_usage_of_imessage_context()
 {
     RouteChain.For <SomeEndpointGuy>(x => x.post_do_nothing(null))
     .ShouldFlushOutgoingMessages()
     .ShouldBeFalse();
 }
Example #20
0
 public static void Configure(RouteChain chain)
 {
     chain.Middleware.Add(new FakeTransaction());
 }
 public override void Modify(RouteChain chain, JasperGenerationRules rules)
 {
     chain.Middleware.Add(new FakeWrapper2());
 }
Example #22
0
 public override void Modify(RouteChain chain)
 {
     chain.Middleware.Add(new FakeWrapper2());
 }
 public void do_flush_if_method_uses_IMessageContext()
 {
     RouteChain.For <SomeEndpointGuy>(x => x.post_do_stuff_with_messages(null, null))
     .ShouldFlushOutgoingMessages()
     .ShouldBeTrue();
 }