Exemple #1
0
        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));
        }
Exemple #2
0
        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));
        }
Exemple #3
0
        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));
        }
Exemple #4
0
        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 += "},";
        }
Exemple #5
0
        private void RegExCode(string htmlfile, string codefile)
        {
            var fullcode = HtmlFormatters.StringReplace(File.ReadAllText(codefile, Encoding.GetEncoding("Windows-1252")));
            var newCode  = "";

            var lines = fullcode.Split(new string[] { "\n" },
                                       StringSplitOptions.None);
            var linecounter = 0;

            foreach (var line in lines)
            {
                newCode += "<tr><td class='codebox linenumber' id='" + (linecounter + 1) + "'>" + (linecounter + 1) +
                           "</td><td><pre>" + lines[linecounter] + "</pre></td></tr>";
                linecounter++;
            }
            File.WriteAllText(htmlfile, File.ReadAllText(htmlfile).Replace("&CodeBoxArea&", newCode));
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        private void RegExDocumentation(string htmlfile, string codefile)
        {
            //
            string CommentBlock = "";

            List <string>   exampleslist = new List <string>();
            List <string>   obslist      = new List <string>();
            List <string>   todolist     = new List <string>();
            List <string[]> param        = new List <string[]>();
            List <string[]> returnvar    = new List <string[]>();
            //
            var search       = "";
            var fullcode     = HtmlFormatters.StringReplace(File.ReadAllText(codefile, Encoding.GetEncoding("Windows-1252")));
            var regexPattern = "";

            CodeErrorList = "";

            #region COMMENT BLOCK [commentblock] SECTION
            regexPattern = Xml.Regex("commentblock");
            Regex regex = new Regex(regexPattern, RegexOptions.Singleline | RegexOptions.IgnoreCase);
            search = fullcode;
            Match match = regex.Match(search);

            if (match.Success)
            {
                CommentBlock = match.Value;

                #region COMMENT BLOCK - GETS THE [examples] ARRAY
                regexPattern = Xml.Regex("examples");
                regex        = new Regex(regexPattern, RegexOptions.IgnoreCase);
                search       = CommentBlock;
                foreach (Match m in regex.Matches(search))
                {
                    var currexample = RemoveRegexItemText(Xml.Regex("examples"), m.Value);
                    exampleslist.Add(currexample);
                }
                #endregion

                #region COMMENT BLOCK - GETS THE [obs] ARRAY
                regexPattern = Xml.Regex("observations");
                regex        = new Regex(regexPattern, RegexOptions.IgnoreCase);
                search       = CommentBlock;
                foreach (Match m in regex.Matches(search))
                {
                    var currobs = RemoveRegexItemText(Xml.Regex("observations"), m.Value);
                    obslist.Add(currobs);
                }
                #endregion

                #region COMMENT BLOCK - GETS THE [param] ARRAY
                regexPattern = Xml.Regex("param");
                regex        = new Regex(regexPattern, RegexOptions.IgnoreCase);

                if (regex.Matches(CommentBlock).Count > 0)
                {
                    foreach (Match m in regex.Matches(search))
                    {
                        var currparam       = RemoveRegexItemText(Xml.Regex("param"), m.Value);
                        var currregex       = new Regex(@".*?,", RegexOptions.IgnoreCase);
                        var matchcollection = currregex.Matches(currparam);
                        if (matchcollection.Count > 0)
                        {
                            if (matchcollection.Count > 1)
                            {
                                var str = new string[3];
                                currparam = currparam.Replace(matchcollection[0].Value, "");
                                currparam = currparam.Replace(matchcollection[1].Value, "");
                                str[0]    = matchcollection[0].Value.Replace(",", "").Replace(" ", "");
                                str[1]    = matchcollection[1].Value.Replace(",", "").Replace(" ", "").ToLower();
                                str[2]    = currparam; // Descrição = resto do @param que não foi validado pelo RegEx
                                param.Add(str);
                            }
                        }
                        else
                        {
                            var errormsg = "";
                            errormsg = "&Dic:err_param&";

                            FeedError("danger", errormsg);
                        }
                    }
                }
                else // No [param] was identified in the CommentBlock
                {
                    var errormsg = "";
                    errormsg = "&Dic:err_paramnotfound&";

                    FeedError("info", errormsg);
                }

                #endregion

                #region COMMENT BLOCK - GETS THE [todo] ARRAY
                regexPattern = Xml.Regex("todo");
                regex        = new Regex(regexPattern, RegexOptions.IgnoreCase);
                search       = CommentBlock;
                foreach (Match m in regex.Matches(search))
                {
                    var currtodo = RemoveRegexItemText(Xml.Regex("todo"), m.Value); // removendo texto @Todo e espaços
                    todolist.Add((todolist.Count + 1) + ") " + currtodo);
                }
                #endregion

                #region COMMENT BLOCK - GETS THE [return]
                regexPattern = Xml.Regex("return");
                regex        = new Regex(regexPattern, RegexOptions.IgnoreCase);
                search       = CommentBlock;
                if (regex.Matches(search).Count > 0)
                {
                    foreach (Match m in regex.Matches(search))
                    {
                        var currreturn      = RemoveRegexItemText(Xml.Regex("return"), m.Value); // removendo texto @return e espaços
                        var currregex       = new Regex(@"[^,]+.*?(?=,)", RegexOptions.IgnoreCase);
                        var matchcollection = currregex.Matches(currreturn);
                        if (matchcollection.Count > 0)
                        {
                            var str = new string[3];
                            currreturn = currreturn.Replace(matchcollection[0].Value, "");
                            currreturn = (matchcollection.Count > 2) ? currreturn.Replace(matchcollection[1].Value, "") : currreturn.Replace(",", "");
                            str[0]     = matchcollection[0].Value;
                            str[1]     = (matchcollection.Count > 2) ? matchcollection[1].Value : "";
                            str[2]     = currreturn; // Descrição = resto do @return que não foi validado pelo RegEx
                            returnvar.Add(str);
                        }
                        else
                        {
                            var errormsg = "";
                            errormsg = "&Dic:err_return&";

                            FeedError("danger", errormsg);
                        }
                    }
                }
                else // Nenhum @return foi identificado no Protheus.Doc
                {
                    var errormsg = "";
                    errormsg = "&Dic:err_returnnotfound&";

                    FeedError("info", errormsg);
                }
                #endregion
            }
            else
            {
                var errormsg = "";
                errormsg = "&Dic:err_commentblock&";
                FeedError("danger", errormsg);
            }

            // Após analisar todas as variáveis, substitui o arquivo HTML:
            SetExamples(htmlfile, exampleslist);
            SetObservations(htmlfile, obslist);
            SetParam(htmlfile, param);
            SetReturn(htmlfile, returnvar);
            SetToDo(htmlfile, todolist);
            #endregion
            PrepareErrorList(htmlfile);
            Replace_ErrorArea(htmlfile);
            Replace_ErrorBadgeArea(htmlfile);
        }
Exemple #8
0
        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;
        }