コード例 #1
0
        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);
                }
            }
        }
コード例 #2
0
 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 {}
     }
 }
コード例 #3
0
        private static void tick(object state)
        {
            TelemetryStatics.ExecuteBlockWithStandardExceptionHandling(
                delegate {
                // We need to schedule the next tick even if there is an exception thrown in this one. Use try-finally instead of CallEveryMethod so we don't lose
                // exception stack traces.
                try {
                    foreach (var key in periodicEvictionKeys)
                    {
                        var entryWrapper = cache.Get(key) as Lazy <object>;
                        if (entryWrapper == null)
                        {
                            continue;
                        }
                        var entry = entryWrapper.Value as PeriodicEvictionCompositeCacheEntry;
                        if (entry == null)
                        {
                            continue;
                        }

                        entry.EvictOldEntries();
                    }
                }
                finally {
                    try {
                        timer.Change(tickInterval, Timeout.Infinite);
                    }
                    catch (ObjectDisposedException) {
                        // This should not be necessary with the Timer.Dispose overload we are using, but see http://stackoverflow.com/q/12354883/35349.
                    }
                }
            });
        }
コード例 #4
0
        private void tick(object state)
        {
            TelemetryStatics.ExecuteBlockWithStandardExceptionHandling(
                () => {
                // We need to schedule the next tick even if there is an exception thrown in this one. Use try-finally instead of CallEveryMethod so we don't lose
                // exception stack traces.
                try {
                    var currentInstant = SystemClock.Instance.GetCurrentInstant();
                    var interval       = new TickInterval(new Interval(lastTickInstant, currentInstant));
                    lastTickInstant    = currentInstant;

                    if (ConfigurationStatics.IsLiveInstallation && interval.FitsPattern(OperationRecurrencePattern.CreateDaily(0, 0)))
                    {
                        EmailStatics.SendHealthCheckEmail(WindowsServiceMethods.GetServiceInstalledName(service));
                    }

                    service.Tick(interval);
                }
                finally {
                    try {
                        timer.Change(tickInterval, Timeout.Infinite);
                    }
                    catch (ObjectDisposedException) {
                        // This should not be necessary with the Timer.Dispose overload we are using, but see http://stackoverflow.com/q/12354883/35349.
                    }
                }
            });
        }
コード例 #5
0
        private void tick(object state)
        {
            TelemetryStatics.ExecuteBlockWithStandardExceptionHandling(
                () => {
                // We need to schedule the next tick even if there is an exception thrown in this one. Use try-finally instead of CallEveryMethod so we don't lose
                // exception stack traces.
                try {
                    var now = DateTime.Now;
                    if (ConfigurationStatics.IsLiveInstallation && !ConfigurationStatics.MachineIsStandbyServer &&
                        new[] { lastHealthCheckDateAndTime, now }.Any(dt => dt.Date.IsBetweenDateTimes(lastHealthCheckDateAndTime, now)))
                    {
                        EmailStatics.SendHealthCheckEmail(WindowsServiceMethods.GetServiceInstalledName(service));
                    }
                    lastHealthCheckDateAndTime = now;

                    service.Tick();
                }
                finally {
                    try {
                        timer.Change(tickInterval, Timeout.Infinite);
                    }
                    catch (ObjectDisposedException) {
                        // This should not be necessary with the Timer.Dispose overload we are using, but see http://stackoverflow.com/q/12354883/35349.
                    }
                }
            });
        }
コード例 #6
0
        /// <summary>
        /// Private use only.
        /// </summary>
        protected override void OnStop()
        {
            TelemetryStatics.ExecuteBlockWithStandardExceptionHandling(
                () => {
                if (timer != null)
                {
                    var waitHandle = new ManualResetEvent(false);
                    timer.Dispose(waitHandle);
                    waitHandle.WaitOne();
                }

                service.CleanUp();
            });
        }
