Exemplo n.º 1
0
        public SingleItemRequest DecodeItemLink(string link)
        {
            try
            {
                var uri          = new Uri(link);
                var routeMatcher = new RouteMatcher();
                var values       = routeMatcher.Match(aliexpressItemLinkTemplate, uri.LocalPath);

                var singleItem = new SingleItemRequest()
                {
                    Source = "Aliexpress"
                };

                singleItem.Title = values.ContainsKey("itemTitle") ? values["itemTitle"].ToString() : String.Empty;
                singleItem.ID    = values.ContainsKey("itemid") ? values["itemid"].ToString() : String.Empty;
                singleItem.Link  = link;

                return(singleItem);
            }
            catch (Exception e)
            {
                return(new SingleItemRequest()
                {
                    Link = link
                });
            }
        }
Exemplo n.º 2
0
    private (string, string, string) GetRouteMatchedTagParser(SiteArticleDefinition definition, string routeToMatch)
    {
        if (definition is null)
        {
            Log.Debug("SiteDefinition is null. Falling back to adaptive parser.");
            return("adaptive-parser", "", "");
        }

        if (definition.RouteTemplates?.Length > 0)
        {
            var matcher = new RouteMatcher();
            foreach (var articleRoute in definition.RouteTemplates)
            {
                if (matcher.Match(articleRoute.Template, "/" + routeToMatch) != null)
                {
                    Log.Information("Matched route {routeName} on template {template}", articleRoute.Name, articleRoute.Template);
                    return(articleRoute.Parser, articleRoute.ArticleSelector, articleRoute.ParagraphSelector);
                }
            }

            // Might have forgotten to create a **catch-all template, fall back to adaptive parser
            Log.Warning("Missing **catch-all template. Falling back to adaptive parser.");
            return("adaptive-parser", "", "");
        }
        else
        {
            // No route templates defined, fall back to older style definition or adpative parser
            Log.Debug("No route templates defined. falling back to {@parser}", definition);
            return(string.IsNullOrEmpty(definition.Parser) ? "adaptive-parser" : definition.Parser,
                   definition.ArticleSelector, definition.ParagraphSelector);
        }
    }
Exemplo n.º 3
0
        public bool Match(HttpContext context)
        {
            var routeMatcher = new RouteMatcher();

            var result = routeMatcher.Match(route, context.Request.Path);

            if (result != null)
            {
                context.Features[typeof(IRouteValuesFeature)] = new RouteValuesFeature(result);

                return(true);
            }

            return(false);
        }
Exemplo n.º 4
0
        public void VariousPathAndQueryStringMatches()
        {
            // arrange
            var sut = new RouteMatcher();

            // act/assert
            var query     = new QueryCollection(Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery("?sorted=date"));
            var noopQuery = new QueryCollection(Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery("?sorted=noop"));

            sut.Match("/api/customers/{id}/orders?sorted=date", "/api/customers/1234567/orders", query).ShouldNotBeNull();
            sut.Match("/api/customers/{id}/orders?sorted=date", "api/customers/1234567/orders", query).ShouldNotBeNull();
            sut.Match("api/customers/{id}/orders?sorted=date", "/api/customers/1234567/orders", query).ShouldNotBeNull();
            sut.Match("api/customers/{id}/orders?sorted=date", "api/customers/1234567/orders", query).ShouldNotBeNull();
            sut.Match("/api/customers/{id}/orders?sorted=date", "/api/customers/1234567/orders?sorted=date", query).ShouldNotBeNull();
            sut.Match("/api/customers/{id}/orders?sorted=date", "/api/customers/1234567/orders").ShouldBeNull();
            sut.Match("/api/customers/{id}/orders?sorted=date", "/api/customers/1234567/orders", noopQuery).ShouldBeNull();
            sut.Match("/api/customers/{id}/orders?sorted=date", "/api/customers/1234567/orders", query).ContainsKey("id").ShouldBeTrue();
            sut.Match("/api/customers/{id}/orders?sorted=date", "/api/customers/1234567/orders", query)["id"].ShouldBe("1234567");
            //sut.Match("/api/customers/{id}/orders?orderId={orderId}", "/api/customers/1234567/orders?orderId=778899", query).ContainsKey("orderId").ShouldBeTrue();
            //sut.Match("/api/customers/{id}/orders?orderId={orderId}", "/api/customers/1234567/orders?orderId=778899", query)["orderId"].ShouldBe("778899");
            //sut.Match("/api/customers/{id}/orders/{orderId}", "/api/customers/1234567/orders/778899")["orderId"].ShouldBe(778899);
        }
Exemplo n.º 5
0
        public void VariousPathMatches()
        {
            // arrange
            var sut = new RouteMatcher();

            // act/assert
            sut.Match("/api/customers", "/api/customers").ShouldNotBeNull();
            sut.Match("api/customers", "/api/customers").ShouldNotBeNull();
            sut.Match("/api/customers", "api/customers").ShouldNotBeNull();
            sut.Match("api/customers", "api/customers").ShouldNotBeNull();
            sut.Match("/api/customers", "/api/customers/1234567").ShouldBeNull();
            sut.Match("/api/customers/{id}", "/api/customers/1234567").ShouldNotBeNull();
            sut.Match("/api/customers/{id}", "/api/customers/1234567").ContainsKey("id").ShouldBeTrue();
            sut.Match("/api/customers/{id}", "/api/customers/1234567")["id"].ShouldBe("1234567");
            sut.Match("/api/customers/{id}", "/api/customers/1234567/orders").ShouldBeNull();
            sut.Match("/api/customers/{id}/orders", "/api/customers/1234567/orders").ShouldNotBeNull();
            sut.Match("/api/customers/{id}/orders/{orderId}", "/api/customers/1234567/orders/778899").ShouldNotBeNull();
            sut.Match("/api/customers/{id}/orders/{orderId}", "/api/customers/1234567/orders/778899")["orderId"].ShouldBe("778899");
            sut.Match("/api/customers/{id:int}", "/api/customers/1234567")["id"].ShouldBe(1234567);
        }
Exemplo n.º 6
0
        public static Routing.RouteValueDictionary GetRouteData(this HttpRequest request, Mock mock)
        {
            var routeMatcher = new RouteMatcher();

            return(routeMatcher.Match(mock.Route, request.Path));
        }