Exemple #1
0
        /// <summary>
        /// Gets the matching site map menu item.
        /// </summary>
        /// <param name="menuName">Name of the menu.</param>
        /// <param name="pathAndQuery">The path and query.</param>
        /// <param name="useCache">if set to <c>true</c> [use cache].</param>
        /// <returns></returns>
        public ISiteMapMenuItem GetMatchingSiteMapMenuItem(string menuName, string pathAndQuery, bool useCache)
        {
            if (!this.SiteMapMenus.ContainsKey(menuName))
            {
                throw new NavigationException("Menu " + menuName + " not found at the SiteMapMenu section.");
            }

            ISiteMapMenu    menu = this.SiteMapMenus[menuName];
            IUrlRewriteItem rewriteItem;

            if (useCache && menu.EnableCaching)
            {// we want to get the menu item from cache
                // define cachekey
                string cacheKey = "__" + menuName + "_" + pathAndQuery;
                lock (_ISiteMapMenuItemLock)
                {
                    ISiteMapMenuItem item = HttpRuntime.Cache[cacheKey] as ISiteMapMenuItem;
                    if (item != null)
                    {// item found at cache collection, so return it
                        return(item);
                    }
                    else
                    {// item not found at cache collection, so find/insert it
                        rewriteItem = this.SiteMapUrls.GetMatchingRewriteItem(pathAndQuery);
                        if (rewriteItem != null)
                        {
                            item = menu.GetMatchingSiteMapMenuItem(rewriteItem.Name);
                        }

                        if (item != null)
                        {
                            HttpRuntime.Cache.Remove(cacheKey);
                            HttpRuntime.Cache.Insert(cacheKey
                                                     , item
                                                     , null
                                                     , DateTime.Now.AddSeconds(menu.CacheDurationInSeconds)
                                                     , Cache.NoSlidingExpiration
                                                     , menu.CacheItemPriority
                                                     , null);
                            return(item);
                        }
                    }
                }
            }

            rewriteItem = this.SiteMapUrls.GetMatchingRewriteItem(pathAndQuery);
            if (rewriteItem != null)
            {
                return(menu.GetMatchingSiteMapMenuItem(rewriteItem.Name));
            }

            return(null);
        }
Exemple #2
0
        /// <summary>
        /// Gets an ISiteMapMenuItem from the ISiteMapMenuItem collection by name
        /// </summary>
        /// <param name="name">The name</param>
        /// <returns></returns>
        public ISiteMapMenu GetSiteMapMenu(string name)
        {
            ISiteMapMenu item       = null;
            IEnumerator  enumerator = this.SiteMapMenuElementCollection.GetEnumerator();

            while (enumerator.MoveNext())
            {
                if (((ISiteMapMenu)enumerator.Current).Name.Equals(name))
                {
                    item = ((ISiteMapMenu)enumerator.Current);
                    break;
                }
            }

            return(item);
        }