コード例 #1
0
        public override void ProcessFileCustomize()
        {
            this.Status = ProcessStatus.Start;
            string error = string.Empty;

            try
            {
                ConvertCategory category = this.ProcessCategory;
                Console.WriteLine(string.Format("Processing Thread[{0}] : {1}", this.Id, this.FullPath));
                string globalContent   = this.GlobalContent;
                string mooncakeContent = this.MooncakeContent;

                this.ProcessConvertJson(ref globalContent, ref mooncakeContent);
            }
            catch (Exception ex)
            {
                error = ex.Message.ToString();
            }
            finally
            {
            }

            this.Status = ProcessStatus.Complete;
            Console.WriteLine("Check Status of the Thread[{0}] : {1}", this.Id, this.Status.ToString());
        }
コード例 #2
0
ファイル: FileCustomize.cs プロジェクト: lingliw/Production
        public bool GetProcessConvertRuleValidService(ref JObject JConvert, ConvertCategory category, int iIndex, ConvertItem key, string filePath)
        {
            bool   bProcess  = false;
            string valReturn = string.Empty;

            string[] validKey = null;

            try
            {
                valReturn = JConvert[category.ToString()][iIndex][key.ToString()].ToString();
                validKey  = valReturn.Split(':');
                foreach (string curtVal in validKey)
                {
                    if (filePath.Contains(curtVal) == true)
                    {
                        bProcess = true;
                        break;
                    }
                }
                bProcess = false;
            }
            catch (Exception ex)
            {
                bProcess = true;
            }

            return(bProcess);
        }
コード例 #3
0
ファイル: FileCustomize.cs プロジェクト: lingliw/Production
        public FileCustomize(int id, string filename, string directory, string customizedate, ConvertCategory category)
        {
            this.Id   = id;
            this.File = filename;
            string[] para = directory.Split('/');

            this.SetFullPathName(para);
            this.CustomizedDate  = customizedate;
            this.ProcessCategory = category;

            this.CheckFileList = new ArrayList();
        }
コード例 #4
0
        public virtual 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;
            Regex  reg         = null;

            //AuthorReplacement Section
            int iCount = 0;

            ConvertCategory category = this.ProcessCategory;



            //CLIReplacment Section
            if (category == ConvertCategory.CLIReplacement)
            {
                iCount = JUrl[ConvertCategory.CLIReplacement.ToString()].Count();

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


            //articleContent += "\n";
        }
コード例 #5
0
ファイル: FileCustomize.cs プロジェクト: lingliw/Production
        public void ProcessFileCustomize()
        {
            this.Status = ProcessStatus.Start;

            FileStream fs = new FileStream(this.Fullpath, FileMode.OpenOrCreate);

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

            try
            {
                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());
        }
コード例 #6
0
        public FileCustomize(int id, string filename, string customizedate, ConvertCategory category, ConvertProcess process)
        {
            this.Id   = id;
            this.File = filename;
            string[] para = directory.Split('/');

            this.SetFullPathName(para);
            this.CustomizedDate  = customizedate;
            this.ProcessCategory = category;
            this.WarningMessage  = string.Empty;

            this.ShowHistory = process;
            //this.ForceTerminate = false;
            this.CheckRound    = 0;
            this.CheckFileList = new ArrayList();
            //this.CancelToke = cancelToke;
        }
コード例 #7
0
        public void ProcessFileCustomize()
        {
            this.Status = ProcessStatus.Start;

            string fullContent = string.Empty;

            bool needLog = true;

            string error = "";

            // If we involve the ReplaceLink function. It will cause the images file missing.
            // images function will reference the include file check itself.
            //this.ReplaceIncludeLinkWithContent(this.FullPath, ref fullContent);
            string globalprefix = CommonFun.GetConfigurationValue("GlobalRepository", ref error);


            string mooncakeprefix = CommonFun.GetConfigurationValue("MooncakeImageRepository", ref error);


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

                this.CountOriginAndModifyImageCount(this.ImagePath, globalprefix, mooncakeprefix);


                //Check Broken Link No need to modified the content.
                //sw = new StreamWriter(this.Fullpath,false);
                //sw.Write(fullcontent);
                //sw.Flush();
            }
            catch (Exception ex)
            {
                this.BrokenLink += string.Format("Error : {0}\n", ex.Message.ToString());
                Console.WriteLine(string.Format("Thread[{0}]({1}) occure error with {2}. ", this.Id, this.FullPath, ex.Message.ToString()));
            }
            finally
            {
            }

            this.Status = ProcessStatus.Complete;
            Console.WriteLine("The Thread[{0}] run successfully : {1}", this.Id, this.Status.ToString());
        }
コード例 #8
0
ファイル: CommonFun.cs プロジェクト: lingliw/Production
        public static void GenerateDownloadFile(ConvertCategory category, ref StringBuilder sbText)
        {
            FileStream fs = null;

            try
            {
                string downloadPath = AppDomain.CurrentDomain.BaseDirectory;

                string curtTime = string.Format(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Replace(":", "-");

                string sFilePath = string.Format("{0}\\{1}-{2}.txt", downloadPath, category.ToString(), curtTime);


                if (!File.Exists(sFilePath))
                {
                    fs = new FileStream(sFilePath, FileMode.CreateNew);
                }
                else
                {
                    fs = new FileStream(sFilePath, FileMode.Append);
                }

                using (StreamWriter sw = new StreamWriter(fs))
                {
                    sw.WriteLine(sbText.ToString());
                    sw.Flush();
                    sw.Close();
                }

                Console.WriteLine("The file {0} genereare successfully!", sFilePath);
            }
            catch
            {
            }
            finally
            {
                if (fs != null)
                {
                    fs.Dispose();
                }
            }
        }
コード例 #9
0
ファイル: FileCustomize.cs プロジェクト: lingliw/Production
        public void ProcessFileCustomize()
        {
            this.Status = ProcessStatus.Start;

            string fullContent = string.Empty;

            bool needLog = true;

            fullContent = this.ReadArticleContent(this.FullPath, needLog);

            // If we involve the ReplaceLink function. It will cause the images file missing.
            // images function will reference the include file check itself.
            //this.ReplaceIncludeLinkWithContent(this.FullPath, ref fullContent);

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

                this.ProcessConvertJson(ref fullContent);

                //Check Broken Link No need to modified the content.
                //sw = new StreamWriter(this.Fullpath,false);
                //sw.Write(fullcontent);
                //sw.Flush();
            }
            catch (Exception ex)
            {
                this.BrokenLink += string.Format("Error : {0}\n", ex.Message.ToString());
                Console.WriteLine(string.Format("Thread[{0}]({1}) occure error with {2}. ", this.Id, this.FullPath, ex.Message.ToString()));
            }
            finally
            {
            }

            this.Status = ProcessStatus.Complete;
            Console.WriteLine("The Thread[{0}] run successfully : {1}", this.Id, this.Status.ToString());
        }
