/// <summary> /// /// </summary> /// <param name="args"></param> static void Main(string[] args) { int iCount = args.Count(); ConvertCategory category = ConvertCategory.ALL; 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 "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; default: curtpara = CommandPara.VerifyFail; break; } break; case CommandPara.Null: curtpara = CommandPara.VerifyFail; break; case CommandPara.VerifyFail: ShowUseageTip(); return; } break; } } string error = ""; string configfile = CommonFun.GetConfigurationValue("customerfilepath", ref error); if (error.Length > 0) { return; } StreamReader sr = null; string filename = ""; string directory = ""; string customizedate = ""; List <FileCustomize> fileList = new List <FileCustomize>(); ArrayList arrFile = new ArrayList(); 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; } //Get the thread count ThreadPool.SetMinThreads(1000, 1000); threadCount = arrFile.Count; Thread[] newThreads = new Thread[threadCount]; // Declare the application thread. string[] para = new string[] { }; 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); 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)); // Console.WriteLine(string.Format("Join the {0} thread in application", threadIdx)); #if DEBUG newThreads[i].Join(); #endif } 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(); }
/// <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(); }