/// <summary> /// start a test (in a number of separate threads) /// </summary> private void StartTest() { // create the pool object and start the test pool = new TraderPool(LogSafe, OnConnected); pool.Start(OnPoolStop); lblConnectionStatus.Text = "connecting..."; lblConnectionStatus.Visible = true; btnStop.Enabled = true; }
/// <summary> /// ensure the target folder and save the report's time /// </summary> public static void BuildReport(TraderPool pool) { var folder = $"{DateTime.Now:yyyy-MM-dd HHmmss}"; EnsureFolder(folder); folder = ExecutablePath.Combine(RootFolder, folder); SaveStatisticsReport(pool, folder); SaveServerReport(pool, folder); }
/// <summary> /// handle the test's finish /// </summary> private void OnPoolStop() { LogSafe("Stopping..."); Invoke(new Action(() => { TestReportBuilder.BuildReport(pool); pool = null; btnStop.Enabled = false; lblConnectionStatus.Visible = false; })); LogSafe("Stopped"); }
/// <summary> /// save the report (included in the pool parameter) in a file /// </summary> private static void SaveStatisticsReport(TraderPool pool, string folder) { var stat = pool.statistics; var jsonPath = Path.Combine(folder, "rawdata.js"); var json = stat.Stringify(false); using (var sw = new StreamWriter(jsonPath, false, Encoding.UTF8)) sw.Write("window.rawdata = " + json); // copy report file var newPath = ExecutablePath.Combine(folder, "report.html"); var srcPath = ExecutablePath.Combine("report.html"); if (File.Exists(newPath)) { File.Delete(newPath); } File.Copy(srcPath, newPath); }
/// <summary> /// move the report file from the tempory path to the destination path ("report" folder) /// </summary> private static void SaveServerReport(TraderPool pool, string folder) { pool.serverStatPicker.CopyReportToTargetDir(folder); }