コード例 #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            int             iCount   = args.Count();
            ConvertCategory category = ConvertCategory.ALL;

            if (iCount > 1)
            {
                ShowUseageTip();
                return;
            }
            else if (iCount == 1)
            {
                string sParam      = args[0].TrimStart('-').ToUpper();
                int    iParamCount = sParam.Trim().Length;


                if (iParamCount == 1)
                {
                    switch (sParam)
                    {
                    case "A":
                        category = ConvertCategory.AuthorReplacement;
                        break;

                    case "U":
                        category = ConvertCategory.URLReplacement;
                        break;

                    case "C":
                        category = ConvertCategory.URLCorrection;
                        break;

                    case "F":
                        category = ConvertCategory.FindArticle;
                        break;

                    case "I":
                        category = ConvertCategory.IncludeParentFile;
                        break;

                    case "T":
                        category = ConvertCategory.ToolReplacement;
                        break;

                    case "H":
                    default:
                        ShowUseageTip();
                        return;
                    }
                }
                else
                {
                    switch (sParam)
                    {
                    case "HELP":
                        ShowUseageTip();
                        return;

                    default:
                        Console.WriteLine("You type the wrong command:");
                        ShowUseageTip();
                        return;
                    }
                }
            }


            string error      = "";
            string configfile = CommonFun.GetConfigurationValue("customerfilepath", ref error);

            if (error.Length > 0)
            {
                return;
            }

            StreamReader sr  = File.OpenText(configfile);
            string       row = "";

            row = sr.ReadLine();

            string filename      = "";
            string directory     = "";
            string customizedate = "";

            List <FileCustomize> fileList = new List <FileCustomize>();

            //Get the thread count
            int threadCount = 0;

            while (row != null)
            {
                string[] para = row.Split(new Char[] { '\t' });

                filename      = para[0];
                directory     = para[1];
                customizedate = para[2];

                //fileList.Add(new FileCustomize(filename, directory, customizedate));
                threadCount += 1;
                row          = sr.ReadLine();
            }

            ThreadPool.SetMinThreads(1000, 1000);

            // Declare the application thread.
            Thread[] newThreads = new Thread[threadCount];
            sr.BaseStream.Seek(0, SeekOrigin.Begin);

            int threadIdx = 0;

            row = sr.ReadLine();
            while (row != null)
            {
                string[] para = row.Split(new Char[] { '\t' });

                filename      = para[0];
                directory     = para[1];
                customizedate = para[2];
                FileCustomize curtFile = new FileCustomize(threadIdx, filename, directory, customizedate, category);
                fileList.Add(curtFile);
                newThreads[threadIdx]      = new Thread(new ThreadStart(curtFile.ProcessFileCustomize));
                newThreads[threadIdx].Name = string.Format("{0}/{1}", directory, filename);
                newThreads[threadIdx].Start();
                Console.WriteLine(string.Format("Start the Thread[{0}] in application...", threadIdx));


                // Console.WriteLine(string.Format("Join the {0} thread in application", threadIdx));
#if DEBUG
                newThreads[threadIdx].Join();
#endif


                row        = sr.ReadLine();
                threadIdx += 1;
            }

            sr.Close();

            bool allThreadOver = false;
            while (allThreadOver == false)
            {
                Thread.Sleep(20000);
                allThreadOver = true;
                for (int i = 0; i < threadCount; i++)
                {
                    if (newThreads[i].ThreadState != ThreadState.Stopped)
                    {
                        allThreadOver = false;
                        Console.WriteLine(string.Format("Checking status of the Thread[{0}] \t : \t {1} -> \t {2}", i, newThreads[i].ThreadState.ToString(), newThreads[i].Name.ToString()));
                        break;
                    }
                }
            }


            if (category == ConvertCategory.ALL || category == ConvertCategory.IncludeParentFile)
            {
                //Display the Parent of Include file in Console.
                string sPath       = string.Empty;
                string sFileName   = string.Empty;
                int    idxLastDash = 0;

                foreach (FileCustomize curtFile in fileList)
                {
                    if (curtFile.ArticleCategory == FileCategory.Includes)
                    {
                        idxLastDash = curtFile.ParentFile.LastIndexOf(@"\");
                        if (idxLastDash >= 0)
                        {
                            sPath     = curtFile.ParentFile.Substring(0, idxLastDash);
                            sFileName = curtFile.ParentFile.Substring(idxLastDash + 1);
                        }
                        else
                        {
                            sPath     = "";
                            sFileName = "";
                        }

                        Console.WriteLine(string.Format("The parent file of\t{0}\tis\t{1}\t{2}\t.", curtFile.File, sPath, sFileName));
                    }
                }


                //Save the download file for the parent of Include file in text file.
                StringBuilder sbText = new StringBuilder();

                Console.WriteLine();
                sbText.AppendLine(String.Format("**********************Check Process Result({0})**********************", ConvertCategory.IncludeParentFile.ToString()));
                //Console.WriteLine(String.Format("**********************Check Process Result({0})**********************", category.ToString()));

                foreach (FileCustomize curtFile in fileList)
                {
                    if (curtFile.ArticleCategory == FileCategory.Includes)
                    {
                        //if (!string.IsNullOrEmpty(curtFile.ParentFile))
                        //{
                        idxLastDash = curtFile.ParentFile.LastIndexOf(@"\");
                        if (idxLastDash >= 0)
                        {
                            sPath     = curtFile.ParentFile.Substring(0, idxLastDash);
                            sFileName = curtFile.ParentFile.Substring(idxLastDash + 1);
                        }
                        else
                        {
                            sPath     = "";
                            sFileName = "";
                        }
                        sbText.AppendLine(string.Format("The parent file of\t{0}\tis\t{1}\t{2}\t.", curtFile.File, sPath, sFileName));
                        //}
                    }
                }

                CommonFun.GenerateDownloadFile(category, ref sbText);
            }

            //Thread.Sleep(5000);
            Console.WriteLine("Program run finished, Press <Enter> to exit....");

            ExitWithUserConfirm();
        }
コード例 #11
0
ファイル: FileCustomize.cs プロジェクト: lingliw/Production
        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";
        }
