static void StopForJobVerification(BatchJobGrp batchJobGrp) { Console.WriteLine("------------------------------------------------------------"); Console.WriteLine("Execution stopped"); Console.WriteLine("Next BJG [" + batchJobGrp.Name + "] was marked as [needs verification]"); Log.Write(1, "Execution stopped for BJG verification"); Log.Write(2, "Next BJG [" + batchJobGrp.Name + "] was marked as [needs verification]"); string pathMasterImpFile = batchJobGrp.OutFilePath; string pathTestImpFile = batchJobGrp.OutFilePath.Replace("apsam26", "apsam58").Replace("UAT7", "UAT8"); bool pathError = false; if (!File.Exists(pathMasterImpFile)) { Console.WriteLine(); Console.WriteLine("Cannot find Master import file for automatic comparison"); Log.Write(2, "Master import file was not found"); pathError = true; } if (!File.Exists(pathTestImpFile)) { Console.WriteLine(); Console.WriteLine("Cannot find Test import file for automatic comparison"); Log.Write(2, "Test import file was not found"); pathError = true; } if (pathError) { WaitForManualCorrection(); } else { Console.WriteLine("Attempt to match files automatically..."); Log.Write(2, "Attempt to match import files automatically..."); if (FileEquals(pathMasterImpFile, pathTestImpFile)) { Console.WriteLine(" +Files are equal"); Log.Write(4, "Files are equal"); Console.WriteLine(); Console.WriteLine("OK, continue execution..."); Log.Write(2, "Script automatically returned to execution"); return; } else { Console.WriteLine(" -Files are different"); Log.Write(5, "Files are different"); WaitForManualCorrection(); } } }
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(); }