Exemplo n.º 1
0
        public void ProcessConvertJson(ref string articleContent)
        {
            this.Status = ProcessStatus.Process;

            string ruleJson = string.Empty;

            lock (ObjJason)
            {
                string ruleDir = AppDomain.CurrentDomain.BaseDirectory;
                ruleDir = Path.GetFullPath("../../ConvertJson/ConvertRule.json");
                FileStream   fsRule = new FileStream(ruleDir, FileMode.Open);
                StreamReader sr     = new StreamReader(fsRule);
                ruleJson = sr.ReadToEnd();
                sr.Close();
            }



            JObject JUrl = (JObject)JsonConvert.DeserializeObject(ruleJson);

            string urlGlobal     = string.Empty;
            string urlMooncake   = string.Empty;
            bool   bGlobal       = false;
            bool   bMooncake     = false;
            bool   bValidService = false;

            Regex reg = null;

            //AuthorReplacement Section
            int iCount = 0;

            ConvertCategory category = this.ProcessCategory;

            if (category == ConvertCategory.ALL || category == ConvertCategory.FindArticle)
            {
                //Empth code to find the articles in Source Tree.
                articleContent += "\n";
            }

#if DEBUG
            DateTime dStart    = DateTime.Now;
            DateTime dEnd      = DateTime.Now;
            string   sTakeTime = string.Empty;
#endif


            if (category == ConvertCategory.ALL || category == ConvertCategory.AuthorReplacement)
            {
                iCount = JUrl[ConvertCategory.AuthorReplacement.ToString()].Count();



                for (int i = 0; i < iCount; i++)
                {
                    bGlobal   = this.GetProcessConvertRule(ref JUrl, ConvertCategory.AuthorReplacement, i, ConvertItem.global, ref urlGlobal);
                    bMooncake = this.GetProcessConvertRule(ref JUrl, ConvertCategory.AuthorReplacement, i, ConvertItem.mooncake, ref urlMooncake);
                    if (bGlobal && bMooncake)
                    {
                        this.RepalceParameter(ref urlMooncake);
                        reg            = new Regex(urlGlobal, RegexOptions.Multiline);
                        articleContent = reg.Replace(articleContent, urlMooncake);
                    }

#if DEBUG
                    dEnd      = DateTime.Now;
                    sTakeTime = CommonFun.DateDiff(ref dEnd, ref dStart);
                    Console.WriteLine(string.Format("{0}{1} Regular Express {2} --> {3} takes\t{4}", ConvertCategory.AuthorReplacement.ToString(), i, urlGlobal, urlMooncake, sTakeTime));
#endif
                }
            }



            //URLReplacement Section
            if (category == ConvertCategory.ALL || category == ConvertCategory.URLReplacement)
            {
                iCount = JUrl[ConvertCategory.URLReplacement.ToString()].Count();

                for (int i = 0; i < iCount; i++)
                {
                    bGlobal   = this.GetProcessConvertRule(ref JUrl, ConvertCategory.URLReplacement, i, ConvertItem.global, ref urlGlobal);
                    bMooncake = this.GetProcessConvertRule(ref JUrl, ConvertCategory.URLReplacement, i, ConvertItem.mooncake, ref urlMooncake);

                    if (bGlobal && bMooncake)
                    {
                        reg            = new Regex(urlGlobal);
                        articleContent = reg.Replace(articleContent, urlMooncake);
                    }
#if DEBUG
                    dEnd      = DateTime.Now;
                    sTakeTime = CommonFun.DateDiff(ref dEnd, ref dStart);
                    Console.WriteLine(string.Format("{0}{1} Regular Express {2} --> {3} takes\t{4}", ConvertCategory.URLReplacement.ToString(), i, urlGlobal, urlMooncake, sTakeTime));
#endif
                }
            }


            //URLCorrection Section
            if (category == ConvertCategory.ALL || category == ConvertCategory.URLCorrection)
            {
                iCount = JUrl[ConvertCategory.URLCorrection.ToString()].Count();

                for (int i = 0; i < iCount; i++)
                {
                    bGlobal   = this.GetProcessConvertRule(ref JUrl, ConvertCategory.URLCorrection, i, ConvertItem.global, ref urlGlobal);
                    bMooncake = this.GetProcessConvertRule(ref JUrl, ConvertCategory.URLCorrection, i, ConvertItem.mooncake, ref urlMooncake);
                    //bValidService = this.GetProcessConvertRuleValidService(ref JUrl, ConvertCategory.URLReplacement, i, ConvertItem.validservice, this.Fullpath);
                    if (bGlobal && bMooncake)
                    {
                        reg            = new Regex(urlGlobal);
                        articleContent = reg.Replace(articleContent, urlMooncake);
                    }
#if DEBUG
                    dEnd      = DateTime.Now;
                    sTakeTime = CommonFun.DateDiff(ref dEnd, ref dStart);
                    Console.WriteLine(string.Format("{0}{1} Regular Express {2} --> {3} takes\t{4}", ConvertCategory.URLCorrection.ToString(), i, urlGlobal, urlMooncake, sTakeTime));
#endif
                }

                //For only md File

                string filePostfix = this.File.Trim().Substring(this.File.Trim().Length - 3).ToLower();

                if (filePostfix == ".md")
                {
                    iCount = JUrl[ConvertCategory.MDFileCorrection.ToString()].Count();

                    for (int i = 0; i < iCount; i++)
                    {
                        bGlobal   = this.GetProcessConvertRule(ref JUrl, ConvertCategory.MDFileCorrection, i, ConvertItem.global, ref urlGlobal);
                        bMooncake = this.GetProcessConvertRule(ref JUrl, ConvertCategory.MDFileCorrection, i, ConvertItem.mooncake, ref urlMooncake);
                        //bValidService = this.GetProcessConvertRuleValidService(ref JUrl, ConvertCategory.URLReplacement, i, ConvertItem.validservice, this.Fullpath);
                        if (bGlobal && bMooncake)
                        {
                            reg            = new Regex(urlGlobal);
                            articleContent = reg.Replace(articleContent, urlMooncake);
                        }
#if DEBUG
                        dEnd      = DateTime.Now;
                        sTakeTime = CommonFun.DateDiff(ref dEnd, ref dStart);
                        Console.WriteLine(string.Format("{0}{1} Regular Express {2} --> {3} takes\t{4}", ConvertCategory.MDFileCorrection.ToString(), i, urlGlobal, urlMooncake, sTakeTime));
#endif
                    }
                }

                if (filePostfix == "yml")
                {
                    //For only yml File
                    iCount = JUrl[ConvertCategory.YMLFileCorrection.ToString()].Count();

                    for (int i = 0; i < iCount; i++)
                    {
                        bGlobal   = this.GetProcessConvertRule(ref JUrl, ConvertCategory.YMLFileCorrection, i, ConvertItem.global, ref urlGlobal);
                        bMooncake = this.GetProcessConvertRule(ref JUrl, ConvertCategory.YMLFileCorrection, i, ConvertItem.mooncake, ref urlMooncake);
                        //bValidService = this.GetProcessConvertRuleValidService(ref JUrl, ConvertCategory.URLReplacement, i, ConvertItem.validservice, this.Fullpath);
                        if (bGlobal && bMooncake)
                        {
                            reg            = new Regex(urlGlobal);
                            articleContent = reg.Replace(articleContent, urlMooncake);
                        }
#if DEBUG
                        dEnd      = DateTime.Now;
                        sTakeTime = CommonFun.DateDiff(ref dEnd, ref dStart);
                        Console.WriteLine(string.Format("{0}{1} Regular Express {2} --> {3} takes\t{4}", ConvertCategory.YMLFileCorrection.ToString(), i, urlGlobal, urlMooncake, sTakeTime));
#endif
                    }
                }
            }

            //ToolReplacement Section
            if (category == ConvertCategory.ALL || category == ConvertCategory.ToolReplacement)
            {
                iCount = JUrl[ConvertCategory.ToolReplacement.ToString()].Count();

                for (int i = 0; i < iCount; i++)
                {
                    bGlobal   = this.GetProcessConvertRule(ref JUrl, ConvertCategory.ToolReplacement, i, ConvertItem.global, ref urlGlobal);
                    bMooncake = this.GetProcessConvertRule(ref JUrl, ConvertCategory.ToolReplacement, i, ConvertItem.mooncake, ref urlMooncake);
                    if (bGlobal && bMooncake)
                    {
                        reg            = new Regex(urlGlobal);
                        articleContent = reg.Replace(articleContent, urlMooncake);
                    }
#if DEBUG
                    dEnd      = DateTime.Now;
                    sTakeTime = CommonFun.DateDiff(ref dEnd, ref dStart);
                    Console.WriteLine(string.Format("{0}{1} Regular Express {2} --> {3} takes\t{4}", ConvertCategory.ToolReplacement.ToString(), i, urlGlobal, urlMooncake, sTakeTime));
#endif
                }
            }

            //Find Reference file of Include File
            if (category == ConvertCategory.ALL || category == ConvertCategory.IncludeParentFile)
            {
                if (this.ArticleCategory == FileCategory.Includes)
                {
                    if (this.CheckFileList == null && this.CheckFileList.Count > 0)
                    {
                        this.CheckFileList.Clear();
                    }
                    this.ParentFile = this.FindParentOfIncludeFile();
                }
            }

            //articleContent += "\n";
        }
