private void Replace_SearchArea(string file, bool newSearchList, string newFolder = "") { var tfsFolder = new DirectoryInfo(Xml.LocalFolder); var f = new FileInfo(file); if (newSearchList) { searchList = ""; searchFolder = newFolder.ToLower(); foreach (var codefile in tfsFolder.EnumerateFiles("*", SearchOption.AllDirectories).Where(d => Xml.Extensions.Contains(d.Extension.ToLower()))) { var searchText = WebUtility.HtmlEncode(Xml.ProjectTitle + @"\" + codefile.FullName.Replace(Xml.LocalFolder, "")); var replace = HtmlFormatters.URLReplace(Xml.HtmlFolder + Xml.ProjectTitle); string[] split = f.Directory.FullName.Replace(replace, "").Split(Path.DirectorySeparatorChar); var goback = string.Concat(Enumerable.Repeat("../", split.Length - 1)); var href = codefile.FullName.Replace(Xml.LocalFolder, ""); href = goback + HtmlFormatters.URLReplace(href) + ".html"; searchList += " <li "+ "class='nav-item text-right'><a " + "class='search-item nav-link a-custom-main' " + "href='" + href + "'>" + searchText + "</a></li>" + Environment.NewLine; } } File.WriteAllText(file, File.ReadAllText(file).Replace("&searchArea&", searchList)); }
private void Replace_FileProtocolArea(string file) { var f = new FileInfo(file); var replace = HtmlFormatters.URLReplace(Xml.HtmlFolder + Xml.ProjectTitle); string[] split = f.Directory.FullName.Replace(replace, "").Split(Path.DirectorySeparatorChar); var goback = string.Concat(Enumerable.Repeat("../", split.Length - 1)); File.WriteAllText(file, File.ReadAllText(file).Replace("&fileProtocolArea&", goback)); }
private void Replace_BreadcrumbArea(string file, string originalfilename) { var f = new FileInfo(originalfilename.ToLower()); var replace = (Xml.LocalFolder).ToLower(); var breadcrumbfolders = @"\" + f.FullName.Replace(replace, "").Replace(@"\main.html", ""); var folderSplit = f.Name == "main.html" ? new String[1] : breadcrumbfolders.Split(Path.DirectorySeparatorChar); var breadcrumbText = ""; int x; for (x = 0; x < folderSplit.Length; x++) { if (folderSplit[x] == null) { folderSplit[x] = ""; } var currentpath = HtmlFormatters.URLReplace(Xml.LocalFolder); int y; for (y = 0; y < x + 1; y++) { currentpath += folderSplit[y] + @"\"; } if (f.Name != "main.html" && x == 0) { var goback = string.Concat(Enumerable.Repeat("../", folderSplit.Length - 2)); var href = currentpath.Replace(HtmlFormatters.URLReplace(Xml.LocalFolder + @"\"), "") + ((folderSplit[x] == "") ? "main" : folderSplit[x]); href = goback + HtmlFormatters.URLReplace(href) + ".html"; breadcrumbText += " <li "+ "class='breadcrumb-item'>" + "<a href='" + href + "'>" + ((folderSplit[x] == "") ? Xml.ProjectTitle : folderSplit[x].First().ToString().ToUpper() + folderSplit[x].Substring(1).ToLower()) + "</a></li>" + Environment.NewLine; } else { breadcrumbText += " <li "+ "class='breadcrumb-item active' " + "aria-current='page'>" + ((folderSplit[x] == "") ? Xml.ProjectTitle : folderSplit[x].First().ToString().ToUpper() + folderSplit[x].Substring(1).ToLower()) + "</li>" + Environment.NewLine; } } File.WriteAllText(file, File.ReadAllText(file).Replace("&breadcrumbArea&", breadcrumbText)); }
private void Create_Tree(string file, int recursivelevel = 0) { var folder = new DirectoryInfo(file); recursivelevel++; // Somente para checar o nível da recursividade da função foreach (var directory in folder.EnumerateDirectories("*", SearchOption.TopDirectoryOnly).Where(d => !d.FullName.ToString().Contains(".vscode") && !d.FullName.ToString().Contains(".git") && !d.FullName.ToString().Contains(".svn"))) { Tree += "{"; Tree += @"text:""" + directory.Name + @""""; var dInfo = new DirectoryInfo(directory.FullName); if (dInfo.EnumerateDirectories("*", SearchOption.TopDirectoryOnly).Count() != 0) { Tree += ",nodes:["; Create_Tree(directory.FullName, recursivelevel); } else { Tree += ",nodes:["; foreach (var codefile in dInfo.EnumerateFiles("*", SearchOption.TopDirectoryOnly) .Where(d => Xml.Extensions.Contains(d.Extension.ToLower()))) { var href = codefile.FullName.Replace(Xml.LocalFolder, ""); href = @".\" + HtmlFormatters.URLReplace(href) + ".html"; Tree += "{"; Tree += @"text:""" + codefile.Name + @""","; Tree += "icon:'far fa-file',"; Tree += @"href:""" + href.Replace(@"\", @"/") + @"""},"; } Tree += "]},"; } } foreach (var codefile in folder.EnumerateFiles("*", SearchOption.TopDirectoryOnly) .Where(d => Xml.Extensions.Contains(d.Extension.ToLower()))) { var href = codefile.FullName.Replace(Xml.LocalFolder, ""); href = @".\" + HtmlFormatters.URLReplace(href) + ".html"; Tree += "{"; Tree += @"text:""" + codefile.Name + @""","; Tree += "icon:'far fa-file',"; Tree += @"href:""" + href.Replace(@"\", @"/") + @"""},"; } Tree += "],"; // } Tree += "},"; }
private bool CreateDocumentation() { const bool lRet = false; var htmlFolder = HtmlFormatters.URLReplace(Xml.HtmlFolder + Xml.ProjectTitle); var htmlfile = ""; var dir = new DirectoryInfo(htmlFolder); try { if (Xml.DeleteFiles == "true" && Directory.Exists(htmlFolder)) { dir.Delete(true); } } catch (IOException e) { Logging.WriteLog("ATTENTION: IT WAS NOT POSSIBLE TO EXCLUDE THE DIRECTORY: " + dir.FullName + ". THE PROCESS WILL CONTINUE.\n" + e); } Directory.CreateDirectory(htmlFolder); #region Copiando arquivos css originais do bináiro para o diretório HTML: var css = new CssGenerator(); css.LoadXml(Xml); css.CopyCss(htmlFolder); #endregion #region CRIANDO ÁRVORE DE PASTAS E ROTINAS PARA A NAVEGAÇÃO PRINCIPAL Create_Tree(Xml.LocalFolder); // Ajuste final na árvore: Tree = Tree.Replace(@"},]", @"}]").Replace(@"],}", @"]}"); Tree = Tree.Substring(0, Tree.Length - 2); #endregion #region CRIANDO ARQUIVO NAVIGATION PRINCIPAL (MAIN.HTML) //Iniciando o project com o arquivo Main.Html htmlfile = htmlFolder + @"\main.html"; CreateHTMLFile(htmlfile, "Navigation.html"); Replace_TreeArea(htmlfile); Replace_NameArea(htmlfile, Xml.ProjectTitle); Replace_ButtonArea(Xml.LocalFolder, htmlfile); Replace_FileProtocolArea(htmlfile); Replace_SearchArea(htmlfile, true); Replace_BreadcrumbArea(htmlfile, htmlfile); Replace_Dictionary(htmlfile); Logging.WriteLog("main.html file created successfully. Generating the documentation."); #endregion #region CRIANDO ARQUIVOS CODE var tfsFolder = new DirectoryInfo(Xml.LocalFolder); var counter = tfsFolder.EnumerateFiles("*", SearchOption.AllDirectories).Count(d => Xml.Extensions.Contains(d.Extension.ToLower())); var current = 0; foreach (var codefile in tfsFolder.EnumerateFiles("*", SearchOption.AllDirectories) .Where(d => Xml.Extensions.Contains(d.Extension.ToLower()))) { current++; Logging.WriteLog(current + " of " + counter + " files processed.", true); var originalfilename = codefile.FullName; //var newdirectory = WebUtility.HtmlEncode(codefile.Directory.FullName); var newdirectory = HtmlFormatters.URLReplace(codefile.Directory.FullName); newdirectory = (newdirectory.Substring(newdirectory.Length - 1) == @"\") ? newdirectory : newdirectory + @"\"; newdirectory = htmlFolder + @"\" + HtmlFormatters.URLReplace(newdirectory.Replace(Xml.LocalFolder, "")); Directory.CreateDirectory(newdirectory); htmlfile = HtmlFormatters.URLReplace(codefile.Name) + ".html"; htmlfile = newdirectory + @"\" + htmlfile; byte[] result; System.Security.Cryptography.SHA1 sha = new System.Security.Cryptography.SHA1CryptoServiceProvider(); // This is one implementation of the abstract class SHA1. FileStream fs = File.OpenRead(originalfilename); result = sha.ComputeHash(fs); var SHA1 = ""; foreach (var line in result) { SHA1 += line.ToString(); } fs.Close(); if (!File.Exists(htmlfile) || FileHash.CompareHash(htmlfile, SHA1)) { CreateHTMLFile(htmlfile, "Code.html", SHA1); Replace_NameArea(htmlfile, Xml.ProjectTitle); Replace_FileNameArea(htmlfile, codefile.Name); Replace_FileProtocolArea(htmlfile); FileInfo f = new FileInfo(htmlfile); Replace_SearchArea(htmlfile, f.Directory.FullName.ToLower() != searchFolder, f.Directory.FullName); Replace_BreadcrumbArea(htmlfile, originalfilename); RegExDocumentation(htmlfile, codefile.FullName); RegExCode(htmlfile, codefile.FullName); Replace_History(htmlfile, codefile.FullName); Replace_Dictionary(htmlfile); } } #endregion return(lRet); }
private void Replace_ButtonArea(string HTMLFolder, string mainfile) { var currentFolder = new DirectoryInfo(HTMLFolder); var buttonList = ""; var buttonCollapseList = ""; var f = new FileInfo(mainfile); foreach (var directory in currentFolder.EnumerateDirectories("*", SearchOption.TopDirectoryOnly) .Where(d => Xml.Extensions.Contains(d.Extension.ToLower()))) { var identifier = directory.Name; identifier = HtmlFormatters.URLReplace(identifier); var buttonText = WebUtility.HtmlEncode(directory.Name); buttonList += " <button "+ "type='button' " + "class='btn btn-secondary btn-lg btn-custom-main' " + "data-toggle='collapse' " + "data-target='#" + identifier + "' " + "aria-expanded='false' " + "aria-controls='" + identifier + "'>" + buttonText + "</button>" + Environment.NewLine; #region Criando collapses para subpastas dentro do Button buttonCollapseList += " <div class='collapse' id='"+ identifier + "'>" + Environment.NewLine; buttonCollapseList += " <div class='card card-body'>"+ Environment.NewLine; buttonCollapseList += " <h3>Diretório "+ buttonText + "</h3>" + Environment.NewLine; buttonCollapseList += " <ul class='list-group'>"+ Environment.NewLine; var innerFolder = new DirectoryInfo(directory.FullName); foreach (var subdirectories in innerFolder.EnumerateDirectories("*.*", SearchOption.TopDirectoryOnly)) { var subText = WebUtility.HtmlEncode(subdirectories.Name); var href = directory.Name + @"\" + subdirectories.Name + @"\" + subdirectories.Name; href = HtmlFormatters.URLReplace(href) + ".html"; buttonCollapseList += " <li class='list-group-item'>" + "<a class='a-custom-main' " + "href='" + href + "'>" + "<i class='far fa-folder fa-custom'></i>" + subText + "</a></li>" + Environment.NewLine; } foreach (var subfiles in innerFolder.EnumerateFiles("*", SearchOption.TopDirectoryOnly).Where(d => Xml.Extensions.Contains(d.Extension.ToLower()))) { var subText = WebUtility.HtmlEncode(subfiles.Name); var href = directory.Name + @"\" + subfiles.Name; href = HtmlFormatters.URLReplace(href) + ".html"; buttonCollapseList += " <li class='list-group-item'>" + "<a class='a-custom-main' " + "href='" + href + "'>" + "<i class='far fa-file-code fa-custom'></i>" + subText + "</a></li>" + Environment.NewLine; } #endregion buttonCollapseList += " </ul>"+ Environment.NewLine; buttonCollapseList += " </div>"+ Environment.NewLine; buttonCollapseList += " </div>"+ Environment.NewLine; } #region loop em ARQUIVOS- Gera uma tag <a> para cada arquivo encontrado foreach (var codefile in currentFolder.EnumerateFiles("*", SearchOption.TopDirectoryOnly) .Where(d => Xml.Extensions.Contains(d.Extension.ToLower()))) { var href = codefile.Name; href = HtmlFormatters.URLReplace(href) + ".html"; var buttonText = WebUtility.HtmlEncode(codefile.Name); buttonList += " <a "+ "role='button' " + "class='btn btn-secondary btn-lg btn-custom-main' " + "href='" + href + "'>" + buttonText + "</a>" + Environment.NewLine; } #endregion File.WriteAllText(mainfile, File.ReadAllText(mainfile).Replace("&btnArea&", buttonList).Replace("&btnCollapseArea&", buttonCollapseList)); return; }