Exemplo n.º 1
0
 /// <summary>
 /// Finds the moment of the first occurence of a reminder in the future.
 /// Null only for non-repeating reminders from the past.
 /// </summary>
 public virtual DateTime?GetNextReminderOccurence(ReminderEntity reminder, DateTime now)
 {
     if (!reminder.IsRepeatable())
     {
         return(GetNextOccurenceOfNonRepeatingReminder(reminder, now));
     }
     else
     {
         return(GetNextOccurenceOfRepeatingReminder(reminder, now));
     }
 }
        //todo: all these return statements are risky, they prevent the only chance for the user the make next step and don't give him another chance. e.g. if snooze feautre is disabled while ringing form is open, and than user clicks snooze
        //todo: when component is disabled we skip all processing, not just going to next state, review this once more to bse sure that this is ok. Same for snooze, snooze elapsed,
        //todo: hide snooze button if that feature is disabled(Ringer can call service via WCF webservice to check is snooze is enabled), we will probably need to handle closing the form as dismiss, not snooze. We also need to prevent accidental closing of form on escape button.
        //todo: validation if reminders as paramters to dismiss and snooze, are indeed excepted (or we first expect some other), or just remove them (less safe)
        public void DismissReminder(ReminderEntity reminderEntity)
        {
            DateTime now = DateTime.UtcNow;

            if (UserState != UserInteractionState.WaitingUserResponse)
            {
                Log.Logger.Error($"Ignoring attempt to dismiss reminder [name = {reminderEntity.Name}] because current scheduler state is {UserState} instead od WaitingUserResponse");
                return;
            }

            // Protection of some kind of double dismis request (maybe by multiple ringing windows or something else) that would cause next occurance of reminder to be skipped
            if (!ValidateReminderShouldBeRinging(reminderEntity, now))
            {
                return;
            }

            if (reminderEntity.IsRepeatable())
            {
                //setting next ringing of the reminder on its first next occurence by its schedule
                DateTime nextReminderRinging = new NextReminderOccurenceCalculator().GetNextReminderOccurence(reminderEntity, now).Value;
                reminderEntity.ScheduledTime = nextReminderRinging;
            }
            else
            {
                reminderEntity.Dismissed = true;
            }

            ElapsedActiveReminders.RemoveAll(r => r.Name == reminderEntity.Name);

            //TODO: test this - we are here potenitally calling ringer again before response for Dismissing is returned.
            GoToRingingOrIdleState(now);

            //indirectly also triggers UpdateReminderList on this object //TODO: what are effects of that, probably none?
            //TODO: immediate notifying of this change to NextReminderNOtifier is not needed. Should it be prevented or it produces no harm, as it only gives us duplicate reminders here?
            FilePersistenceAdapters.RemiderFilePersistence.OnEntitesChanged();
        }