Example #1
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));
        }
Example #2
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);
        }