Exemple #1
0
        public IEnumerable <Endpoint> FindEndpoints(RouteValuesAddress address)
        {
            if (address.AmbientValues == null || address.ExplicitValues == null)
            {
                return(Enumerable.Empty <Endpoint>());
            }


            // Try to get the contained item first, then the container content item
            string contentItemId = address.ExplicitValues[_options.ContainedContentItemIdKey]?.ToString();

            if (string.IsNullOrEmpty(contentItemId))
            {
                contentItemId = address.ExplicitValues[_options.ContentItemIdKey]?.ToString();
            }

            if (string.IsNullOrEmpty(contentItemId) || !_entries.TryGetEntryByContentItemId(contentItemId, out var autorouteEntry))
            {
                return(Enumerable.Empty <Endpoint>());
            }

            if (Match(address.ExplicitValues))
            {
                // Once we have the contained content item id value we no longer want it in the route values.
                address.ExplicitValues.Remove(_options.ContainedContentItemIdKey);

                var routeValues = new RouteValueDictionary(address.ExplicitValues);

                if (address.ExplicitValues.Count > _options.GlobalRouteValues.Count + 1)
                {
                    foreach (var entry in address.ExplicitValues)
                    {
                        if (String.Equals(entry.Key, _options.ContentItemIdKey, StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }

                        if (!_options.GlobalRouteValues.ContainsKey(entry.Key))
                        {
                            routeValues.Remove(entry.Key);
                        }
                    }
                }

                var endpoint = new RouteEndpoint
                               (
                    c => null,
                    RoutePatternFactory.Parse(autorouteEntry.Path, routeValues, null),
                    0,
                    null,
                    null
                               );

                return(new[] { endpoint });
            }

            return(Enumerable.Empty <Endpoint>());
        }
        public IEnumerable <Endpoint> FindEndpoints(RouteValuesAddress address)
        {
            if (address.AmbientValues == null || address.ExplicitValues == null)
            {
                return(Enumerable.Empty <Endpoint>());
            }

            string sitemapId = address.ExplicitValues[_options.SitemapIdKey]?.ToString();

            if (string.IsNullOrEmpty(sitemapId))
            {
                return(Enumerable.Empty <Endpoint>());
            }

            (var found, var path) = _entries.TryGetPathBySitemapIdAsync(sitemapId).GetAwaiter().GetResult();

            if (!found)
            {
                return(Enumerable.Empty <Endpoint>());
            }

            if (Match(address.ExplicitValues))
            {
                var routeValues = new RouteValueDictionary(address.ExplicitValues);

                if (address.ExplicitValues.Count > _options.GlobalRouteValues.Count + 1)
                {
                    foreach (var entry in address.ExplicitValues)
                    {
                        if (String.Equals(entry.Key, _options.SitemapIdKey, StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }

                        if (!_options.GlobalRouteValues.ContainsKey(entry.Key))
                        {
                            routeValues.Remove(entry.Key);
                        }
                    }
                }

                var endpoint = new RouteEndpoint
                               (
                    c => null,
                    RoutePatternFactory.Parse(path, routeValues, null),
                    0,
                    null,
                    null
                               );

                return(new[] { endpoint });
            }

            return(Enumerable.Empty <Endpoint>());
        }
Exemple #3
0
 private void GetUriByAddressCallback(
     HttpContext httpContext,
     RouteValuesAddress address,
     RouteValueDictionary values,
     RouteValueDictionary ambientValues,
     string scheme,
     HostString?host,
     PathString?pathBase,
     FragmentString fragment,
     LinkOptions options)
 {
     RouteValues = values;
 }
        public IEnumerable <Endpoint> FindEndpoints(RouteValuesAddress address)
        {
            if (address.AmbientValues == null || address.ExplicitValues == null)
            {
                return(Enumerable.Empty <Endpoint>());
            }

            var homeRoute = _siteService.GetSiteSettingsAsync().GetAwaiter().GetResult().HomeRoute;

            if (Match(homeRoute, address.ExplicitValues))
            {
                var routeValues = new RouteValueDictionary(address.ExplicitValues);

                if (address.ExplicitValues.Count > homeRoute.Count)
                {
                    foreach (var entry in address.ExplicitValues)
                    {
                        if (!homeRoute.ContainsKey(entry.Key))
                        {
                            routeValues.Remove(entry.Key);
                        }
                    }
                }

                var endpoint = new RouteEndpoint
                               (
                    c => null,
                    RoutePatternFactory.Parse(String.Empty, routeValues, null),
                    0,
                    null,
                    null
                               );

                return(new[] { endpoint });
            }

            return(Enumerable.Empty <Endpoint>());
        }