示例#1
0
        /// <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();
        }
示例#2
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();
        }