private void Onrecord(ScheduleType scheduleType) { Schedule schedule = null; if (_upcomingProgram != null) { schedule = SchedulerAgent.GetScheduleById(_upcomingProgram.ScheduleId); } if (_upcomingProgram != null && schedule != null && schedule.ScheduleType == scheduleType)//delete schedule { if (_upcomingProgram.IsCancelled) { SchedulerAgent.UncancelUpcomingProgram(_upcomingProgram.ScheduleId, _upcomingProgram.GuideProgramId, _upcomingProgram.Channel.ChannelId, _upcomingProgram.StartTime); try { //refresh _upcomingProgram _upcomingProgram = SchedulerAgent.GetUpcomingPrograms(schedule, true)[0]; } catch { } } else { if (_upcomingProgram.IsPartOfSeries) { 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) { SchedulerAgent.DeleteSchedule(schedule.ScheduleId); _upcomingProgram = null; } } } else { SchedulerAgent.DeleteSchedule(_upcomingProgram.ScheduleId); _upcomingProgram = null; } } } else//create new schedule { TimeSpan duration = new TimeSpan(Int32.Parse(_spinHoursDuration.GetLabel()), Int32.Parse(_spinMinutesDuration.GetLabel()), 0); DateTime startTime = new DateTime(Int32.Parse(_spinStartYear.GetLabel()), Int32.Parse(_spinStartMonth.GetLabel()), Int32.Parse(_spinStartDay.GetLabel()), Int32.Parse(_spinStartHour.GetLabel()), Int32.Parse(_spinStartMinute.GetLabel()), 0); ScheduleDaysOfWeek daysOfWeek = new ScheduleDaysOfWeek(); //TODO: What if we have multiple channels with the same name Channel channel = SchedulerAgent.GetChannelByDisplayName(_channelType, _spinChannel.GetLabel()); Schedule newSchedule = null; newSchedule = SchedulerAgent.CreateNewSchedule(_channelType, scheduleType); newSchedule.Rules.Add(ScheduleRuleType.Channels, channel.ChannelId); newSchedule.Rules.Add(ScheduleRuleType.ManualSchedule, startTime, new ScheduleTime(duration)); if (!_recordOnce) { string days = " "; if (_mondayButton.Selected) { daysOfWeek = daysOfWeek | ScheduleDaysOfWeek.Mondays; days += Utility.GetLocalizedText(TextId.Mon) + ","; } if (_tuesdayButton.Selected) { daysOfWeek = daysOfWeek | ScheduleDaysOfWeek.Tuesdays; days += Utility.GetLocalizedText(TextId.Tue) + ","; } if (_wednesdayButton.Selected) { daysOfWeek = daysOfWeek | ScheduleDaysOfWeek.Wednesdays; days += Utility.GetLocalizedText(TextId.Wed) + ","; } if (_thursdayButton.Selected) { daysOfWeek = daysOfWeek | ScheduleDaysOfWeek.Thursdays; days += Utility.GetLocalizedText(TextId.Thu) + ","; } if (_fridayButton.Selected) { daysOfWeek = daysOfWeek | ScheduleDaysOfWeek.Fridays; days += Utility.GetLocalizedText(TextId.Fri) + ","; } if (_saturdayButton.Selected) { daysOfWeek = daysOfWeek | ScheduleDaysOfWeek.Saturdays; days += Utility.GetLocalizedText(TextId.Sat) + ","; } if (_sundayButton.Selected) { daysOfWeek = daysOfWeek | ScheduleDaysOfWeek.Sundays; days += Utility.GetLocalizedText(TextId.Sun) + ","; } days = days.Remove(days.Length - 1); newSchedule.Rules.Add(ScheduleRuleType.DaysOfWeek, daysOfWeek); newSchedule.Name = String.Format(CultureInfo.CurrentCulture, "{0} {1} {2:t}-{3:t}", channel.DisplayName, days, startTime, startTime.Add(duration)); } else { newSchedule.Name = String.Format(CultureInfo.CurrentCulture, "{0} {1:g}-{2:t}", channel.DisplayName, startTime, startTime.Add(duration)); } //TODO: try to prevent dublicate manual schedules //and find a better way to get the newly created "_schedule" and "_upcomingProgram" if (newSchedule != null) { newSchedule.ScheduleType = scheduleType; SchedulerAgent.SaveSchedule(newSchedule); bool found = false; UpcomingProgram[] _programs = SchedulerAgent.GetAllUpcomingPrograms(scheduleType, true); foreach (UpcomingProgram _prog in _programs) { if (_prog.Channel.ChannelId == channel.ChannelId && _prog.Duration == duration && !found) { Schedule _schedule = SchedulerAgent.GetScheduleById(_prog.ScheduleId); if (_schedule.Rules.FindRuleByType(ScheduleRuleType.ManualSchedule) != null) { if (_schedule.Name == newSchedule.Name) { if (_recordOnce && _prog.StartTime == startTime) { _upcomingProgram = _prog; found = true; } else if (!_recordOnce && _schedule.Rules.FindRuleByType(ScheduleRuleType.DaysOfWeek) != null && _schedule.Rules.FindRuleByType(ScheduleRuleType.DaysOfWeek).Arguments[0].ToString() == daysOfWeek.ToString() && Convert.ToDateTime(_schedule.Rules.FindRuleByType(ScheduleRuleType.ManualSchedule).Arguments[0]) == startTime) { _upcomingProgram = _prog; found = true; } Update(_schedule); break; } } } } if (!found) { GUIWindowManager.ShowPreviousWindow(); } } } }
private void Onrecord(ScheduleType scheduleType) { Schedule schedule = null; if (_upcomingProgram != null) { schedule = Proxies.SchedulerService.GetScheduleById(_upcomingProgram.ScheduleId).Result; } if (_upcomingProgram != null && schedule != null && schedule.ScheduleType == scheduleType) //delete schedule { if (_upcomingProgram.IsCancelled) { Proxies.SchedulerService.UncancelUpcomingProgram(_upcomingProgram.ScheduleId, _upcomingProgram.GuideProgramId, _upcomingProgram.Channel.ChannelId, _upcomingProgram.StartTime).Wait(); try { //refresh _upcomingProgram _upcomingProgram = Proxies.SchedulerService.GetUpcomingPrograms(schedule, true).Result[0]; } catch { } } else { if (_upcomingProgram.IsPartOfSeries) { 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) { Proxies.SchedulerService.DeleteSchedule(schedule.ScheduleId).Wait(); _upcomingProgram = null; } } } else { Proxies.SchedulerService.DeleteSchedule(_upcomingProgram.ScheduleId).Wait(); _upcomingProgram = null; } } } else//create new schedule { TimeSpan duration = new TimeSpan(Int32.Parse(_spinHoursDuration.GetLabel()), Int32.Parse(_spinMinutesDuration.GetLabel()), 0); DateTime startTime = new DateTime(Int32.Parse(_spinStartYear.GetLabel()), Int32.Parse(_spinStartMonth.GetLabel()), Int32.Parse(_spinStartDay.GetLabel()), Int32.Parse(_spinStartHour.GetLabel()), Int32.Parse(_spinStartMinute.GetLabel()), 0); ScheduleDaysOfWeek daysOfWeek = new ScheduleDaysOfWeek(); //TODO: What if we have multiple channels with the same name Channel channel = Proxies.SchedulerService.GetChannelByDisplayName(_channelType, _spinChannel.GetLabel()).Result; Schedule newSchedule = null; newSchedule = Proxies.SchedulerService.CreateNewSchedule(_channelType, scheduleType).Result; newSchedule.Rules.Add(ScheduleRuleType.Channels, channel.ChannelId); newSchedule.Rules.Add(ScheduleRuleType.ManualSchedule, startTime, new ScheduleTime(duration)); if (!_recordOnce) { string days = " "; if (_mondayButton.Selected) { daysOfWeek = daysOfWeek | ScheduleDaysOfWeek.Mondays; days += Utility.GetLocalizedText(TextId.Mon) + ","; } if (_tuesdayButton.Selected) { daysOfWeek = daysOfWeek | ScheduleDaysOfWeek.Tuesdays; days += Utility.GetLocalizedText(TextId.Tue) + ","; } if (_wednesdayButton.Selected) { daysOfWeek = daysOfWeek | ScheduleDaysOfWeek.Wednesdays; days += Utility.GetLocalizedText(TextId.Wed) + ","; } if (_thursdayButton.Selected) { daysOfWeek = daysOfWeek | ScheduleDaysOfWeek.Thursdays; days += Utility.GetLocalizedText(TextId.Thu) + ","; } if (_fridayButton.Selected) { daysOfWeek = daysOfWeek | ScheduleDaysOfWeek.Fridays; days += Utility.GetLocalizedText(TextId.Fri) + ","; } if (_saturdayButton.Selected) { daysOfWeek = daysOfWeek | ScheduleDaysOfWeek.Saturdays; days += Utility.GetLocalizedText(TextId.Sat) + ","; } if (_sundayButton.Selected) { daysOfWeek = daysOfWeek | ScheduleDaysOfWeek.Sundays; days += Utility.GetLocalizedText(TextId.Sun) + ","; } days = days.Remove(days.Length - 1); newSchedule.Rules.Add(ScheduleRuleType.DaysOfWeek, daysOfWeek); newSchedule.Name = String.Format(CultureInfo.CurrentCulture, "{0} {1} {2:t}-{3:t}", channel.DisplayName, days, startTime, startTime.Add(duration)); } else { newSchedule.Name = String.Format(CultureInfo.CurrentCulture, "{0} {1:g}-{2:t}", channel.DisplayName, startTime, startTime.Add(duration)); } //TODO: try to prevent dublicate manual schedules //and find a better way to get the newly created "_schedule" and "_upcomingProgram" if (newSchedule != null) { newSchedule.ScheduleType = scheduleType; Proxies.SchedulerService.SaveSchedule(newSchedule).Wait(); bool found = false; var _programs = Proxies.SchedulerService.GetAllUpcomingPrograms(scheduleType, true).Result; foreach (UpcomingProgram _prog in _programs) { if (_prog.Channel.ChannelId == channel.ChannelId && _prog.Duration == duration && !found) { Schedule _schedule = Proxies.SchedulerService.GetScheduleById(_prog.ScheduleId).Result; if (_schedule.Rules.FindRuleByType(ScheduleRuleType.ManualSchedule) != null) { if (_schedule.Name == newSchedule.Name) { if (_recordOnce && _prog.StartTime == startTime) { _upcomingProgram = _prog; found = true; } else if (!_recordOnce && _schedule.Rules.FindRuleByType(ScheduleRuleType.DaysOfWeek) != null && _schedule.Rules.FindRuleByType(ScheduleRuleType.DaysOfWeek).Arguments[0].ToString() == daysOfWeek.ToString() && Convert.ToDateTime(_schedule.Rules.FindRuleByType(ScheduleRuleType.ManualSchedule).Arguments[0]) == startTime) { _upcomingProgram = _prog; found = true; } Update(_schedule); break; } } } } if (!found) { GUIWindowManager.ShowPreviousWindow(); } } } }