public IntAddressScheme(EndpointDataSource dataSource) { _dataSource = dataSource; }
public void Write(EndpointDataSource dataSource, TextWriter writer) { var builder = _services.GetRequiredService <DfaMatcherBuilder>(); var endpoints = dataSource.Endpoints; for (var i = 0; i < endpoints.Count; i++) { if (endpoints[i] is RouteEndpoint endpoint && (endpoint.Metadata.GetMetadata <ISuppressMatchingMetadata>()?.SuppressMatching ?? false) == false) { builder.AddEndpoint(endpoint); } } // Assign each node a sequential index. var visited = new Dictionary <DfaNode, int>(); var tree = builder.BuildDfaTree(includeLabel: true); writer.WriteLine("digraph DFA {"); tree.Visit(WriteNode); writer.WriteLine("}"); void WriteNode(DfaNode node) { if (!visited.TryGetValue(node, out var label)) { label = visited.Count; visited.Add(node, label); } // We can safely index into visited because this is a post-order traversal, // all of the children of this node are already in the dictionary. if (node.Literals != null) { foreach (var literal in node.Literals) { writer.WriteLine($"{label} -> {visited[literal.Value]} [label=\"/{literal.Key}\"]"); } } if (node.Parameters != null) { writer.WriteLine($"{label} -> {visited[node.Parameters]} [label=\"/*\"]"); } if (node.CatchAll != null && node.Parameters != node.CatchAll) { writer.WriteLine($"{label} -> {visited[node.CatchAll]} [label=\"/**\"]"); } if (node.PolicyEdges != null) { foreach (var policy in node.PolicyEdges) { writer.WriteLine($"{label} -> {visited[policy.Value]} [label=\"{policy.Key}\"]"); } } writer.WriteLine($"{label} [label=\"{node.Label}\"]"); } }
public ODataOpenApiController(EndpointDataSource dataSource) { _dataSource = dataSource; }
public static OpenApiDocument CreateDocument(HttpContext context, string prefixName) { IDictionary <string, ODataPath> tempateToPathDict = new Dictionary <string, ODataPath>(); ODataOpenApiPathProvider provider = new ODataOpenApiPathProvider(); IEdmModel model = null; EndpointDataSource dataSource = context.RequestServices.GetRequiredService <EndpointDataSource>(); foreach (var endpoint in dataSource.Endpoints) { IODataRoutingMetadata metadata = endpoint.Metadata.GetMetadata <IODataRoutingMetadata>(); if (metadata == null) { continue; } if (metadata.Prefix != prefixName) { continue; } model = metadata.Model; RouteEndpoint routeEndpoint = endpoint as RouteEndpoint; if (routeEndpoint == null) { continue; } // get rid of the prefix int length = prefixName.Length; string routePathTemplate = routeEndpoint.RoutePattern.RawText.Substring(length); routePathTemplate = routePathTemplate.StartsWith("/") ? routePathTemplate : "/" + routePathTemplate; if (tempateToPathDict.TryGetValue(routePathTemplate, out ODataPath pathValue)) { var methods = GetHttpMethods(endpoint); foreach (var method in methods) { pathValue.HttpMethods.Add(method); } continue; } var path = metadata.Template.Translate(); if (path == null) { continue; } path.PathTemplate = routePathTemplate; provider.Add(path); var method1 = GetHttpMethods(endpoint); foreach (var method in method1) { path.HttpMethods.Add(method); } tempateToPathDict[routePathTemplate] = path; } OpenApiConvertSettings settings = new OpenApiConvertSettings { PathProvider = provider, ServiceRoot = BuildAbsolute(context, prefixName) }; return(model.ConvertToOpenApi(settings)); }
public TestDynamicControllerEndpointSelectorCache(EndpointDataSource dataSource, int key) { AddDataSource(dataSource, key); }
public abstract Matcher CreateMatcher(EndpointDataSource dataSource);
public NotFoundSelectorPolicy(EndpointDataSource endpointDataSource) { _notFound = new Lazy <Endpoint>(GetNotFoundEndpoint); _endpointDataSource = endpointDataSource; }
public EndpointMetadataApiDescriptionProvider(EndpointDataSource endpointDataSource, IHostEnvironment environment) : this(endpointDataSource, environment, null) { }
public DebugController(DfaGraphWriter graphWriter, EndpointDataSource endpointDataSource) { _graphWriter = graphWriter; _endpointDataSource = endpointDataSource; }
/// <summary> /// Initializes a new instance /// </summary> /// <param name="serviceProvider">The injected service provider</param> /// <param name="endpointDataSource">The injected endpoint datasource</param> /// <param name="batchRequestOptions">The injected batch request options</param> public BatchRequestService(IHttpContextAccessor httpContextAccessor, IServiceProvider serviceProvider, EndpointDataSource endpointDataSource, BatchRequestOptions batchRequestOptions) { _httpContextAccessor = httpContextAccessor; _serviceProvider = serviceProvider; _routeEndpoints = endpointDataSource.Endpoints .Select(endpoint => endpoint as RouteEndpoint) .Where(endpoint => endpoint != null) .ToArray(); _batchRequestOptions = batchRequestOptions; }
public EndpointNameAddressScheme(EndpointDataSource dataSource) { _cache = new DataSourceDependentCache <Dictionary <string, Endpoint[]> >(dataSource, Initialize); }
public TestDynamicPageEndpointSelector(EndpointDataSource dataSource) : base(dataSource) { }
public RouteValuesAddressScheme(EndpointDataSource dataSource) { _cache = new DataSourceDependentCache <StateEntry>(dataSource, Initialize); }
public GrpcHttpApiDescriptionProvider(EndpointDataSource endpointDataSource) { _endpointDataSource = endpointDataSource; }
public TestDynamicControllerEndpointSelector(EndpointDataSource dataSource) : base(dataSource) { }
public override Matcher CreateMatcher(EndpointDataSource dataSource) { return(new TestMatcher(_isHandled)); }
public void Write(EndpointDataSource dataSource, TextWriter writer) { // get the DfaMatcherBuilder - internal, so needs reflection :( Type matcherBuilder = typeof(IEndpointSelectorPolicy).Assembly .GetType("Microsoft.AspNetCore.Routing.Matching.DfaMatcherBuilder"); var rawBuilder = _services.GetRequiredService(matcherBuilder); IDfaMatcherBuilder builder = rawBuilder.ActLike <IDfaMatcherBuilder>(); var endpoints = dataSource.Endpoints; for (var i = 0; i < endpoints.Count; i++) { if (endpoints[i] is RouteEndpoint endpoint && (endpoint.Metadata.GetMetadata <ISuppressMatchingMetadata>()?.SuppressMatching ?? false) == false) { builder.AddEndpoint(endpoint); } } // Assign each node a sequential index. var visited = new Dictionary <IDfaNode, int>(); var rawTree = builder.BuildDfaTree(includeLabel: true); IDfaNode tree = rawTree.ActLike <IDfaNode>(); writer.WriteLine("digraph DFA {"); Visit(tree, WriteNode); writer.WriteLine("}"); void WriteNode(IDfaNode node) { if (!visited.TryGetValue(node, out var label)) { label = visited.Count; visited.Add(node, label); } // We can safely index into visited because this is a post-order traversal, // all of the children of this node are already in the dictionary. if (node.Literals != null) { foreach (DictionaryEntry dictEntry in node.Literals) { var edgeLabel = (string)dictEntry.Key; IDfaNode value = dictEntry.Value.ActLike <IDfaNode>(); int nodelLabel = visited[value]; writer.WriteLine($"{label} -> {nodelLabel} [label=\"/{edgeLabel}\" {_options.LiteralEdge}]"); } } if (node.Parameters != null) { IDfaNode parameters = node.Parameters.ActLike <IDfaNode>(); writer.WriteLine($"{label} -> {visited[parameters]} [label=\"/*\" {_options.ParametersEdge}]"); } if (node.CatchAll != null && node.Parameters != node.CatchAll) { IDfaNode catchAll = node.CatchAll.ActLike <IDfaNode>(); int nodeLabel = visited[catchAll]; writer.WriteLine($"{label} -> {nodeLabel} [label=\"/**\" {_options.CatchAllEdge}]"); } if (node.PolicyEdges != null) { foreach (DictionaryEntry dictEntry in node.PolicyEdges) { var edgeLabel = (object)dictEntry.Key; IDfaNode value = dictEntry.Value.ActLike <IDfaNode>(); int nodeLabel = visited[value]; writer.WriteLine($"{label} -> {nodeLabel} [label=\"{edgeLabel}\" {_options.PolicyEdge}]"); } } var extras = node?.Matches?.Count switch { int x when x > 1 => _options.AmbiguousMatchingNode, 1 => _options.MatchingNode, _ => _options.DefaultNode, }; writer.WriteLine($"{label} [label=\"{node.Label}\" {extras}]"); } }
public ReflectionGrpcServiceActivator(EndpointDataSource endpointDataSource, ILoggerFactory loggerFactory) { _logger = loggerFactory.CreateLogger <ReflectionGrpcServiceActivator>(); _endpointDataSource = endpointDataSource; }
public DiscoverApiRoutes(IActionDescriptorCollectionProvider actionDescriptor, EndpointDataSource endpointData) { this.actionDescriptor = actionDescriptor; this.endpointData = endpointData; }
/// <summary> /// Initializes a new instance of the <see cref="RoutableDocumentFilter"/> class. /// </summary> public RoutableDocumentFilter(IOptions <GlobalSettings> globalSettings, IOptions <WebRoutingSettings> routingSettings, IHostingEnvironment hostingEnvironment, EndpointDataSource endpointDataSource) { _globalSettings = globalSettings.Value; _routingSettings = routingSettings.Value; _hostingEnvironment = hostingEnvironment; _endpointDataSource = endpointDataSource; _endpointDataSource.GetChangeToken().RegisterChangeCallback(EndpointsChanged, null); }
public IndexModel(EndpointDataSource endpointsDataSource) { _endpointsDataSource = endpointsDataSource; }
/// <summary> /// Handle ~/$odata request /// </summary> /// <param name="context">The http context.</param> /// <returns>The task.</returns> public static async Task HandleOData(HttpContext context) { EndpointDataSource dataSource = context.RequestServices.GetRequiredService <EndpointDataSource>(); StringBuilder sb = new StringBuilder(); foreach (var endpoint in dataSource.Endpoints) { IODataRoutingMetadata metadata = endpoint.Metadata.GetMetadata <IODataRoutingMetadata>(); if (metadata == null) { continue; } ControllerActionDescriptor controllerActionDescriptor = endpoint.Metadata.GetMetadata <ControllerActionDescriptor>(); if (controllerActionDescriptor == null) { continue; } // controller and action details StringBuilder action = new StringBuilder(); if (controllerActionDescriptor.MethodInfo.ReturnType != null) { action.Append(controllerActionDescriptor.MethodInfo.ReturnType.Name + " "); } else { action.Append("void "); } action.Append(controllerActionDescriptor.MethodInfo.Name + "("); action.Append(string.Join(",", controllerActionDescriptor.MethodInfo.GetParameters().Select(p => p.ParameterType.Name))); action.Append(")"); sb.Append("<tr>"); sb.Append($"<td>{controllerActionDescriptor.ControllerTypeInfo.FullName}</td>"); sb.Append($"<td>{action}</td>"); // http methods string httpMethods = string.Join(",", metadata.HttpMethods); sb.Append($"<td>{httpMethods}</td>"); // OData routing templates int index = 1; sb.Append("<td>"); foreach (var template in metadata.Template.GetTemplates()) { sb.Append($"{index++})").Append(" ~/").Append(template).Append("<br/>"); } sb.Append("</td></tr>"); } string output = ODataRouteMappingHtmlTemplate.Replace("{CONTNET}", sb.ToString()); context.Response.Headers["Content_Type"] = "text/html"; await context.Response.WriteAsync(output); //string content = sb.ToString(); //byte[] requestBytes = Encoding.UTF8.GetBytes(content); //context.Response.Headers.ContentLength = requestBytes.Length; //context.Response.Body = new MemoryStream(requestBytes); //await Task.CompletedTask; }
public GatewayServer(GatewayController gatewayController, EndpointDataSource endpointDataSource) { _endpointDataSource = endpointDataSource; _gatewayController = gatewayController; }
/// <summary> /// Initializes a new instance of the <see cref="ODataEndpointController" /> class. /// </summary> /// <param name="dataSource">The data source.</param> public ODataEndpointController(EndpointDataSource dataSource) { _dataSource = dataSource; }
/// <summary> /// 创建与AshxApi有关的路由 /// </summary> /// <param name="endpointData">路由核心对象</param> /// <param name="template">路由的规则</param> /// <returns>路由核心对象</returns> public static EndpointDataSource MapApiRoute( this EndpointDataSource endpointData, string template) { return(MapApiRoute(endpointData, null, template)); }