Ejemplo n.º 1
0
        private PageDirectoryRoute MapRoute(PageDirectory dbDirectory)
        {
            MissingIncludeException.ThrowIfNull(dbDirectory, d => d.PageDirectoryLocales);
            MissingIncludeException.ThrowIfNull(dbDirectory, d => d.AccessRules);

            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();

            route.AccessRuleSets = new List <EntityAccessRuleSet>();
            var accessRuleSet = _entityAccessRuleSetMapper.Map(dbDirectory);

            if (accessRuleSet != null)
            {
                route.AccessRuleSets.Add(accessRuleSet);
            }

            // FullUrlPaths set elsewhere

            return(route);
        }
Ejemplo n.º 2
0
 private void ExpandAccessRules(PageDirectoryRoute parent, PageDirectoryRoute routingInfo)
 {
     foreach (var accessRuleSet in parent.AccessRuleSets)
     {
         routingInfo.AccessRuleSets.Add(accessRuleSet);
     }
     ;
 }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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 mappedRoute = MapRoute(dbRoute);
                mappedRoute.FullUrlPath = CombineUrl(parent.FullUrlPath, mappedRoute.UrlPath);
                ExpandDirectoryLocales(parent, mappedRoute);
                ExpandAccessRules(parent, mappedRoute);

                foreach (var childRoute in SetChildRoutes(mappedRoute, allDbRoutes))
                {
                    yield return(childRoute);
                }

                yield return(mappedRoute);
            }
        }
Ejemplo n.º 6
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 permutations 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;
        }