/// <summary>
        /// Set the scheduled time of periodic updates
        /// </summary>
        /// <param name="infoUpdatePeriodicTime">Scheduled time</param>
        /// <returns>True if the operation was successful</returns>
        public bool SetScheduleUpdatePeriodic(dc_InfoUpdatePeriodicTime infoUpdatePeriodicTime)
        {
            bool bOk = m_localData.SetPeriodicTimeInfo(infoUpdatePeriodicTime);

            m_timerPeriodicUpdate.Stop();
            ReScheduleTimers();

            return(bOk);
        }
Example #2
0
        /// <summary>
        /// Set the periodic updates information
        /// </summary>
        /// <param name="infoUpdatePeriodicTime">Periodic updates information</param>
        /// <returns>True if the operation was successful</returns>
        public bool SetPeriodicTimeInfo(dc_InfoUpdatePeriodicTime infoUpdatePeriodicTime)
        {
            bool bRet = false;

            string table = "updateSchedule";

            string[] keyList = new string[5];
            keyList[0] = "updatePeriodicAvailable";
            keyList[1] = "updatePeriodicModeDaily";
            keyList[2] = "updatePeriodicWeekday";
            keyList[3] = "updatePeriodicHour";
            keyList[4] = "updatePeriodicMinute";

            string[] valueList = new string[5];
            if (infoUpdatePeriodicTime.available)
            {
                valueList[0] = CONST_TRUE;
            }
            else
            {
                valueList[0] = CONST_FALSE;
            }
            if (infoUpdatePeriodicTime.modeDaily)
            {
                valueList[1] = CONST_TRUE;
            }
            else
            {
                valueList[1] = CONST_FALSE;
            }
            valueList[2] = (infoUpdatePeriodicTime.weekday).ToString();
            valueList[3] = (infoUpdatePeriodicTime.hour).ToString();
            valueList[4] = (infoUpdatePeriodicTime.minute).ToString();

            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);
        }
Example #3
0
        /// <summary>
        /// Get the periodic updates information
        /// </summary>
        /// <returns>Configuration of the periodic updates</returns>
        public dc_InfoUpdatePeriodicTime GetPeriodicTimeInfo()
        {
            dc_InfoUpdatePeriodicTime periodicTimeInfo = new dc_InfoUpdatePeriodicTime();

            periodicTimeInfo.available = false;
            periodicTimeInfo.modeDaily = false;
            periodicTimeInfo.weekday   = (byte)1;
            periodicTimeInfo.hour      = (byte)0;
            periodicTimeInfo.minute    = (byte)0;

            string table = "updateSchedule";

            string[] keyList = new string[5];
            keyList[0] = "updatePeriodicAvailable";
            keyList[1] = "updatePeriodicModeDaily";
            keyList[2] = "updatePeriodicWeekday";
            keyList[3] = "updatePeriodicHour";
            keyList[4] = "updatePeriodicMinute";
            string[] valueList = new string[1];

            try
            {
                m_semaphoreData.WaitOne();
                if (m_DBConnection.SelectQuery(keyList, table, ref valueList))
                {
                    periodicTimeInfo.available = bool.Parse(valueList[0]);
                    periodicTimeInfo.modeDaily = bool.Parse(valueList[1]);
                    periodicTimeInfo.weekday   = byte.Parse(valueList[2]);
                    periodicTimeInfo.hour      = byte.Parse(valueList[3]);
                    periodicTimeInfo.minute    = byte.Parse(valueList[4]);
                }
                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(periodicTimeInfo);
        }
        /// <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();
            }
        }
Example #5
0
 /// <summary>
 /// Schedule a periodic schedule update
 /// </summary>
 /// <param name="infoUpdatePeriodicTime">Periodic scheduled update configuration</param>
 /// <returns>True if the update schedule was succesful</returns>
 public bool SetUpdatePeriodicTime(dc_InfoUpdatePeriodicTime infoUpdatePeriodicTime)
 {
     return(m_updatesManager.SetUpdatePeriodicTime(infoUpdatePeriodicTime));
 }
Example #6
0
 /// <summary>
 /// Set the scheduled time of periodic updates
 /// </summary>
 /// <param name="infoUpdatePeriodicTime">Scheduled time</param>
 /// <returns>True if the operation was successful</returns>
 public bool SetUpdatePeriodicTime(dc_InfoUpdatePeriodicTime infoUpdatePeriodicTime)
 {
     return(m_scheduleUpdates.SetScheduleUpdatePeriodic(infoUpdatePeriodicTime));
 }