Ejemplo n.º 1
0
        private static void SetInterval(int intervalMinutes)
        {
            try
            {
                while (true)
                {
                    string startInfo = string.Format("{0} Reminding the start", DateTime.Now);
                    ConsoleAndLog(startInfo);

                    _reminderManager.ReminderAll();

                    string completeInfo = string.Format("{0} Reminding the end.After {1} minutes, it will run again.", DateTime.Now, ReminderConfig.RunTimeInterval());
                    ConsoleAndLog(completeInfo);

                    //程序暂停一段时间,再次执行
                    Thread.Sleep(intervalMinutes * 1000 * 60);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);

                //异常后,恢复执行
                SetInterval(ReminderConfig.RunTimeInterval());
            }
        }
Ejemplo n.º 2
0
        private bool IsCanRun()
        {
            //执行时间段
            if (DateTime.Now.Hour != ReminderConfig.RunTimeSpan())
            {
                Console.WriteLine("Not in the period of execution");
                return(false);
            }

            //是否存在正在执行的程序
            if (_historyManager.ExistsRunning())
            {
                Console.WriteLine("A reminder is being carried out and will continue later");
                return(false);
            }

            //当日是否执行过
            if (_historyManager.GetLastModelByRunDate(DateTime.Now))
            {
                Console.WriteLine("Today has been reminded, no more reminding.");
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
 protected override void OnStart(string[] args)
 {
     //邮件提醒
     _reminderEmailTimer = new System.Timers.Timer();
     //分钟换毫秒
     _reminderEmailTimer.Interval = ReminderConfig.RunTimeInterval() * 60 * 1000;
     _reminderEmailTimer.Enabled  = true;
     _reminderEmailTimer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Reminder);
     _reminderEmailTimer.Start();
 }
Ejemplo n.º 4
0
        private static void RunCompleted()
        {
            string info = string.Format("{0} Run comepled.After {1} minutes, it will run again.", DateTime.Now.ToString(), ReminderConfig.RunTimeInterval());

            ConsoleAndLog(info);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 邮件定时提醒:近三天没有处理过的Ticket
        /// </summary>
        void Timer_Reminder(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                string startInfo = string.Format("{0} Reminding the start", DateTime.Now);
                WriteLog(startInfo);

                ReminderManager reminderManager = new ReminderManager();
                reminderManager.ReminderAll();

                string completeInfo = string.Format("{0} Reminding the end.After {1} minutes, it will run again.", DateTime.Now, ReminderConfig.RunTimeInterval());
                WriteLog(completeInfo);
            }
            catch (Exception exception)
            {
                WriteLog("程序异常:" + exception.Message);
            }
        }