private void BtRun_Click(object sender, EventArgs e) { ExcelLogFile xlLog = new ExcelLogFile(DG, logFolder); xlLog.SaveLog(); string DebugMode = ""; ClearGrid(); isStopped = false; BtRun.Enabled = false; CmbTests.Enabled = false; BtUp.Enabled = false; BtDown.Enabled = false; ProcessStartInfo MyProcess = new ProcessStartInfo(); string Gateway = ""; string Client = ""; Gateway = " -g " + CmbGateway.Text; if (CmbClient1.Text != "None") { Client = " -s " + CmbClient1.Text; if (CmbClient2.Text != "None") { Client += " -s " + CmbClient2.Text; if (CmbClient3.Text != "None") { Client += " -s " + CmbClient3.Text; if (CmbClient4.Text != "None") { Client += " -s " + CmbClient4.Text; } } } } if (StripDebug.Checked) { DebugMode = " /d"; } bool loop = StripLoop.Checked; try { do { xlLog.NewLine(); testIndex = 0; for (int i = 0; i < DG.Rows.Count; i++) { if (DG.Rows[i].Cells[0].Value.ToString() == "True") { testIndex = i; currentTest = DG.Rows[testIndex].Cells[1].Value.ToString(); MyProcess.FileName = WorkingDirectory(CmbTests.SelectedItem.ToString()); MyProcess.Arguments = "-t " + currentTest + Gateway + Client + DebugMode; MyProcess.WindowStyle = ProcessWindowStyle.Hidden; DG.Rows[testIndex].Cells[2].Value = "Running..."; testProcess = Process.Start(MyProcess); testProcess.EnableRaisingEvents = true; testProcess.Exited += new EventHandler(Test_Exited); testCompleted = false; do { Application.DoEvents(); } while (isStopped == false && testCompleted == false); if (isStopped == false) { CheckResult(xlLog); } } if (isStopped) { break; } } isStopped = false; BtRun.Enabled = true; CmbTests.Enabled = true; BtUp.Enabled = true; BtDown.Enabled = true; loop = StripLoop.Checked; } while (loop && !isStopped); } catch (Exception) { } }
private void CheckResult(ExcelLogFile xlLog) { string[] FileContent; string LogP; bool DidClient = false; bool DidGateway = false; string testName = DG.Rows[testIndex].Cells[1].Value.ToString(); string[] dirs = Directory.GetDirectories(logFolder, testName + "*"); DateTime newestDirTime = new DateTime(1900, 1, 1); string newestDirPath = ""; foreach (string subDir in dirs) { DateTime created = new DirectoryInfo(subDir).LastWriteTime; if (created > newestDirTime) { newestDirPath = subDir; newestDirTime = created; } } LogP = newestDirPath + "\\IEX_Summary.xml"; try { FileContent = File.ReadAllLines(LogP); if (FileContent[1].Contains("Test Status=" + (char)34 + "Failed" + (char)34)) { DataGridViewCellStyle CellStyle = new DataGridViewCellStyle(); CellStyle.BackColor = Color.Red; CellStyle.ForeColor = Color.White; DG.Rows[testIndex].Cells[2].Style = CellStyle; DG.Rows[testIndex].Cells[2].Value = "FAILED"; } else if (FileContent[1].Contains("Test Status=" + (char)34 + "Passed" + (char)34)) { DataGridViewCellStyle CellStyle = new DataGridViewCellStyle(); CellStyle.BackColor = Color.Green; CellStyle.ForeColor = Color.White; DG.Rows[testIndex].Cells[2].Style = CellStyle; DG.Rows[testIndex].Cells[2].Value = "PASSED"; } for (int i = FileContent.Count() - 1; i > -1; i--) { if (DidClient && DidGateway) { break; } if (FileContent[i].Contains("Status=" + (char)34 + "Failed" + (char)34)) { string Reason = FileContent[i].Remove(0, FileContent[i].IndexOf("Reason")); DataGridViewCellStyle CellStyle = new DataGridViewCellStyle(); CellStyle.BackColor = Color.Red; CellStyle.ForeColor = Color.White; if (Reason.Contains("Client") && !DidClient) { DG.Rows[testIndex].Cells[4].Style = CellStyle; DG.Rows[testIndex].Cells[4].Value = "FAILED"; DidClient = true; } else if (Reason.Contains("Gateway") && !DidGateway) { DG.Rows[testIndex].Cells[3].Style = CellStyle; DG.Rows[testIndex].Cells[3].Value = "FAILED"; DidGateway = true; } Reason = Reason.Substring(Reason.IndexOf("=") + 2, (Reason.IndexOf((char)34 + " ") - 3) - Reason.IndexOf("=") + 1); DG.Rows[testIndex].Cells[5].Value = Reason; } else if (FileContent[i].Contains("Status=" + (char)34 + "Passed" + (char)34)) { string Reason = FileContent[i].Remove(0, FileContent[i].IndexOf("Reason")); DataGridViewCellStyle CellStyle = new DataGridViewCellStyle(); CellStyle.BackColor = Color.Green; CellStyle.ForeColor = Color.White; if (Reason.Contains("Client") && !DidClient) { DG.Rows[testIndex].Cells[4].Style = CellStyle; DG.Rows[testIndex].Cells[4].Value = "PASSED"; DidClient = true; } else if (Reason.Contains("Gateway") && !DidGateway) { DG.Rows[testIndex].Cells[3].Style = CellStyle; DG.Rows[testIndex].Cells[3].Value = "PASSED"; DidGateway = true; } } } xlLog.PrintMsg(testIndex, GetLogFile(ServerType.Gateway, false), GetLogFile(ServerType.Client1, false)); } catch { DG.Rows[testIndex].Cells[2].Value = "FINISHED"; DG.Rows[testIndex].Cells[5].Value = "Log isn't available"; } }