コード例 #1
0
        /// <summary>
        /// gets Weekends Schedules in a given list of schedules for the next 30 days
        /// canceled Schedules are ignored
        /// </summary>
        /// <param name="schedulesList">a IList contaning the schedules to parse</param>
        /// <returns>a collection containing the Weekends schedules</returns>
        private void getWeekendsSchedules(IList <Schedule> schedulesList, IList <Schedule> refFillList)
        {
            foreach (Schedule schedule in schedulesList)
            {
                ScheduleRecordingType scheduleType = (ScheduleRecordingType)schedule.ScheduleType;
                if (schedule.Canceled != Schedule.MinSchedule)
                {
                    continue;
                }
                if (scheduleType != ScheduleRecordingType.Weekends)
                {
                    continue;
                }
                DateTime tempDate;
                //  generate the weekly schedules for the next 30 days
                for (int i = 0; i <= 30; i++)
                {
                    tempDate = DateTime.Now.AddDays(i);
                    if (WeekEndTool.IsWeekend(tempDate.DayOfWeek) && (tempDate.Date >= schedule.StartTime.Date))
                    {
                        Schedule tempSchedule = schedule.Clone();

                        #region Set Schedule Time & Date

                        // adjusts Endtime for schedules that overlap 2 days (eg : 23:00 - 00:30)
                        if (tempSchedule.StartTime.Day != tempSchedule.EndTime.Day)
                        {
                            tempSchedule.StartTime = new DateTime(tempDate.Year, tempDate.Month, tempDate.Day,
                                                                  tempSchedule.StartTime.Hour, tempSchedule.StartTime.Minute,
                                                                  tempSchedule.StartTime.Second);
                            tempSchedule.EndTime = new DateTime(tempDate.Year, tempDate.Month, tempDate.Day, tempSchedule.EndTime.Hour,
                                                                tempSchedule.EndTime.Minute, tempSchedule.EndTime.Second);
                            tempSchedule.EndTime = tempSchedule.EndTime.AddDays(1);
                        }
                        else
                        {
                            tempSchedule.StartTime = new DateTime(tempDate.Year, tempDate.Month, tempDate.Day,
                                                                  tempSchedule.StartTime.Hour, tempSchedule.StartTime.Minute,
                                                                  tempSchedule.StartTime.Second);
                            tempSchedule.EndTime = new DateTime(tempDate.Year, tempDate.Month, tempDate.Day, tempSchedule.EndTime.Hour,
                                                                tempSchedule.EndTime.Minute, tempSchedule.EndTime.Second);
                        }

                        #endregion

                        refFillList.Add(tempSchedule);
                    } //if (_tempDate.DayOfWeek == _Schedule.StartTime.DayOfWeek && _tempDate >= _Schedule.StartTime)
                }     //for (int i = 0; i < 30; i++)
            }         //foreach (Schedule _Schedule in schedulesList)
            foreach (Schedule sched in refFillList)
            {
                schedulesList.Remove(sched);
            }
        }
        /// <summary>
        /// GetWakeupTime determines the wakeup time for a Schedule when no guide data is present
        /// Note that this obviously only works for the following ScheduleRecordingsType's:
        /// - Once
        /// - Daily
        /// - Weekends
        /// - WorkingDays
        /// - Weekly
        /// </summary>
        /// <param name="schedule">Schedule to determine next wakeup time for</param>
        /// <returns>DateTime indicating the wakeup time for this Schedule</returns>
        private static DateTime GetWakeupTime(Schedule schedule)
        {
            ScheduleRecordingType type = (ScheduleRecordingType)schedule.ScheduleType;
            DateTime now   = DateTime.Now;
            DateTime start = new DateTime(now.Year, now.Month, now.Day, schedule.StartTime.Hour, schedule.StartTime.Minute,
                                          schedule.StartTime.Second);
            DateTime stop = new DateTime(now.Year, now.Month, now.Day, schedule.EndTime.Hour, schedule.EndTime.Minute,
                                         schedule.EndTime.Second);

            switch (type)
            {
            case ScheduleRecordingType.Once:
                return(schedule.StartTime.AddMinutes(-schedule.PreRecordInterval));

            case ScheduleRecordingType.Daily:
                // if schedule was already due today, then run tomorrow
                if (now > stop.AddMinutes(schedule.PostRecordInterval))
                {
                    start = start.AddDays(1);
                }
                return(start.AddMinutes(-schedule.PreRecordInterval));

            case ScheduleRecordingType.Weekends:
                // check if it's a weekend currently
                if (WeekEndTool.IsWeekend(now.DayOfWeek))
                {
                    // check if schedule has been due already today
                    if (now > stop.AddMinutes(schedule.PostRecordInterval))
                    {
                        // if so, add appropriate days to wakeup time
                        start = WeekEndTool.IsFirstWeekendDay(now.DayOfWeek) ? start.AddDays(1) : start.AddDays(6);
                    }
                }
                else
                {
                    // it's not a weekend so calculate number of days to add to current time
                    int days = (int)WeekEndTool.FirstWeekendDay - (int)now.DayOfWeek;
                    start = start.AddDays(days);
                }
                return(start.AddMinutes(-schedule.PreRecordInterval));

            case ScheduleRecordingType.WorkingDays:
                // check if current time is in weekend; if so add appropriate number of days
                if (now.DayOfWeek == WeekEndTool.FirstWeekendDay)
                {
                    start = start.AddDays(2);
                }
                else if (now.DayOfWeek == WeekEndTool.SecondWeekendDay)
                {
                    start = start.AddDays(1);
                }
                else
                {
                    // current time is on a working days; check if schedule has already been due
                    if (now > stop.AddMinutes(schedule.PostRecordInterval))
                    {
                        // schedule has been due, so add appropriate number of days
                        start = now.DayOfWeek < (WeekEndTool.FirstWeekendDay - 1) ? start.AddDays(1) : start.AddDays(3);
                    }
                }
                return(start.AddMinutes(-schedule.PreRecordInterval));

            case ScheduleRecordingType.Weekly:
                // check if current day of week is same as schedule's day of week
                if (now.DayOfWeek == schedule.StartTime.DayOfWeek)
                {
                    // check if schedule has been due
                    if (now > stop.AddMinutes(schedule.PostRecordInterval))
                    {
                        // schedule has been due, so record again next week
                        start = start.AddDays(7);
                    }
                }
                else
                {
                    // current day of week isn't schedule's day of week, so
                    // add appropriate number of days
                    if (now.DayOfWeek < schedule.StartTime.DayOfWeek)
                    {
                        // schedule is due this week
                        int days = schedule.StartTime.DayOfWeek - now.DayOfWeek;
                        start = start.AddDays(days);
                    }
                    else
                    {
                        // schedule should start next week
                        int days = 7 - (now.DayOfWeek - schedule.StartTime.DayOfWeek);
                        start = start.AddDays(days);
                    }
                }
                return(start.AddMinutes(-schedule.PreRecordInterval));
            }
            // other recording types cannot be determined manually (every time on ...)
            return(DateTime.MaxValue);
        }