public bool ScheduleRecording(RecordingRequest rr, out RPRequest rpRequest, out RecordingResult earlyFailureResult) { EventWaitHandle ewhScheduleRecording = new EventWaitHandle(false, EventResetMode.AutoReset); storeManager.ScheduleRecording(rr, ewhScheduleRecording); ewhScheduleRecording.WaitOne(TimeSpan.FromSeconds(500)); // Destroy the stargate ewhScheduleRecording = null; DebugNormal("MCData: schedulerecording finished, storeManager.ScheduleInitialSucceeded:" + storeManager.ScheduleInitialSucceeded); if (!storeManager.ScheduleInitialSucceeded) { rpRequest = null; earlyFailureResult = storeManager.ScheduleInitialFailureResult; return(false); } else { // Retrieve the shared objects that were generated rpRequest = Conversion.RPRequestFromRequest(storeManager.requestInProgress); // THIS IS ERRORING earlyFailureResult = null; } return(true); }
// Helpers public static string FriendlyFailureReason(RecordingResult rr) { if (rr == null) { return("RecordingResult was null"); } string txtFailureReason = "An unknown failure occurred. Sorry, we wish we could be more helpful there."; if (rr.RequestResult != RequestResults.OK) { switch (rr.RequestResult) { case RequestResults.NoProgrammesFound: txtFailureReason = "Recording not scheduled - The channel or programme could not be found."; break; case RequestResults.FailedWithError: if (!string.IsNullOrEmpty(rr.ErrorMessage)) { return(rr.ErrorMessage); } else { return("Recording not scheduled due to an unspecified error."); } case RequestResults.AlreadyScheduled: txtFailureReason = "Recording not scheduled - this showing is already scheduled to be recorded."; break; case RequestResults.Conflicts: txtFailureReason = "Recording not scheduled as it would conflict with an existing recording."; break; case RequestResults.ExceededMaxRequests: txtFailureReason = "Recording not scheduled - the number of programmes that would be recorded is above the maximum of 50."; break; case RequestResults.OK: txtFailureReason = "Recording was OK and did not fail! This message should not have been displayed."; break; default: break; } return(txtFailureReason); } return(txtFailureReason); }
public static RecordingResult FromXML(string theXML) { RecordingResult newRR = new RecordingResult(); XmlSerializer serializer = new XmlSerializer(newRR.GetType()); StringReader sr = new StringReader(theXML); try { return((RecordingResult)serializer.Deserialize(sr)); } catch { return(newRR); } }
// Helpers public static string FriendlyFailureReason(RecordingResult rr) { if (rr == null) return "RecordingResult was null"; string txtFailureReason = "An unknown failure occurred. Sorry, we wish we could be more helpful there."; if (rr.RequestResult != RequestResults.OK) { switch (rr.RequestResult) { case RequestResults.NoProgrammesFound: txtFailureReason = "Recording not scheduled - The channel or programme could not be found."; break; case RequestResults.FailedWithError: if (!string.IsNullOrEmpty(rr.ErrorMessage)) return rr.ErrorMessage; else return "Recording not scheduled due to an unspecified error."; case RequestResults.AlreadyScheduled: txtFailureReason = "Recording not scheduled - this showing is already scheduled to be recorded."; break; case RequestResults.Conflicts: txtFailureReason = "Recording not scheduled as it would conflict with an existing recording."; break; case RequestResults.ExceededMaxRequests: txtFailureReason = "Recording not scheduled - the number of programmes that would be recorded is above the maximum of 50."; break; case RequestResults.OK: txtFailureReason = "Recording was OK and did not fail! This message should not have been displayed."; break; default: break; } return txtFailureReason; } return txtFailureReason; }
public static string FriendlySuccessReport(RecordingResult rr) { string txtReport = "Unknown result."; if (rr.WereConflicts) { if (String.IsNullOrEmpty(rr.ConflictInfo)) { return("There were one or more conflicts on some of the requested recordings."); } else { return(rr.ConflictInfo); } } if ( (rr.GeneratedRecordingsBlob == null) || (rr.GeneratedRecordingsBlob.RPRecordings == null) || (rr.GeneratedRecordingsBlob.RPRecordings.Count == 0) ) { return("No shows were found or scheduled to record."); } else if (rr.GeneratedRecordingsBlob.RPRecordings.Count == 1) { return("The scheduling was successful - one recording has been scheduled."); } else if (rr.GeneratedRecordingsBlob.RPRecordings.Count > 1) { return("The scheduling was successful - " + rr.GeneratedRecordingsBlob.RPRecordings.Count.ToString() + " recordings have been scheduled."); } // Default return(txtReport); }
//Request rqInProgress; public void ScheduleRecording(RecordingRequest rr, EventWaitHandle _ewh) { // Store pointer to handle locally ewhScheduleRecording = _ewh; ScheduleInitialFailureResult = new RecordingResult(); // For now, set shared result to assume failure (in case of time outs etc) ScheduleInitialFailureResult.ErrorMessage = "An error message was never generated."; ScheduleInitialSucceeded = false; // Channel check if (rr.MCChannelID < 1) { ScheduleInitialFailureResult.ErrorMessage = "No MC Channel ID was specified."; ScheduleInitialFailureResult.RequestResult = RecordingResult.RequestResults.FailedWithError; ScheduleRecordingCompleted(); return; } // Too much padding if ((rr.Postpadding > 1800) && (rr.Prepadding > 1800)) { ScheduleInitialFailureResult.ErrorMessage = "Pre or Post padding must be less than 30 minutes."; ScheduleInitialFailureResult.RequestResult = RecordingResult.RequestResults.FailedWithError; ScheduleRecordingCompleted(); return; } // Get service StoredObject so = os.Fetch(rr.MCChannelID); if (!(so is Channel)) { ScheduleInitialFailureResult.ErrorMessage = "The retrieved TV channel was not valid."; DebugError("OSM: Retrieved TV channel not valid: ID is [" + rr.MCChannelID.ToString() + "] and so is [" + so.ToString() + "]"); ScheduleInitialFailureResult.RequestResult = RecordingResult.RequestResults.FailedWithError; ScheduleRecordingCompleted(); return; } Channel channel = (Channel)so; // Get TV programme (ie schedule entry) ScheduleEntry schedEntry = null; if (rr.RequestType != RecordingRequestType.Manual) { StoredObject sto = os.Fetch(rr.TVProgrammeID); if (!(sto is ScheduleEntry)) { ScheduleRecordingCompleted(); return; } schedEntry = (ScheduleEntry)sto; } // Store request requestInProgress = null; switch (rr.RequestType) { case RecordingRequestType.Series: // Check schedentry has series info if (schedEntry.Program != null) if (schedEntry.Program.Series == null) { ScheduleInitialFailureResult.ErrorMessage = "This show is not part of a recognised series within Media Center."; ScheduleInitialFailureResult.RequestResult = RecordingResult.RequestResults.FailedWithError; ScheduleRecordingCompleted(); return; } SeriesRequest sreq = recScheduler.CreateSeriesRequest(schedEntry, channel); sreq.RunType = (rr.FirstRunOnly) ? RunType.FirstRunOnly : RunType.Any; // sreq.IsRecurring = true ?? sreq.AnyChannel = (rr.SeriesRequestSubType == SeriesRequestSubTypes.AnyChannelAnyTime); // Series request HAS to have IsRecurring set to TRUE. Series requests CANNOT be non recurring! sreq.IsRecurring = true; //= ((rr.SeriesRequestSubType == SeriesRequestSubTypes.AnyChannelAnyTime) || (rr.SeriesRequestSubType == SeriesRequestSubTypes.ThisChannelAnyTime)); /* // Experimental - AIR TIME string strAirtimecheck = ""; if (!sreq.Airtime.HasValue) strAirtimecheck += "null"; else strAirtimecheck += sreq.Airtime.Value.ToString(); DebugNormal("Airtime (before alteration) is:" + strAirtimecheck); // 12 hour window if (rr.SeriesRequestSubType == SeriesRequestSubTypes.ThisChannelAnyTime) { sreq.Airtime = TimeSpan.FromHours(12); } else if (rr.SeriesRequestSubType == SeriesRequestSubTypes.ThisChannelThisTime) { sreq.Airtime = TimeSpan.FromHours(3); } */ // Look also at... //sreq.Airtime //sreq.DaysOfWeek // sreq.ScheduleLimit - maximum number to schedule // If keep until is 'latest episodes', set the number here... if (rr.KeepUntil == KeepUntilTypes.LatestEpisodes) { if (rr.KeepNumberOfEpisodes > 0) sreq.RecordingLimit = rr.KeepNumberOfEpisodes; } requestInProgress = (Request)sreq; break; case RecordingRequestType.OneTime: OneTimeRequest oreq = recScheduler.CreateOneTimeRequest(schedEntry, channel); requestInProgress = (Request)oreq; requestInProgress.AnyChannel = false; //requestInProgress.ScheduleLimit = 5; // This didn't do anything! break; case RecordingRequestType.Manual: ManualRequest mreq = recScheduler.CreateManualRequest(rr.StartTime, TimeSpan.FromMinutes(rr.Duration), channel, rr.ManualRecordingName, "", "", "", (System.Globalization.CultureInfo.CurrentCulture.LCID), false); requestInProgress = (Request)mreq; break; } // Universal Request Settings - all types of recording requestInProgress.PostPaddingRequested = TimeSpan.FromSeconds(rr.Postpadding); requestInProgress.PrePaddingRequested = TimeSpan.FromSeconds(rr.Prepadding); // Keep Until if (rr.KeepUntil != KeepUntilTypes.NotSet) { try { DebugNormal("OSM: Setting 7MC request keeplength using string " + rr.KeepUntil.ToString()); requestInProgress.KeepLength = (KeepLength)Enum.Parse(typeof(KeepLength), rr.KeepUntil.ToString(), true); DebugNormal("OSM: 7MC request keepLength is now " + requestInProgress.KeepLength.ToString()); } catch { DebugNormal("ERROR: Couldn't parse KeepUntil value."); } } // ELSE ... ASSUME media center uses KeepUntil default when creating recording? If not, SET HERE ===> requestInProgress.Quality = rr.Quality; // Update request... (TODO is this step strictly necessary?) //rqInProgress.Updated += new StoredObjectEventHandler(ScheduleRecording_2); //rqInProgress.UpdateRequest(); requestInProgress.UpdateRequestedPrograms(); UpdateDelegate upd = new UpdateDelegate(ScheduleRecording_Done); requestInProgress.UpdateAndSchedule(upd, recScheduler); }
// DETERMINE SUCCESS public RecordingResult DetermineIfRequestSucceeded(RPRequest rpRequest) { // Asume failure RecordingResult recResult = new RecordingResult(); recResult.Completed = true; recResult.ErrorMessage = "An unknown error occurred."; Request recRequest = GetRequestWithID(rpRequest.ID); if (recRequest == null) { recResult.RequestResult = RecordingResult.RequestResults.FailedWithError; recResult.ErrorMessage = "Could not re-located the recording request to determine success or failure. It may have succeeded."; return recResult; } // No requested programmes were generated - so report failure and cancel; it's a useless request. if ((recRequest.RequestedPrograms == null) && (!(recRequest is WishListRequest))) // allow a keyword to continue { recResult.RequestResult = RecordingResult.RequestResults.NoProgrammesFound; return recResult; } // Let's compile some stats... // if (recRequest.HasConflictedRequestedPrograms) { DebugNormal("Request has conflicted requested programmes. (only in EPG, there may yet be enough tuners.):"); // We know that only one programme is requested. Are there any recordings at all? bool FoundAnyRequestedProgrammesThatWillRecord = false; int numberOfRequestedProgrammes = 0; int numberOfRequestedProgrammesThatWillRecord = 0; DebugNormal("Enumerating all requested programmes to see which will record:"); foreach (RequestedProgram rprog in recRequest.RequestedPrograms) { numberOfRequestedProgrammes++; DebugNormal("Program: " + rprog.ToString()); // should work DebugNormal("WillRecord: " + rprog.WillRecord); //DebugNormal("IsAssigned: " + rprog.IsAssigned); //DebugNormal("IsRequestFilled: " + rprog.IsRequestFilled); //DebugNormal("IsReal: " + rprog.IsReal); if (rprog.WillRecord) { numberOfRequestedProgrammesThatWillRecord++; FoundAnyRequestedProgrammesThatWillRecord = true; // dont bother checking first to speed up } } // What kind of request? // ******************************** ONE TIME / MANUAL CONFLICTS ******************************** if ( (recRequest is OneTimeRequest) || (recRequest is ManualRequest) ) { if (!FoundAnyRequestedProgrammesThatWillRecord) { // No requested programmes will record... ...this is the end of the line recResult.WereConflicts = true; // not strictly necessary recRequest.Cancel(); recResult.Completed = true; recResult.RequestResult = RecordingResult.RequestResults.Conflicts; return recResult; } } // ******************************** SERIES / WISHLIST CONFLICTS ******************************** if ((recRequest is SeriesRequest) || (recRequest is WishListRequest)) { // if !FoundAnyRequested... Abandon if none will record ? NOT FOR NOW // Conflicts mean nothing, it comes down to what will actually record, so it's possible // that everything is actually okay. Check now: if (numberOfRequestedProgrammesThatWillRecord < numberOfRequestedProgrammes) { // Calculate how many are in conflict and warn user recResult.ConflictInfo = "Out of " + numberOfRequestedProgrammes.ToString() + " shows found, " + (numberOfRequestedProgrammes - numberOfRequestedProgrammesThatWillRecord).ToString() + " will not record as they conflict with existing recordings."; recResult.WereConflicts = true; } // else everything is Okay } } // *********************** SUCCESS ********************************* // RECORDINGS / TV PROGRAMMES List<RPRecording> rprecordings = new List<RPRecording>(); List<TVProgramme> tvprogrammes = new List<TVProgramme>(); // Make a blob RPRecordingsBlob blob = new RPRecordingsBlob(); // Store NEW request in blob. (might have changed since the one that was passed to this method) RPRequest newRequest = Conversion.RPRequestFromRequest(recRequest); blob.RPRequests = new List<RPRequest>() { newRequest }; // Don't store anything else inside the blob here - it's done in the main callback in EPGManager.cs when all recordings are refreshed. // Store the blob inside the record result recResult.GeneratedRecordingsBlob = blob; // Success! (?) recResult.Success = true; recResult.Completed = true; recResult.RequestResult = RecordingResult.RequestResults.OK; // Return the result (to waitHandle etc) return recResult; }
public bool ScheduleRecording(RecordingRequest rr, out RPRequest rpRequest, out RecordingResult earlyFailureResult) { EventWaitHandle ewhScheduleRecording = new EventWaitHandle(false, EventResetMode.AutoReset); storeManager.ScheduleRecording(rr, ewhScheduleRecording); ewhScheduleRecording.WaitOne(TimeSpan.FromSeconds(500)); // Destroy the stargate ewhScheduleRecording = null; DebugNormal("MCData: schedulerecording finished, storeManager.ScheduleInitialSucceeded:" + storeManager.ScheduleInitialSucceeded); if (!storeManager.ScheduleInitialSucceeded) { rpRequest = null; earlyFailureResult = storeManager.ScheduleInitialFailureResult; return false; } else { // Retrieve the shared objects that were generated rpRequest = Conversion.RPRequestFromRequest(storeManager.requestInProgress); // THIS IS ERRORING earlyFailureResult = null; } return true; }
public static RecordingResult FromXML(string theXML) { RecordingResult newRR = new RecordingResult(); XmlSerializer serializer = new XmlSerializer(newRR.GetType()); StringReader sr = new StringReader(theXML); try { return (RecordingResult)serializer.Deserialize(sr); } catch { return newRR; } }
public static string FriendlySuccessReport(RecordingResult rr) { string txtReport = "Unknown result."; if (rr.WereConflicts) { if (String.IsNullOrEmpty(rr.ConflictInfo)) return "There were one or more conflicts on some of the requested recordings."; else return rr.ConflictInfo; } if ( (rr.GeneratedRecordingsBlob == null) || (rr.GeneratedRecordingsBlob.RPRecordings == null) || (rr.GeneratedRecordingsBlob.RPRecordings.Count == 0) ) { return "No shows were found or scheduled to record."; } else if (rr.GeneratedRecordingsBlob.RPRecordings.Count == 1) { return "The scheduling was successful - one recording has been scheduled."; } else if (rr.GeneratedRecordingsBlob.RPRecordings.Count > 1) { return "The scheduling was successful - " + rr.GeneratedRecordingsBlob.RPRecordings.Count.ToString() + " recordings have been scheduled."; } // Default return txtReport; }