Ejemplo n.º 1
0
        public static void LoadLinks(
            ContentAdminLinksConfiguration config,
            XmlNode documentElement)
        {
            if (HttpContext.Current == null)
            {
                return;
            }
            if (documentElement.Name != "adminMenuLinks")
            {
                return;
            }

            foreach (XmlNode node in documentElement.ChildNodes)
            {
                if (node.Name == "adminMenuLink")
                {
                    ContentAdminLink item = new ContentAdminLink();

                    XmlAttributeCollection attributeCollection
                        = node.Attributes;

                    if (attributeCollection["resourceFile"] != null)
                    {
                        item.resourceFile = attributeCollection["resourceFile"].Value;
                    }

                    if (attributeCollection["resourceKey"] != null)
                    {
                        item.resourceKey = attributeCollection["resourceKey"].Value;
                    }

                    if (attributeCollection["url"] != null)
                    {
                        item.url = attributeCollection["url"].Value;
                    }

                    if (attributeCollection["visibleToRoles"] != null)
                    {
                        item.visibleToRoles = attributeCollection["visibleToRoles"].Value;
                    }

                    config.AdminLinks.Add(item);
                }
            }
        }
Ejemplo n.º 2
0
        public static ContentAdminLinksConfiguration GetConfig(int siteId)
        {
            ContentAdminLinksConfiguration config = null;
            string cacheKey = "ContentAdminLinksConfiguration-" + siteId.ToString();

            if (
                (HttpRuntime.Cache[cacheKey] != null) &&
                (HttpRuntime.Cache[cacheKey] is ContentAdminLinksConfiguration)
                )
            {
                return((ContentAdminLinksConfiguration)HttpRuntime.Cache[cacheKey]);
            }
            else
            {
                config = new ContentAdminLinksConfiguration();

                String configFolderName = "~/Setup/initialcontent/supplementaladminmenulinks";

                string pathToConfigFolder
                    = HttpContext.Current.Server.MapPath(configFolderName);

                if (!Directory.Exists(pathToConfigFolder))
                {
                    return(config);
                }


                DirectoryInfo directoryInfo
                    = new DirectoryInfo(pathToConfigFolder);

                FileInfo[] files = directoryInfo.GetFiles("*.config");

                foreach (FileInfo fileInfo in files)
                {
                    XmlDocument configFile = new XmlDocument();

                    configFile.Load(fileInfo.FullName);

                    ContentAdminLink.LoadLinks(
                        config,
                        configFile.DocumentElement);
                }

                // now look for site specific links
                configFolderName = "~/Data/Sites/"
                                   + siteId.ToString()
                                   + "/supplementaladminmenulinks";

                pathToConfigFolder
                    = HttpContext.Current.Server.MapPath(configFolderName);

                if (Directory.Exists(pathToConfigFolder))
                {
                    directoryInfo
                        = new DirectoryInfo(pathToConfigFolder);

                    files = directoryInfo.GetFiles("*.config");

                    foreach (FileInfo fileInfo in files)
                    {
                        XmlDocument configFile = new XmlDocument();

                        configFile.Load(fileInfo.FullName);

                        ContentAdminLink.LoadLinks(
                            config,
                            configFile.DocumentElement);
                    }
                }

                // cache can be cleared by touching Web.config
                CacheDependency cacheDependency
                    = new CacheDependency(HttpContext.Current.Server.MapPath("~/Web.config"));


                HttpRuntime.Cache.Insert(
                    cacheKey,
                    config,
                    cacheDependency,
                    DateTime.Now.AddYears(1),
                    TimeSpan.Zero,
                    CacheItemPriority.Default,
                    null);

                return((ContentAdminLinksConfiguration)HttpRuntime.Cache[cacheKey]);
            }
        }