Ejemplo n.º 1
0
        internal void CleanUp()
        {
            // Skip non-transactional modification methods because they could cause database connections to be reinitialized.
            cleanUpDatabaseConnectionsAndExecuteNonTransactionalModificationMethods(skipNonTransactionalModificationMethods: true);

            if (errorException != null)
            {
                AppTools.EmailAndLogError(errorPrefix, errorException);
                MiniProfiler.Stop();
            }
            else
            {
                var duration = DateTime.Now - beginTime;
                MiniProfiler.Stop();
                if (MiniProfiler.Current != null)
                {
                    duration = TimeSpan.FromMilliseconds((double)MiniProfiler.Current.DurationMilliseconds);
                }
                const int thresholdInSeconds = 30;
                if (duration > new TimeSpan(0, 0, thresholdInSeconds) && !AppTools.IsDevelopmentInstallation)
                {
                    AppTools.EmailAndLogError("Request took " + duration.TotalSeconds + " seconds to process. The threshold is " + thresholdInSeconds + " seconds.", null);
                }
            }
        }
Ejemplo n.º 2
0
 private 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 {
             StandardLibraryMethods.CallEveryMethod(
                 delegate {
                 const string prefix = "An exception occurred that could not be handled by the main exception handler:";
                 if (setErrorInRequestState)
                 {
                     RequestState.SetError(prefix, e);
                 }
                 else
                 {
                     AppTools.EmailAndLogError(prefix, e);
                 }
             },
                 delegate {
                 if (set500StatusCode)
                 {
                     this.set500StatusCode("Exception");
                 }
             });
         }
         catch {}
     }
 }
Ejemplo n.º 3
0
        /// <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.
                AppTools.EmailAndLogError(e);
            }
            finally {
                if (webTester != null)
                {
                    webTester.teardown();
                }
            }

            return(Environment.ExitCode);
        }
Ejemplo n.º 4
0
        /// <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)
                {
                    AppTools.EmailAndLogError("", 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);
        }