internal static void ExecuteWithBasicExceptionHandling(Action handler, bool setErrorInRequestState, bool set500StatusCode) { try { handler(); } catch (Exception e) { // Suppress all exceptions since there is no way to report them and in some cases they could wreck the control flow for the request. try { EwlStatics.CallEveryMethod( delegate { const string prefix = "An exception occurred that could not be handled by the main exception handler:"; if (setErrorInRequestState) { Instance.RequestState.SetError(prefix, e); } else { TelemetryStatics.ReportError(prefix, e); } }, delegate { if (set500StatusCode) { Instance.set500StatusCode("Exception"); } }); } catch {} } }
internal void CleanUp() { // Skip non-transactional modification methods because they could cause database connections to be reinitialized. cleanUpDatabaseConnectionsAndExecuteNonTransactionalModificationMethods(skipNonTransactionalModificationMethods: true); if (errorPrefix.Any() || errorException != null) { TelemetryStatics.ReportError(errorPrefix, errorException); MiniProfiler.Stop(); } else { var duration = SystemClock.Instance.GetCurrentInstant() - beginInstant; MiniProfiler.Stop(); if (MiniProfiler.Current != null) { duration = Duration.FromMilliseconds((double)MiniProfiler.Current.DurationMilliseconds); } const int thresholdInSeconds = 30; if (duration > Duration.FromSeconds(thresholdInSeconds) && !ConfigurationStatics.IsDevelopmentInstallation) { TelemetryStatics.ReportError( "Request took " + duration.TotalSeconds + " seconds to process. The threshold is " + thresholdInSeconds + " seconds.", null); } } }
/// <summary> /// Installs testing software if necessary, initializes the test browser and executes all tests for the system. /// Returns a non-zero code if a failure was encountered when running a test. It is possible to have a zero return code when there is a failure if the /// failure occurs before the tests begin to run, for example. /// </summary> public static int RunAllWebTestsForSystem() { WebTester webTester = null; try { OneTimeInstall.InstallSeleniumServiceIfNecessary(); // NOTE: Moving selenium initialization here instead of setupBrowser will simplify things and make it so we don't have to create the WebTester reference too early. // We also won't need to hold a selenium member variable. Console.WriteLine("Executing web tests..."); webTester = new WebTester(); // Only do this if the intermediate log on didn't fail. if (Environment.ExitCode == 0) { foreach (var testClass in Assembly.GetCallingAssembly().GetTypes().Where(t => t.GetCustomAttributes(typeof(TestFixtureAttribute), true).Any()).OrderBy(tc => tc.Name)) { webTester.executeTest(testClass); } Console.WriteLine("Web tests complete."); } } catch (Exception e) { // NOTE: After we eliminate environment.exit code setting, try to wrap this method in standard exception handling instead. TelemetryStatics.ReportError(e); } finally { if (webTester != null) { webTester.teardown(); } } return(Environment.ExitCode); }
/// <summary> /// Adds a row to this table. /// </summary> public void AddRow(RowSetup rowSetup, params EwfTableCell[] cells) { // If SetUpColumns was never called, implicitly set up the columns based on this first row. if (columnSetups == null) { columnSetups = cells.Select(c => new ColumnSetup()).ToList(); } rowSetups.Add(rowSetup); if (!rowSetup.IsHeader) { dataRowCount++; } var defaultCsvLine = cells.Select(cell => (cell as CellPlaceholder).SimpleText).ToList(); if (rowSetup.CsvLine == null) { rowSetup.CsvLine = defaultCsvLine; } // Verify that this row has the right number of cells. try { if (cells.Sum(c => c.FieldSpan) + previousRowColumnSpans.Sum(rcSpan => rcSpan.ColumnSpan) != columnSetups.Count) { throw new ApplicationException("Row to be added has the wrong number of cells."); } // Despite that it would make no sense to do this and all latest browsers will draw tables incorrectly when this happens, I cannot find official documentation // saying that it is wrong. NOTE: This check isn't as good as the logic we are going to add to EwfTableItemRemainingData (to ensure that the item has at // least one cell) because it doesn't catch a case like two cells that each have a row span greater than one and together span all columns. if (cells.Any(c => c.ItemSpan > 1 && c.FieldSpan == columnSetups.Count)) { throw new ApplicationException("Cell may not take up all columns and span multiple rows."); } } catch (ApplicationException e) { if (!AppTools.IsDevelopmentInstallation) { TelemetryStatics.ReportError(e); } else { throw; } } foreach (var rowColumnSpanPair in previousRowColumnSpans) { rowColumnSpanPair.RowSpan--; } previousRowColumnSpans = (previousRowColumnSpans.Where(rowSpan => rowSpan.RowSpan > 0) .Concat( cells.Where(c => c.ItemSpan != 1) .Select(rowSpanCell => new RowColumnSpanPair { RowSpan = rowSpanCell.ItemSpan - 1, ColumnSpan = rowSpanCell.FieldSpan }))).ToList(); var cellPlaceHolders = new List <CellPlaceholder>(cells); TableOps.DrawRow(table, rowSetup, cellPlaceHolders, columnSetups, false); }