コード例 #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //Check the Redirect URL Category
            int             iCount   = args.Count();
            ConvertCategory category = ConvertCategory.redirections;

            if (iCount > 1)
            {
                ShowUseageTip();
                return;
            }
            else if (iCount == 1)
            {
                string curtArg = args[0].ToUpper().Trim();
                switch (args[0].TrimStart('-'))
                {
                case "RDR":
                    category = ConvertCategory.redirections;
                    break;

                default:
                    ShowUseageTip();
                    return;
                }
            }

            //Get the following config file , redirect file(both global and mooncake repository)
            bool   errFlag    = false;
            string error      = "";
            string configfile = CommonFun.GetConfigurationValue("customerfilepath", ref error);

            if (error.Length > 0)
            {
                return;
            }

            string fileGlobal = CommonFun.GetConfigurationValue("GlobalRedirectFile", ref error);

            if (error.Length > 0)
            {
                return;
            }

            string fileMooncake = CommonFun.GetConfigurationValue("MooncakeRedirectFile", ref error);

            if (error.Length > 0)
            {
                return;
            }

            string mooncakeSite = CommonFun.GetConfigurationValue("MooncakeSite", ref error);

            if (error.Length > 0)
            {
                return;
            }


            ////Get the redirect file content(both global and mooncake repository)
            string fileGlobalContent   = string.Empty;
            string fileMooncakeContent = string.Empty;

            errFlag = CommonFun.GetFileContent(fileGlobal, ref fileGlobalContent) && CommonFun.GetFileContent(fileMooncake, ref fileMooncakeContent);
            if (errFlag == false)
            {
                return;
            }

            List <CollectRedirectFileByArticle> fileList = new List <CollectRedirectFileByArticle>();

            //Get the thread count
            int threadCount = 0;

            errFlag = CommonFun.GetConfigFileRowCount(configfile, ref threadCount);

            if (errFlag == false)
            {
                return;
            }

            Thread[] newThreads = new Thread[threadCount];

            StreamReader sr  = File.OpenText(configfile);
            string       row = "";


            string filename      = "";
            string directory     = "";
            string customizedate = "";

            //sr.BaseStream.Seek(0, SeekOrigin.Begin);

            int threadIdx = 0;

            row = sr.ReadLine();
            while (row != null)
            {
                string[] para = row.Split(new Char[] { '\t' });

                filename      = para[0];
                directory     = para[1];
                customizedate = para[2];
                CollectRedirectFileByArticle curtFile = new CollectRedirectFileByArticle(threadIdx, filename, directory, customizedate, category, mooncakeSite, fileGlobalContent, fileMooncakeContent);
                fileList.Add(curtFile);
                newThreads[threadIdx] = new Thread(new ThreadStart(curtFile.ProcessFileCustomize));
                newThreads[threadIdx].Start();
                Console.WriteLine(string.Format("Start the Thread[{0}] in application", threadIdx));
                //newThreads[threadIdx].Join();
                // Console.WriteLine(string.Format("Join the {0} thread in application", threadIdx));
                row        = sr.ReadLine();
                threadIdx += 1;
            }

            sr.Close();


            bool allThreadOver = false;

            while (allThreadOver == false)
            {
                Thread.Sleep(10000);
                allThreadOver = true;
                for (int i = 0; i < threadCount; i++)
                {
                    if (newThreads[i].ThreadState != ThreadState.Stopped)
                    {
                        allThreadOver = false;
                        Console.WriteLine(string.Format("Checking status of the Thread[{0}] : {1} ", i, newThreads[i].ThreadState.ToString()));
                        break;
                    }
                }
            }

            if (category == ConvertCategory.ALL || category == ConvertCategory.redirections)
            {
                foreach (CollectRedirectFileByArticle curtFile in fileList)
                {
                    Console.WriteLine("------------------------");
                    Console.WriteLine(curtFile.RelativeFile);
                    Console.WriteLine("Global Redirections");
                    Console.Write(curtFile.RedirectGContent);
                    Console.WriteLine("Mooncake Redirections");
                    Console.Write(curtFile.RedirectMContent);
                }

                Console.WriteLine("************Result Start for Json**************");
                foreach (CollectRedirectFileByArticle curtFile in fileList)
                {
                    if (curtFile.RedirectGContent.Length > 0 && curtFile.RedirectMContent.Length == 0)
                    {
                        Console.Write(curtFile.RedirectGContent);
                    }
                }
                Console.WriteLine("************Result End for Json**************");

                Console.WriteLine("************Result Start for Excel**************");
                foreach (CollectRedirectFileByArticle curtFile in fileList)
                {
                    if (curtFile.RedirectGContent.Length > 0 && curtFile.RedirectMContent.Length == 0)
                    {
                        Console.Write(curtFile.RedirectExcelContent);
                    }
                }
                Console.WriteLine("************Result End for Excel**************");

                Console.WriteLine("************Delete File List Start for Excel**************");
                foreach (CollectRedirectFileByArticle curtFile in fileList)
                {
                    if (curtFile.RedirectGContent.Length == 0 && curtFile.RedirectMContent.Length == 0)
                    {
                        Console.WriteLine(curtFile.FullPath);
                    }
                }
                Console.WriteLine("************Delete File List End for Excel**************");
            }

            Console.WriteLine("Program run finished, Press <Enter> to exit....");

            ExitWithUserConfirm();
        }
コード例 #13
0
        public void ProcessConvertJson(ref string globalContent, ref string mooncakeContent)
        {
            this.Status = ProcessStatus.Process;

            ConvertCategory category = this.ProcessCategory;

            JObject JGlobal   = null;
            JObject JMoonCake = null;
            int     iGCount   = 0;
            int     iMCount   = 0;

            //Redirect Section
            if (category == ConvertCategory.CheckRedirectByFile || category == ConvertCategory.CheckRedirectByService)
            {
                try
                {
                    JGlobal = (JObject)JsonConvert.DeserializeObject(globalContent);
                    iGCount = JGlobal[ConvertCategory.redirections.ToString()].Count();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Convert Global Redirection Json file Failed: ");
                    Console.WriteLine(string.Format("Reason: {0}", ex.Message.ToString()));
                }

                try
                {
                    JMoonCake = (JObject)JsonConvert.DeserializeObject(mooncakeContent);
                    iMCount   = JMoonCake[ConvertCategory.redirections.ToString()].Count();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Convert Mooncake Redirection Json file Failed: ");
                    Console.WriteLine(string.Format("Reason: {0}", ex.Message.ToString()));
                }


                Regex  reg                = null;
                string sourcePath         = string.Empty;
                string redirectUrl        = string.Empty;
                string redirectDocumentid = string.Empty;

                bool bGlobalFetch = false;
                bool bMoonFetch   = false;
                bool bFetch       = false;

                for (int i = 0; i < iGCount; i++)
                {
                    bFetch = this.GetProcessConvertRule(ref JGlobal, ConvertCategory.redirections, i, ConvertItem.source_path, ref sourcePath);
                    if (bFetch == true)
                    {
                        if (sourcePath.ToLower() == this.RelativeFile.ToLower())
                        {
                            bFetch = this.GetProcessConvertRule(ref JGlobal, ConvertCategory.redirections, i, ConvertItem.redirect_url, ref redirectUrl) &&
                                     this.GetProcessConvertRule(ref JGlobal, ConvertCategory.redirections, i, ConvertItem.redirect_document_id, ref redirectDocumentid);
                            if (bFetch == true)
                            {
                                this.RedirectGContent     += this.GenerateRedirectJson(sourcePath, redirectUrl, redirectDocumentid);
                                this.RedirectTableContent += this.GenerateTableRedirectJson(this.MooncakeSite, sourcePath, redirectUrl, redirectDocumentid);
                                this.RedirectExcelContent += this.GenerateExcelRedirectJson(sourcePath, redirectUrl, redirectDocumentid);
                                bGlobalFetch = true;
                                //break;
                            }
                        }
                    }
                }

                for (int i = 0; i < iMCount; i++)
                {
                    bFetch = this.GetProcessConvertRule(ref JMoonCake, ConvertCategory.redirections, i, ConvertItem.source_path, ref sourcePath);
                    if (bFetch == true)
                    {
                        if (sourcePath.ToLower() == this.RelativeFile.ToLower())
                        {
                            bFetch = this.GetProcessConvertRule(ref JMoonCake, ConvertCategory.redirections, i, ConvertItem.redirect_url, ref redirectUrl) &&
                                     this.GetProcessConvertRule(ref JMoonCake, ConvertCategory.redirections, i, ConvertItem.redirect_document_id, ref redirectDocumentid);
                            if (bFetch == true)
                            {
                                this.RedirectMContent += this.GenerateRedirectJson(sourcePath, redirectUrl, redirectDocumentid);
                                bMoonFetch             = true;
                                //break;
                            }
                        }
                    }
                }
            }


            //articleContent += "\n";
        }
