public GetRecordingTimes ( TvDatabase.Schedule rec ) : List |
||
rec | TvDatabase.Schedule | |
Résultat | List |
public DateTime GetNextWakeupTime(DateTime earliestWakeupTime) { TvBusinessLayer layer = new TvBusinessLayer(); Schedule recSchedule = null; DateTime scheduleWakeupTime = DateTime.MaxValue; DateTime nextWakeuptime = DateTime.MaxValue; foreach (Schedule schedule in Schedule.ListAll()) { if (schedule.Canceled != Schedule.MinSchedule) continue; List<Schedule> schedules = layer.GetRecordingTimes(schedule); if (schedules.Count > 0) { int i = 0; // Take first occurrence of this schedule if not a canceled serie while (i < schedules.Count) { recSchedule = schedules[i]; if (!recSchedule.IsSerieIsCanceled(recSchedule.StartTime)) break; i++; } if (recSchedule != null) { scheduleWakeupTime = recSchedule.StartTime.AddMinutes(-recSchedule.PreRecordInterval); } } if (recSchedule == null) { // manually determine schedule's wakeup time of no guide data is present scheduleWakeupTime = GetWakeupTime(schedule); } if (scheduleWakeupTime < nextWakeuptime && scheduleWakeupTime >= earliestWakeupTime) nextWakeuptime = scheduleWakeupTime; } return nextWakeuptime; }
public static void CreateProgram(Program program, int scheduleType, int dialogId) { Log.Debug("TVProgramInfo.CreateProgram: program = {0}", program.ToString()); Schedule schedule; Schedule saveSchedule = null; TvBusinessLayer layer = new TvBusinessLayer(); if (IsRecordingProgram(program, out schedule, false)) // check if schedule is already existing { Log.Debug("TVProgramInfo.CreateProgram - series schedule found ID={0}, Type={1}", schedule.IdSchedule, schedule.ScheduleType); Log.Debug(" - schedule= {0}", schedule.ToString()); //schedule = Schedule.Retrieve(schedule.IdSchedule); // get the correct informations if (schedule.IsSerieIsCanceled(schedule.GetSchedStartTimeForProg(program), program.IdChannel)) { //lets delete the cancelled schedule. saveSchedule = schedule; schedule = new Schedule(program.IdChannel, program.Title, program.StartTime, program.EndTime); schedule.PreRecordInterval = saveSchedule.PreRecordInterval; schedule.PostRecordInterval = saveSchedule.PostRecordInterval; schedule.ScheduleType = (int)ScheduleRecordingType.Once; // needed for layer.GetConflictingSchedules(...) } } else { Log.Debug("TVProgramInfo.CreateProgram - no series schedule"); // no series schedule => create it schedule = new Schedule(program.IdChannel, program.Title, program.StartTime, program.EndTime); schedule.PreRecordInterval = Int32.Parse(layer.GetSetting("preRecordInterval", "5").Value); schedule.PostRecordInterval = Int32.Parse(layer.GetSetting("postRecordInterval", "5").Value); schedule.ScheduleType = scheduleType; } // check if this program is conflicting with any other already scheduled recording IList conflicts = layer.GetConflictingSchedules(schedule); Log.Debug("TVProgramInfo.CreateProgram - conflicts.Count = {0}", conflicts.Count); TvServer server = new TvServer(); bool skipConflictingEpisodes = false; if (conflicts.Count > 0) { TVConflictDialog dlg = (TVConflictDialog)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_TVCONFLICT); if (dlg != null) { dlg.Reset(); dlg.SetHeading(GUILocalizeStrings.Get(879)); // "recording conflict" foreach (Schedule conflict in conflicts) { Log.Debug("TVProgramInfo.CreateProgram: Conflicts = " + conflict); GUIListItem item = new GUIListItem(conflict.ProgramName); item.Label2 = GetRecordingDateTime(conflict); Channel channel = Channel.Retrieve(conflict.IdChannel); if (channel != null && !string.IsNullOrEmpty(channel.DisplayName)) { item.Label3 = channel.DisplayName; } else { item.Label3 = conflict.IdChannel.ToString(); } item.TVTag = conflict; dlg.AddConflictRecording(item); } dlg.ConflictingEpisodes = (scheduleType != (int)ScheduleRecordingType.Once); dlg.DoModal(dialogId); switch (dlg.SelectedLabel) { case 0: // Skip new Recording { Log.Debug("TVProgramInfo.CreateProgram: Skip new recording"); return; } case 1: // Don't record the already scheduled one(s) { Log.Debug("TVProgramInfo.CreateProgram: Skip old recording(s)"); foreach (Schedule conflict in conflicts) { Program prog = new Program(conflict.IdChannel, conflict.StartTime, conflict.EndTime, conflict.ProgramName, "-", "-", Program.ProgramState.None, DateTime.MinValue, string.Empty, string.Empty, string.Empty, string.Empty, -1, string.Empty, -1); CancelProgram(prog, Schedule.Retrieve(conflict.IdSchedule), dialogId); } break; } case 2: // keep conflict { Log.Debug("TVProgramInfo.CreateProgram: Keep Conflict"); break; } case 3: // Skip for conflicting episodes { Log.Debug("TVProgramInfo.CreateProgram: Skip conflicting episode(s)"); skipConflictingEpisodes = true; break; } default: // Skipping new Recording { Log.Debug("TVProgramInfo.CreateProgram: Default => Skip new recording"); return; } } } } if (saveSchedule != null) { Log.Debug("TVProgramInfo.CreateProgram - UnCancleSerie at {0}", program.StartTime); saveSchedule.UnCancelSerie(program.StartTime, program.IdChannel); //saveSchedule.UnCancelSerie(); saveSchedule.Persist(); currentSchedule = saveSchedule; } else { Log.Debug("TVProgramInfo.CreateProgram - create schedule = {0}", schedule.ToString()); schedule.Persist(); if (currentSchedule == null || (currentSchedule.ScheduleType > 0 && schedule.ScheduleType != (int)ScheduleRecordingType.Once)) { currentSchedule = schedule; } } if (skipConflictingEpisodes) { List<Schedule> episodes = layer.GetRecordingTimes(schedule); foreach (Schedule episode in episodes) { if (DateTime.Now > episode.EndTime) { continue; } if (episode.IsSerieIsCanceled(episode.StartTime, program.IdChannel)) { continue; } foreach (Schedule conflict in conflicts) { if (episode.IsOverlapping(conflict)) { Log.Debug("TVProgramInfo.CreateProgram - skip episode = {0}", episode.ToString()); CanceledSchedule canceledSchedule = new CanceledSchedule(schedule.IdSchedule, program.IdChannel, episode.StartTime); canceledSchedule.Persist(); } } } } server.OnNewSchedule(); }