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 = folder.Name.Replace("_", " "); if (UIHelpers.IsNew(folder.FullName)) { node.CustomAttributes.Add(new ConfigItem("isNew", "true", ParameterMode.Raw)); } node.IconCls = iconCls; string url = UIHelpers.PhysicalToVirtual(folder.FullName + "/"); node.NodeID = "e" + Math.Abs(url.ToLower().GetHashCode()); nodes.Add(node); } return(nodes); }
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); } // Reset the static rootCfg so that the main xml file is re-read. if (rootCfg != null) { rootCfg = null; } 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); }
private void Load() { this.Description = "No description"; XmlDocument xml = new XmlDocument(); if (File.Exists(path)) { try { xml.Load(path); } catch (FileNotFoundException) { return; } } XmlNode root = xml.SelectSingleNode("example"); if (root == null) { return; } XmlAttribute iconCls = root.Attributes["iconCls"]; if (iconCls != null) { this.IconCls = iconCls.Value; } XmlNode desc = root.SelectSingleNode("description"); if (desc != null) { this.Description = desc.InnerText; } XmlNodeList files = root.SelectNodes("include/file"); if (files != null) { string url = UIHelpers.PhysicalToAbsolute(path); foreach (XmlNode file in files) { XmlAttribute urlAttr = file.Attributes["url"]; XmlAttribute zipAttr = file.Attributes["zip"]; if (includeDescriptors && zipAttr != null && zipAttr.InnerText.ToLower() == "false") { continue; } if (urlAttr != null && !string.IsNullOrEmpty(urlAttr.InnerText)) { string fileUrl = urlAttr.InnerText; Uri uri = new Uri(new Uri(url, UriKind.Absolute), fileUrl); this.OuterFiles.Add(HttpContext.Current.Server.MapPath(uri.AbsolutePath)); if (includeDescriptors && (fileUrl.EndsWith("ashx.cs") || fileUrl.EndsWith("asmx.cs"))) { uri = new Uri(new Uri(url, UriKind.Absolute), fileUrl.Remove(fileUrl.Length - 3, 3)); this.OuterFiles.Add(HttpContext.Current.Server.MapPath(uri.AbsolutePath)); } } } } XmlNodeList folders = root.SelectNodes("zip-folders/folder"); if (folders != null) { string url = UIHelpers.PhysicalToAbsolute(path); foreach (XmlNode folder in folders) { XmlAttribute urlAttr = folder.Attributes["url"]; if (urlAttr != null && !string.IsNullOrEmpty(urlAttr.InnerText)) { string folderUrl = urlAttr.InnerText; Uri uri = new Uri(new Uri(url, UriKind.Absolute), folderUrl); this.ZipFolders.Add(HttpContext.Current.Server.MapPath(uri.AbsolutePath)); } } } folders = root.SelectNodes("order/folder"); if (folders != null) { foreach (XmlNode folder in folders) { XmlAttribute urlAttr = folder.Attributes["name"]; if (urlAttr != null && !string.IsNullOrEmpty(urlAttr.InnerText)) { string folderName = urlAttr.InnerText; this.OrderFolders.Add(folderName.ToLower()); } } } // This will match only new items for the current version a.b.c. folders = root.SelectNodes("new[@version = \"" + ExtNetVersion.WithBuild + "\"]/folder"); if (folders != null) { foreach (XmlNode folder in folders) { XmlAttribute urlAttr = folder.Attributes["name"]; if (urlAttr != null && !string.IsNullOrEmpty(urlAttr.InnerText)) { string folderName = urlAttr.InnerText; this.NewFolders.Add(folderName.ToLower()); } } } // This will match only new items for the current version a.b.c. folders = root.SelectNodes("updated[@version = \"" + ExtNetVersion.WithBuild + "\"]/folder"); if (folders != null) { foreach (XmlNode folder in folders) { XmlAttribute urlAttr = folder.Attributes["name"]; if (urlAttr != null && !string.IsNullOrEmpty(urlAttr.InnerText)) { string folderName = urlAttr.InnerText; this.UpdFolders.Add(folderName.ToLower()); } } } XmlNodeList xmlComments = root.SelectNodes("comments/comment"); if (xmlComments != null) { foreach (XmlNode xmlComment in xmlComments) { try { ExampleComment comment = new ExampleComment(); XmlAttribute attr = xmlComment.Attributes["name"]; if (attr != null && !string.IsNullOrEmpty(attr.InnerText)) { comment.Name = HttpContext.Current.Server.HtmlEncode(attr.InnerText); } attr = xmlComment.Attributes["title"]; if (attr != null && !string.IsNullOrEmpty(attr.InnerText)) { comment.Title = HttpContext.Current.Server.HtmlEncode(attr.InnerText); } attr = xmlComment.Attributes["time"]; if (attr != null && !string.IsNullOrEmpty(attr.InnerText)) { comment.Time = DateTime.Parse(attr.InnerText, new CultureInfo("en-US")); } XmlNode message = xmlComment.SelectSingleNode("message"); if (message != null && !string.IsNullOrEmpty(message.InnerText)) { comment.Message = HttpContext.Current.Server.HtmlEncode(message.InnerText); } this.Comments.Add(comment); } catch { } } } XmlNode tagsNode = root.SelectSingleNode("tags"); if (tagsNode != null) { this.Tags.AddRange(tagsNode.InnerText.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)); } }
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); }
private string BuildSourceTabs(string id, string wId, ExampleConfig cfg, DirectoryInfo dir) { List <string> files = cfg != null ? cfg.OuterFiles : new List <string>(); FileInfo[] filesInfo = dir.GetFiles(); List <FileInfo> fileList = new List <FileInfo>(filesInfo); int dIndex = 0; for (int ind = 0; ind < fileList.Count; ind++) { if (fileList[ind].Name.ToLower() == "default.aspx") { dIndex = ind; } } if (dIndex > 0) { FileInfo fi = fileList[dIndex]; fileList.RemoveAt(dIndex); fileList.Insert(0, fi); } foreach (string file in files) { fileList.Add(new FileInfo(file)); } DirectoryInfo[] resources = dir.GetDirectories("resources", SearchOption.TopDirectoryOnly); if (resources.Length > 0) { GetSubFiles(fileList, resources[0]); } TabPanel tabs = new TabPanel { ID = "tpw" + id, Border = false, ActiveTabIndex = 0 }; int i = 0; foreach (FileInfo fileInfo in fileList) { if (excludeList.Contains(fileInfo.Name) || excludeExtensions.Contains(fileInfo.Extension.ToLower())) { continue; } Panel panel = new Panel(); panel.ID = "tptw" + id + i++; panel.Title = fileInfo.Name; panel.CustomConfig.Add(new ConfigItem("url", UIHelpers.PhysicalToVirtual(fileInfo.FullName), ParameterMode.Value)); switch (fileInfo.Extension) { case ".aspx": case ".ascx": panel.Icon = Icon.PageWhiteCode; break; case ".cs": panel.Icon = Icon.PageWhiteCsharp; break; case ".xml": case ".xsl": panel.Icon = Icon.ScriptCodeRed; break; case ".js": panel.Icon = Icon.Script; break; case ".css": panel.Icon = Icon.Css; break; } panel.Loader = new ComponentLoader(); panel.Loader.Url = UIHelpers.ApplicationRoot + "/GenerateSource.ashx"; panel.Loader.Mode = LoadMode.Frame; panel.Loader.Params.Add(new Parameter("f", UIHelpers.PhysicalToVirtual(fileInfo.FullName), ParameterMode.Value)); panel.Loader.LoadMask.ShowMask = true; tabs.Items.Add(panel); } return(tabs.ToScript(RenderMode.AddTo, wId)); }