コード例 #7
0
        /// <summary>
        /// Starts all web sites and services associated with this installation.
        /// </summary>
        public void Start()
        {
            var allServices = ServiceController.GetServices();

            foreach (var service in RuntimeConfiguration.WindowsServices)
            {
                var serviceController = allServices.SingleOrDefault(sc => sc.ServiceName == service.InstalledName);
                if (serviceController == null)
                {
                    TelemetryStatics.ReportFault(
                        "Failed to start the \"{0}\" service because it is missing. Re-install the services for the installation to correct this error.".FormatWith(
                            service.InstalledName));
                    continue;
                }

                try {
                    serviceController.Start();
                }
                catch (InvalidOperationException e) {
                    const string message = "Failed to start service.";

                    // We have seen this happen when an exception was thrown while initializing global logic for the system.
                    if (e.InnerException is Win32Exception &&
                        e.InnerException.Message.Contains("The service did not respond to the start or control request in a timely fashion"))
                    {
                        throw new UserCorrectableException(message, e);
                    }

                    throw new ApplicationException(message, e);
                }
                serviceController.WaitForStatusWithTimeOut(ServiceControllerStatus.Running);

                TewlContrib.ProcessTools.RunProgram("sc", "config \"{0}\" start= delayed-auto".FormatWith(serviceController.ServiceName), "", true);

                // Set failure actions.
                const int restartDelay = 60000;                 // milliseconds
                TewlContrib.ProcessTools.RunProgram(
                    "sc",
                    "failure \"{0}\" reset= {1} actions= restart/{2}".FormatWith(serviceController.ServiceName, serviceFailureResetPeriod, restartDelay),
                    "",
                    true);
                TewlContrib.ProcessTools.RunProgram("sc", "failureflag \"{0}\" 1".FormatWith(serviceController.ServiceName), "", true);
            }
            if (runtimeConfiguration.WebApplications.Any(i => i.IisApplication != null) && runtimeConfiguration.InstallationType != InstallationType.Development)
            {
                IsuStatics.StartIisAppPool(IisAppPoolName);
            }
        }
コード例 #8
0
        /// <summary>
        /// Private use only.
        /// </summary>
        protected override void OnStart(string[] args)
        {
            if (GlobalInitializationOps.SecondaryInitFailed)
            {
                ExitCode = 0x425;                 // Win32 error code; see http://msdn.microsoft.com/en-us/library/cc231199.aspx.
                Stop();
                return;
            }

            Action method = () => {
                lastTickInstant = SystemClock.Instance.GetCurrentInstant();
                service.Init();

                timer = new Timer(tick, null, tickInterval, Timeout.Infinite);
            };

            if (!TelemetryStatics.ExecuteBlockWithStandardExceptionHandling(method))
            {
                ExitCode = 0x428;                 // Win32 error code; see http://msdn.microsoft.com/en-us/library/cc231199.aspx.
                Stop();
            }
        }
コード例 #9
0
        private void tick(object state)
        {
            TelemetryStatics.ExecuteBlockWithStandardExceptionHandling(
                () => {
                // We need to schedule the next tick even if there is an exception thrown in this one. Use try-finally instead of CallEveryMethod so we don't lose
                // exception stack traces.
                try {
                    var currentInstant = SystemClock.Instance.GetCurrentInstant();
                    var interval       = new TickInterval(new Interval(lastTickInstant, currentInstant));
                    lastTickInstant    = currentInstant;

                    service.Tick(interval);
                }
                finally {
                    try {
                        timer.Change(tickInterval, Timeout.Infinite);
                    }
                    catch (ObjectDisposedException) {
                        // This should not be necessary with the Timer.Dispose overload we are using, but see http://stackoverflow.com/q/12354883/35349.
                    }
                }
            });
        }
コード例 #10
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.
                TelemetryStatics.ReportError(e);
            }
            finally {
                if (webTester != null)
                {
                    webTester.teardown();
                }
            }

            return(Environment.ExitCode);
        }
コード例 #11
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)
                {
                    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);
        }