public static String Output(DirectoryNode node, int depth) { var sb = new StringBuilder(); var indentCharcter = "\t"; var indent1 = String.Concat(Enumerable.Repeat(indentCharcter, depth).ToArray()); var indent2 = String.Concat(Enumerable.Repeat(indentCharcter, depth + 1).ToArray()); var indent3 = String.Concat(Enumerable.Repeat(indentCharcter, depth + 2).ToArray()); var indent4 = String.Concat(Enumerable.Repeat(indentCharcter, depth + 3).ToArray()); var indent5 = String.Concat(Enumerable.Repeat(indentCharcter, depth + 4).ToArray()); sb.Append(indent1 + "<ul>\r\n"); sb.Append(indent2 + "<li class=\"jstree-open\">\r\n"); sb.Append(indent3 + "<a href=\"#\">" + node.Name + "</a>\r\n"); sb.Append(indent3 + "<ul>\r\n"); node.SubDirectoryList.ForEach(x => sb.Append(Output(x, depth + 3))); node.FileList.ForEach(x => { sb.Append(indent4 + "<li name=\"" + x.Path.Replace('\\', '/') + ".html" + "\">\r\n"); sb.Append(indent5 + "<a href=\"#\">" + x.Name + "</a>\r\n"); sb.Append(indent4 + "</li>\r\n"); }); sb.Append(indent3 + "</ul>\r\n"); sb.Append(indent2 + "</li>\r\n"); sb.Append(indent1 + "</ul>\r\n"); return sb.ToString(); }
public void Write(String filePath, DirectoryNode root) { var content = Output(root, 0); var result = this.template.Inject(new { content, }); File.WriteAllText(filePath, result); }
public void Read(String srcDirectoryPath, String dstDirectoryPath) { this.HtmlDirectoryPath = Path.Combine(dstDirectoryPath, "html"); var title = Path.GetFileName(srcDirectoryPath); var directoryList = new Dictionary<String, DirectoryNode>(); var fileList = new Dictionary<String, FileNode>(); this.Root = new DirectoryNode(title); directoryList.Add(".\\html", Root); var targetLength = srcDirectoryPath.Length; this.FilePathList = Directory.GetFiles(srcDirectoryPath, "*", SearchOption.AllDirectories) .Where(x => brushFactory.ContainsExt(Path.GetExtension(x).ToLower())); foreach (var x in FilePathList.Select(x => this.HtmlDirectoryPath + x.Substring(targetLength))) { var dir = Path.GetDirectoryName(x); var relativeDirPath = "." + dir.Substring(dstDirectoryPath.Length); var tmp = relativeDirPath; while (true) { if (!directoryList.ContainsKey(tmp)) { directoryList.Add(tmp, new DirectoryNode(Path.GetFileName(tmp))); } tmp = Path.GetDirectoryName(tmp); if (tmp == ".") { break; } } var relativeFilePath = "." + x.Substring(dstDirectoryPath.Length); if (!fileList.ContainsKey(relativeFilePath)) { fileList.Add(relativeFilePath, new FileNode(Path.GetFileName(x), relativeFilePath)); } } foreach (var file in fileList.OrderBy(x => x.Key)) { var dirPath = Path.GetDirectoryName(file.Key); directoryList[dirPath].AddFile(file.Value); } foreach (var dir in directoryList.OrderBy(x => x.Key)) { var dirPath = Path.GetDirectoryName(dir.Key); if (directoryList.ContainsKey(dirPath)) { directoryList[dirPath].AddDirectory(dir.Value); } else { //Console.WriteLine("not contains : " + dirPath); } } }
public void AddDirectory(DirectoryNode subDirectory) { this.SubDirectoryList.Add(subDirectory); }