예제 #1
0
        public void SetFullPathName(string[] para)
        {
            string diskpath     = "";
            string message      = "";
            string relativefile = "";

            if (para[0].ToLower() == "articles")
            {
                diskpath             = CommonFun.GetConfigurationValue("GlobalArticleDir", ref message);
                relativefile         = GetRightFileName(para);
                this.Fullpath        = string.Format(@"{0}\{1}\{2}", diskpath, relativefile, this.File);
                this.ArticleCategory = FileCategory.Article;
            }

            if (para[0].ToLower() == "includes")
            {
                diskpath             = CommonFun.GetConfigurationValue("GlobalIncludeDir", ref message);
                relativefile         = GetRightFileName(para);
                this.Fullpath        = string.Format(@"{0}\{2}", diskpath, relativefile, this.File);
                this.ArticleCategory = FileCategory.Includes;
            }
        }
예제 #2
0
        public ArrayList GetAllFileByServiceWithCustomziedate(string customizedate)
        {
            ArrayList fileList   = new ArrayList();
            string    message    = string.Empty;
            string    diskpath   = string.Empty;
            string    parentpath = string.Empty;

            if (this.CheckFileList != null && this.CheckFileList.Count > 0)
            {
                this.CheckFileList = new ArrayList();
            }

            foreach (InvolvedService curtService in Enum.GetValues(typeof(InvolvedService)))
            {
                if (curtService.ToString().ToLower() == "articles".ToLower())
                {
                    //Did not collect the articles in the <repository-parth>/articles/ direction
                    break;
                }
                if (curtService.ToString().ToLower() == "includes".ToLower())
                {
                    diskpath   = CommonFun.GetConfigurationValue("GlobalIncludeDir", ref message);
                    parentpath = string.Format("{0}", diskpath);
                }
                else
                {
                    diskpath   = CommonFun.GetConfigurationValue("GlobalArticleDir", ref message);
                    parentpath = string.Format("{0}\\{1}", diskpath, curtService.ToString().Replace('_', '-'));
                }

                this.GetAllFilesInDirectoryWithCustomizedate(parentpath, customizedate);
            }

            fileList = this.CheckFileList;
            return(fileList);
        }
