Ejemplo n.º 1
0
 protected override void OnStart(string[] args)
 {
     try
     {
         //Thread.Sleep(15 * 1000);
         logService = new EventLogService(eventLog1);
         //configService = new ConfigService(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.xml"));
         configService = new ConfigService(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Lubi Datakonsult\\FileSysWatcher\\config.xml"));
         configService.OnConfigChanged += Reschedule;
         cleanFolderService             = new CleanFolderService(logService,
                                                                 configService.GetNode("/FileSysWatcher/CleanFolderService"));
         scheduleService = new ScheduleService(cleanFolderService);
         scheduleTimer   = new Timer
         {
             Interval = defaultRetry.TotalMilliseconds,
             Enabled  = true
         };
         scheduleTimer.Elapsed += ScheduleTimerElapsed;
     }
     catch (Exception ex)
     {
         logService?.ErrorLog(ex.ToString());
         Stop();
     }
 }
Ejemplo n.º 2
0
 private void ScheduleTimerElapsed(object sender, ElapsedEventArgs e)
 {
     scheduleTimer.Enabled = false;
     try
     {
         var nextCheck       = scheduleService.CheckAndReschedule();
         var timeToNextCheck = nextCheck - DateTime.Now;
         scheduleTimer.Interval = Math.Max(timeToNextCheck.TotalMilliseconds, 1000);
     }
     catch (Exception ex)
     {
         logService.ErrorLog(ex.ToString());
         scheduleTimer.Interval = defaultRetry.TotalMilliseconds;
     }
     scheduleTimer.Enabled = false;
 }
Ejemplo n.º 3
0
 private void Reschedule(object sender, FileSystemEventArgs e)
 {
     logService?.ErrorLog("Config changed, rescheduling for checking folders now");
     scheduleTimer.Interval = 2000;
 }