public static bool IsNotDiagnosticRoute(BehaviorChain chain) { if (chain is DiagnosticChain) return false; if (chain.Calls.Any(x => x.HandlerType.Assembly == Assembly.GetExecutingAssembly())) { return false; } if (chain.Calls.Any(x => x.HasInput && x.InputType().Assembly == Assembly.GetExecutingAssembly())) { return false; } if (chain.HasOutput() && chain.ResourceType().Assembly == Assembly.GetExecutingAssembly()) { return false; } if (chain.HasOutput()) { if (chain.Output.Writers.OfType<ViewNode>().Any(x => x.View.Namespace.Contains("Visualization.Visualizers"))) { return false; } } return true; }
public void has_output_depends_on_the_output_node_now() { var chain = new BehaviorChain(); chain.AddToEnd(ActionCall.For <OneController>(x => x.Query(null))); chain.HasOutput().ShouldBeFalse(); chain.Output.AddFormatter <JsonFormatter>(); chain.HasOutput().ShouldBeTrue(); }
public static bool IsNotDiagnosticRoute(BehaviorChain chain) { if (chain.Route != null) { if (chain.Route.Pattern.Contains("_data/" + typeof(RequestLog).Name)) { return(false); } if (chain.Route.Pattern.Contains("_data/" + typeof(RouteReport).Name)) { return(false); } return(!chain.Route.Pattern.Contains(DiagnosticsRegistration.DIAGNOSTICS_URL_ROOT)); } // TODO -- figure out how to do this again // if (chain.As<ITracedModel>().AllEvents().OfType<ChainImported>().Any(x => x.Source.ProvenanceChain.OfType<ServiceRegistryProvenance>().Any(x => x.)) // { // return false; // } if (chain.Calls.Any(x => x.HandlerType.Assembly == Assembly.GetExecutingAssembly())) { return(false); } if (chain.Calls.Any(x => x.HasInput && x.InputType().Assembly == Assembly.GetExecutingAssembly())) { return(false); } if (chain.HasOutput() && chain.ResourceType().Assembly == Assembly.GetExecutingAssembly()) { return(false); } if (chain.HasOutput()) { if (chain.Output.Writers.OfType <ViewNode>().Any(x => x.View.Namespace.Contains("Visualization.Visualizers"))) { return(false); } } return(true); }
public static string TitleForChain(BehaviorChain chain) { if (chain.GetRoutePattern().IsNotEmpty()) { return chain.GetRoutePattern(); } if (chain.GetRoutePattern() == string.Empty) { return "(home)"; } if (chain.Calls.Any()) { return chain.Calls.Select(x => x.Description).Join(", "); } if (chain.HasOutput() && chain.Output.Writers.Any()) { return chain.Output.Writers.Select(x => Description.For(x).Title).Join(", "); } if (chain.InputType() != null) { return "Handler for " + chain.InputType().FullName; } return "BehaviorChain " + chain.UniqueId; }
// SAMPLE: conneg-manipulation public static void MessWithConneg(BehaviorChain chain) { // Remove all readers chain.Input.ClearAll(); // Accept 'application/x-www-form-urlencoded' with model binding chain.Input.Add(typeof(ModelBindingReader <>)); // Add basic Json reading chain.Input.Add(new NewtonsoftJsonFormatter()); // Query whether or not the chain uses the basic Json reading var readsJson = chain.Input.CanRead(MimeType.Json); // Add a completely custom Reader chain.Input .Add(new SpecialContentMediaReader()); // Are there any Readers? chain.HasReaders(); // Is there any output? chain.HasOutput(); // Remove all writers chain.Output.ClearAll(); }
public static string TitleForChain(BehaviorChain chain) { if (chain.GetRoutePattern().IsNotEmpty()) { return(chain.GetRoutePattern()); } if (chain.GetRoutePattern() == string.Empty) { return("(home)"); } if (chain.Calls.Any()) { return(chain.Calls.Select(x => x.Description).Join(", ")); } if (chain.HasOutput() && chain.Output.Writers.Any()) { return(chain.Output.Writers.Select(x => Description.For(x).Title).Join(", ")); } if (chain.InputType() != null) { return("Handler for " + chain.InputType().FullName); } return("BehaviorChain " + chain.UniqueId); }
public static bool IsNotDiagnosticRoute(BehaviorChain chain) { if (chain.Route != null) { if (chain.Route.Pattern.Contains("_data/" + typeof(RequestLog).Name)) return false; if (chain.Route.Pattern.Contains("_data/" + typeof(RouteReport).Name)) return false; return !chain.Route.Pattern.Contains(DiagnosticsRegistration.DIAGNOSTICS_URL_ROOT); } // TODO -- figure out how to do this again // if (chain.As<ITracedModel>().AllEvents().OfType<ChainImported>().Any(x => x.Source.ProvenanceChain.OfType<ServiceRegistryProvenance>().Any(x => x.)) // { // return false; // } if (chain.Calls.Any(x => x.HandlerType.Assembly == Assembly.GetExecutingAssembly())) { return false; } if (chain.Calls.Any(x => x.HasInput && x.InputType().Assembly == Assembly.GetExecutingAssembly())) { return false; } if (chain.HasOutput() && chain.ResourceType().Assembly == Assembly.GetExecutingAssembly()) { return false; } if (chain.HasOutput()) { if (chain.Output.Writers.OfType<ViewNode>().Any(x => x.View.Namespace.Contains("Visualization.Visualizers"))) { return false; } } return true; }
// SAMPLE: conneg-manipulation public static void MessWithConneg(BehaviorChain chain) { // Remove all readers chain.Input.ClearAll(); // Accept 'application/x-www-form-urlencoded' with model binding chain.Input.AllowHttpFormPosts = true; // Add basic Json reading chain.Input.AddFormatter <JsonFormatter>(); // Query whether or not the chain uses the basic Json reading bool readsJson = chain.Input.UsesFormatter <JsonFormatter>(); // Add a completely custom Reader var specialReader = chain.Input .AddReader <SpecialContentMediaReader>(); // Reorder the special reader to move it to the first // as the default specialReader.MoveToFront(); // Add a new Reader as the last reader chain.Input.Readers.AddToEnd(new ModelBind(chain.InputType())); // Are there any Readers? chain.HasReaders(); // Is there any output? chain.HasOutput(); // Add the default Conneg policies to this chain // model binding, json, or xml in and json or xml out chain.ApplyConneg(); // Manipulate an existing writer var writer = chain.Output.Writers.First(); manipulateWriter(writer); // Remove all writers chain.Output.ClearAll(); // Add the HtmlStringWriter chain.Output.AddHtml(); // Add basic Json output chain.OutputJson(); // Add basic Xml output chain.OutputXml(); }
public static void RemoveConneg(this BehaviorChain chain) { if (chain.HasReaders()) { chain.Input.ClearAll(); } if (chain.HasOutput()) { chain.Output.ClearAll(); } }
public void has_output_depends_on_the_output_node_now() { var chain = new BehaviorChain(); chain.AddToEnd(ActionCall.For<OneController>(x => x.Query(null))); chain.HasOutput().ShouldBeFalse(); chain.Output.AddFormatter<JsonFormatter>(); chain.HasOutput().ShouldBeTrue(); }