コード例 #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            int             iCount   = args.Count();
            ConvertCategory category = ConvertCategory.CheckBrokenLinkByService;
            ConvertProcess  process  = ConvertProcess.ShowResult;

            DateTime timeStart = DateTime.Now;

            //TimeSpan runTime = new TimeSpan();
            //DateTime timeEnd = new DateTime();


            if (iCount != 2)
            {
                ShowUseageTip();
                return;
            }
            else
            {
                switch (args[0].TrimStart('-'))
                {
                case "S":
                case "s":
                    category = ConvertCategory.CheckBrokenLinkByService;
                    break;

                case "F":
                case "f":
                    category = ConvertCategory.CheckBrokenLinkByFile;
                    break;

                default:
                    ShowUseageTip();
                    return;
                }

                if (iCount == 2)
                {
                    switch (args[1].TrimStart('-'))
                    {
                    case "H":
                    case "h":
                        process = ConvertProcess.ShowHistory;
                        break;

                    case "R":
                    case "r":
                        process = ConvertProcess.ShowResult;
                        break;

                    default:
                        ShowUseageTip();
                        return;
                    }
                }
            }


            string error = "";

            string fileprefix = CommonFun.GetConfigurationValue("GlobalRepository", ref error);

            if (error.Length > 0)
            {
                Console.WriteLine(error);
                ExitWithUserConfirm();
                return;
            }

            string customizedate = CommonFun.GetConfigurationValue("CustomizeDate", ref error);

            if (error.Length > 0)
            {
                Console.WriteLine(error);
                ExitWithUserConfirm();
                return;
            }

            bool   successFlag   = false;
            int    MaxCheckRound = 0;
            string configValue   = CommonFun.GetConfigurationValue("CheckRound", ref error);

            if (error.Length > 0)
            {
                Console.WriteLine(error);
                ExitWithUserConfirm();
                return;
            }
            else
            {
                successFlag = int.TryParse(configValue, out MaxCheckRound);
                if (successFlag == true)
                {
                }
                else
                {
                    Console.WriteLine("Convert {0} to int failed!", configValue);
                    ExitWithUserConfirm();
                    return;
                }
            }



            string filename     = "";
            string directory    = "";
            string curtFullName = "";

            List <FileCustomize> fileList = new List <FileCustomize>();
            ArrayList            arrFile  = new ArrayList();

            //Get the thread count
            int threadCount = 0;

            switch (category)
            {
            case ConvertCategory.CheckBrokenLinkByService:
                arrFile = GetFileListByService();
                break;

            case ConvertCategory.CheckBrokenLinkByFile:
                arrFile = GetFileListByArticles();
                break;
            }


            threadCount = arrFile.Count;
            Thread[] newThreads = new Thread[threadCount];
            //CancellationTokenSource[] threadCancel = new CancellationTokenSource[threadCount];

            for (int i = 0; i < threadCount; i++)
            {
                curtFullName = arrFile[i].ToString();
                filename     = Path.GetFileName(curtFullName);
                directory    = curtFullName.Substring(fileprefix.Length, curtFullName.Length - fileprefix.Length - filename.Length - 1).Replace("\\", "/");

                //threadCancel[i] = new CancellationTokenSource();

                FileCustomize curtFile = new FileCustomize(i, filename, directory, customizedate, category, process);
                fileList.Add(curtFile);
                newThreads[i] = new Thread(new ThreadStart(curtFile.ProcessFileCustomize));


                newThreads[i].Start();

#if DEBUG
                newThreads[i].Join();
#endif
            }


            bool allThreadOver = false;
            while (allThreadOver == false)
            {
                Thread.Sleep(10000);
                allThreadOver = true;
                for (int i = 0; i < threadCount; i++)
                {
                    if (newThreads[i].ThreadState != ThreadState.Stopped && newThreads[i].ThreadState != ThreadState.Aborted)
                    {
                        allThreadOver = false;
                        Console.WriteLine(string.Format("Checking status of the Thread[{0}] : {1} ", i, newThreads[i].ThreadState.ToString()));
                        fileList[i].CheckRound += 1;



                        if (fileList[i].CheckRound == MaxCheckRound)
                        {
                            newThreads[i].Priority = ThreadPriority.AboveNormal;
                            Console.WriteLine(string.Format("Levelrage the porior of Thread[{0}] to {1} ", i, newThreads[i].Priority.ToString()));
                        }


                        if (fileList[i].CheckRound > MaxCheckRound * 2)
                        {
                            fileList[i].BrokenLink += string.Format("Error : The Check Round({0}) Exceed the limit of {1}", fileList[i].CheckRound, MaxCheckRound);
                            Console.WriteLine(string.Format("Abort the Thread[{0}] to {1} ", i, newThreads[i].Priority.ToString()));
                            newThreads[i].Abort();
                        }

                        break;
                    }
                }
            }

            if (category == ConvertCategory.ALL || category == ConvertCategory.IncludeParentFile)
            {
                Console.WriteLine();
                Console.WriteLine(String.Format("**********************Check Process Result({0})**********************", ConvertCategory.IncludeParentFile.ToString()));

                foreach (FileCustomize curtFile in fileList)
                {
                    if (curtFile.ArticleCategory == FileCategory.Includes)
                    {
                        Console.WriteLine("The parent file of \t{0} \tis \t{1}", curtFile.File, curtFile.ParentFile);
                    }
                }
            }

            if (category == ConvertCategory.ALL || category == ConvertCategory.H1ToTitle)
            {
                Console.WriteLine();
                Console.WriteLine(String.Format("**********************Check Process Result({0})**********************", ConvertCategory.H1ToTitle.ToString()));

                foreach (FileCustomize curtFile in fileList)
                {
                    if (!string.IsNullOrEmpty(curtFile.WarningMessage))
                    {
                        Console.WriteLine(curtFile.FullPath);
                        Console.WriteLine("File: \t{0} \tMessage: \t{1}", curtFile.FullPath, curtFile.WarningMessage);
                    }
                }
            }

            if (category == ConvertCategory.CheckBrokenLinkByFile || category == ConvertCategory.CheckBrokenLinkByService)
            {
                StringBuilder sbText = new StringBuilder();

                Console.WriteLine();
                sbText.AppendLine(String.Format("**********************Check Process Result({0})**********************", category.ToString()));
                //Console.WriteLine(String.Format("**********************Check Process Result({0})**********************", category.ToString()));

                int iIdx = 1;

                foreach (FileCustomize curtFile in fileList)
                {
                    if (!string.IsNullOrEmpty(curtFile.BrokenLink))
                    {
                        //Console.WriteLine("{0} : {1} ",iIdx++,  curtFile.File);
                        //Console.WriteLine(curtFile.BrokenLink);
                        sbText.AppendLine(string.Format("{0} : {1}", iIdx++, curtFile.FullPath.Replace(fileprefix, "").Replace("/", "\\")));
                        string[] param = curtFile.BrokenLink.Split('\n');
                        foreach (string curtText in param)
                        {
                            sbText.AppendLine(curtText);
                        }
                    }
                }


                sbText.AppendLine(string.Format("--------------Abort List in this round of Check Broken Link--------------"));
                iIdx = 1;
                foreach (FileCustomize curtFile in fileList)
                {
                    if (curtFile.CheckRound > MaxCheckRound * 2)
                    {
                        sbText.AppendLine(string.Format("{0} : {1}", iIdx++, curtFile.FullPath.Replace(fileprefix, "").Replace("/", "\\")));
                    }
                }

                sbText.AppendLine(string.Format("Total {0} abourt thread in the round of Check Broken List.", --iIdx));
                CommonFun.GenerateDownloadFile(category, ref sbText);
            }


            ExitWithUserConfirm();
        }
