public static ContentPageConfiguration GetConfig()
        {
            ContentPageConfiguration contentPageConfig
                = new ContentPageConfiguration();

            //FileInfo contentConfig
            //    = new FileInfo(HttpContext.Current.Server.MapPath("~/Setup/initialcontent/content.config"));

            //XmlDocument contentConfigFile = new XmlDocument();
            //contentConfigFile.Load(contentConfig.FullName);

            //ContentPage.LoadPages(
            //    contentPageConfig,
            //    contentConfigFile.DocumentElement);


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

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

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


            DirectoryInfo directoryInfo
                = new DirectoryInfo(pathToConfigFolder);

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

            foreach (FileInfo fileInfo in pageFiles)
            {
                XmlDocument contentConfigFile = new XmlDocument();
                contentConfigFile.Load(fileInfo.FullName);

                ContentPage.LoadPages(
                    contentPageConfig,
                    contentConfigFile.DocumentElement);
            }

            return(contentPageConfig);
        }
Пример #2
0
        public static void LoadPages(
            ContentPageConfiguration contentPageConfig,
            XmlNode documentElement)
        {
            if (HttpContext.Current == null)
            {
                return;
            }
            if (documentElement.Name != "siteContent")
            {
                return;
            }

            XmlNode pagesNode = null;

            foreach (XmlNode node in documentElement.ChildNodes)
            {
                if (node.Name == "pages")
                {
                    pagesNode = node;
                    break;
                }
            }

            if (pagesNode == null)
            {
                return;
            }

            foreach (XmlNode node in pagesNode.ChildNodes)
            {
                if (node.Name == "page")
                {
                    ContentPage contentPage = new ContentPage();

                    XmlAttributeCollection attributeCollection
                        = node.Attributes;

                    if (attributeCollection["pageGuid"] != null)
                    {
                        contentPage.pageGuid = new Guid(attributeCollection["pageGuid"].Value);
                    }

                    if (attributeCollection["parentGuid"] != null)
                    {
                        contentPage.parentGuid = new Guid(attributeCollection["parentGuid"].Value);
                    }


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

                    if (attributeCollection["name"] != null)
                    {
                        contentPage.name = attributeCollection["name"].Value;
                    }


                    if (attributeCollection["title"] != null)
                    {
                        contentPage.title = attributeCollection["title"].Value;
                    }


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

                    if (attributeCollection["menuImage"] != null)
                    {
                        contentPage.menuImage = attributeCollection["menuImage"].Value;
                    }

                    if (attributeCollection["pageOrder"] != null)
                    {
                        int sort = 1;
                        if (int.TryParse(attributeCollection["pageOrder"].Value,
                                         out sort))
                        {
                            contentPage.pageOrder = sort;
                        }
                    }

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

                    if (attributeCollection["editRoles"] != null)
                    {
                        contentPage.editRoles = attributeCollection["editRoles"].Value;
                    }

                    if (attributeCollection["draftEditRoles"] != null)
                    {
                        contentPage.draftEditRoles = attributeCollection["draftEditRoles"].Value;
                    }

                    if (attributeCollection["createChildPageRoles"] != null)
                    {
                        contentPage.createChildPageRoles = attributeCollection["createChildPageRoles"].Value;
                    }

                    if (attributeCollection["pageMetaKeyWords"] != null)
                    {
                        contentPage.pageMetaKeyWords = attributeCollection["pageMetaKeyWords"].Value;
                    }

                    if (attributeCollection["pageMetaDescription"] != null)
                    {
                        contentPage.pageMetaDescription = attributeCollection["pageMetaDescription"].Value;
                    }

                    if (
                        (attributeCollection["requireSSL"] != null) &&
                        (attributeCollection["requireSSL"].ToString().ToLower() == "true")
                        )
                    {
                        contentPage.requireSSL = true;
                    }


                    foreach (XmlNode contentFeatureNode in node.ChildNodes)
                    {
                        if (contentFeatureNode.Name == "contentFeature")
                        {
                            ContentPageItem.LoadPageItem(
                                contentPage,
                                contentFeatureNode);
                        }
                    }

                    if (contentPage.pageGuid == Guid.Empty)
                    {
                        log.Error("could not install page " + contentPage.Name
                                  + ". Invalid PageGuid.");
                        return;
                    }


                    contentPageConfig.ContentPages.Add(contentPage);
                }
            }
        }