protected override void OnStop() { var serviceStopTime = new ServiceStopTime { ScheduleEndTime = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture) }; try { var schedulerExportPath = GlobalAppSettings.GetSchedulerExportPath(); if (Directory.Exists(schedulerExportPath) == false) { Directory.CreateDirectory(schedulerExportPath); } new SchedulerJob().SerializeTime(serviceStopTime, GlobalAppSettings.GetSchedulerExportPath() + "config.xml"); LogExtension.LogInfo("Service stopped", MethodBase.GetCurrentMethod()); } catch (Exception e) { LogExtension.LogError("Exception is thrown while stopping service", e, MethodBase.GetCurrentMethod()); } finally { base.OnStop(); } }
public void ReschedulePastSchedulerJobs(DateTime currentTime) { if (!File.Exists(GlobalAppSettings.GetSchedulerExportPath() + "config.xml")) { return; } try { var serviceStopTime = DeserializeTime(GlobalAppSettings.GetSchedulerExportPath() + "config.xml"); var lastProcessedDate = Convert.ToDateTime(serviceStopTime.ScheduleEndTime, CultureInfo.InvariantCulture); var pastSchedules = scheduleJobProcessor.GetFailedJobs(lastProcessedDate, currentTime); scheduleJobProcessor.RescheduleUnProcessedJobs(pastSchedules); File.Delete(GlobalAppSettings.GetSchedulerExportPath() + "config.xml"); } catch (Exception e) { LogExtension.LogError("Exception while re scheduling past schedules", e, MethodBase.GetCurrentMethod()); } }