コード例 #1
0
        public void RemindStartOfWeek(Reminder startOfWeekReminder)
        {
            var dateToday = DateTime.Now;
            TimeSpan accumulatedTime = new TimeSpan(0, 0, 0);
            if (dateToday.ToString("ddd") == "Mon" && dateToday.Hour == startOfWeekReminder.TimeOfActivation.Hour && dateToday.Minute == startOfWeekReminder.TimeOfActivation.Minute ) //should get the hour from a reminder!dateToday.ToString("h tt") == "4 PM"
            {
                IRepository repo = new Repository();
                var startOfWeekTime = dateToday.AddDays(-7);
                //var dateTomorrow = dateToday.AddDays(1);

                var list = repo.GetByStartDate(startOfWeekTime, dateToday);

                foreach (SparkTask task in list)
                {
                    if(task.State != TaskState.reported){ accumulatedTime = accumulatedTime.Add(task.TimeElapsed); }
                }

                if (accumulatedTime >= new TimeSpan(36, 0, 0))
                {
                    ReminderEventArgs args = new ReminderEventArgs(startOfWeekReminder, new SparkTask()); //should be the reminder im using send the task can stay like this.
                    reminderControl.OnEventHaveToReport(args);
                    startOfWeekReminder.TimeOfActivation = startOfWeekReminder.TimeOfActivation.AddHours(1);
                    repo.Update(startOfWeekReminder);
                }

            }
        }
コード例 #2
0
        public void RemindEndOfWeek(Reminder endOfWeekReminder)
        {
            var dateToday = DateTime.Now;
            TimeSpan accumulatedTime = new TimeSpan(0,0,0);

            if (dateToday.ToString("ddd") == "Mon" && dateToday.Hour == endOfWeekReminder.TimeOfActivation.Hour && dateToday.Minute == endOfWeekReminder.TimeOfActivation.Minute)
            {
                IRepository repo = new Repository();
                var startOfWeekTime = dateToday.AddDays(-4);

                var list = repo.GetByStartDate(startOfWeekTime, dateToday);

                foreach(SparkTask task in list)
                {
                    if (task.State != TaskState.reported){ accumulatedTime = accumulatedTime.Add(task.TimeElapsed); }
                }

                if (accumulatedTime >= new TimeSpan(36, 0, 0))
                {
                    ReminderEventArgs args = new ReminderEventArgs(endOfWeekReminder, new SparkTask());
                    reminderControl.OnEventHaveToReport(args);
                    endOfWeekReminder.TimeOfActivation = endOfWeekReminder.TimeOfActivation.AddHours(1);
                    repo.Update(endOfWeekReminder);
                    //event!
                }
            }
        }
コード例 #3
0
 public void NotifyIntervalPassed(object obj, ReminderEventArgs args)
 {
     Console.WriteLine("{0} minutes have passed in the task: {1}, are you still working in the same task?", args.TheReminder.Interval, args.TheTask.Description);
 }
コード例 #4
0
        public void ActivateReminders()
        {
            IRepository repo = new Repository();
            StartTime = DateTime.Now;
            ActiveTaskProcess taskProcessor = new ActiveTaskProcess();
            ReportWeekReminder reportWeekReminder = new ReportWeekReminder();
            DailyReminders dailyReminders = new DailyReminders();

            while (true)
            {

                Thread.Sleep(60000);
                SparkLogic.Initialize();
                var listOfReminders = SparkLogic.ReturnReminderList();

                var timeElapsed = DateTime.Now - StartTime;
                var activeTask = repo.GetActiveTask();

                if (activeTask != null)
                {
                    taskProcessor.AddElapsedTime();
                }

                foreach (Reminder reminder in listOfReminders)
                {

                    ReminderEventArgs eventArgs = new ReminderEventArgs(reminder, activeTask);
                    ReminderControl reminderControl = new ReminderControl();

                    if (timeElapsed.Minutes >= 1)
                    {
                        if (timeElapsed.Minutes % reminder.Interval == 0 && activeTask == null && reminder.Type == ReminderType.NoActiveTask)
                        {
                            reminderControl.OnEventNoActiveTask(eventArgs);
                        }
                        if (timeElapsed.Minutes % reminder.Interval == 0 && activeTask != null && reminder.Type == ReminderType.DefaultHourly)
                        {
                            reminderControl.OnEventIntervalPassed(eventArgs);
                        }
                        if (reminder.Type==ReminderType.EndOfWeek) { reportWeekReminder.RemindEndOfWeek(reminder); }
                        if (reminder.Type==ReminderType.StartOfWeek) { reportWeekReminder.RemindStartOfWeek(reminder); }
                        if (reminder.Type == ReminderType.StartOfDay) { dailyReminders.RemindStartOfDay(reminder); }
                        if (reminder.Type == ReminderType.EndOfDay) { dailyReminders.RemindEndOfDay(reminder); }
                    }
                }
            }
        }
コード例 #5
0
 public void OnEventNoActiveTask(ReminderEventArgs args)
 {
     if (_eventNoActiveTask != null) { _eventNoActiveTask(this, args); }
 }
コード例 #6
0
 public void OnEventItIsTimeOfActivation(ReminderEventArgs args)
 {
     if (_eventItIsTimeOfActivation != null) { _eventItIsTimeOfActivation(this, args); }
 }
コード例 #7
0
 public void OnEventIntervalPassed(ReminderEventArgs args)
 {
     if (_eventIntervalPassed != null) { _eventIntervalPassed(this, args); }
 }
コード例 #8
0
 public void OnEventHaveToReport(ReminderEventArgs args)
 {
     if (_eventHaveToReportWeek != null) { _eventHaveToReportWeek(this, args); }
 }
コード例 #9
0
 public void NotifyLackOfActiveTask(object obj, ReminderEventArgs args)
 {
     Console.WriteLine("There is no Active Task.");
 }