Example #1
0
        /// <summary>
        /// When running timer, stops timer, replans, configures timer, runs it(if planned)
        /// </summary>
        /// <exception cref="ArgumentNullException">ActionProc not setted</exception>
        public void Resume()
        {
            if (!_task.EnableScheduling)
            {
                return;
            }
            if (!_actionTimer.Enabled)
            {
                return;
            }

            double   difference = -1;
            DateTime now        = DateTime.Now;

            _zeroHour = new DateTime(now.Year, now.Month, now.Day, _task.Hours, _task.Minutes, 0);

            if (_task.IsThisDayOfWeekScheduled(_zeroHour.DayOfWeek))
            {
                difference = _zeroHour.Subtract(now).TotalMilliseconds;
            }
            else
            {
                // this day cannot be scheduled
                difference = -1;
            }

            while (difference < 0)
            {
                // here we're searching for scheduled time
                do
                {
                    _zeroHour = _zeroHour.AddDays(1);
                }while (!_task.IsThisDayOfWeekScheduled(_zeroHour.DayOfWeek));

                difference = _zeroHour.Subtract(now).TotalMilliseconds;
            }

            _actionTimer.Interval = _TIMER_PERIOD_IN_SECONDS;

            lock (this)
            {
                _actionTimer.Enabled = true;
            }
        }
        public override void SetOptionsToUi(object settings)
        {
            _task = (BackupTask)settings;

            foreach (DayOfWeek enumItem in DayOfWeek.GetValues(typeof(DayOfWeek)))
            {
                scheduledDaysCheckedListBox.SetItemChecked((int)enumItem, _task.IsThisDayOfWeekScheduled(enumItem));
            }

            hourComboBox.SelectedIndex   = _task.Hours;
            minuteComboBox.SelectedIndex = _task.Minutes;
        }