} // Request => TV Programmes (not really used, better to get recordings as more info and you can then get the tv progs for each recording) public static TVService TVService(this RPRequest rq) // Request => TV Service { foreach (TVService tvs in AllTVChannels.Values) { if (tvs.UniqueId.Equals(rq.ServiceID.ToString())) { return(tvs); } } return(null); }
public static List <RPRecording> Recordings(this RPRequest rq) { List <RPRecording> output = new List <RPRecording>(); foreach (RPRecording rec in AllRecordings.Values) { if (rec.RPRequestID != rq.ID) { continue; } output.Add(rec); } return(output); } // Request => Recordings (from which you can get the tv progs)
} // Recording => TV Programme public static List <TVProgramme> TVProgrammes(this RPRequest rq) { List <TVProgramme> output = new List <TVProgramme>(); foreach (RPRecording rec in AllRecordings.Values) { if (rec.RPRequestID != rq.ID) { continue; } TVProgramme tvp = rec.TVProgramme(); if (tvp != null) { output.Add(tvp); } } return(output); } // Request => TV Programmes (not really used, better to get recordings as more info and you can then get the tv progs for each recording)
// Schedule Recordings /// <summary> /// Schedule a recording - this examines the request and populates Service ID, etc. /// The MCDATA.Schedule... method should never be called directly outside this method /// </summary> public static RecordingResult ScheduleRecording(RecordingRequest rr) { // Populate defaults, e.g. quality, if not set PopulateDefaultsIfUnset(ref rr); RecordingResult failedResult = new RecordingResult(); failedResult.Completed = false; if (rr.RequestType != RecordingRequestType.Manual) // manual recordings already have a service ID specified { if (rr.TVProgrammeID < 1) { failedResult.ErrorMessage = "No TV Programme ID was specified."; return(failedResult); } // Populate the Service ID if not already populated TVProgramme tvp = mcData.GetTVProgramme(rr.TVProgrammeID.ToString()); if (tvp == null) { failedResult.ErrorMessage = "No TV Programme with the specified ID could be found."; return(failedResult); } rr.ServiceID = long.Parse(tvp.ServiceID); // could fail } // Get the channel ID from the service ID TVService tvs = TVServiceWithIDOrNull(rr.ServiceID.ToString()); if (tvs == null) { failedResult.ErrorMessage = "No TV Channel with the retrieved ID could be found."; return(failedResult); } rr.MCChannelID = tvs.MCChannelID; // ************** SCHEDULE THE RECORDING ************************ RPRequest generatedRequest; RecordingResult earlyRecResult; if (!mcData.ScheduleRecording(rr, out generatedRequest, out earlyRecResult)) { bool debug2 = (Settings.Default.DebugAdvanced); Functions.WriteLineToLogFileIfSetting(debug2, "Failed already - return the early result"); return(earlyRecResult); } RecordingResult recResult = mcData.DetermineRecordingResultForRequest(generatedRequest); bool debug = (Settings.Default.DebugAdvanced); Functions.WriteLineToLogFileIfSetting(debug, "recResult.Success=" + recResult.Success); // Success? if (recResult.Success) { // Wait a moment so Scheduler can catch up and associate our request with our recordings... System.Threading.Thread.Sleep(600); Functions.WriteLineToLogFileIfSetting(debug, "// Now refresh and get the generated recordings..."); EPGManager.ReloadAllRecordings(); try { RPRequest req = recResult.GeneratedRecordingsBlob.RPRequests[0]; Functions.WriteLineToLogFileIfSetting(debug, "req.Title=" + req.Title); // Add recordings recResult.GeneratedRecordingsBlob.RPRecordings = req.Recordings(); Functions.WriteLineToLogFileIfSetting(debug, "recordings added"); // Add programs linked to these recordings foreach (RPRecording rec in recResult.GeneratedRecordingsBlob.RPRecordings) { TVProgramme tvp = rec.TVProgramme(); if (tvp != null) { recResult.GeneratedRecordingsBlob.TVProgrammes.Add(tvp); Functions.WriteLineToLogFileIfSetting(debug, tvp.Filename + " added"); } } } catch (Exception ex) { Functions.WriteLineToLogFile("ScheduleRecording(): Error retrieving recordings:"); Functions.WriteExceptionToLogFile(ex); recResult.Success = false; recResult.ErrorMessage = "Exception occured while retrieving recordings - the recording may have been scheduled."; } } return(recResult); }