Exemple #1
0
        protected override void OnStart(string[] args)
        {
            try
            {
                AppDomain currentDomain = AppDomain.CurrentDomain;
                currentDomain.UnhandledException += UnhandledExceptionEventHandler;

                string info = string.Format(Emailer.startedMessageTempl, Environment.MachineName, DateTime.Now);
                log.Info(info);

                InitializeDivaInstance();
                InitializeSettings(GetSettingsFromDatabase());
                ServiceDAO.ResetIlcState();
                ExecutorFactory.Instance.ConstructExecutor(ServiceDAO.GetScenarios());
                projectIdsByCronExpressions = GetProjectIdsByCronExpressions();
                InitializeSchedulerAsync();

                settingsReloadTimer = new Timer(CheckSettingsVersionAndReloadIfNeeded, null, TIMER_DUE, TIMER_PERIOD);

                fileWatcher = new FileSystemWatcher(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName));
                fileWatcher.NotifyFilter        = NotifyFilters.LastWrite;
                fileWatcher.Filter              = Process.GetCurrentProcess().MainModule.ModuleName + ".config";
                fileWatcher.EnableRaisingEvents = true;
                fileWatcher.Changed            += OnConfigFileChanged;

                if (Emailer.SendEmail("", info, AppSettings.GetCommonRecipientEmailAddresses()))
                {
                    scheduler.Start();
                    // Normal exit
                    return;
                }
                log.Error("Failed to send email. Service will be stopped.");
            }
            catch (CompileErrorException e)
            {
                log.Error("Script compiler error.");
                Emailer.SendEmail(e.Message, "Script compiler error.",
                                  AppSettings.GetCommonRecipientEmailAddresses(), e.FileName);
            }
            catch (Exception e)
            {
                String failureMessage = e.Message + "\n" + e.StackTrace;
                log.Error("OnStart()", e);
                // Error handling
                Emailer.SendEmail(failureMessage, Emailer.generalFailureSubject,
                                  AppSettings.GetCommonRecipientEmailAddresses());
            }
            Stop();
        }
Exemple #2
0
        IDictionary <CronExpression, List <int> > GetProjectIdsByCronExpressions()
        {
            log.Info("Getting project Ids grouped by cron expressions.");
            IList <KeyValuePair <string, int> >      list        = ServiceDAO.GetCronStringsByProjectIds();
            Dictionary <CronExpression, List <int> > expressions = new Dictionary <CronExpression, List <int> >(new CronComparer());

            foreach (KeyValuePair <string, int> kvp in list)
            {
                CronExpression cronExp = new CronExpression(kvp.Key);
                List <int>     projectsList;
                if (!expressions.TryGetValue(cronExp, out projectsList))
                {
                    projectsList         = new List <int>();
                    expressions[cronExp] = projectsList;
                }
                projectsList.Add(kvp.Value);
            }

            return(expressions);
        }
Exemple #3
0
        private bool IsReloadNeeded()
        {
            if (configFileChanged)
            {
                return(true);
            }

            try
            {
                uint ver = ServiceDAO.GetSettingsVersion();
                if (AppSettings.GetSettingsVersion() != ver)
                {
                    log.Info("Service settings have been changed from " + AppSettings.GetSettingsVersion() +
                             " to " + ver);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                log.Info("Can't get service settings version from database", ex);
            }
            return(false);
        }
Exemple #4
0
 private IDictionary GetSettingsFromDatabase()
 {
     log.Info("Getting settings from database.");
     return(ServiceDAO.GetIlcConfigurationSettings());
 }