private async void buttonGenerateReport_Click(object sender, EventArgs e) { SetStatus("Running, please wait..."); //Disable UI/button to prevent the user to start it again buttonGenerateReport.Enabled = false; this.UseWaitCursor = true; Application.DoEvents(); //Create an progress object so we can get updates. //This will capture the current SyncContext so we can assign an event handler directly without any special handling Progress <RunnerProgressDetail> progressRunner = new Progress <RunnerProgressDetail>(); progressRunner.ProgressChanged += RunnerProgressUpdate; //Do this also for the report creation Progress <ReportCreationProgress> progressReport = new Progress <ReportCreationProgress>(); progressReport.ProgressChanged += ReportProgressUpdate; SimplifiedXteq5Runner simpleRunner = new SimplifiedXteq5Runner(textBoxFolder.Text, textBoxUserText.Text, _outputFormat); bool result = await simpleRunner.RunAsync(progressRunner, progressReport); //Enable UI again this.UseWaitCursor = false; buttonGenerateReport.Enabled = true; Application.DoEvents(); if (result == true) { //All good. Show the report. ExecuteAndForget.Execute(simpleRunner.ReportFilepath); SetStatus("Done. The report will be displayed in a second."); } else { //An error during execution was detected SetStatus("Failed"); //Error message from Firefox: Well, this is embarrassing //Error message from Apache server: We're sorry, but something went wrong string title = "We're sorry, but something went wrong"; string message = string.Format("{0}\r\n\r\n\r\nDo you wish to view technical details?", simpleRunner.FailedMessage); if (MessageBox.Show(message, title, MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes) { MonospacedTextForm mtform = new MonospacedTextForm(); mtform.Title = "Details"; mtform.Content = simpleRunner.FailedException.ToString(); mtform.ShowDialog(); } } }
public const int ERROR_BAD_COMMAND = 22; //Did not work at all. Wrong arguments, compilation folder not found, PowerShell broken etc. static int Main(string[] args) { //Set to error code by default int returnCode = ERROR_BAD_COMMAND; Console.WriteLine("Xteq5CLI " + AssemblyInformation.Version); Console.WriteLine(AssemblyInformation.Copyright); Console.WriteLine(AssemblyInformation.Description); Console.WriteLine(); //Create the work order. If something isn't right with the arguments, WorkOrder will print to console automatically WorkInstruction instruction = new WorkInstruction(args); if (instruction.Execute == false) { Console.WriteLine("Nothing to do, exiting."); } else { Console.WriteLine("Compilation folder: " + instruction.CompilationPath); //Create default UIRunner SimplifiedXteq5Runner simpleRunner = new SimplifiedXteq5Runner(instruction.CompilationPath); if (instruction.GenerateReport) { Console.WriteLine("Destination file : " + instruction.DestinationFilepath); Console.WriteLine("Destination format: " + instruction.DestinationFormat.ToString()); if (string.IsNullOrWhiteSpace(instruction.UserText) == false) { Console.WriteLine("Additional text : " + instruction.UserText); } simpleRunner = new SimplifiedXteq5Runner(instruction.CompilationPath, instruction.UserText, instruction.DestinationFormat, instruction.DestinationFilepath); } //Start the runner Console.WriteLine(); Console.WriteLine("Running, please wait..."); Progress <RunnerProgressDetail> progressRunner = new Progress <RunnerProgressDetail>(); progressRunner.ProgressChanged += RunnerProgressUpdate; bool result = simpleRunner.Run(progressRunner); if (result == true) { //Execution finished Console.WriteLine("Finished."); Console.WriteLine(); //Check if these is an issue in order to set the return code correctly if (simpleRunner.Report.IssuesFound) { Console.WriteLine("There is at least one asset or test that reports an issue"); returnCode = ERROR_INVALID_DATA; } else { Console.WriteLine("No issues found. Your system is operating within established parameters."); returnCode = ERROR_SUCCESS; } } else { //This did not work at all Console.WriteLine(); Console.WriteLine("Error: "); Console.WriteLine(" " + simpleRunner.FailedMessage); Console.WriteLine(); Console.WriteLine("Details:"); Console.WriteLine(" " + simpleRunner.FailedException.GetType().ToString() + " - " + simpleRunner.FailedException.Message); } //All done } Console.WriteLine(); Console.WriteLine("Exiting, return code is {0}.", returnCode); #if DEBUG Console.ReadLine(); #endif return(returnCode); }