/// <summary> /// Generate Gnuplot graf files /// </summary> public static void GenerateGnuplotFiles() { try { if (!Directory.Exists(ApplicationSettings.Instance.ReportsPath)) { Directory.CreateDirectory(ApplicationSettings.Instance.ReportsPath); } using (TextWriter fstream = new StreamWriter(Path.Combine(ApplicationSettings.Instance.ReportsPath, Program.GNUPLOT_GENERATOR_FILE) + (SystemHelper.IsWindows() ? ".bat" : ".sh"))) { string gnuvar = "%GNUPLOT_PATH%"; if (SystemHelper.IsWindows()) { fstream.Write("@echo off\n" + "title \"Relatorio de grafos com GNUPLOT\"\n" + "set GNUPLOT_PATH=\"{0}\"\n", ApplicationSettings.Instance.GnuplotFullPath); } else { fstream.Write("echo \"Relatorio de grafos com GNUPLOT\"\n" + "GNUPLOT_PATH=\"{0}\"\n", ApplicationSettings.Instance.GnuplotFullPath); gnuvar = "$GNUPLOT_PATH"; } for (int i = 0; i < Program.ALGORTIHMS.Length; i++) { fstream.Write("echo Running {0} sort plot\n" + "{1} -p \"{0}.plt\"\n", Program.ALGORTIHMS[i], gnuvar); } fstream.Write("echo Running All sort plot\n" + "{0} -p \"All.plt\"\n", gnuvar); fstream.Write("\npause"); fstream.Close(); } } catch (Exception e) { Console.WriteLine(e.Message); } }
/// <summary> /// Triggerd when any button get clicked /// </summary> /// <param name="sender">Object who trigger event</param> /// <param name="e">Event arguments</param> private void ButtonClick(object sender, EventArgs e) { if (sender == btnAlgorithmsSelectAll) { for (int i = 0; i < cblAlgorithms.Items.Count; i++) { cblAlgorithms.SetItemChecked(i, true); } return; } if (sender == btnAlgorithmsDeselectAll) { for (int i = 0; i < cblAlgorithms.Items.Count; i++) { cblAlgorithms.SetItemChecked(i, false); } return; } if (sender == btnAlgorithmsInvert) { for (int i = 0; i < cblAlgorithms.Items.Count; i++) { cblAlgorithms.SetItemChecked(i, !cblAlgorithms.GetItemChecked(i)); } return; } if (sender == btnViewLog) { if (bgWorker.IsBusy) { return; } cblAlgorithms.Visible = !cblAlgorithms.Visible; btnViewLog.Text = cblAlgorithms.Visible ? "View &Log" : "Hide &Log"; } if (sender == btnSearchGnuplotExe) { using (var openDialog = new OpenFileDialog()) { string workingDir = SystemHelper.IsWindows() ? Path.GetDirectoryName(ApplicationSettings.Instance.GnuplotFullPath) : (ApplicationSettings.Instance.GnuplotFullPath.Equals("gnuplot") ? "/usr/bin" : Path.GetDirectoryName(ApplicationSettings.Instance.GnuplotFullPath)); openDialog.CheckFileExists = true; openDialog.AddExtension = false; openDialog.CheckPathExists = true; openDialog.RestoreDirectory = true; openDialog.InitialDirectory = workingDir; openDialog.FileName = (SystemHelper.IsWindows() ? "wgnuplot.exe" : "gnuplot"); openDialog.Filter = SystemHelper.IsWindows() ? "Gnuplot windows executable (wgnuplot.exe)|wgnuplot.exe" : "Gnuplot executable (gnuplot*)|gnuplot*"; if (openDialog.ShowDialog() == DialogResult.OK) { ApplicationSettings.Instance.GnuplotFullPath = tbGnuplotExecutable.Text = openDialog.FileName; } } return; } if (sender == btnSaveReportsTo) { using (var folderDialog = new FolderBrowserDialog()) { folderDialog.Description = @"Folder to save all reports and algorithm work"; folderDialog.SelectedPath = Application.StartupPath; if (folderDialog.ShowDialog() == DialogResult.OK) { // Absolute to partial path convertion string path = folderDialog.SelectedPath.Replace(Application.StartupPath, string.Empty); if (!string.IsNullOrEmpty(path) && path.Substring(0, 1) == Path.DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture)) { path = path.Remove(0, 1); } ApplicationSettings.Instance.ReportsPath = tbSaveReportsTo.Text = path; } } return; } if (sender == cbAutoOpenPlots) { ApplicationSettings.Instance.AutoOpenPlot = cbAutoOpenPlots.Checked; return; } if (sender == cbArrayRandomBetweenValues) { ApplicationSettings.Instance.ArrayRandomBetweenValues = cbArrayRandomBetweenValues.Checked; nmArrayMaxRandomNumber.Enabled = cbArrayRandomBetweenValues.Checked; nmArrayNumberGrowFactor.Enabled = !cbArrayRandomBetweenValues.Checked; return; } if (sender == btnStart) { if (bgWorker.IsBusy) { return; } ApplicationSettings.Save(); Report.GenerateGnuplotFiles(); gbOptions.Enabled = false; btnStart.Enabled = false; btnStop.Enabled = btnPause.Enabled = true; pbLoad.Value = 0; pbLoad.Text = @"Starting"; Program.Logging.Clear(); tsAlgortimsBar.Enabled = cblAlgorithms.Visible = false; Stopwatcher.Reset(); Stopwatcher.Start(); tmClock.Start(); bgWorker.RunWorkerAsync(); return; } if (sender == btnPause) { btnPause.Text = btnPause.Text.Equals("Pause") ? "Resume" : "Pause"; return; } if (sender == btnStop) { if (bgWorker.CancellationPending) { return; } if ( MessageBox.Show("Have you sure you want stop current work?\nAfter stop there are no backwards", @"Cancellation", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) != DialogResult.Yes) { return; } bgWorker.AbortCancel(); btnPause.Enabled = btnStop.Enabled = false; btnPause.Text = "Pause"; lbStatus.Text += @" -> Cancel Requested -> Waiting for finish"; } }