protected virtual async Task <RecordingStatus?> CreateSchedule(IProgram program, ScheduleRecordingType recordingType = ScheduleRecordingType.Once) { IScheduleControlAsync scheduleControl = _tvHandler.ScheduleControl; RecordingStatus? newStatus = null; if (scheduleControl != null) { RecordingStatus?recordingStatus = await GetRecordingStatusAsync(program); if (recordingStatus.HasValue && (recordingStatus.Value.HasFlag(RecordingStatus.Scheduled) || recordingStatus.Value.HasFlag(RecordingStatus.SeriesScheduled))) { // Delete any existing schedule if (await scheduleControl.RemoveScheduleForProgramAsync(program, recordingStatus.Value.HasFlag(RecordingStatus.SeriesScheduled) ? ScheduleRecordingType.EveryTimeOnEveryChannel : ScheduleRecordingType.Once)) { newStatus = RecordingStatus.None; } } // Now create new schedule var result = await scheduleControl.CreateScheduleAsync(program, recordingType); if (result.Success) { newStatus = recordingType == ScheduleRecordingType.Once ? RecordingStatus.Scheduled : RecordingStatus.SeriesScheduled; UpdateRecordingStatus(program, (RecordingStatus)newStatus, recordingType); SlimTvClientMessaging.SendSlimTvProgramChangedMessage(program); } } return(newStatus); }
protected virtual async Task <RecordingStatus?> CreateOrDeleteSchedule(IProgram program, ScheduleRecordingType recordingType = ScheduleRecordingType.Once) { IScheduleControlAsync scheduleControl = _tvHandler.ScheduleControl; RecordingStatus? newStatus = null; if (scheduleControl != null) { RecordingStatus?recordingStatus = await GetRecordingStatusAsync(program); if (recordingStatus.HasValue && (recordingStatus.Value.HasFlag(RecordingStatus.Scheduled) || recordingStatus.Value.HasFlag(RecordingStatus.SeriesScheduled))) { if (await scheduleControl.RemoveScheduleForProgramAsync(program, recordingType)) { newStatus = RecordingStatus.None; } } else { var result = await scheduleControl.CreateScheduleAsync(program, recordingType); if (result.Success) { newStatus = recordingType == ScheduleRecordingType.Once ? RecordingStatus.Scheduled : RecordingStatus.SeriesScheduled; } } } return(newStatus); }
private UPnPError OnCreateSchedule(DvAction action, IList <object> inParams, out IList <object> outParams, CallContext context) { outParams = new List <object>(); IProgramInfoAsync programInfo = ServiceRegistration.Get <ITvProvider>() as IProgramInfoAsync; IScheduleControlAsync scheduleControl = ServiceRegistration.Get <ITvProvider>() as IScheduleControlAsync; if (programInfo == null || scheduleControl == null) { return(new UPnPError(500, "IProgramInfo or IScheduleControl service not available")); } int programId = (int)inParams[0]; ScheduleRecordingType recordingType = (ScheduleRecordingType)inParams[1]; IProgram program; ISchedule schedule = null; bool result = false; if (programInfo.GetProgram(programId, out program)) { var scheduleResult = scheduleControl.CreateScheduleAsync(program, recordingType).Result; result = scheduleResult.Success; schedule = scheduleResult.Result; } outParams = new List <object> { result, schedule }; return(null); }