/// <summary> /// Set the scheduled time to start a update in a concrete date /// </summary> /// <param name="infoUpdateSpecificTime">Scheduled time</param> /// <returns>True if the operation was successful</returns> public bool SetUpdateSpecificTime(dc_InfoUpdateSpecificTime infoUpdateSpecificTime) { bool bOk = m_localData.SetSpecificTimeInfo(infoUpdateSpecificTime); m_timerSpecificUpdate.Stop(); ReScheduleTimers(); return(bOk); }
/// <summary> /// Set the specific updates information /// </summary> /// <param name="infoUpdateSpecificTime">Specific updates information</param> /// <returns>True if the operation was successful</returns> public bool SetSpecificTimeInfo(dc_InfoUpdateSpecificTime infoUpdateSpecificTime) { bool bRet = false; string table = "updateSchedule"; string[] keyList = new string[2]; keyList[0] = "updateSpecificAvailable"; keyList[1] = "updateSpecificTime"; string[] valueList = new string[2]; if (infoUpdateSpecificTime.available) { valueList[0] = CONST_TRUE; } else { valueList[0] = CONST_FALSE; } valueList[1] = infoUpdateSpecificTime.time.ToString("yyyy-MM-dd HH:mm:ss"); try { m_semaphoreData.WaitOne(); bRet = m_DBConnection.UpdateQuery(keyList, table, valueList); if (!bRet) { LoggerModule.logger.Error(System.Reflection.MethodInfo.GetCurrentMethod().Name + ". Error with DB Update Query"); } } catch (Exception ex) { LoggerModule.logger.Error(System.Reflection.MethodInfo.GetCurrentMethod().Name + ". Error: " + ex.Message); } finally { m_semaphoreData.Release(); } return(bRet); }
/// <summary> /// Get the specific updates information /// </summary> /// <returns>Configuration of the specific update</returns> public dc_InfoUpdateSpecificTime GetSpecificTimeInfo() { dc_InfoUpdateSpecificTime specificTimeInfo = new dc_InfoUpdateSpecificTime(); specificTimeInfo.available = false; specificTimeInfo.time = DateTime.Now; string table = "updateSchedule"; string[] keyList = new string[2]; keyList[0] = "updateSpecificAvailable"; keyList[1] = "updateSpecificTime"; string[] valueList = new string[1]; try { m_semaphoreData.WaitOne(); if (m_DBConnection.SelectQuery(keyList, table, ref valueList)) { specificTimeInfo.available = bool.Parse(valueList[0]); specificTimeInfo.time = DateTime.Parse(valueList[1]); } else { LoggerModule.logger.Error(System.Reflection.MethodInfo.GetCurrentMethod().Name + ". Error with DB Select Query"); } } catch (Exception ex) { LoggerModule.logger.Error(System.Reflection.MethodInfo.GetCurrentMethod().Name + ". Error: " + ex.Message); } finally { m_semaphoreData.Release(); } return(specificTimeInfo); }
/// <summary> /// Re-schedule the timers /// </summary> /// <remarks>The scheduled time can exceed the maximum timer interval (Int32 ~ 24.8 days)</remarks> private void ReScheduleTimers() { //Periodic Update dc_InfoUpdatePeriodicTime infoUpdatePeriodic = m_localData.GetPeriodicTimeInfo(); if (infoUpdatePeriodic.available) { if (!m_timerPeriodicUpdate.Enabled) { DateTime actDate = DateTime.Now; int interval = 0; interval += System.Convert.ToInt32((infoUpdatePeriodic.hour - actDate.Hour) * 60 * 60); interval += System.Convert.ToInt32((infoUpdatePeriodic.minute - actDate.Minute) * 60); if (infoUpdatePeriodic.modeDaily) { if (interval <= 0) { interval += 24 * 60 * 60; //le sumamos un dia } } else { int dayDiff = infoUpdatePeriodic.weekday - (int)actDate.DayOfWeek; if (dayDiff < 0) { dayDiff += 7; } interval += dayDiff * 24 * 60 * 60; if (interval <= 0) { interval += 7 * 24 * 60 * 60; //le sumamos una semana } } m_timerPeriodicUpdate.Interval = interval * 1000; //miliseconds m_timerPeriodicUpdate.Start(); } } else { m_timerPeriodicUpdate.Stop(); } //Specific Update dc_InfoUpdateSpecificTime infoUpdateSpecific = m_localData.GetSpecificTimeInfo(); if (infoUpdateSpecific.available) { if (!m_timerSpecificUpdate.Enabled) { DateTime actDate = DateTime.Now; if ((infoUpdateSpecific.time - actDate).TotalMilliseconds < int.MaxValue && (infoUpdateSpecific.time - actDate).TotalMilliseconds > 0) { m_timerSpecificUpdate.Interval = System.Convert.ToDouble((infoUpdateSpecific.time - actDate).TotalMilliseconds); m_timerSpecificUpdate.Start(); } else { m_timerSpecificUpdate.Stop(); } } } else { m_timerSpecificUpdate.Stop(); } }
/// <summary> /// Schedule a specific scheduled update /// </summary> /// <param name="infoUpdateSpecificTime">Specific scheduled update configuration</param> /// <returns>True if the update schedule was successful</returns> public bool SetUpdateSpecificTime(dc_InfoUpdateSpecificTime infoUpdateSpecificTime) { return(m_updatesManager.SetUpdateSpecificTime(infoUpdateSpecificTime)); }
/// <summary> /// Set the scheduled time to start a update in a concrete date /// </summary> /// <param name="infoUpdateSpecificTime">Scheduled time</param> /// <returns>True if the operation was successful</returns> public bool SetUpdateSpecificTime(dc_InfoUpdateSpecificTime infoUpdateSpecificTime) { return(m_scheduleUpdates.SetUpdateSpecificTime(infoUpdateSpecificTime)); }