Esempio n. 1
0
        /// <summary>
        /// changes settings on the fly if needed
        /// </summary>
        /// <param name="stateInfo">parameter required by callback signature</param>
        public void CheckSettingsVersionAndReloadIfNeeded(Object stateInfo)
        {
            log.Info("CheckSettingsVersionAndReloadIfNeeded()...");
            try
            {
                // To avoid Timer Event Reentrance
                settingsReloadTimer.Change(Timeout.Infinite, Timeout.Infinite);

                if (!IsReloadNeeded())
                {
                    return;
                }

                // restart quartz
                scheduler.Shutdown(true);

                IDictionary settings = null;
                try
                {
                    settings = GetSettingsFromDatabase();
                    projectIdsByCronExpressions = GetProjectIdsByCronExpressions();

                    log.Info("Trying to apply new settings. Version: " + settings[AppSettings.SettingsVersion]);
                }
                catch (Exception ex)
                {
                    log.Info("Can't get service settings from database", ex);
                    log.Info("Trying to restore previous settings. Version: " + AppSettings.GetSettingsVersion());
                    settings = AppSettings.AppSettingsMap;
                }

                configFileChanged = false;

                foreach (string s in new string[] { "appSettings", "connectionStrings", "log4net", "common/logging" })
                {
                    ConfigurationManager.RefreshSection(s);
                }

                LogManager.Adapter = null;
                log = LogManager.GetLogger(AppSettings.GetCommonLoggerName());

                InitializeSettings(settings);

                InitializeSchedulerAsync();
                scheduler.Start();
            }
            catch (Exception e)
            {
                // we can't get settings
                String failureMessage = e.Message + "\n" + e.StackTrace;
                log.Error("CheckSettingsVersionAndReloadIfNeeded", e);

                Emailer.SendEmail(failureMessage, Emailer.generalFailureSubject,
                                  AppSettings.GetCommonRecipientEmailAddresses());

                Stop();
            }
            finally
            {
                settingsReloadTimer.Change(TIMER_DUE, TIMER_PERIOD);
            }
        }