Пример #1
0
        private IEnumerable <PageDirectoryRoute> SetChildRoutes(PageDirectoryRoute parent, IReadOnlyCollection <PageDirectory> allDbRoutes)
        {
            if (!parent.ParentPageDirectoryId.HasValue)
            {
                yield return(parent);
            }

            foreach (var dbRoute in allDbRoutes.Where(r => r.ParentPageDirectoryId == parent.PageDirectoryId))
            {
                var routingInfo = MapRoute(dbRoute);
                routingInfo.FullUrlPath = CombineUrl(parent.FullUrlPath, routingInfo.UrlPath);
                ExpandDirectoryLocales(parent, routingInfo);
                foreach (var childRoute in SetChildRoutes(routingInfo, allDbRoutes))
                {
                    yield return(childRoute);
                }

                yield return(routingInfo);
            }
        }
Пример #2
0
        private PageDirectoryRoute MapRoute(PageDirectory dbDirectory)
        {
            var route = new PageDirectoryRoute();

            route.Name                  = dbDirectory.Name;
            route.PageDirectoryId       = dbDirectory.PageDirectoryId;
            route.ParentPageDirectoryId = dbDirectory.ParentPageDirectoryId;
            route.UrlPath               = dbDirectory.UrlPath;
            route.LocaleVariations      = dbDirectory
                                          .PageDirectoryLocales
                                          .Select(d => new PageDirectoryRouteLocale()
            {
                LocaleId = d.LocaleId,
                UrlPath  = d.UrlPath
            })
                                          .ToList();

            // FullUrlPaths set elsewhere

            return(route);
        }
Пример #3
0
        /// <summary>
        /// If a locale is defined in a parent directory but not in the child we define one
        /// using the parent info. This is so we have all locale permitations of this directory even if
        /// locales are defined further down the directory tree.
        /// </summary>
        private void ExpandDirectoryLocales(PageDirectoryRoute parent, PageDirectoryRoute routingInfo)
        {
            var locales = routingInfo.LocaleVariations.ToList();

            var missingLocales = parent
                                 .LocaleVariations
                                 .Where(pl => !locales.Any(l => l.LocaleId == pl.LocaleId))
                                 .Select(pl => new PageDirectoryRouteLocale()
            {
                LocaleId = pl.LocaleId,
                UrlPath  = routingInfo.UrlPath
            });

            locales.AddRange(missingLocales);

            foreach (var locale in locales)
            {
                locale.FullUrlPath = CombineUrl(parent.FullUrlPath, locale.UrlPath);
            }

            routingInfo.LocaleVariations = locales;
        }
Пример #4
0
 public static IEnumerable <PageRoute> FilterByDirectory(this IEnumerable <PageRoute> routes, PageDirectoryRoute directory, int?localeId = null)
 {
     return(routes
            .Where(r => (r.PageDirectory == null && directory == null) || r.PageDirectory == directory)
            .Where(r => (r.Locale == null && !localeId.HasValue) || r.Locale.LocaleId == localeId)
            );
 }