private void UpdateProgress( FilingResult result ) { this.testingProgress.pgbOverall.Value++; Label lbl = this.testingProgress.Controls[ "lblStatus" ] as Label; lbl.Text = string.Format( "Status: {0}/{1}", this.threadCounter.CompletionState, this.threadCounter.CompletionTarget ); ListViewItem item = new ListViewItem( result.Name ); item.SubItems.Add( new ListViewItem.ListViewSubItem( item, result.Success.ToString() ) ); item.SubItems.Add( new ListViewItem.ListViewSubItem( item, result.Errors.ToString() ) ); item.SubItems.Add( new ListViewItem.ListViewSubItem( item, result.Reason ) ); item.Tag = result; this.txtOutput.Items.Add( item ); this.txtOutput.AutoResizeColumns( ColumnHeaderAutoResizeStyle.ColumnContent ); if( result.Success == false || result.Errors > 0 ) this.lblDifferencesCount.Text = ( int.Parse( this.lblDifferencesCount.Text ) + 1 ).ToString(); }
/// <summary> /// Runs a test on the given base (could be either a folder or zip file containing R Files). The method can /// accept either a zip or a folder of R files. The name of the folder/zip of the new files must match that /// of the base path. /// </summary> /// <param name="testSummary"></param> /// <param name="testErrors"></param> /// <param name="baseZipOrDir"></param> public static void RunTest(FilingResult testSummaryItem, StringBuilder testErrors, string baseZipOrDir) { // The name of the filing is used to build all paths testSummaryItem.Name = Path.GetFileNameWithoutExtension(baseZipOrDir); string filingLogFolder = Test_Abstract.PathCombine(AutoTester.logPath, testSummaryItem.Name); // Preparing (clean/create) folders for output Test_Abstract.CleanAndPrepareFolder(filingLogFolder); int errorCount = 0; IDirectoryInfo baseDirInfo = null; IDirectoryInfo newDirInfo = null; try { // The base can be a directory, and if it is, then it needs to be handled differently. if (Directory.Exists(baseZipOrDir)) { baseDirInfo = new ExtendedDirectoryInfo(baseZipOrDir); } else if (File.Exists(baseZipOrDir)) { baseDirInfo = new ZipDirectoryInfo(baseZipOrDir); } else { // This shouldn't occur if the method was called from a file listing, but handle anyway string message = "The the zip or folder for the Base filing was missing. Tried to process the following as a directory and zip file: \r\n\t"; message += baseZipOrDir; string resultPath = Test_Abstract.PathCombine(filingLogFolder, "Base Filing Zip or Folder Missing.txt"); File.WriteAllText(resultPath, message); testSummaryItem.Success = false; testSummaryItem.Reason = "The base file name given to the processor could not be found."; return; } // When picking the new files, prefer directory over zip if (Directory.Exists(Test_Abstract.PathCombine(AutoTester.newFilingsPath, testSummaryItem.Name))) { string dirPath = Test_Abstract.PathCombine(AutoTester.newFilingsPath, testSummaryItem.Name); newDirInfo = new ExtendedDirectoryInfo(dirPath); } else if (File.Exists(Test_Abstract.PathCombine(AutoTester.newFilingsPath, testSummaryItem.Name + ".zip"))) { string zipPath = Test_Abstract.PathCombine(AutoTester.newFilingsPath, testSummaryItem.Name + ".zip"); newDirInfo = new ZipDirectoryInfo(zipPath); } else { string message = "The the zip or folder for the New filing was missing. Tried the directory: \r\n\t"; message += Test_Abstract.PathCombine(AutoTester.newFilingsPath, testSummaryItem.Name); message += "\r\nAnd the file: \r\n\t"; message += Test_Abstract.PathCombine(AutoTester.newFilingsPath, testSummaryItem.Name + ".zip"); string resultPath = Test_Abstract.PathCombine(filingLogFolder, "New Filing Zip or Folder Missing.txt"); File.WriteAllText(resultPath, message); testSummaryItem.Success = false; testSummaryItem.Reason = "The new file corresponding to the base file could not be found."; return; } // using (ErrorWriter writer = new ErrorWriter()) { Test_Abstract.VerifyIndividualReports(writer, baseDirInfo, newDirInfo, filingLogFolder); Test_Abstract.VerifyCharts(writer, baseDirInfo, newDirInfo); if (writer.HasErrors) { writer.Flush(); writer.SaveResults(filingLogFolder); testSummaryItem.Errors = writer.Errors; testSummaryItem.Success = true; testSummaryItem.Reason = "See error log."; testErrors.AppendFormat("Error in: {0}\r\n{1}\r\n\r\n\r\n", testSummaryItem.Name, writer.GetStringBuilder().ToString().Trim()); } else { testSummaryItem.Success = true; } errorCount = writer.Errors; } } catch (Exception e) { testSummaryItem.Success = false; testSummaryItem.Reason = "Exception) " + e.Message; } finally { if (errorCount == 0) { try { Directory.Delete(filingLogFolder, true); } catch { } } } }
private void RunTest( string threadPath, object o ) { this.throttler.WaitOne(); try { // Discontinue loop if cancelled if( !this.workerTester.CancellationPending ) { FilingResult result = new FilingResult(); StringBuilder testErrors = new StringBuilder(); Data.AutoTester.RunTest( result, testErrors, threadPath ); lock( this.errorFileInfo ) { using( StreamWriter writer = new StreamWriter( this.errorFileInfo.FullName, true ) ) { writer.Write( testErrors.ToString() ); } } //.NET 2.0 equivalent of "Action" delegate ThreadStart actUpdateProgress = new ThreadStart( () => this.UpdateProgress( result ) ); //execute on the UI thread this.testingProgress.Invoke( actUpdateProgress ); } } catch( Exception ex ) { if( this.workerTester.CancellationPending ) { //suppress exceptions caused by cancelation } else { //otherwise, throw the exception throw ex; } } // Release thread in any case finally { this.threadCounter.CompletionState++; this.throttler.Release(); } }
/// <summary> /// Runs a test on the given base (could be either a folder or zip file containing R Files). The method can /// accept either a zip or a folder of R files. The name of the folder/zip of the new files must match that /// of the base path. /// </summary> /// <param name="testSummary"></param> /// <param name="testErrors"></param> /// <param name="baseZipOrDir"></param> public static void RunTest( FilingResult testSummaryItem, StringBuilder testErrors, string baseZipOrDir ) { // The name of the filing is used to build all paths testSummaryItem.Name = Path.GetFileNameWithoutExtension( baseZipOrDir ); string filingLogFolder = Test_Abstract.PathCombine( AutoTester.logPath, testSummaryItem.Name ); // Preparing (clean/create) folders for output Test_Abstract.CleanAndPrepareFolder(filingLogFolder); int errorCount = 0; IDirectoryInfo baseDirInfo = null; IDirectoryInfo newDirInfo = null; try { // The base can be a directory, and if it is, then it needs to be handled differently. if (Directory.Exists(baseZipOrDir)) { baseDirInfo = new ExtendedDirectoryInfo( baseZipOrDir ); } else if (File.Exists(baseZipOrDir)) { baseDirInfo = new ZipDirectoryInfo( baseZipOrDir ); } else { // This shouldn't occur if the method was called from a file listing, but handle anyway string message = "The the zip or folder for the Base filing was missing. Tried to process the following as a directory and zip file: \r\n\t"; message += baseZipOrDir; string resultPath = Test_Abstract.PathCombine(filingLogFolder, "Base Filing Zip or Folder Missing.txt"); File.WriteAllText(resultPath, message); testSummaryItem.Success = false; testSummaryItem.Reason = "The base file name given to the processor could not be found."; return; } // When picking the new files, prefer directory over zip if( Directory.Exists( Test_Abstract.PathCombine( AutoTester.newFilingsPath, testSummaryItem.Name) ) ) { string dirPath = Test_Abstract.PathCombine( AutoTester.newFilingsPath, testSummaryItem.Name ); newDirInfo = new ExtendedDirectoryInfo( dirPath ); } else if( File.Exists( Test_Abstract.PathCombine( AutoTester.newFilingsPath, testSummaryItem.Name + ".zip" ) ) ) { string zipPath = Test_Abstract.PathCombine( AutoTester.newFilingsPath, testSummaryItem.Name + ".zip" ); newDirInfo = new ZipDirectoryInfo( zipPath ); } else { string message = "The the zip or folder for the New filing was missing. Tried the directory: \r\n\t"; message += Test_Abstract.PathCombine( AutoTester.newFilingsPath, testSummaryItem.Name ); message += "\r\nAnd the file: \r\n\t"; message += Test_Abstract.PathCombine( AutoTester.newFilingsPath, testSummaryItem.Name + ".zip" ); string resultPath = Test_Abstract.PathCombine(filingLogFolder, "New Filing Zip or Folder Missing.txt"); File.WriteAllText(resultPath, message); testSummaryItem.Success = false; testSummaryItem.Reason = "The new file corresponding to the base file could not be found."; return; } // using (ErrorWriter writer = new ErrorWriter()) { Test_Abstract.VerifyIndividualReports(writer, baseDirInfo, newDirInfo, filingLogFolder); Test_Abstract.VerifyCharts( writer, baseDirInfo, newDirInfo ); if (writer.HasErrors) { writer.Flush(); writer.SaveResults(filingLogFolder); testSummaryItem.Errors = writer.Errors; testSummaryItem.Success = true; testSummaryItem.Reason = "See error log."; testErrors.AppendFormat( "Error in: {0}\r\n{1}\r\n\r\n\r\n", testSummaryItem.Name, writer.GetStringBuilder().ToString().Trim() ); } else { testSummaryItem.Success = true; } errorCount = writer.Errors; } } catch (Exception e) { testSummaryItem.Success = false; testSummaryItem.Reason = "Exception) "+ e.Message; } finally { if( errorCount == 0 ) { try { Directory.Delete( filingLogFolder, true ); } catch { } } } }