private void LoadInitialSettings() { RegistrySetting oRegistrySetting = new RegistrySetting(); try { servicetimer = new System.Timers.Timer((HourlyDailyEntity.HourlyReadInterval != 0) ? CheckInterval(HourlyDailyEntity.HourlyReadInterval) : 1000); servicetimer.Elapsed += new System.Timers.ElapsedEventHandler(servicetimer_Elapsed); DBConnect.InitialSettings(); HourlyDailyEntity.HasReadRunWithHourly = false; // Fix for Read run twice for a day HourlyDailyEntity.ShouldReadRunWithHourly = HourlyDailyEntity.DailyAutoReadTime.Split(':')[1].ToString() == "00" ? true : false; oRegistrySetting.ReadRegistrySettings(HourlyDailyEntity.sRegistryPath); LogManager.WriteLog("HourlyReadHour from Registry: " + HourlyDailyEntity.HourlyReadHour.ToString() + " Date format from Registry: " + HourlyDailyEntity.LastAutoRead.ToString() + " Regional setting date format: " + System.Globalization.CultureInfo.CurrentCulture.DisplayName + " Service started", LogManager.enumLogLevel.Info); //HourlyDailyEventLog.WriteToEventLog(HourlyDailyEntity.EventLogName,"LoadInitialSettings: ", "Hourly Daily Service initiated", EventLogEntryType.Information); } catch (Exception ex) { //HourlyDailyEventLog.WriteToEventLog(HourlyDailyEntity.EventLogName, "LoadInitialSettings: ", "Message: " + ex.Message + "Source: " + ex.Source, EventLogEntryType.Error); ExceptionManager.Publish(ex); } }
public void RunService() { //Dictionary<string, string> dictServiceentries = new Dictionary<string, string>(); RegistrySetting oRegistrySetting = new RegistrySetting(); try { #if (DEBUG) { if (IsRunning == false) { IsRunning = true; servicetimer.Enabled = true; TimerCount = TimerCount + 1; oRegistrySetting.ReadRegistrySettings(HourlyDailyEntity.sRegistryPath); if (DateTime.Now.Hour != HourlyDailyEntity.HourlyReadHour) { //LogManager.WriteLog("The Hour: " + HourlyDailyEntity.HourlyReadHour.ToString(), LogManager.enumLogLevel.Debug); if (DBConnect.CheckSqlConnectionExists()) { DBConnect.InitialSettings(); oHourlyServiceHandle.DoWork(); HourlyDailyEntity.HourlyReadHour = DateTime.Now.Hour; dictServiceentries.Add(HourlyDailyEntity.sRegistryPath + "\\\\HourlyReadHour", HourlyDailyEntity.HourlyReadHour.ToString()); oRegistrySetting.SetRegistryEntries(dictServiceentries, HourlyDailyEntity.sRegistryPath); } } if (TimerCount == 10) { oRegistrySetting.ReadRegistrySettings(HourlyDailyEntity.sRegistryPath); oDailyReadServiceHandle.DoWork(); TimerCount = 0; } IsRunning = false; } } #else { if (IsRunning == false) { IsRunning = true; servicetimer.Enabled = true; TimerCount = TimerCount + 1; oRegistrySetting.ReadRegistrySettings(HourlyDailyEntity.sRegistryPath); if (DateTime.Now.Hour != HourlyDailyEntity.HourlyReadHour) { //LogManager.WriteLog("The Hour: " + HourlyDailyEntity.HourlyReadHour.ToString(), LogManager.enumLogLevel.Debug); if (DBConnect.CheckSqlConnectionExists()) { DBConnect.InitialSettings(); oHourlyServiceHandle.DoWork(); HourlyDailyEntity.HourlyReadHour = DateTime.Now.Hour; BMCRegistryHelper.SetRegKeyValue(HourlyDailyEntity.sRegistryPath, "HourlyReadHour", Microsoft.Win32.RegistryValueKind.String, HourlyDailyEntity.HourlyReadHour.ToString()); } } if (TimerCount == 10) { oRegistrySetting.ReadRegistrySettings(HourlyDailyEntity.sRegistryPath); oDailyReadServiceHandle.DoWork(); TimerCount = 0; } IsRunning = false; } } #endif } catch (Exception ex) { IsRunning = false; //HourlyDailyEventLog.WriteToEventLog(HourlyDailyEntity.EventLogName, "RunService: ", "Message: " + ex.Message + "Source: " + ex.Source, EventLogEntryType.Error); ExceptionManager.Publish(ex); } }