BuildTreeLevel() 개인적인 정적인 메소드

private static BuildTreeLevel ( DirectoryInfo root, int level, int maxLevel, XmlElement siteMap ) : NodeCollection
root System.IO.DirectoryInfo
level int
maxLevel int
siteMap System.Xml.XmlElement
리턴 NodeCollection
예제 #1
0
        public static NodeCollection BuildTreeNodes(bool refreshSiteMap)
        {
            XmlDocument map          = null;
            XmlElement  root         = null;
            XmlElement  examplesNode = null;

            if (refreshSiteMap)
            {
                map = new XmlDocument();
                XmlDeclaration dec = map.CreateXmlDeclaration("1.0", "utf-8", null);
                map.AppendChild(dec);

                root = map.CreateElement("siteMap");
                root.SetAttribute("xmlns", "http://schemas.microsoft.com/AspNet/SiteMap-File-1.0");
                map.AppendChild(root);

                examplesNode = map.CreateElement("siteMapNode");
                examplesNode.SetAttribute("title", "Examples");
                root.AppendChild(examplesNode);
            }

            string path = HttpContext.Current.Server.MapPath("~/Examples/");

            NodeCollection result = UIHelpers.BuildTreeLevel(new DirectoryInfo(path), 1, 3, examplesNode);

            if (root != null && root.ChildNodes.Count > 0)
            {
                map.Save(HttpContext.Current.Server.MapPath("Web.sitemap"));
            }

            return(result);
        }
예제 #2
0
        private static NodeCollection BuildTreeLevel(DirectoryInfo root, int level, int maxLevel, XmlElement siteMap)
        {
            DirectoryInfo[] folders = root.GetDirectories();

            folders = SortFolders(root, folders);

            NodeCollection nodes = new NodeCollection(false);

            foreach (DirectoryInfo folder in folders)
            {
                if ((folder.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden ||
                    excludeList.Contains(folder.Name) || folder.Name.StartsWith("_"))
                {
                    continue;
                }

#if !PREEXTENSIONS
                if (level == 1 && (folder.Name == "Gantt" || folder.Name == "Scheduler"))
                {
                    continue;
                }
#endif

                ExampleConfig cfg = new ExampleConfig(folder.FullName + "\\config.xml", false);

                string     iconCls  = string.IsNullOrEmpty(cfg.IconCls) ? "" : cfg.IconCls;
                Node       node     = new Node();
                XmlElement siteNode = null;

                string folderName = folder.Name.Replace("_", " ");

                if (level < maxLevel)
                {
                    node.Text = folderName;

                    flagNode(ref node, folder.FullName);

                    node.IconCls = iconCls;
                    node.NodeID  = BaseControl.GenerateID();
                    //node.SingleClickExpand = true;

                    if (siteMap != null)
                    {
                        siteNode = siteMap.OwnerDocument.CreateElement("siteMapNode");
                        siteNode.SetAttribute("title", folderName);
                        siteMap.AppendChild(siteNode);
                    }

                    node.Children.AddRange(UIHelpers.BuildTreeLevel(folder, level + 1, maxLevel, siteNode));
                }
                else
                {
                    node.Text = folderName;

                    flagNode(ref node, folder.FullName);

                    node.IconCls = iconCls;
                    string url = PhysicalToVirtual(folder.FullName + "/");
                    node.NodeID = "e" + Math.Abs(url.ToLower().GetHashCode());
                    //node.Href = Regex.Replace(url, "^/Examples","");
                    node.CustomAttributes.Add(new ConfigItem("url", Regex.Replace(url, "^/Examples", "")));

                    node.Leaf = true;

                    if (siteMap != null)
                    {
                        siteNode = siteMap.OwnerDocument.CreateElement("siteMapNode");
                        siteNode.SetAttribute("title", folderName);
                        siteNode.SetAttribute("description", string.IsNullOrEmpty(cfg.Description) ? "No description" : cfg.Description);
                        siteNode.SetAttribute("url", "~" + UIHelpers.PhysicalToVirtual(folder.FullName + "/"));
                        siteMap.AppendChild(siteNode);
                    }
                }

                node.CustomAttributes.Add(new { tags = cfg.Tags.Select(item => item.ToLower()) });

                nodes.Add(node);
            }

            return(nodes);
        }