示例#1
0
        /// <summary>
        /// Starts timer for the next reminder whici is assumed to exist
        /// </summary>
        protected virtual void ScheduleNextReminder(DateTime now)
        {
            ReminderEntity nextReminder = ActiveSortedReminders.First();

            int intervalMs = GetTimeInMsUntilNextRinging(nextReminder, now);

            Log.Logger.Information($"Starting NextReminderNotifier timer [Reminder name = {nextReminder.Name}, Interval = {intervalMs} ms, Scheduled at {nextReminder.ScheduledTime} UTC] ");

            NextReminderTimer.Interval = intervalMs;
            NextReminderTimer.Start();
        }
示例#2
0
        /// <summary>
        /// Updates the list of active reminders, and starts the timer if needed.
        /// It is ok to call the method even when the component is disabled.
        /// </summary>
        /// <param name="upToDateReminders"></param>
        public void UpdateReminderList(IList <ReminderEntity> upToDateReminders)
        {
            DateTime now = DateTime.UtcNow; //good to be constant in a variable during this analysis in method so that it doesn't change during analysis. It could make some kind of timer deadlock where timer would never ring.

            //pause timer util we decide when should it ring again so that it does not make conccurency issues while we are changing the list
            if (isEnabled)
            {
                Log.Logger.Information("Pausing NextReminderNotifier timer (if it is running at all)"); //maybe there were no events
                NextReminderTimer.Stop();
            }

            //TODO: maybe not do this now but when needed, we can just find 1 first; keep list ordered instead of oredering it each time
            ActiveSortedReminders = CloneAndSortOnlyActiveReminders(upToDateReminders);

            //if scheduler is enabled continue timer (if there is need for this at all after change of reminders)
            if (isEnabled)
            {
                TryToScheduleNextReminder(now);
            }
        }
示例#3
0
        protected virtual void HandleStatusChange(bool wasEnabledBefore)
        {
            bool startedNow = !wasEnabledBefore && isEnabled;
            bool stoppedNow = wasEnabledBefore && !isEnabled;

            if (startedNow)
            {
                DateTime now = DateTime.UtcNow;
                TryToScheduleNextReminder(now);
                Log.Logger.Information($"Started NextReminderNotifier");
            }
            else if (stoppedNow)
            {
                NextReminderTimer.Stop();
                Log.Logger.Information($"Stopped NextReminderNotifier");
            }
            else
            {
                Log.Logger.Information($"NextReminderNotifier already {(isEnabled ? "started" : "stopped")}");
            }
        }