public int StopRecording(IPEndPoint venue) { lock (this) { ConferenceRecorder recorder = (ConferenceRecorder)sessions[venue]; if (recorder != null && recorder.IsRecording) { int refs = (int)references[venue]; // Decrease our reference count --refs; // Only stop recording if no one wants this recording if (refs <= 0) { // Stop recording recorder.StopRecording(); references.Remove(venue); sessions.Remove(venue); } else { references[venue] = refs; } return(refs); } else // if we aren't recording any more, return a -1, signifying "references were already 0!" { return(-1); // Consider this an "error code", of sorts. } } }
/// <summary> /// Records the conference. /// </summary> /// <param name="conferenceDescription">A description of the conference being recorded.</param> /// <param name="venueIdentifier">Venue name for the conference.</param> /// <param name="venue">Venue to record from.</param> /// <returns>The number of ongoing requests to record this conference.</returns> public int Record(string conferenceDescription, string venueIdentifier, IPEndPoint venue) { try { lock (this) { CheckForIPv6(venue); ConferenceRecorder ongoingRecording = CheckVenueForPlayback(venue); int refs; object refsObj = references[venue]; if (refsObj == null) { refs = 0; } else { refs = (int)refsObj; } // If a recording exists, the references to it should not equal zero Debug.Assert(ongoingRecording == null || refs != 0); ConferenceRecorder recorder = null; if (refs == 0) { // Start a ConferenceRecorder eventLog.WriteEntry("Recording a new conference." + "\n Conference Description: " + conferenceDescription + "\n Venue Identifier: " + venueIdentifier + "\n Venue IP/Port: " + venue, EventLogEntryType.Information, ArchiveServiceEventLog.ID.Starting); recorder = new ConferenceRecorder(); recorder.RecordConference(conferenceDescription, venueIdentifier, venue); sessions.Add(venue, recorder); } else { recorder = ongoingRecording; } ++refs; references[venue] = refs; return(refs); } } catch (Exception ex) { eventLog.WriteEntry(ex.ToString(), EventLogEntryType.Error, ArchiveServiceEventLog.ID.Error); throw; } }
/// <summary> /// Records the conference. /// </summary> /// <param name="conferenceDescription">A description of the conference being recorded.</param> /// <param name="venueIdentifier">Venue name for the conference.</param> /// <param name="venue">Venue to record from.</param> /// <returns>The number of ongoing requests to record this conference.</returns> public int Record( string conferenceDescription, string venueIdentifier, IPEndPoint venue ) { try { lock(this) { CheckForIPv6(venue); ConferenceRecorder ongoingRecording = CheckVenueForPlayback(venue); int refs; object refsObj = references[venue]; if( refsObj == null ) refs = 0; else refs = (int)refsObj; // If a recording exists, the references to it should not equal zero Debug.Assert(ongoingRecording == null || refs != 0); ConferenceRecorder recorder = null; if( refs == 0 ) { // Start a ConferenceRecorder eventLog.WriteEntry(string.Format(CultureInfo.CurrentCulture, Strings.RecordingANewConference, conferenceDescription, venueIdentifier, venue), EventLogEntryType.Information, ArchiveServiceEventLog.ID.Starting); recorder = new ConferenceRecorder(); recorder.RecordConference(conferenceDescription, venueIdentifier, venue); sessions.Add(venue, recorder); } else { recorder = ongoingRecording; } ++refs; references[venue] = refs; return refs; } } catch (Exception ex) { eventLog.WriteEntry(ex.ToString(), EventLogEntryType.Error, ArchiveServiceEventLog.ID.Error); throw; } }