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); } }
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); }
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); }
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(); }
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(); }
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(); }
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)); } }
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); }
public bool TryToApply(RouteChain chain) { if (chain.ResourceType != typeof(int)) { return(false); } chain.Postprocessors.Add(new SetStatusCode(chain)); return(true); }
public bool TryToApply(RouteChain chain) { if (chain.ResourceType != typeof(string)) { return(false); } chain.Postprocessors.Add(new CallWriteText(chain.Action.ReturnVariable)); return(true); }
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); }
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); }
public SetStatusCode(RouteChain chain) : base(false) { _return = chain.Action.ReturnVariable; _usage = _return.Usage; }
public UseWriter(RouteChain chain) : base(typeof(IMessageSerializer), _method) { Arguments[0] = chain.Action.ReturnVariable; IsLocal = true; }
public UseChosenWriter(RouteChain chain) : base(typeof(IResponseWriter), _method) { Arguments[0] = chain.Action.ReturnVariable; IsLocal = true; }
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(); }
public static void Configure(RouteChain chain) { chain.Middleware.Add(new FakeTransaction()); }
public override void Modify(RouteChain chain, JasperGenerationRules rules) { chain.Middleware.Add(new FakeWrapper2()); }
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(); }