Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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));
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 10
0
        public bool TryToApply(RouteChain chain)
        {
            if (chain.ResourceType != typeof(int))
            {
                return(false);
            }


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

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

            return(true);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
                    }
                }
            }
        }
Ejemplo n.º 14
0
 public bool TryToApply(RouteChain chain)
 {
     return(false);
 }
Ejemplo n.º 15
0
 public SetStatusCode(RouteChain chain) : base(false)
 {
     _return = chain.Action.ReturnVariable;
     _usage  = _return.Usage;
 }
Ejemplo n.º 16
0
        public UseWriter(RouteChain chain) : base(typeof(IMessageSerializer), _method)
        {
            Arguments[0] = chain.Action.ReturnVariable;

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

            IsLocal = true;
        }
Ejemplo n.º 18
0
 public override void Modify(RouteChain chain)
 {
     chain.Middleware.Add(new FakeTransaction());
 }
Ejemplo n.º 19
0
 public void do_not_flush_if_no_usage_of_imessage_context()
 {
     RouteChain.For <SomeEndpointGuy>(x => x.post_do_nothing(null))
     .ShouldFlushOutgoingMessages()
     .ShouldBeFalse();
 }
Ejemplo n.º 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());
 }
Ejemplo n.º 22
0
 public override void Modify(RouteChain chain)
 {
     chain.Middleware.Add(new FakeWrapper2());
 }
Ejemplo n.º 23
0
 public void do_flush_if_method_uses_IMessageContext()
 {
     RouteChain.For <SomeEndpointGuy>(x => x.post_do_stuff_with_messages(null, null))
     .ShouldFlushOutgoingMessages()
     .ShouldBeTrue();
 }