예제 #3
0
        public string FindParentOfIncludeFile()
        {
            string parentFile = string.Empty;
            //string parentFile = this.GetParentIncludeFileOfIncludeFile();

            string message     = string.Empty;
            string diskpath    = CommonFun.GetConfigurationValue("GlobalArticleDir", ref message);
            string parentpath  = string.Empty;
            string filecontent = string.Empty;
            string regRule     = "\\[\\!INCLUDE \\[([\\S|\\s]+)(\\.md)?\\]\\(((\\.\\.\\/)*)includes\\/{0}\\)\\]";
            //string regRule = "\\[\\!INCLUDE \\[(\\S+)(\\.md)?\\]\\(((\\.\\.\\/)*)includes\\/{0}\\)\\]";
            Regex reg;

            FileStream   fs;
            StreamReader sr;
            StreamWriter sw;
            bool         findFile = false;


            foreach (InvolvedService curtService in Enum.GetValues(typeof(InvolvedService)))
            {
                if (this.CheckFileList != null && this.CheckFileList.Count > 0)
                {
                    this.CheckFileList = new ArrayList();
                }

                findFile   = false;
                parentpath = string.Format("{0}\\{1}", diskpath, curtService.ToString().Replace('_', '-'));

                this.GetAllFilesInDirectory(parentpath);
                ArrayList fileList = this.CheckFileList;

                foreach (string curtFile in fileList)
                {
                    //Console.WriteLine(string.Format("Tread[{0}] checking {1}", this.Id, curtFile));
                    try
                    {
                        Mutex fileMutex = new Mutex(false, GetMetuxFileName(curtFile));
                        fileMutex.WaitOne();
                        fs = new FileStream(curtFile, FileMode.OpenOrCreate);

                        try
                        {
                            sr          = new StreamReader(fs);
                            filecontent = sr.ReadToEnd();
                            sr.Close();

                            reg = new Regex(string.Format(regRule, this.File.Replace(".", "\\.")));

                            if (reg.IsMatch(filecontent))
                            {
                                sw           = new StreamWriter(curtFile, false);
                                filecontent += string.Format("\n<!--The parent file of includes file of {0}-->", this.File);
                                filecontent += string.Format("\n<!--ms.date:{0}-->", this.CustomizedDate);
                                sw.Write(filecontent);
                                sw.Flush();
                                sw.Close();
                                parentFile = curtFile;
                                findFile   = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message.ToString());
                        }
                        finally
                        {
                            fileMutex.ReleaseMutex();
                            if (fs != null)
                            {
                                fs.Close();
                                fs = null;
                            }
                        }
                        if (findFile == true)
                        {
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }

                if (findFile == true)
                {
                    break;
                }
            }

            return(parentFile);
        }
예제 #4
0
        public string GetParentIncludeFileOfIncludeFile()
        {
            string parentInclude = string.Empty;
            string message       = string.Empty;
            string parentpath    = CommonFun.GetConfigurationValue("GlobalIncludeDir", ref message);

            string filecontent   = string.Empty;
            string regRule       = "\\[\\!INCLUDE \\[([\\S|\\s]+)(\\.md)?\\]\\(((\\.\\.\\/)*)includes\\/{0}\\)\\]";
            string curtCheckFile = string.Empty;

            Regex reg;

            FileStream   fs;
            StreamReader sr;
            StreamWriter sw;
            bool         findFile = false;

            if (this.CheckFileList != null && this.CheckFileList.Count > 0)
            {
                this.CheckFileList = new ArrayList();
            }


            this.GetAllFilesInDirectory(parentpath);
            ArrayList fileList = this.CheckFileList;

            int idx = 1;

            parentInclude = this.Fullpath;

            while (parentInclude != string.Empty)
            {
                foreach (string curtFile in fileList)
                {
                    //Console.WriteLine(string.Format("Tread[{0}] checking {1}", this.Id, curtFile));
                    try
                    {
                        curtCheckFile = curtFile;

                        Mutex fileMutex = new Mutex(false, GetMetuxFileName(curtCheckFile));
                        fileMutex.WaitOne();
                        fs = new FileStream(curtCheckFile, FileMode.OpenOrCreate);

                        try
                        {
                            sr          = new StreamReader(fs);
                            filecontent = sr.ReadToEnd();
                            sr.Close();

                            reg = new Regex(string.Format(regRule, Path.GetFileName(parentInclude).Replace(".", "\\.")));

                            if (reg.IsMatch(filecontent))
                            {
                                sw           = new StreamWriter(curtCheckFile, false);
                                filecontent += string.Format("\n<!--Not Available the {0} parent file {1} of includes file of {2}-->", idx, Path.GetFileName(curtCheckFile), Path.GetFileName(parentInclude));
                                filecontent += string.Format("\n<!--ms.date:{0}-->", this.CustomizedDate);
                                sw.Write(filecontent);
                                sw.Flush();
                                sw.Close();
                                parentInclude          = curtCheckFile;
                                this.ParentIncludeFile = Path.GetFileName(parentInclude);

                                findFile = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message.ToString());
                        }
                        finally
                        {
                            fileMutex.ReleaseMutex();
                            if (fs != null)
                            {
                                fs.Close();
                                fs = null;
                            }
                        }
                        if (findFile == true)
                        {
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }

                if (findFile == false)
                {
                    parentInclude = string.Empty;
                }
            }

            if (this.ParentIncludeFile == string.Empty)
            {
                parentInclude = this.File;
            }
            else
            {
                parentInclude = this.ParentIncludeFile;
            }

            return(parentInclude);
        }
예제 #5
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";
        }
예제 #6
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";
        }
예제 #7
0
        public void ProcessFileCustomize()
        {
            this.Status = ProcessStatus.Start;

            FileStream fs = null;

            StreamReader sr    = null;
            StreamWriter sw    = null;
            string       error = "";

            try
            {
                string sDirectoryName = this.Fullpath;
                sDirectoryName = sDirectoryName.Replace(this.File, "");

                if (!System.IO.Directory.Exists(sDirectoryName))
                {
                    System.IO.Directory.CreateDirectory(sDirectoryName);
                }

                fs = new FileStream(this.Fullpath, FileMode.OpenOrCreate);
                sr = new StreamReader(fs);
                string fullcontent = sr.ReadToEnd();

                sr.Close();

                ConvertCategory category = this.ProcessCategory;
                Console.WriteLine(string.Format("Processing Thread[{0}] : {1}", this.Id, this.Fullpath));

                this.ProcessConvertJson(ref fullcontent);

                sw = new StreamWriter(this.Fullpath, false);
                sw.Write(fullcontent);
                sw.Flush();
            }
            catch (Exception ex)
            {
                error = ex.Message.ToString();
                CommonFun.GenerateErrorDownloadFile(ref error);
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                }

                if (sw != null)
                {
                    sw.Close();
                }

                if (fs != null)
                {
                    fs.Close();
                }
            }

            this.Status = ProcessStatus.Complete;
            Console.WriteLine("Check Status of the Thread[{0}] : {1}", this.Id, this.Status.ToString());
        }