private static bool IsNew(string folder) { if (ExamplesModel.rootCfg == null) { ExamplesModel.rootCfg = new ExampleConfig(new DirectoryInfo(HttpContext.Current.Server.MapPath(ExamplesModel.ExamplesRoot)) + "\\config.xml"); } foreach (string newFolder in rootCfg.NewFolders) { if (string.Concat(HttpContext.Current.Server.MapPath(ExamplesModel.ExamplesRoot), newFolder).StartsWith(folder, StringComparison.CurrentCultureIgnoreCase)) { return(true); } } return(false); }
private static void BuildViewsLevel(DirectoryInfo area, Node areaNode) { DirectoryInfo[] folders = new DirectoryInfo(area.FullName + "\\Views").GetDirectories(); folders = ExamplesModel.SortFolders(area, folders); 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"); string iconCls = string.IsNullOrEmpty(cfg.IconCls) ? "" : cfg.IconCls; Node node = new Node(); string folderName = folder.Name.Replace("_", " "); node.Text = folderName; if (ExamplesModel.IsNew(folder.FullName)) { node.CustomAttributes.Add(new ConfigItem("isNew", "true", ParameterMode.Raw)); } node.IconCls = iconCls; string url = string.Concat(ExamplesModel.ApplicationRoot, "/", area.Name, "/", folder.Name, "/"); node.NodeID = "e" + Math.Abs(url.ToLower().GetHashCode()); //node.Href = url; node.CustomAttributes.Add(new ConfigItem("url", url)); node.Leaf = true; node.CustomAttributes.Add(new { tags = cfg.Tags.Select(item => item.ToLower()) }); areaNode.Children.Add(node); } }
private static DirectoryInfo[] SortFolders(DirectoryInfo root, DirectoryInfo[] folders) { string cfgPath = root.FullName + "\\config.xml"; if (File.Exists(root.FullName + "\\config.xml")) { ExampleConfig rootCfg = new ExampleConfig(cfgPath); if (rootCfg.OrderFolders.Count > 0) { List <DirectoryInfo> list = new List <DirectoryInfo>(folders); int pasteIndex = 0; foreach (string orderFolder in rootCfg.OrderFolders) { int dIndex = 0; for (int ind = 0; ind < list.Count; ind++) { if (list[ind].Name.ToLower() == orderFolder) { dIndex = ind; } } if (dIndex > 0) { DirectoryInfo di = list[dIndex]; list.RemoveAt(dIndex); list.Insert(pasteIndex++, di); } } folders = list.ToArray(); } } return(folders); }
private static bool IsUpdated(string folder) { if (rootCfg == null) { rootCfg = new ExampleConfig(new DirectoryInfo(HttpContext.Current.Server.MapPath(ExamplesModel.ExamplesRoot)) + "\\config.xml", false); } foreach (string updFolder in rootCfg.UpdFolders) { string updPath = string.Concat(HttpContext.Current.Server.MapPath(ExamplesModel.ExamplesRoot), updFolder); if (updPath.StartsWith(folder, StringComparison.CurrentCultureIgnoreCase)) { string end = updPath.Substring(folder.Length); if ((end.StartsWith("\\") || end.Equals(""))) { return(true); } } } return(false); }
private static NodeCollection BuildAreasLevel() { string path = HttpContext.Current.Server.MapPath(ExamplesModel.ExamplesRoot); DirectoryInfo root = new DirectoryInfo(path); DirectoryInfo[] folders = root.GetDirectories(); folders = ExamplesModel.SortFolders(root, folders); NodeCollection nodes = new NodeCollection(false); var staticIcons = new StaticNodeIcon(path); 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"); string iconCls = string.IsNullOrEmpty(cfg.IconCls) ? "" : cfg.IconCls; Node node = null; var index = folder.Name.IndexOf('_'); if (cfg.MainGroup || index < 0) { node = new Node(); node.NodeID = BaseControl.GenerateID(); node.Text = folder.Name.Replace("_", " "); nodes.Add(node); if (String.IsNullOrWhiteSpace(iconCls)) { staticIcons.TryGetIconCLS(out iconCls, folder.Name); } node.IconCls = iconCls; if (ExamplesModel.IsNew(folder.FullName)) { node.CustomAttributes.Add(new ConfigItem("isNew", "true", ParameterMode.Raw)); } } else { string otherIconCls; var mainGroupName = folder.Name.Substring(0, index); node = nodes.FirstOrDefault(n => n.Text == mainGroupName); if (node == null) { node = new Node(); node.NodeID = BaseControl.GenerateID(); node.Text = mainGroupName; nodes.Add(node); } if (staticIcons.TryGetIconCLS(out otherIconCls, mainGroupName)) { node.IconCls = otherIconCls; } if (ExamplesModel.IsNew(folder.FullName) && !node.CustomAttributes.Contains("isNew")) { node.CustomAttributes.Add(new ConfigItem("isNew", "true", ParameterMode.Raw)); } var groupNode = new Node(); var subGroupNodeName = folder.Name.Substring(index + 1); groupNode.NodeID = BaseControl.GenerateID(); groupNode.Text = subGroupNodeName.Replace("_", " "); if (iconCls.IsNotEmpty()) { groupNode.IconCls = iconCls; } else if (staticIcons.TryGetIconCLS(out otherIconCls, mainGroupName, subGroupNodeName)) { groupNode.IconCls = otherIconCls; } if (ExamplesModel.IsNew(folder.FullName) && !groupNode.CustomAttributes.Contains("isNew")) { groupNode.CustomAttributes.Add(new ConfigItem("isNew", "true", ParameterMode.Raw)); } node.Children.Add(groupNode); node = groupNode; } ExamplesModel.BuildViewsLevel(folder, node); } return nodes; }
private static DirectoryInfo[] SortFolders(DirectoryInfo root, DirectoryInfo[] folders) { string cfgPath = root.FullName + "\\config.xml"; if (File.Exists(root.FullName + "\\config.xml")) { ExampleConfig rootCfg = new ExampleConfig(cfgPath); if (rootCfg.OrderFolders.Count > 0) { List<DirectoryInfo> list = new List<DirectoryInfo>(folders); int pasteIndex = 0; foreach (string orderFolder in rootCfg.OrderFolders) { int dIndex = 0; for (int ind = 0; ind < list.Count; ind++) { if (list[ind].Name.ToLower() == orderFolder) { dIndex = ind; } } if (dIndex > 0) { DirectoryInfo di = list[dIndex]; list.RemoveAt(dIndex); list.Insert(pasteIndex++, di); } } folders = list.ToArray(); } } return folders; }
private static bool IsNew(string folder) { if (ExamplesModel.rootCfg == null) { ExamplesModel.rootCfg = new ExampleConfig(new DirectoryInfo(HttpContext.Current.Server.MapPath(ExamplesModel.ExamplesRoot)) + "\\config.xml"); } foreach (string newFolder in rootCfg.NewFolders) { string newPath = string.Concat(HttpContext.Current.Server.MapPath(ExamplesModel.ExamplesRoot), newFolder); if (newPath.StartsWith(folder, StringComparison.CurrentCultureIgnoreCase)) { string end = newPath.Substring(folder.Length); if ((end.StartsWith("\\") || end.Equals(""))) { return true; } } } return false; }
private static NodeCollection BuildAreasLevel() { string path = HttpContext.Current.Server.MapPath(ExamplesModel.ExamplesRoot); DirectoryInfo root = new DirectoryInfo(path); DirectoryInfo[] folders = root.GetDirectories(); folders = ExamplesModel.SortFolders(root, folders); NodeCollection nodes = new NodeCollection(false); var staticIcons = new StaticNodeIcon(path); 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"); string iconCls = string.IsNullOrEmpty(cfg.IconCls) ? "" : cfg.IconCls; Node node = null; var index = folder.Name.IndexOf('_'); if (cfg.MainGroup || index < 0) { node = new Node(); node.NodeID = BaseControl.GenerateID(); node.Text = folder.Name.Replace("_", " "); nodes.Add(node); if (String.IsNullOrWhiteSpace(iconCls)) { staticIcons.TryGetIconCLS(out iconCls, folder.Name); } node.IconCls = iconCls; if (ExamplesModel.IsNew(folder.FullName)) { node.CustomAttributes.Add(new ConfigItem("isNew", "true", ParameterMode.Raw)); } } else { string otherIconCls; var mainGroupName = folder.Name.Substring(0, index); node = nodes.FirstOrDefault(n => n.Text == mainGroupName); if (node == null) { node = new Node(); node.NodeID = BaseControl.GenerateID(); node.Text = mainGroupName; nodes.Add(node); } if (staticIcons.TryGetIconCLS(out otherIconCls, mainGroupName)) { node.IconCls = otherIconCls; } if (ExamplesModel.IsNew(folder.FullName) && !node.CustomAttributes.Contains("isNew")) { node.CustomAttributes.Add(new ConfigItem("isNew", "true", ParameterMode.Raw)); } var groupNode = new Node(); var subGroupNodeName = folder.Name.Substring(index + 1); groupNode.NodeID = BaseControl.GenerateID(); groupNode.Text = subGroupNodeName.Replace("_", " "); if (iconCls.IsNotEmpty()) { groupNode.IconCls = iconCls; } else if (staticIcons.TryGetIconCLS(out otherIconCls, mainGroupName, subGroupNodeName)) { groupNode.IconCls = otherIconCls; } if (ExamplesModel.IsNew(folder.FullName) && !groupNode.CustomAttributes.Contains("isNew")) { groupNode.CustomAttributes.Add(new ConfigItem("isNew", "true", ParameterMode.Raw)); } node.Children.Add(groupNode); node = groupNode; } ExamplesModel.BuildViewsLevel(folder, node); } return(nodes); }
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; } XmlAttribute mainGroup = root.Attributes["group"]; if (mainGroup != null) { this.MainGroup = mainGroup.Value == "1"; } XmlNode desc = root.SelectSingleNode("description"); if (desc != null) { this.Description = desc.InnerText; } XmlNodeList 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()); } } } folders = root.SelectNodes("new/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()); } } } XmlNode tagsNode = root.SelectSingleNode("tags"); if (tagsNode != null) { this.Tags.AddRange(tagsNode.InnerText.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)); } XmlNodeList files = root.SelectNodes("include/file"); if (files != null) { string url = ExampleConfig.PhysicalToAbsolute(path); foreach (XmlNode file in files) { XmlAttribute urlAttr = file.Attributes["url"]; XmlAttribute zipAttr = file.Attributes["zip"]; 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)); } } } }
public static List <FileInfo> GetFiles(string url, bool download) { var list = new List <FileInfo>(); var match = SourceModel.example_RE.Match(url); if (!match.Success) { return(list); } var area = match.Groups[1].Value; var controller = match.Groups[2].Value; string path = HttpContext.Current.Server.MapPath(ExamplesModel.ExamplesRoot + area); list.Add(new FileInfo(string.Concat(path, "/Controllers/", controller, "Controller.cs"))); var model = string.Concat(path, "/Models/", controller, "Model.cs"); if (File.Exists(model)) { list.Add(new FileInfo(model)); } string configPath = path + "\\Views\\" + controller + "\\config.xml"; if (File.Exists(configPath)) { ExampleConfig cfg = new ExampleConfig(configPath, true); foreach (string file in cfg.OuterFiles) { list.Add(new FileInfo(file)); } } model = path + "/Models/SharedModel.cs"; if (File.Exists(model)) { list.Add(new FileInfo(model)); } DirectoryInfo viewFolder = new DirectoryInfo(string.Concat(path, "/Views/", controller)); FileInfo[] filesInfo = viewFolder.GetFiles(); int dIndex = 0; int len = list.Count; for (int ind = 0; ind < filesInfo.Length; ind++) { var fileInfo = filesInfo[ind]; if (Path.GetFileNameWithoutExtension(fileInfo.Name).ToLowerInvariant() == "index") { dIndex = ind + len; } if (excludeList.Contains(fileInfo.Name) || (!download && excludeExtensions.Contains(fileInfo.Extension.ToLowerInvariant()))) { len--; continue; } list.Add(fileInfo); } if (download) { foreach (DirectoryInfo folder in viewFolder.GetDirectories()) { if (excludeFolders.Contains(folder.Name.ToLower()) || folder.Name.StartsWith("_")) { continue; } SourceModel.GetSubFiles(list, folder); } } if (dIndex > 0) { FileInfo fi = list[dIndex]; list.RemoveAt(dIndex); list.Insert(0, fi); } return(list); }
private static NodeCollection BuildAreasLevel() { string path = HttpContext.Current.Server.MapPath(ExamplesModel.ExamplesRoot); DirectoryInfo root = new DirectoryInfo(path); DirectoryInfo[] folders = root.GetDirectories(); folders = ExamplesModel.SortFolders(root, folders); NodeCollection nodes = new NodeCollection(false); var staticIcons = new StaticNodeIcon(path); 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"); string iconCls = string.IsNullOrEmpty(cfg.IconCls) ? "" : cfg.IconCls; Node node = null; int index = 0; if (cfg.MainGroupSplitAt < 2) { index = folder.Name.IndexOf('_'); } else { var split_folder = folder.Name.Split('_'); if (split_folder.Length <= cfg.MainGroupSplitAt) { // The setting specifies to split the group beyond the // available amount of underscore splitters in the // folder string. index = -1; } else { index += cfg.MainGroupSplitAt - 1; for (var i = 0; i < cfg.MainGroupSplitAt; i++) { index += split_folder[i].Length; } } } if (cfg.MainGroup || index < 1) { node = new Node(); node.NodeID = BaseControl.GenerateID(); node.Text = folder.Name.Replace("_", " "); nodes.Add(node); if (String.IsNullOrWhiteSpace(iconCls)) { staticIcons.TryGetIconCLS(out iconCls, folder.Name); } node.IconCls = iconCls; flagNode(ref node, folder.FullName); } else { string otherIconCls; var rawMainGroupName = folder.Name.Substring(0, index); var mainGroupName = rawMainGroupName.Replace('_', ' '); node = nodes.FirstOrDefault(n => n.Text == mainGroupName); if (node == null) { node = new Node(); node.NodeID = BaseControl.GenerateID(); node.Text = mainGroupName; nodes.Add(node); } if (staticIcons.TryGetIconCLS(out otherIconCls, rawMainGroupName)) { node.IconCls = otherIconCls; } flagNode(ref node, folder.FullName); var groupNode = new Node(); var subGroupNodeName = folder.Name.Substring(index + 1); groupNode.NodeID = BaseControl.GenerateID(); groupNode.Text = subGroupNodeName.Replace("_", " "); if (iconCls.IsNotEmpty()) { groupNode.IconCls = iconCls; } else if (staticIcons.TryGetIconCLS(out otherIconCls, rawMainGroupName, subGroupNodeName)) { groupNode.IconCls = otherIconCls; } flagNode(ref groupNode, folder.FullName); node.Children.Add(groupNode); node = groupNode; } ExamplesModel.BuildViewsLevel(folder, node); } return(nodes); }
public static bool ClearExamplesTree() { rootCfg = null; return(true); }
public static List<FileInfo> GetFiles(string url, bool download) { var list = new List<FileInfo>(); var match = SourceModel.example_RE.Match(url); if (!match.Success) { return list; } var area = match.Groups[1].Value; var controller = match.Groups[2].Value; string path = HttpContext.Current.Server.MapPath(ExamplesModel.ExamplesRoot + area); list.Add(new FileInfo(string.Concat(path, "/Controllers/", controller, "Controller.cs"))); var model = string.Concat(path, "/Models/", controller, "Model.cs"); if (File.Exists(model)) { list.Add(new FileInfo(model)); } string configPath = path + "\\Views\\" + controller + "\\config.xml"; if (File.Exists(configPath)) { ExampleConfig cfg = new ExampleConfig(configPath, true); foreach (string file in cfg.OuterFiles) { list.Add(new FileInfo(file)); } } model = path + "/Models/SharedModel.cs"; if (File.Exists(model)) { list.Add(new FileInfo(model)); } DirectoryInfo viewFolder = new DirectoryInfo(string.Concat(path, "/Views/", controller)); FileInfo[] filesInfo = viewFolder.GetFiles(); int dIndex = 0; int len = list.Count; for (int ind = 0; ind < filesInfo.Length; ind++) { var fileInfo = filesInfo[ind]; if (Path.GetFileNameWithoutExtension(fileInfo.Name).ToLowerInvariant() == "index") { dIndex = ind + len; } if (excludeList.Contains(fileInfo.Name) || (!download && excludeExtensions.Contains(fileInfo.Extension.ToLowerInvariant()))) { len--; continue; } list.Add(fileInfo); } if (download) { foreach (DirectoryInfo folder in viewFolder.GetDirectories()) { if (excludeFolders.Contains(folder.Name.ToLower()) || folder.Name.StartsWith("_")) { continue; } SourceModel.GetSubFiles(list, folder); } } if (dIndex > 0) { FileInfo fi = list[dIndex]; list.RemoveAt(dIndex); list.Insert(0, fi); } return list; }