Пример #1
0
        public TimerLogic()
        {
            m_timer = new Timer();
            m_timer.Interval = m_tick;

            m_timer.Tick += delegate
            {
                m_log.Debug("Tick event happened");
                m_timer.Stop();
                // Commented until find bugs
            //				if(MousePositionHelper.MouseNotMoving == false)
            //				{
                    List<Task> tasksToShow = new DbHelper().LoadTasksForShowing();
                    m_log.DebugFormat("Loaded {0} tasks for showing", tasksToShow.Count);
                    foreach (Task task in tasksToShow)
                    {
                        new TaskShowController(task).PrepareWindow(); //Įkėliau viską į preparerį.
                        m_log.DebugFormat("Showed task with id {0}, name {1}, showTime {2}",
                                          task.Id, task.Text, DBTypesConverter.ToFullDateStringByCultureInfo(task.DateRemainder));
                    }
            //				}

                SetNewTimerInterval();
                m_timer.Start();
            };

            m_timer.Start();
        }
Пример #2
0
 public void SetNewTimerInterval()
 {
     int interval = new DbHelper().SelectNextInterval();
     if (interval < 0)
         interval = m_sleepTick;
     if (interval == 0)
         interval = 1;
     m_log.DebugFormat("Picked new timer interval which is {0} ms ({1} min.)",
                       interval, RoundHelper.Round(interval / 1000.0m / 60.0m, 2));
     m_timer.Interval = interval;
 }
Пример #3
0
        public string FormatNextTaskRemindingDate()
        {
            int maxTimeTextLength = 38; // Text length without task description
            int maxLength = 64; // for NotifyIcon.Text property it's maximum
            int maxTaskNameLength = maxLength - maxTimeTextLength;
            string text = "Nothing to be mindered about";
            Task nextTask = new DbHelper().NextTaskToShow();
            if (nextTask == null)
                return text;
            if (string.IsNullOrEmpty(nextTask.Text) == false
                && nextTask.Text.Length > maxTaskNameLength)
                nextTask.Text = nextTask.Text.Substring(0, maxTaskNameLength);
            DateTime? nextDate = nextTask.DateRemainder;
            if (nextDate.HasValue == false)
                return text;

            text = string.Format("Task {0} minders at {1}", nextTask.Text, DBTypesConverter.ToFullDateStringByCultureInfo(nextDate.Value));
            TimeSpan difference = nextDate.Value.Subtract(DateTime.Now);

            decimal days = RoundHelper.Round((decimal)difference.TotalDays, 0);
            if (days < 1)
                text = string.Format("Task {0} minders at {1}", nextTask.Text, nextDate.Value.ToShortTimeString());

            decimal minutes = RoundHelper.Round((decimal)difference.TotalMinutes, 0);
            if (difference.TotalHours < 1)
                text = string.Format("Task {0} minders in {1} minutes", nextTask.Text, minutes);
            if (minutes < 1)
                text = (string.Format("Task {0} minders in less than a minute", nextTask.Text));
            return text;
        }