コード例 #15
0
 public CollectRedirectFileByArticle(int id, string filename, string directory, string customizedate, ConvertCategory category, string mooncakeSite, string globalContent, string mooncakeContent) : base(id, filename, directory, customizedate, category, mooncakeSite)
 {
     this.GlobalContent        = globalContent;
     this.MooncakeContent      = mooncakeContent;
     this.RedirectGContent     = string.Empty;
     this.RedirectMContent     = string.Empty;
     this.RedirectTableContent = string.Empty;
     this.RedirectExcelContent = string.Empty;
 }
コード例 #16
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";
        }
コード例 #17
0
ファイル: Program.cs プロジェクト: harrish0225/Production
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //Check the Redirect URL Category
            int             iCount   = args.Count();
            ConvertCategory category = ConvertCategory.CheckRedirectByFile;
            ConvertProcess  process  = ConvertProcess.ShowResult;

            CommandPara curtpara = CommandPara.Null;

            for (int i = 0; i < iCount; i++)
            {
                switch (args[i].ToUpper().Trim())
                {
                case "--SERVICE":
                case "-S":
                    curtpara = CommandPara.Servcie;
                    break;

                case "--CUSTOMIZE":
                case "-C":
                    curtpara = CommandPara.Customize;
                    break;

                case "--HELP":
                case "-H":
                    ShowUseageTip();
                    return;

                default:
                    switch (curtpara)
                    {
                    case CommandPara.Servcie:
                        switch (args[i].ToUpper().Trim())
                        {
                        case "S":
                            category = ConvertCategory.CheckRedirectByService;
                            break;

                        case "F":
                            category = ConvertCategory.CheckRedirectByFile;
                            break;

                        default:
                            curtpara = CommandPara.VerifyFail;
                            break;
                        }
                        break;

                    case CommandPara.Customize:
                        switch (args[i].ToUpper().Trim())
                        {
                        case "R":
                            process = ConvertProcess.ShowResult;
                            break;

                        case "H":
                            process = ConvertProcess.ShowHistory;
                            break;

                        default:
                            curtpara = CommandPara.VerifyFail;
                            break;
                        }
                        break;

                    case CommandPara.Null:
                        curtpara = CommandPara.VerifyFail;
                        break;

                    case CommandPara.VerifyFail:
                        ShowUseageTip();
                        return;
                    }

                    if (curtpara == CommandPara.VerifyFail)
                    {
                        ShowUseageTip();
                        return;
                    }
                    break;
                }
            }



            //Get the following config file , redirect file(both global and mooncake repository)
            bool   errFlag    = false;
            string error      = "";
            string configfile = CommonFun.GetConfigurationValue("CustomerFilePath", ref error);

            if (error.Length > 0)
            {
                Console.WriteLine(error);
                ExitWithUserConfirm();
                return;
            }

            string fileGlobal = CommonFun.GetConfigurationValue("GlobalRedirectFile", ref error);

            if (error.Length > 0)
            {
                Console.WriteLine(error);
                ExitWithUserConfirm();
                return;
            }

            string fileMooncakeDir = CommonFun.GetConfigurationValue("MooncakeRedirectDir", ref error);

            if (error.Length > 0)
            {
                Console.WriteLine(error);
                ExitWithUserConfirm();
                return;
            }

            string fileGlobalDir = CommonFun.GetConfigurationValue("GlobalRedirectDir", ref error);

            if (error.Length > 0)
            {
                Console.WriteLine(error);
                ExitWithUserConfirm();
                return;
            }

            string fileMooncake = CommonFun.GetConfigurationValue("MooncakeRedirectFile", ref error);

            if (error.Length > 0)
            {
                Console.WriteLine(error);
                ExitWithUserConfirm();
                return;
            }


            string mooncakeSite = CommonFun.GetConfigurationValue("MooncakeSite", ref error);

            if (error.Length > 0)
            {
                Console.WriteLine(error);
                ExitWithUserConfirm();
                return;
            }


            ////Get the redirect file content(both global and mooncake repository)
            string fileGlobalContent   = string.Empty;
            string fileMooncakeContent = string.Empty;

            errFlag = CommonFun.GetFileContent(fileGlobal, ref fileGlobalContent) && CommonFun.GetFileContent(fileMooncake, ref fileMooncakeContent);
            if (errFlag == false)
            {
                return;
            }

            List <CollectRedirectFileByArticle> fileList = new List <CollectRedirectFileByArticle>();
            ArrayList arrFile = new ArrayList();

            //Get the thread count
            int threadCount = 0;


            errFlag = CommonFun.GetConfigFileRowCount(configfile, ref threadCount);

            if (errFlag == false)
            {
                return;
            }

            string customizedate = string.Empty;

            switch (category)
            {
            case ConvertCategory.CheckRedirectByService:
                customizedate = DateTime.Now.ToString("MM/dd/yyyy");
                arrFile       = GetFileListByService(customizedate);
                break;

            case ConvertCategory.CheckRedirectByFile:
                arrFile = GetFileListByArticles();
                break;
            }

            threadCount = arrFile.Count;

            Thread[] newThreads = new Thread[threadCount];



            string filename  = "";
            string directory = "";

            string[] para = new string[] { };

            for (int i = 0; i < threadCount; i++)
            {
                para = (string[])arrFile[i];

                filename      = para[0];
                directory     = para[1];
                customizedate = para[2];
                CollectRedirectFileByArticle curtFile = new CollectRedirectFileByArticle(i, filename, directory, customizedate, category, mooncakeSite, fileGlobalContent, fileMooncakeContent);
                fileList.Add(curtFile);
                newThreads[i]      = new Thread(new ThreadStart(curtFile.ProcessFileCustomize));
                newThreads[i].Name = string.Format("{0}/{1}", directory, filename);
                newThreads[i].Start();
                Console.WriteLine(string.Format("Start the Thread[{0}] in application...", i));
#if DEBUG
                newThreads[i].Join();
#endif
                // Console.WriteLine(string.Format("Join the {0} thread in application", threadIdx));
            }



            bool allThreadOver = false;
            while (allThreadOver == false)
            {
                Thread.Sleep(10000);
                allThreadOver = true;
                for (int i = 0; i < threadCount; i++)
                {
                    if (newThreads[i].ThreadState != ThreadState.Stopped)
                    {
                        allThreadOver = false;
                        Console.WriteLine(string.Format("Checking status of the Thread[{0}] : {1} ", i, newThreads[i].ThreadState.ToString()));
                        break;
                    }
                }
            }

            if (category == ConvertCategory.CheckRedirectByService || category == ConvertCategory.CheckRedirectByFile)
            {
                foreach (CollectRedirectFileByArticle curtFile in fileList)
                {
                    Console.WriteLine("------------------------");
                    Console.WriteLine(curtFile.RelativeFile);
                    Console.WriteLine("Global Redirections");
                    Console.Write(curtFile.RedirectGContent);
                    Console.WriteLine("Mooncake Redirections");
                    Console.Write(curtFile.RedirectMContent);
                }

                Console.WriteLine("************Result Start for Json**************");
                foreach (CollectRedirectFileByArticle curtFile in fileList)
                {
                    if (curtFile.RedirectGContent.Length > 0 && curtFile.RedirectMContent.Length == 0)
                    {
                        Console.Write(curtFile.RedirectGContent);
                    }
                }
                Console.WriteLine("************Result End for Json**************");

                Console.WriteLine("************Result Start for Excel**************");
                foreach (CollectRedirectFileByArticle curtFile in fileList)
                {
                    if (curtFile.RedirectGContent.Length > 0 && curtFile.RedirectMContent.Length == 0)
                    {
                        Console.Write(curtFile.RedirectExcelContent);
                    }
                }
                Console.WriteLine("************Result End for Excel**************");

                Console.WriteLine("************Delete File List Start for Excel**************");
                foreach (CollectRedirectFileByArticle curtFile in fileList)
                {
                    if (curtFile.RedirectGContent.Length == 0 && curtFile.RedirectMContent.Length == 0)
                    {
                        Console.WriteLine(curtFile.RelativeFile);
                    }
                }
                Console.WriteLine("************Delete File List End for Excel**************");
            }

            Console.WriteLine("Program run finished, Press <Enter> to exit....");

            ExitWithUserConfirm();
        }