Exemplo n.º 2
0
        public void ProcessConvertJson(ref string articleContent)
        {
            this.Status = ProcessStatus.Process;

            string ruleJson = string.Empty;

            lock (ObjJason)
            {
                string ruleDir = AppDomain.CurrentDomain.BaseDirectory;
                ruleDir = Path.GetFullPath("../../ConvertJson/ConvertRule.json");
                FileStream   fsRule = new FileStream(ruleDir, FileMode.Open);
                StreamReader sr     = new StreamReader(fsRule);
                ruleJson = sr.ReadToEnd();
                sr.Close();
            }



            JObject JUrl = (JObject)JsonConvert.DeserializeObject(ruleJson);

            string urlGlobal     = string.Empty;
            string urlMooncake   = string.Empty;
            bool   bGlobal       = false;
            bool   bMooncake     = false;
            bool   bValidService = false;

            Regex reg = null;

            //AuthorReplacement Section
            int iCount = 0;

            ConvertCategory category = this.ProcessCategory;

            if (category == ConvertCategory.ALL || category == ConvertCategory.FindArticle)
            {
                //Empth code to find the articles in Source Tree.
                articleContent += "\n";
            }

#if DEBUG
            DateTime dStart    = DateTime.Now;
            DateTime dEnd      = DateTime.Now;
            string   sTakeTime = string.Empty;
#endif

            string[] fileKey     = this.Fullpath.Split('\\');
            int      iCheckStart = 0;
            for (int i = 0; i <= fileKey.Length - 1; i++)
            {
                switch (fileKey[i].ToLower())
                {
                case "articles":
                case "includes":
                    iCheckStart = i;
                    break;
                }
            }


            if (category == ConvertCategory.ALL || category == ConvertCategory.AuthorReplacement)
            {
                iCount = JUrl[ConvertCategory.AuthorReplacement.ToString()].Count();

                for (int i = 0; i < iCount; i++)
                {
                    bValidService = this.GetProcessValidService(ref JUrl, ConvertCategory.AuthorReplacement, i, ConvertItem.service, fileKey, iCheckStart, this.File);
                    if (bValidService == false)
                    {
                        continue;
                    }

                    bGlobal   = this.GetProcessConvertRule(ref JUrl, ConvertCategory.AuthorReplacement, i, ConvertItem.global, ref urlGlobal);
                    bMooncake = this.GetProcessConvertRule(ref JUrl, ConvertCategory.AuthorReplacement, i, ConvertItem.mooncake, ref urlMooncake);
                    if (bGlobal && bMooncake)
                    {
                        this.RepalceParameter(ref urlMooncake);
                        reg            = new Regex(urlGlobal, RegexOptions.Multiline);
                        articleContent = reg.Replace(articleContent, urlMooncake);
                    }

#if DEBUG
                    dEnd      = DateTime.Now;
                    sTakeTime = CommonFun.DateDiff(ref dEnd, ref dStart);
                    Console.WriteLine(string.Format("{0}{1} Regular Express {2} --> {3} takes\t{4}", ConvertCategory.AuthorReplacement.ToString(), i, urlGlobal, urlMooncake, sTakeTime));
#endif
                }


                // Append Update_Description for all the articles
                // New files
                //
                string message = "";

                string gArticlediskpath = CommonFun.GetConfigurationValue("GlobalArticleDir", ref message);
                string cArticlediskpath = CommonFun.GetConfigurationValue("ChinaArticleDir", ref message);
                string gIncludediskpath = CommonFun.GetConfigurationValue("GlobalIncludeDir", ref message);
                string cIncludediskpath = CommonFun.GetConfigurationValue("ChinaIncludeDir", ref message);

                bool isExistFile = this.CheckCustomizedFileIsNewFile(gArticlediskpath, cArticlediskpath, gIncludediskpath, cIncludediskpath);

                if (isExistFile == false)
                {
                    string fileDescription = this.File.Replace("-", " ");
                    fileDescription = fileDescription.Substring(0, fileDescription.Length - 3);

                    articleContent += "\n\n";
                    articleContent += string.Format("<!-- Update_Description: new article about {0} -->", fileDescription);
                    articleContent += "\n";
                    articleContent += string.Format("<!--NEW.date: {0}-->", this.CustomizedDate);
                }
                else
                {
                    articleContent += "\n\n";
                    articleContent += string.Format("<!-- Update_Description: update meta properties, wording update, update link -->");
                }
            }



            //URLReplacement Section
            if (category == ConvertCategory.ALL || category == ConvertCategory.URLReplacement)
            {
                iCount = JUrl[ConvertCategory.URLReplacement.ToString()].Count();

                for (int i = 0; i < iCount; i++)
                {
                    bValidService = this.GetProcessValidService(ref JUrl, ConvertCategory.URLReplacement, i, ConvertItem.service, fileKey, iCheckStart, this.File);
                    if (bValidService == false)
                    {
                        continue;
                    }

                    bGlobal   = this.GetProcessConvertRule(ref JUrl, ConvertCategory.URLReplacement, i, ConvertItem.global, ref urlGlobal);
                    bMooncake = this.GetProcessConvertRule(ref JUrl, ConvertCategory.URLReplacement, i, ConvertItem.mooncake, ref urlMooncake);

                    if (bGlobal && bMooncake)
                    {
                        reg            = new Regex(urlGlobal);
                        articleContent = reg.Replace(articleContent, urlMooncake);
                    }
#if DEBUG
                    dEnd      = DateTime.Now;
                    sTakeTime = CommonFun.DateDiff(ref dEnd, ref dStart);
                    Console.WriteLine(string.Format("{0}{1} Regular Express {2} --> {3} takes\t{4}", ConvertCategory.URLReplacement.ToString(), i, urlGlobal, urlMooncake, sTakeTime));
#endif
                }
            }


            //URLCorrection Section
            if (category == ConvertCategory.ALL || category == ConvertCategory.URLCorrection)
            {
                iCount = JUrl[ConvertCategory.URLCorrection.ToString()].Count();

                for (int i = 0; i < iCount; i++)
                {
                    bValidService = this.GetProcessValidService(ref JUrl, ConvertCategory.URLCorrection, i, ConvertItem.service, fileKey, iCheckStart, this.File);
                    if (bValidService == false)
                    {
                        continue;
                    }

                    bGlobal   = this.GetProcessConvertRule(ref JUrl, ConvertCategory.URLCorrection, i, ConvertItem.global, ref urlGlobal);
                    bMooncake = this.GetProcessConvertRule(ref JUrl, ConvertCategory.URLCorrection, i, ConvertItem.mooncake, ref urlMooncake);
                    //bValidService = this.GetProcessConvertRuleValidService(ref JUrl, ConvertCategory.URLReplacement, i, ConvertItem.validservice, this.Fullpath);
                    if (bGlobal && bMooncake)
                    {
                        reg            = new Regex(urlGlobal);
                        articleContent = reg.Replace(articleContent, urlMooncake);
                    }
#if DEBUG
                    dEnd      = DateTime.Now;
                    sTakeTime = CommonFun.DateDiff(ref dEnd, ref dStart);
                    Console.WriteLine(string.Format("{0}{1} Regular Express {2} --> {3} takes\t{4}", ConvertCategory.URLCorrection.ToString(), i, urlGlobal, urlMooncake, sTakeTime));
#endif
                }

                //For only md File

                string filePostfix = this.File.Trim().Substring(this.File.Trim().Length - 3).ToLower();

                if (filePostfix == ".md")
                {
                    iCount = JUrl[ConvertCategory.MDFileCorrection.ToString()].Count();

                    for (int i = 0; i < iCount; i++)
                    {
                        bValidService = this.GetProcessValidService(ref JUrl, ConvertCategory.MDFileCorrection, i, ConvertItem.service, fileKey, iCheckStart, this.File);
                        if (bValidService == false)
                        {
                            continue;
                        }

                        bGlobal   = this.GetProcessConvertRule(ref JUrl, ConvertCategory.MDFileCorrection, i, ConvertItem.global, ref urlGlobal);
                        bMooncake = this.GetProcessConvertRule(ref JUrl, ConvertCategory.MDFileCorrection, i, ConvertItem.mooncake, ref urlMooncake);
                        //bValidService = this.GetProcessConvertRuleValidService(ref JUrl, ConvertCategory.URLReplacement, i, ConvertItem.validservice, this.Fullpath);
                        if (bGlobal && bMooncake)
                        {
                            reg            = new Regex(urlGlobal);
                            articleContent = reg.Replace(articleContent, urlMooncake);
                        }
#if DEBUG
                        dEnd      = DateTime.Now;
                        sTakeTime = CommonFun.DateDiff(ref dEnd, ref dStart);
                        Console.WriteLine(string.Format("{0}{1} Regular Express {2} --> {3} takes\t{4}", ConvertCategory.MDFileCorrection.ToString(), i, urlGlobal, urlMooncake, sTakeTime));
#endif
                    }
                }

                if (filePostfix == "yml")
                {
                    //For only yml File
                    iCount = JUrl[ConvertCategory.YMLFileCorrection.ToString()].Count();

                    for (int i = 0; i < iCount; i++)
                    {
                        bValidService = this.GetProcessValidService(ref JUrl, ConvertCategory.YMLFileCorrection, i, ConvertItem.service, fileKey, iCheckStart, this.File);
                        if (bValidService == false)
                        {
                            continue;
                        }

                        bGlobal   = this.GetProcessConvertRule(ref JUrl, ConvertCategory.YMLFileCorrection, i, ConvertItem.global, ref urlGlobal);
                        bMooncake = this.GetProcessConvertRule(ref JUrl, ConvertCategory.YMLFileCorrection, i, ConvertItem.mooncake, ref urlMooncake);
                        //bValidService = this.GetProcessConvertRuleValidService(ref JUrl, ConvertCategory.URLReplacement, i, ConvertItem.validservice, this.Fullpath);
                        if (bGlobal && bMooncake)
                        {
                            reg            = new Regex(urlGlobal);
                            articleContent = reg.Replace(articleContent, urlMooncake);
                        }
#if DEBUG
                        dEnd      = DateTime.Now;
                        sTakeTime = CommonFun.DateDiff(ref dEnd, ref dStart);
                        Console.WriteLine(string.Format("{0}{1} Regular Express {2} --> {3} takes\t{4}", ConvertCategory.YMLFileCorrection.ToString(), i, urlGlobal, urlMooncake, sTakeTime));
#endif
                    }
                }
            }

            //ToolReplacement Section
            if (category == ConvertCategory.ALL || category == ConvertCategory.ToolReplacement)
            {
                iCount = JUrl[ConvertCategory.ToolReplacement.ToString()].Count();

                for (int i = 0; i < iCount; i++)
                {
                    bValidService = this.GetProcessValidService(ref JUrl, ConvertCategory.ToolReplacement, i, ConvertItem.service, fileKey, iCheckStart, this.File);
                    if (bValidService == false)
                    {
                        continue;
                    }

                    bGlobal   = this.GetProcessConvertRule(ref JUrl, ConvertCategory.ToolReplacement, i, ConvertItem.global, ref urlGlobal);
                    bMooncake = this.GetProcessConvertRule(ref JUrl, ConvertCategory.ToolReplacement, i, ConvertItem.mooncake, ref urlMooncake);

                    if (bGlobal && bMooncake)
                    {
#if DEBUG
                        this.PrintMatchCollection(ref articleContent, ref urlGlobal, ref urlMooncake);
#endif
                        reg            = new Regex(urlGlobal);
                        articleContent = reg.Replace(articleContent, urlMooncake);
                    }
#if DEBUG
                    dEnd      = DateTime.Now;
                    sTakeTime = CommonFun.DateDiff(ref dEnd, ref dStart);
                    Console.WriteLine(string.Format("{0}{1} Regular Express {2} --> {3} takes\t{4}", ConvertCategory.ToolReplacement.ToString(), i, urlGlobal, urlMooncake, sTakeTime));
#endif
                }
            }

            //Find Reference file of Include File
            if (category == ConvertCategory.ALL || category == ConvertCategory.IncludeParentFile)
            {
                if (this.ArticleCategory == FileCategory.Includes)
                {
                    if (this.CheckFileList == null && this.CheckFileList.Count > 0)
                    {
                        this.CheckFileList.Clear();
                    }
                    this.ParentFile = this.FindParentOfIncludeFile();
                }
            }

            //articleContent += "\n";
        }