/// <summary>
        /// Enables processing of the result of an action method by a custom type that inherits from the <see cref="T:System.Web.Mvc.ActionResult"/> class.
        /// </summary>
        /// <param name="context">The context in which the result is executed. The context information includes the controller, HTTP content, request context, and route data.</param>
        public override void ExecuteResult(ControllerContext context)
        {
            var flattenedHierarchy = new HashSet <ISiteMapNode>();

            // Flatten link hierarchy
            if (SiteMapCacheKeys.Any())
            {
                foreach (var key in SiteMapCacheKeys)
                {
                    var siteMap = siteMapLoader.GetSiteMap(key);
                    if (siteMap == null)
                    {
                        throw new UnknownSiteMapException(Resources.Messages.UnknownSiteMap);
                    }
                    this.RootNode = siteMap.RootNode;
                    foreach (var item in FlattenHierarchy(this.RootNode, context, siteMap.VisibilityAffectsDescendants))
                    {
                        flattenedHierarchy.Add(item);
                    }
                }
            }
            else
            {
                foreach (var item in FlattenHierarchy(this.RootNode, context, this.RootNode.SiteMap.VisibilityAffectsDescendants))
                {
                    flattenedHierarchy.Add(item);
                }
            }
            var flattenedHierarchyCount = flattenedHierarchy.LongCount();

            // Determine type of sitemap to generate: sitemap index file or sitemap file
            if (flattenedHierarchyCount > MaxNumberOfLinksPerFile && Page == 0)
            {
                // Sitemap index file
                ExecuteSitemapIndexResult(context, flattenedHierarchy, flattenedHierarchyCount);
            }
            else if (flattenedHierarchyCount > MaxNumberOfLinksPerFile && Page > 0)
            {
                // Sitemap file for links of page X
                ExecuteSitemapResult(context, flattenedHierarchy, flattenedHierarchyCount, Page);
            }
            else
            {
                // Sitemap file for all links
                ExecuteSitemapResult(context, flattenedHierarchy, flattenedHierarchyCount, 1);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Enables processing of the result of an action method by a custom type that inherits from the <see cref="T:System.Web.Mvc.ActionResult"/> class.
        /// </summary>
        /// <param name="context">The context in which the result is executed. The context information includes the controller, HTTP content, request context, and route data.</param>
        public override void ExecuteResult(ControllerContext context)
        {
            var flattenedHierarchy = new List <ISiteMapNode>();

            // Flatten link hierarchy
            if (SiteMapCacheKeys.Count() > 0)
            {
                foreach (var key in SiteMapCacheKeys)
                {
                    var siteMap = siteMapLoader.GetSiteMap(key);
                    if (siteMap == null)
                    {
                        throw new UnknownSiteMapException(Resources.Messages.UnknownSiteMap);
                    }

                    flattenedHierarchy.AddRange(FlattenHierarchy(siteMap.RootNode, BaseUrl));
                }
            }
            else
            {
                flattenedHierarchy.AddRange(FlattenHierarchy(this.RootNode, BaseUrl));
            }
            var flattenedHierarchyCount = flattenedHierarchy.LongCount();

            // Determine type of sitemap to generate: sitemap index file or sitemap file
            if (flattenedHierarchyCount > MaxNumberOfLinksPerFile && Page == 0)
            {
                // Sitemap index file
                ExecuteSitemapIndexResult(context, flattenedHierarchy, flattenedHierarchyCount);
            }
            else if (flattenedHierarchyCount > MaxNumberOfLinksPerFile && Page > 0)
            {
                // Sitemap file for links of page X
                ExecuteSitemapResult(context, flattenedHierarchy, flattenedHierarchyCount, Page);
            }
            else
            {
                // Sitemap file for all links
                ExecuteSitemapResult(context, flattenedHierarchy, flattenedHierarchyCount, 1);
            }
        }
 public static ISiteMap GetSiteMap(string siteMapCacheKey)
 {
     ThrowIfLoaderNotInitialized();
     return(loader.GetSiteMap(siteMapCacheKey));
 }