public static NodeCollection BuildFirstLevel() { string path = HttpContext.Current.Server.MapPath("~/Examples/"); DirectoryInfo root = new DirectoryInfo(path); DirectoryInfo[] folders = root.GetDirectories(); folders = UIHelpers.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; } ExampleConfig cfg = new ExampleConfig(folder.FullName + "\\config.xml", false); string iconCls = string.IsNullOrEmpty(cfg.IconCls) ? "" : cfg.IconCls; Node node = new Node(); node.Text = UIHelpers.MarkNew(folder.FullName, folder.Name.Replace("_", " ")); node.IconCls = iconCls; string url = UIHelpers.PhysicalToVirtual(folder.FullName + "/"); node.NodeID = "e" + Math.Abs(url.ToLower().GetHashCode()); nodes.Add(node); } return(nodes); }
public static void FindExamples(DirectoryInfo root, int level, int maxLevel, List <ExampleGroup> examples) { DirectoryInfo[] folders = root.GetDirectories(); folders = SortFolders(root, folders); foreach (DirectoryInfo folder in folders) { if ((folder.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden || excludeList.Contains(folder.Name) || folder.Name.StartsWith("_")) { continue; } if (level < maxLevel) { if (level == 1) { examples.Add(new ExampleGroup { id = folder.Name, title = folder.Name }); } UIHelpers.FindExamples(folder, level + 1, maxLevel, examples); } else { string imgUrl = UIHelpers.ApplicationRoot + "/resources/images/noimage.gif"; string descr = "No description"; string name = UIHelpers.MarkNew(folder.FullName, folder.Name.Replace("_", " ")); if (File.Exists(folder.FullName + "\\config.xml")) { ExampleConfig cfg = new ExampleConfig(folder.FullName + "\\config.xml", false); descr = cfg.Description; } if (File.Exists(folder.FullName + "\\thumbnail.png")) { imgUrl = PhysicalToVirtual(folder.FullName + "\\thumbnail.png"); } else if (File.Exists(folder.FullName + "\\thumbnail.gif")) { imgUrl = PhysicalToVirtual(folder.FullName + "\\thumbnail.gif"); } string url = PhysicalToVirtual(folder.FullName + "/"); ExampleGroup group = examples[examples.Count - 1]; group.samples.Add(new { id = "e" + Math.Abs(url.ToLower().GetHashCode()), name, url, imgUrl, descr, sub = folder.Parent.Name.Replace("_", " ") }); } } }
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; } 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 = UIHelpers.MarkNew(folder.FullName, folderName); node.IconCls = iconCls; //node.NodeID = "e" + Math.Abs(url.ToLower().GetHashCode()); //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 = UIHelpers.MarkNew(folder.FullName, folderName); node.IconCls = iconCls; string url = PhysicalToVirtual(folder.FullName + "/"); node.NodeID = "e" + Math.Abs(url.ToLower().GetHashCode()); node.Href = 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); } } nodes.Add(node); } return(nodes); }