private IMBotMessage DoCancelCommand(IMBotConversation conversation, IList <string> arguments, bool cancel) { if (arguments.Count == 0) { return(new IMBotMessage("Program number is missing.", IMBotMessage.ErrorColor)); } using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { UpcomingProgram upcomingRecording; IMBotMessage result = FindUpcomingRecording(tvSchedulerAgent, conversation, arguments, out upcomingRecording); if (result == null) { StringBuilder replyText = new StringBuilder(); if (cancel) { if (upcomingRecording.IsPartOfSeries) { tvSchedulerAgent.CancelUpcomingProgram(upcomingRecording.ScheduleId, upcomingRecording.GuideProgramId, upcomingRecording.Channel.ChannelId, upcomingRecording.StartTime); replyText.Append("Cancelled "); } else { tvSchedulerAgent.DeleteSchedule(upcomingRecording.ScheduleId); replyText.Append("Deleted schedule for "); } } else { tvSchedulerAgent.UncancelUpcomingProgram(upcomingRecording.ScheduleId, upcomingRecording.GuideProgramId, upcomingRecording.Channel.ChannelId, upcomingRecording.StartTime); replyText.Append("Uncancelled "); } Utility.AppendProgramDetails(replyText, upcomingRecording.Channel, upcomingRecording); replyText.Append("."); result = new IMBotMessage(replyText.ToString()); } return(result); } }
private IMBotMessage DoCancelCommand(IMBotConversation conversation, IList<string> arguments, bool cancel) { if (arguments.Count == 0) { return new IMBotMessage("Program number is missing.", IMBotMessage.ErrorColor); } using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { UpcomingProgram upcomingRecording; IMBotMessage result = FindUpcomingRecording(tvSchedulerAgent, conversation, arguments, out upcomingRecording); if (result == null) { StringBuilder replyText = new StringBuilder(); if (cancel) { if (upcomingRecording.IsPartOfSeries) { tvSchedulerAgent.CancelUpcomingProgram(upcomingRecording.ScheduleId, upcomingRecording.GuideProgramId, upcomingRecording.Channel.ChannelId, upcomingRecording.StartTime); replyText.Append("Cancelled "); } else { tvSchedulerAgent.DeleteSchedule(upcomingRecording.ScheduleId); replyText.Append("Deleted schedule for "); } } else { tvSchedulerAgent.UncancelUpcomingProgram(upcomingRecording.ScheduleId, upcomingRecording.GuideProgramId, upcomingRecording.Channel.ChannelId, upcomingRecording.StartTime); replyText.Append("Uncancelled "); } Utility.AppendProgramDetails(replyText, upcomingRecording.Channel, upcomingRecording); replyText.Append("."); result = new IMBotMessage(replyText.ToString()); } return result; } }
internal static bool RecordProgram(Channel channel, GuideProgram guideProgram, ScheduleType scheduleType, bool NeedConfirm) { Log.Debug("TVProgammInfo.RecordProgram - channel = {0}, program = {1}", channel.DisplayName, guideProgram.CreateProgramTitle()); using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { bool hasUpcomingRecording = false; bool hasUpcomingAlert = false; if (scheduleType == ScheduleType.Recording) { UpcomingRecording upcomingRecording; if (HasUpcomingRecording(channel.ChannelId, guideProgram, out upcomingRecording)) { hasUpcomingRecording = true; if (upcomingRecording.Program.IsCancelled) { switch (upcomingRecording.Program.CancellationReason) { case UpcomingCancellationReason.Manual: tvSchedulerAgent.UncancelUpcomingProgram(upcomingRecording.Program.ScheduleId, guideProgram.GuideProgramId, channel.ChannelId, guideProgram.StartTime); return true; case UpcomingCancellationReason.AlreadyQueued: { GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK); dlg.Reset(); dlg.SetHeading(Utility.GetLocalizedText(TextId.Record)); dlg.SetLine(1, Utility.GetLocalizedText(TextId.ThisProgramIsAlreadyQueued)); dlg.SetLine(2, Utility.GetLocalizedText(TextId.ForRecordingAtAnEarlierTime)); dlg.DoModal(GUIWindowManager.ActiveWindow); } break; case UpcomingCancellationReason.PreviouslyRecorded: { GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK); dlg.Reset(); dlg.SetHeading(Utility.GetLocalizedText(TextId.Record)); dlg.SetLine(1, Utility.GetLocalizedText(TextId.ThisProgramWasPreviouslyRecorded)); dlg.DoModal(GUIWindowManager.ActiveWindow); } break; } } else { if (upcomingRecording.Program.IsPartOfSeries) { GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); if (dlg != null) { dlg.Reset(); dlg.SetHeading(Utility.GetLocalizedText(TextId.DeleteProgram)); dlg.Add(Utility.GetLocalizedText(TextId.CancelThisShow)); dlg.Add(Utility.GetLocalizedText(TextId.DeleteEntireSchedule)); dlg.DoModal(GUIWindowManager.ActiveWindow); if (dlg.SelectedId > 0) { switch (dlg.SelectedLabel) { case 0: // Cancel tvSchedulerAgent.CancelUpcomingProgram(upcomingRecording.Program.ScheduleId, guideProgram.GuideProgramId, channel.ChannelId, guideProgram.StartTime); return true; case 1: // Delete Schedule schedule = tvSchedulerAgent.GetScheduleById(upcomingRecording.Program.ScheduleId); if (schedule != null) { GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO); if (dlgYesNo != null) { dlgYesNo.SetHeading(Utility.GetLocalizedText(TextId.DeleteEntireSchedule)); dlgYesNo.SetLine(1, "\"" + schedule.Name + "\""); dlgYesNo.SetLine(2, Utility.GetLocalizedText(TextId.AreYouSure)); dlgYesNo.SetLine(3, String.Empty); dlgYesNo.SetDefaultToYes(false); dlgYesNo.DoModal(GUIWindowManager.ActiveWindow); if (dlgYesNo.IsConfirmed) { tvSchedulerAgent.DeleteSchedule(upcomingRecording.Program.ScheduleId); return true; } } } break; } } } } else { if (PluginMain.IsActiveRecording(channel.ChannelId, guideProgram)) { GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO); if (dlgYesNo != null) { dlgYesNo.SetHeading(Utility.GetLocalizedText(TextId.StopRecording)); dlgYesNo.SetLine(1, channel.DisplayName); dlgYesNo.SetLine(2, guideProgram.Title); dlgYesNo.SetLine(3, string.Empty); dlgYesNo.SetDefaultToYes(false); dlgYesNo.DoModal(GUIWindowManager.ActiveWindow); if (!dlgYesNo.IsConfirmed) { return false; } } } else if (PluginMain.IsActiveRecording(channel.ChannelId, guideProgram) == false && NeedConfirm) { GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO); if (dlgYesNo != null) { dlgYesNo.SetHeading(Utility.GetLocalizedText(TextId.DontRecord)); dlgYesNo.SetLine(1, channel.DisplayName); dlgYesNo.SetLine(2, guideProgram.Title); dlgYesNo.SetLine(3, string.Empty); dlgYesNo.SetDefaultToYes(true); dlgYesNo.DoModal(GUIWindowManager.ActiveWindow); if (!dlgYesNo.IsConfirmed) { return false; } } } tvSchedulerAgent.DeleteSchedule(upcomingRecording.Program.ScheduleId); return true; } } } } else if (scheduleType == ScheduleType.Alert) { UpcomingProgram upcomingProgram; if (HasUpcomingProgram(channel.ChannelId, guideProgram, out upcomingProgram, scheduleType)) { hasUpcomingAlert = true; if (upcomingProgram.IsCancelled) { switch (upcomingProgram.CancellationReason) { case UpcomingCancellationReason.Manual: tvSchedulerAgent.UncancelUpcomingProgram(upcomingProgram.ScheduleId, guideProgram.GuideProgramId, channel.ChannelId, guideProgram.StartTime); return true; case UpcomingCancellationReason.AlreadyQueued: { GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK); dlg.Reset(); dlg.SetHeading(Utility.GetLocalizedText(TextId.Record)); dlg.SetLine(1, Utility.GetLocalizedText(TextId.ThisProgramIsAlreadyQueued)); dlg.SetLine(2, Utility.GetLocalizedText(TextId.ForRecordingAtAnEarlierTime)); dlg.DoModal(GUIWindowManager.ActiveWindow); } break; case UpcomingCancellationReason.PreviouslyRecorded: { GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK); dlg.Reset(); dlg.SetHeading(Utility.GetLocalizedText(TextId.Record)); dlg.SetLine(1, Utility.GetLocalizedText(TextId.ThisProgramWasPreviouslyRecorded)); dlg.DoModal(GUIWindowManager.ActiveWindow); } break; } } else { if (upcomingProgram.IsPartOfSeries) { GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); if (dlg != null) { dlg.Reset(); dlg.SetHeading(Utility.GetLocalizedText(TextId.DeleteProgram)); dlg.Add(Utility.GetLocalizedText(TextId.CancelThisShow)); dlg.Add(Utility.GetLocalizedText(TextId.DeleteEntireSchedule)); dlg.DoModal(GUIWindowManager.ActiveWindow); if (dlg.SelectedId > 0) { switch (dlg.SelectedLabel) { case 0: // Cancel tvSchedulerAgent.CancelUpcomingProgram(upcomingProgram.ScheduleId, guideProgram.GuideProgramId, channel.ChannelId, guideProgram.StartTime); return true; case 1: // Delete Schedule schedule = tvSchedulerAgent.GetScheduleById(upcomingProgram.ScheduleId);//GetScheduleById(upcomingRecording.Program.ScheduleId); if (schedule != null) { GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO); if (dlgYesNo != null) { dlgYesNo.SetHeading(Utility.GetLocalizedText(TextId.DeleteEntireSchedule)); dlgYesNo.SetLine(1, "\"" + schedule.Name + "\""); dlgYesNo.SetLine(2, Utility.GetLocalizedText(TextId.AreYouSure)); dlgYesNo.SetLine(3, String.Empty); dlgYesNo.SetDefaultToYes(false); dlgYesNo.DoModal(GUIWindowManager.ActiveWindow); if (dlgYesNo.IsConfirmed) { tvSchedulerAgent.DeleteSchedule(upcomingProgram.ScheduleId); return true; } } } break; } } } } else { if (NeedConfirm) { GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO); if (dlgYesNo != null) { dlgYesNo.SetHeading(Utility.GetLocalizedText(TextId.DontRecord)); dlgYesNo.SetLine(1, channel.DisplayName); dlgYesNo.SetLine(2, guideProgram.Title); dlgYesNo.SetLine(3, string.Empty); dlgYesNo.SetDefaultToYes(true); dlgYesNo.DoModal(GUIWindowManager.ActiveWindow); if (!dlgYesNo.IsConfirmed) { return false; } } } tvSchedulerAgent.DeleteSchedule(upcomingProgram.ScheduleId); return true; } } } } if (!hasUpcomingRecording && !hasUpcomingAlert) { GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); if (dlg != null) { Schedule newSchedule = null; GuideController.RepeatingType dayRepeatingType; dlg.Reset(); dlg.SetHeading(Utility.GetLocalizedText(TextId.SelectScheduleType)); dlg.Add(Utility.GetLocalizedText(TextId.Once)); dlg.Add(Utility.GetLocalizedText(TextId.EverytimeOnThisChannel)); dlg.Add(Utility.GetLocalizedText(TextId.EverytimeOnEveryChannel)); dlg.Add(Utility.GetLocalizedText(TextId.EveryWeekAtThisTime)); dlg.Add(Utility.GetLocalizedText(TextId.EveryDayAtThisTime)); if (guideProgram.StartTime.DayOfWeek == DayOfWeek.Saturday || guideProgram.StartTime.DayOfWeek == DayOfWeek.Sunday) { dayRepeatingType = GuideController.RepeatingType.SatSun; dlg.Add(Utility.GetLocalizedText(TextId.SatSun)); } else { dayRepeatingType = GuideController.RepeatingType.MonFri; dlg.Add(Utility.GetLocalizedText(TextId.MonFri)); } dlg.DoModal(GUIWindowManager.ActiveWindow); switch (dlg.SelectedLabel) { case 0: //once newSchedule = GuideController.CreateRecordOnceSchedule(tvSchedulerAgent, channel.ChannelType, channel.ChannelId, guideProgram.Title, guideProgram.SubTitle, guideProgram.EpisodeNumberDisplay, guideProgram.StartTime); break; case 1: //everytime, this channel newSchedule = GuideController.CreateRecordRepeatingSchedule(tvSchedulerAgent, GuideController.RepeatingType.AnyTimeThisChannel, channel.ChannelType, channel.ChannelId, guideProgram.Title, guideProgram.StartTime, "(" + Utility.GetLocalizedText(TextId.AlwaysThisChannel) + ")"); ScheduleRule newEpisodesRule = FindNewEpisodesOnlyRule(newSchedule); if (newEpisodesRule != null) { newEpisodesRule.Arguments[0] = false; } break; case 2: //everytime, any channel newSchedule = GuideController.CreateRecordRepeatingSchedule(tvSchedulerAgent, GuideController.RepeatingType.AnyTime, channel.ChannelType, null, guideProgram.Title, guideProgram.StartTime, "(" + Utility.GetLocalizedText(TextId.AlwaysEveryChannel) + ")"); ScheduleRule newEpisodesRule2 = FindNewEpisodesOnlyRule(newSchedule); if (newEpisodesRule2 != null) { newEpisodesRule2.Arguments[0] = false; } break; case 3: //weekly newSchedule = GuideController.CreateRecordRepeatingSchedule(tvSchedulerAgent, GuideController.RepeatingType.Weekly, channel.ChannelType, channel.ChannelId, guideProgram.Title, guideProgram.StartTime, "(" + Utility.GetLocalizedText(TextId.Weekly) + ")"); break; case 4: //daily newSchedule = GuideController.CreateRecordRepeatingSchedule(tvSchedulerAgent, GuideController.RepeatingType.Daily, channel.ChannelType, channel.ChannelId, guideProgram.Title, guideProgram.StartTime, "(" + Utility.GetLocalizedText(TextId.Daily) + ")"); break; case 5: //Mon-Fri or Sat-Sun string repeatingTime = string.Empty; if (dayRepeatingType == GuideController.RepeatingType.MonFri) { repeatingTime = "(" + Utility.GetLocalizedText(TextId.MonFri) + ")"; } else if (dayRepeatingType == GuideController.RepeatingType.SatSun) { repeatingTime = "(" + Utility.GetLocalizedText(TextId.SatSun) + ")"; } newSchedule = GuideController.CreateRecordRepeatingSchedule(tvSchedulerAgent, dayRepeatingType, channel.ChannelType, channel.ChannelId, guideProgram.Title, guideProgram.StartTime, repeatingTime); break; } if (newSchedule != null) { newSchedule.ScheduleType = scheduleType; tvSchedulerAgent.SaveSchedule(newSchedule); return true; } } } return false; } }