public void Wait(string pathSCD, string versionSCD) { int serverStatus = 99999; while (true) { serverStatus = GetServerStatus(pathSCD); if (serverStatus == 30) { break; } else { Log.Write(2, "Waiting for " + ServerType + " server [" + ServerName + "] in " + versionSCD + "..."); Log.Write(3, "[Exit Code: " + serverStatus + " Description: " + ExitCodeDescription.ServerExitCodeDescript(serverStatus) + "]"); Console.WriteLine(); Console.WriteLine("Waiting for " + ServerType + " server [" + ServerName + "] in " + versionSCD + "..."); Console.WriteLine("[Exit Code: " + serverStatus + " Description: " + ExitCodeDescription.ServerExitCodeDescript(serverStatus) + "]"); Thread.Sleep(30000); } } }
static void Main(string[] args) { ExitCodeDescription.InitializeExitCodesDict(); string logFile = ""; try { string logDir = Directory.GetCurrentDirectory() + @"\Log"; if (!Directory.Exists(logDir)) { Directory.CreateDirectory(logDir); } logFile = logDir + @"\Scriptovich_log_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt"; Log = new Log(logFile); } catch (Exception) { Console.WriteLine("Cannot create log file. Execution will continue without logging!"); } //--------------------------------------------------------------------------------------------------------------------------------------------------------- string pathConfigs = Directory.GetCurrentDirectory() + @"\Scriptovich_configs.xml"; List <BatchJobGrp> batchJobGrps = new List <BatchJobGrp>(); bool errors = false; //--------------------------------------------------------------------------------------------------------------------------------------------------------- try { Configs = new Configuration(pathConfigs); string pathBatchJobGrps = Directory.GetCurrentDirectory() + @"\BJG_to_run.txt"; char delimiter = ';'; try { List <string> batchJobGrpFile = ReadFileWithBatchJobGrps(pathBatchJobGrps); AllJobs = batchJobGrpFile.Count; List <string> batchJobGrpToRun = FindBJGToStartWith(batchJobGrpFile, delimiter); foreach (string item in batchJobGrpToRun) { string name = item.Split(delimiter)[1]; int verification = int.Parse(item.Split(delimiter)[2]); string outFilePath = item.Split(delimiter)[3]; BatchJobGrp batchJobGrp = new BatchJobGrp(name, verification, outFilePath); batchJobGrps.Add(batchJobGrp); } HandleComparisonOptions(batchJobGrps); } catch (Exception) { Console.WriteLine("------------------------------------------------------------"); Console.WriteLine("Input file: " + pathBatchJobGrps + "\nis missed or incorrect! Please check if the file exists and whether the file has four columns separated by " + "[" + delimiter + "]"); Console.WriteLine("Example of input file:"); Console.WriteLine("First column is the line number"); Console.WriteLine("Second column is BJG name"); Console.WriteLine("Third column is the marker [1/0] where to stop execution for BJG verification"); Console.WriteLine("Fourth column is path to import file from Master SCD (will be used for automatic check)"); Log.Write(2, "Input file: " + pathBatchJobGrps + " with BJGs is incorrect"); errors = true; } } catch (Exception) { Console.WriteLine("The configuration file: " + pathConfigs + "\nis missed or not properly set!"); Log.Write(2, "The configuration file: " + pathConfigs + " is missed or not properly set!"); errors = true; } //--------------------------------------------------------------------------------------------------------------------------------------------------------- List <Server> serversToWait = new List <Server>(); if (!errors) { foreach (var server in Configs.ServersToWait) { Server srv = new Server(server.Key, server.Value, Log); serversToWait.Add(srv); } VerifyServerListForWaiting(serversToWait); } //--------------------------------------------------------------------------------------------------------------------------------------------------------- if (batchJobGrps.Count > 0 && !errors) { Installation masterSCD = new Installation(Configs.PathMasterSCD, "Master", Configs.BatchQueue, Configs.BatchDate, Configs.BatchServer, serversToWait, Log); Installation testSCD = new Installation(Configs.PathTestSCD, "Test", Configs.BatchQueue, Configs.BatchDate, Configs.BatchServer, serversToWait, Log); Console.WriteLine("------------------------------------------------------------"); Console.WriteLine("Execution started"); Console.WriteLine("The batch date = " + Configs.BatchDate); Console.WriteLine(); Log.Write(2, "Execution started"); Log.Write(2, "The batch date = " + Configs.BatchDate); Console.WriteLine("Do NOT close this window till the process will end"); Console.WriteLine("Please see log file for execution details:"); Console.WriteLine(Log.FileName); foreach (BatchJobGrp batchJobGrp in batchJobGrps) { CurrentBatchJobGrp = batchJobGrp.Name; CurrentJobPosition = BatchJobGrpLine; if (batchJobGrp.Name.Contains("XCON_ISS")) { Thread.Sleep(60000); } if (batchJobGrp.Verification == 1) { StopForJobVerification(batchJobGrp); } //Run Test Log.Write(1, "Starting " + BatchJobGrpLine + " of " + AllJobs + " in Test"); Console.WriteLine(); Console.WriteLine("Starting " + BatchJobGrpLine + " of " + AllJobs + " in Test"); Task runTest = new Task(() => testSCD.RunBatchJobGrpTask(batchJobGrp.Name)); runTest.Start(); //Run Master Log.Write(2, "Starting " + BatchJobGrpLine + " of " + AllJobs + " in Master"); Console.WriteLine("Starting " + BatchJobGrpLine + " of " + AllJobs + " in Master"); Task runMaster = new Task(() => masterSCD.RunBatchJobGrpTask(batchJobGrp.Name)); runMaster.Start(); Task.WaitAll(runTest, runMaster); //check Test result testSCD.CheckBatchJobGrpStatus(batchJobGrp.Name, BatchJobGrpLine, AllJobs); //check Master result masterSCD.CheckBatchJobGrpStatus(batchJobGrp.Name, BatchJobGrpLine, AllJobs); //wait for STP to start due to polling 1 min if (batchJobGrp.Name.Contains("STP")) { Thread.Sleep(70000); } BatchJobGrpLine++; } } Log.Write(1, "Script ended"); Console.WriteLine("------------------------------------------------------------"); Console.WriteLine("Script ended"); Console.ReadKey(); }