コード例 #18
0
        public bool GetProcessValidService(ref JObject JConvert, ConvertCategory category, int iIndex, ConvertItem key, string[] fileKey, int iCheckStart, string fileName)
        {
            bool   bProcess  = false;
            string valReturn = string.Empty;

            try
            {
                // service="ALL"
                valReturn = JConvert[category.ToString()][iIndex][key.ToString()].ToString().ToLower();

                bool   bCheckALLPattern = false;
                string sFirstChar       = "";

                string[] invloveService = valReturn.Split('|');
                for (int j = 0; j <= invloveService.Length - 1; j++)
                {
                    if (invloveService[j].ToLower().Substring(0, 1) == "!")
                    {
                        bCheckALLPattern = true;
                        break;
                    }
                }


                for (int i = iCheckStart + 1; i <= fileKey.Length - 1; i++)
                {
                    for (int j = 0; j <= invloveService.Length - 1; j++)
                    {
                        sFirstChar = invloveService[j].ToLower().Substring(0, 1);

                        // Take most priority
                        if (sFirstChar == "!")
                        {
                            bProcess = CheckIsPatternfile(fileKey, invloveService[j].ToLower());
                            if (bProcess == true)
                            {
                                bProcess = false;
                                return(bProcess);
                            }
                        }

                        if (sFirstChar == "*")
                        {
                            bProcess = CheckIsPatternfile(fileKey, invloveService[j].ToLower());
                            if (bCheckALLPattern == false)
                            {
                                return(bProcess);
                            }
                        }


                        if (invloveService[j].ToLower() == "all")
                        {
                            bProcess = true;
                            if (bCheckALLPattern == false)
                            {
                                return(bProcess);
                            }
                        }

                        if (fileKey[i].ToLower() == invloveService[j].ToLower())
                        {
                            bProcess = true;
                            if (bCheckALLPattern == false)
                            {
                                return(bProcess);
                            }
                        }

                        //for check the files in the include directory.
                        if (invloveService[j].Length < fileName.Length && invloveService[j].ToLower() == fileName.Substring(0, invloveService[j].Length))
                        {
                            bProcess = true;
                            if (bCheckALLPattern == false)
                            {
                                return(bProcess);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(bProcess);
        }
コード例 #19
0
ファイル: Program.cs プロジェクト: harrish0225/Production
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //Check the Redirect URL Category
            int             iCount   = args.Count();
            ConvertCategory category = ConvertCategory.CollectNewFileByService;
            ConvertProcess  process  = ConvertProcess.ShowResult;

            CommandPara curtpara = CommandPara.Null;

            for (int i = 0; i < iCount; i++)
            {
                switch (args[i].ToUpper().Trim())
                {
                case "--SERVICE":
                case "-S":
                    curtpara = CommandPara.Servcie;
                    break;

                case "--CUSTOMIZE":
                case "-C":
                    curtpara = CommandPara.Customize;
                    break;

                case "--HELP":
                case "-H":
                    ShowUseageTip();
                    return;

                default:
                    switch (curtpara)
                    {
                    case CommandPara.Servcie:
                        switch (args[i].ToUpper().Trim())
                        {
                        case "S":
                            category = ConvertCategory.CollectNewFileByService;
                            break;

                        default:
                            curtpara = CommandPara.VerifyFail;
                            break;
                        }
                        break;

                    case CommandPara.Customize:
                        switch (args[i].ToUpper().Trim())
                        {
                        case "R":
                            process = ConvertProcess.ShowResult;
                            break;

                        default:
                            curtpara = CommandPara.VerifyFail;
                            break;
                        }
                        break;

                    case CommandPara.Null:
                        curtpara = CommandPara.VerifyFail;
                        break;

                    case CommandPara.VerifyFail:
                        ShowUseageTip();
                        return;
                    }

                    if (curtpara == CommandPara.VerifyFail)
                    {
                        ShowUseageTip();
                        return;
                    }
                    break;
                }
            }



            //Get the following config file , redirect file(both global and mooncake repository)
            bool   errFlag    = false;
            string error      = "";
            string configfile = CommonFun.GetConfigurationValue("CustomerFilePath", ref error);

            if (error.Length > 0)
            {
                Console.WriteLine(error);
                ExitWithUserConfirm();
                return;
            }

            string fileGlobal = CommonFun.GetConfigurationValue("GlobalRedirectFile", ref error);

            if (error.Length > 0)
            {
                Console.WriteLine(error);
                ExitWithUserConfirm();
                return;
            }

            string fileMooncakeDir = CommonFun.GetConfigurationValue("MooncakeRedirectDir", ref error);

            if (error.Length > 0)
            {
                Console.WriteLine(error);
                ExitWithUserConfirm();
                return;
            }

            string fileGlobalDir = CommonFun.GetConfigurationValue("GlobalRedirectDir", ref error);

            if (error.Length > 0)
            {
                Console.WriteLine(error);
                ExitWithUserConfirm();
                return;
            }

            string fileMooncake = CommonFun.GetConfigurationValue("MooncakeRedirectFile", ref error);

            if (error.Length > 0)
            {
                Console.WriteLine(error);
                ExitWithUserConfirm();
                return;
            }


            string mooncakeSite = CommonFun.GetConfigurationValue("MooncakeSite", ref error);

            if (error.Length > 0)
            {
                Console.WriteLine(error);
                ExitWithUserConfirm();
                return;
            }


            ////Get the redirect file content(both global and mooncake repository)
            string fileGlobalContent   = string.Empty;
            string fileMooncakeContent = string.Empty;


            ArrayList arrFile = new ArrayList();

            //Get the thread count
            int threadCount = 0;


            errFlag = CommonFun.GetConfigFileRowCount(configfile, ref threadCount);

            if (errFlag == false)
            {
                return;
            }

            string customizedate = string.Empty;

            switch (category)
            {
            case ConvertCategory.CollectNewFileByService:
                customizedate = DateTime.Now.ToString("MM/dd/yyyy");
                arrFile       = GetFileListByService(customizedate);
                break;
            }

            threadCount = arrFile.Count;


            string filename  = "";
            string directory = "";

            string[] para = new string[] { };

            if (category == ConvertCategory.CollectNewFileByService)
            {
                for (int i = 0; i < threadCount; i++)
                {
                    para = (string[])arrFile[i];

                    filename      = para[0];
                    directory     = para[1];
                    customizedate = para[2];

                    Console.WriteLine(directory + "/" + filename);
                }
            }

            Console.WriteLine("Program run finished, Press <Enter> to exit....");

            ExitWithUserConfirm();
        }
コード例 #20
0
ファイル: FileCustomize.cs プロジェクト: lingliw/Production
        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;

            ConvertCategory category           = this.ProcessCategory;
            string          filePostfix        = string.Empty;
            string          orignalFilePostfix = string.Empty;

            if (category == ConvertCategory.CheckBrokenLinkByFile || category == ConvertCategory.CheckBrokenLinkByService)
            {
                List <string> lstURL = new List <string>();

                MatchCollection matches;

                orignalFilePostfix = this.FullPath.Trim().Substring(this.FullPath.Length - 3);
                filePostfix        = this.FullPath.Trim().Substring(this.FullPath.Length - 3).ToLower();

                if (filePostfix == ".md")
                {
                    // Part I for Links of .md file.
                    //string mdfilePatFirst = "[^(<!--)]\\[([^\\[\\]])*\\]([\\s]*)\\((?<mdfilename>[^\\(\\)]*)\\)";
                    //string mdfilePatFirst = "(?!(<!--[\\s\\S]*))\\[([^\\[\\]])*\\]([\\s]*)\\((?<mdfilename>[^\\(\\)\\[\\]]*)\\)(?!(\\s*-->))";
                    string mdfilePatFirst = "(?!(<!--[\\s\\S]*))\\[(?<labelname>[^\\[\\]]*)\\]([\\s]*)\\((?<mdfilename>[^\\(\\)\\[\\]]*)\\)(?!(\\s*-->))";
                    matches = Regex.Matches(articleContent, mdfilePatFirst);

                    this.CheckMatches(matches, ref lstURL, ref articleContent);

                    // Exception the C++ method style -->  [XXX]::MethodName
                    // Invloved Sample
                    // 1.[XXX]: XXXXX
                    // 2.[XXX]: http(s)://XXXX
                    // 3.[XXX]: XXX
                    // 4.[XXX]: XXXXXX -->   '--> will show us it is link no need to verify in later process.

                    //string mdfilePatSecond = "(?!(<!--[\\s\\S]*))\\[([^\\[\\]]*)\\]([\\s]*)\\:([\\s]*)(?<mdfilename>(https?:)?[^:\\s]*)(?!(\\s*-->))";
                    //string mdfilePatSecond = "(?!(<!--[\\s\\S]*))\\[([^\\[\\]])*\\]([\\s]*)\\:([\\s]*)(?<mdfilename>(http(s)?:)?[^:\\s\\[\\]]+(\\s*-->)?)";
                    string mdfilePatSecond = "(?!(<!--[\\s\\S]*))\\[(?<labelname>[^\\[\\]]*)\\]([\\s]*)\\:([\\s]*)(?<mdfilename>(http(s)?:)?[^:\\s\\[\\]]+(\\s*-->)?)";

                    matches = Regex.Matches(articleContent, mdfilePatSecond);

                    this.CheckMatches(matches, ref lstURL, ref articleContent);
                }

                filePostfix = this.FullPath.Trim().Substring(this.FullPath.Length - 4).ToLower();
                if (filePostfix == ".yml")
                {
                    // Part II for Links of .yml file.
                    string ymlfilePatFirst = "src:([\\s| ]*)([\\'|\\\"| ]{1})(?<mdfilename>[^ \\'\\\"\\r\\n]*)(\\2)";

                    matches = Regex.Matches(articleContent, ymlfilePatFirst);

                    this.CheckMatches(matches, ref lstURL, ref articleContent);

                    string ymlfilePatSecond = "href(\\:|\\=)([\\s| ]*)([\\'|\\\"| ]?)(?<mdfilename>[^ \\'\\\"\\r\\n]*)(\\3)[\\s]*(-->)*";     // (\\3) implement of ([\\'|\\\"| ]?) equal the 3rd element of groups
                    // mdfilename should also not be equal to \r\n, or will be append \r\n and next row's character.
                    matches = Regex.Matches(articleContent, ymlfilePatSecond);

                    this.CheckMatches(matches, ref lstURL, ref articleContent);
                }



                this.CheckAllLinks(lstURL);
            }
        }
コード例 #21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            int                iCount       = args.Count();
            ConvertCategory    category     = ConvertCategory.SXSUpdate;
            CustomizedCategory itercategory = CustomizedCategory.CustomizedByFile;
            CommandPara        curtpara     = CommandPara.Null;

            for (int i = 0; i < iCount; i++)
            {
                switch (args[i].ToUpper().Trim())
                {
                case "--SERVICE":
                case "-S":
                    curtpara = CommandPara.Servcie;
                    break;

                case "--CUSTOMIZE":
                case "-C":
                    curtpara = CommandPara.Customize;
                    break;

                case "--HELP":
                case "-H":
                    ShowUseageTip();
                    return;

                default:
                    switch (curtpara)
                    {
                    case CommandPara.Servcie:
                        switch (args[i].ToUpper().Trim())
                        {
                        case "S":
                            itercategory = CustomizedCategory.CustomizedByService;
                            break;

                        case "F":
                            itercategory = CustomizedCategory.CustomizedByFile;
                            break;

                        default:
                            curtpara = CommandPara.VerifyFail;
                            break;
                        }
                        break;

                    case CommandPara.Customize:
                        switch (args[i].ToUpper().Trim())
                        {
                        case "X":
                            category = ConvertCategory.SXSUpdate;
                            break;

                        default:
                            curtpara = CommandPara.VerifyFail;
                            break;
                        }
                        break;

                    case CommandPara.Null:
                        curtpara = CommandPara.VerifyFail;
                        break;

                    case CommandPara.VerifyFail:
                        ShowUseageTip();
                        return;
                    }
                    break;
                }
            }


            string error = "";

            string fileprefix = CommonFun.GetConfigurationValue("GlobalTaregetRepository", ref error);

            if (error.Length > 0)
            {
                return;
            }

            string customizedate = CommonFun.GetConfigurationValue("CustomizeDate", ref error);

            if (error.Length > 0)
            {
                return;
            }

            string filename     = "";
            string directory    = "";
            string curtFullName = "";

            ArrayList arrFile = new ArrayList();

            List <FileCustomize> fileList = new List <FileCustomize>();

            int threadCount = 0;

            switch (itercategory)
            {
            case CustomizedCategory.CustomizedByService:
                customizedate = DateTime.Now.ToString("MM/dd/yyyy");
                arrFile       = GetFileListByService(customizedate);
                break;

            case CustomizedCategory.CustomizedByFile:
                arrFile = GetFileListByArticles();
                break;
            }

            ThreadPool.SetMinThreads(1000, 1000);

            threadCount = arrFile.Count;
            Thread[] newThreads = new Thread[threadCount];

            string[] para = new string[] { };

            int iRemoveFileCount = 0;

            for (int i = 0; i < threadCount; i++)
            {
                para          = (string[])arrFile[i];
                filename      = para[0];
                directory     = para[1];
                customizedate = para[2];


                FileCustomize curtFile = new FileCustomize(i, filename, directory, customizedate, category);

                if (System.IO.File.Exists(curtFile.FullMasterPath) == true)
                {
                    fileList.Add(curtFile);
                    newThreads[i - iRemoveFileCount] = new Thread(new ThreadStart(curtFile.ProcessFileCustomize));
                    newThreads[i - iRemoveFileCount].Start();
#if DEBUG
                    newThreads[i].Join();
#endif
                }
                else
                {
                    iRemoveFileCount += 1;
                }
            }


            bool allThreadOver = false;
            while (allThreadOver == false)
            {
                Thread.Sleep(10000);
                allThreadOver = true;
                for (int i = 0; i < threadCount - iRemoveFileCount; i++)
                {
                    if (newThreads[i].ThreadState != ThreadState.Stopped)
                    {
                        allThreadOver = false;
                        Console.WriteLine(string.Format("Checking status of the Thread[{0}] : {1} ", i, newThreads[i].ThreadState.ToString()));
                        break;
                    }
                }
            }

            if (category == ConvertCategory.ALL || category == ConvertCategory.IncludeParentFile)
            {
                Console.WriteLine();
                Console.WriteLine(String.Format("**********************Check Process Result({0})**********************", ConvertCategory.IncludeParentFile.ToString()));

                foreach (FileCustomize curtFile in fileList)
                {
                    if (curtFile.ArticleCategory == FileCategory.Includes)
                    {
                        Console.WriteLine("The parent file of \t{0} \tis \t{1}", curtFile.File, curtFile.ParentFile);
                    }
                }
            }

            if (category == ConvertCategory.ALL || category == ConvertCategory.SXSUpdate)
            {
                Console.WriteLine();
                Console.WriteLine(String.Format("**********************Check Process Result({0})**********************", ConvertCategory.SXSUpdate.ToString()));

                foreach (FileCustomize curtFile in fileList)
                {
                    if (!string.IsNullOrEmpty(curtFile.WarningMessage))
                    {
                        Console.WriteLine(curtFile.Fullpath);
                        Console.WriteLine("File: \t{0} \tMessage: \t{1}", curtFile.Fullpath, curtFile.WarningMessage);
                    }
                }
            }

            Console.WriteLine("Program run finished, Press <Enter> to exit....");

            ExitWithUserConfirm();
        }
コード例 #22
0
        public FileCustomize(int id, string imagefilepath, string filename, string directory, string customizedate, ConvertCategory category, ConvertProcess process)
        {
            this.Id        = id;
            this.ImagePath = imagefilepath;

            string fullFileName = "";

            string[] para = directory.Split('/');


            foreach (string vpara in para)
            {
                if (vpara != "media")
                {
                    fullFileName += string.Format("/{0}", vpara);
                }
            }
            fullFileName = fullFileName.TrimStart('/') + "/" + string.Format("{0}.md", filename);
            this.File    = fullFileName;

            if (para[0] == "includes")
            {
                this.ServiceName = para[0];
            }
            else
            {
                this.ServiceName = para[1];
            }


            this.SetFullPathName(para);
            this.CustomizedDate  = customizedate;
            this.ProcessCategory = category;
            this.WarningMessage  = string.Empty;

            this.ShowHistory = process;
            //this.ForceTerminate = false;
            this.CheckRound    = 0;
            this.CheckFileList = new ArrayList();
            //this.CancelToke = cancelToke;
        }