コード例 #1
0
 public IntAddressScheme(EndpointDataSource dataSource)
 {
     _dataSource = dataSource;
 }
コード例 #2
0
        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}\"]");
            }
        }
コード例 #3
0
 public ODataOpenApiController(EndpointDataSource dataSource)
 {
     _dataSource = dataSource;
 }
コード例 #4
0
        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));
        }
コード例 #5
0
 public TestDynamicControllerEndpointSelectorCache(EndpointDataSource dataSource, int key)
 {
     AddDataSource(dataSource, key);
 }
コード例 #6
0
 public abstract Matcher CreateMatcher(EndpointDataSource dataSource);
コード例 #7
0
 public NotFoundSelectorPolicy(EndpointDataSource endpointDataSource)
 {
     _notFound           = new Lazy <Endpoint>(GetNotFoundEndpoint);
     _endpointDataSource = endpointDataSource;
 }
コード例 #8
0
 public EndpointMetadataApiDescriptionProvider(EndpointDataSource endpointDataSource, IHostEnvironment environment)
     : this(endpointDataSource, environment, null)
 {
 }
コード例 #9
0
 public DebugController(DfaGraphWriter graphWriter, EndpointDataSource endpointDataSource)
 {
     _graphWriter        = graphWriter;
     _endpointDataSource = endpointDataSource;
 }
コード例 #10
0
 /// <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;
 }
コード例 #11
0
 public EndpointNameAddressScheme(EndpointDataSource dataSource)
 {
     _cache = new DataSourceDependentCache <Dictionary <string, Endpoint[]> >(dataSource, Initialize);
 }
コード例 #12
0
 public TestDynamicPageEndpointSelector(EndpointDataSource dataSource)
     : base(dataSource)
 {
 }
コード例 #13
0
 public RouteValuesAddressScheme(EndpointDataSource dataSource)
 {
     _cache = new DataSourceDependentCache <StateEntry>(dataSource, Initialize);
 }
コード例 #14
0
 public GrpcHttpApiDescriptionProvider(EndpointDataSource endpointDataSource)
 {
     _endpointDataSource = endpointDataSource;
 }
コード例 #15
0
 public TestDynamicControllerEndpointSelector(EndpointDataSource dataSource)
     : base(dataSource)
 {
 }
コード例 #16
0
 public override Matcher CreateMatcher(EndpointDataSource dataSource)
 {
     return(new TestMatcher(_isHandled));
 }
コード例 #17
0
        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}]");
            }
        }
コード例 #18
0
 public ReflectionGrpcServiceActivator(EndpointDataSource endpointDataSource, ILoggerFactory loggerFactory)
 {
     _logger             = loggerFactory.CreateLogger <ReflectionGrpcServiceActivator>();
     _endpointDataSource = endpointDataSource;
 }
コード例 #19
0
 public DiscoverApiRoutes(IActionDescriptorCollectionProvider actionDescriptor, EndpointDataSource endpointData)
 {
     this.actionDescriptor = actionDescriptor;
     this.endpointData     = endpointData;
 }
コード例 #20
0
 /// <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);
 }
コード例 #21
0
 public IndexModel(EndpointDataSource endpointsDataSource)
 {
     _endpointsDataSource = endpointsDataSource;
 }
コード例 #22
0
        /// <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;
        }
コード例 #23
0
 public GatewayServer(GatewayController gatewayController, EndpointDataSource endpointDataSource)
 {
     _endpointDataSource = endpointDataSource;
     _gatewayController  = gatewayController;
 }
コード例 #24
0
 /// <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;
 }
コード例 #25
0
 /// <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));
 }