Exemple #1
0
        public WTVStreamingVideoResult StartStreamer(WTVStreamingVideoRequest strq)
        {
            int newStreamerID = -1;

            // Too many streamers?
            if (mediaStreamers.Count > MAXIMUM_STREAMERS)
            {
                Functions.WriteLineToLogFile("DSStreamingManager: too many streamers (" + mediaStreamers.Count.ToString() + " streamers are running, which is above the maximum of " + MAXIMUM_STREAMERS.ToString() + ")");
                return(new WTVStreamingVideoResult(DSStreamResultCodes.ErrorTooManyStreamers));
            }

            // For now, some overrides and assumptions
            if (!File.Exists(strq.FileName))
            {
                Functions.WriteLineToLogFile("WebSvc Start Streaming FAIL: File not found: " + strq.FileName);
                return(new WTVStreamingVideoResult(DSStreamResultCodes.ErrorFileNotFound));
            }

            try
            {
                DSStreamer mediaStreamer = new DSStreamer();
                mediaStreamer                        = new FatAttitude.WTVTranscoder.DSStreamer();
                mediaStreamer.Finished              += new EventHandler <DSTranscoderBase.ConversionEndedEventArgs>(mediaStreamer_Finished);
                mediaStreamer.ConversionCompleted   += new EventHandler(mediaStreamer_ConversionCompleted);
                mediaStreamer.DebugMessageGenerated += new EventHandler <DSTranscoderBase.DebugMessageEventArgs>(mediaStreamer_DebugMessageGenerated);
                Functions.WriteLineToLogFile("DSStreamingManager: DSStreamer object created.");

                // Which port should we use?
                int portToTry = GetNextFreePort();

                // Try streaming  (Async)
                Functions.WriteLineToLogFileIfSetting(Settings.Default.DebugStreaming, "DSStreamingManager: Attempting to stream using port " + portToTry.ToString());
                WTVStreamingVideoResult streamResult = mediaStreamer.StreamWithFileAndPort(strq, portToTry, false, true);

                if (streamResult.ResultCode == DSStreamResultCodes.OK)
                {
                    // Add to local streamers
                    newStreamerID    = AddNewStreamer(mediaStreamer);
                    mediaStreamer.ID = newStreamerID;

                    // Add streamer ID to result code too
                    streamResult.StreamerID = newStreamerID.ToString();
                }
                // Return
                return(streamResult);
            }
            catch (Exception e)
            {
                Functions.WriteLineToLogFile("Exception setting up mediaStreaming object:");
                Functions.WriteExceptionToLogFile(e);
                return(new WTVStreamingVideoResult(DSStreamResultCodes.ErrorExceptionOccurred, "Error setting up mediastreaming object: " + e.Message + " (see server log for more details)"));
            }
        }
Exemple #2
0
        private static bool GetAllRecordingScheduleForLiveTV(double daysBack, bool merge)
        {
            bool debug = (Settings.Default.DebugAdvanced);

            Functions.WriteLineToLogFileIfSetting(debug, "" + ReloadingRecordings + "," + daysBack + "ReloadingRecordings, daysBack");

            lock (oneEntryAtATime) //-	Live TV: Handled race condition where scheduling live TV always comes up with all recordings busy.
            {
                if (ReloadingRecordings)
                {
                    Functions.WriteLineToLogFileIfSetting(debug, "ReloadingRecordings=True");
                    return(true); // Don't bother, already doing it
                }

                // Set flag
                ReloadingRecordings = true;


                if (!isWMCOnline)
                {
                    Functions.WriteLineToLogFileIfSetting(debug, "isWMCOnline=False");
                    return(false);
                }
                //if (!merge)
                {
                    Functions.WriteLineToLogFileIfSetting(debug, "WMC is online now clearing requests and recordings");
                    Functions.WriteLineToLogFileIfSetting(debug, "recording count=" + AllRecordings.Count());
                    Functions.WriteLineToLogFileIfSetting(debug, "AllRequests count=" + AllRequests.Count());
                    AllRecordings.Clear();
                    AllRequests.Clear();
                }

                DateRange theRange = new DateRange(DateTime.Now.ToUniversalTime().AddDays(-daysBack), DateTime.Now.ToUniversalTime().AddDays(100));

                MergeInRequests(mcData.GetAllRequests(theRange));
                MergeInRecordings(mcData.GetAllRecordings(theRange));

                Functions.WriteLineToLogFileIfSetting(debug, "recording count=" + AllRecordings.Count());
                Functions.WriteLineToLogFileIfSetting(debug, "AllRequests count=" + AllRequests.Count());

                // SortAllRecordingsByDate();
                //  SortAllRequestsByTitle();

                // Unset flag
                ReloadingRecordings = false;
                Functions.WriteLineToLogFileIfSetting(debug, "ReloadingRecordings set to False");
            }

            return(true);
        }
Exemple #3
0
        // Refresh
        public static bool UpdateTVChannels()
        {
            bool debug = ((Settings.Default.DebugChannels) & (Settings.Default.DebugAdvanced));

            Functions.WriteLineToLogFileIfSetting(debug, "EPG: UpdateTVChannels() Running:");

            // If we don't have any existing channels at all then get some
            if ((AllTVChannels == null) || (AllTVChannels.Count < 1))
            {
                Functions.WriteLineToLogFileIfSetting(debug, "EPG: UpdateTVChannels(): No existing TV Channels, populating from cache first...");
                if (!PopulateTVChannels(false))
                {
                    return(false);
                }

                Functions.WriteLineToLogFileIfSetting(debug, "EPG: UpdateTVChannels(): Populated from cache: there are " + AllTVChannels.Count.ToString() + " channels.");
                if (AllTVChannels.Count < 1)
                {
                    return(false);
                }
            }

            Functions.WriteLineToLogFileIfSetting(debug, "EPG: UpdateTVChannels(): Backing up " + AllTVChannels.Count.ToString() + " channels.");
            Dictionary <string, TVService> OldTVChannelsKeyedByChannelNumberString = new Dictionary <string, TVService>();

            foreach (TVService tvs in AllTVChannels.Values)
            {
                TVService copiedOldService = tvs.DeepCopy();

                // Skip duplicate keys otherwise you spend 4 hours on a Sunday trying to remotely debug a native code crash
                if (OldTVChannelsKeyedByChannelNumberString.ContainsKey(copiedOldService.ChannelNumberString()))
                {
                    Functions.WriteLineToLogFileIfSetting(debug, "EPG: UpdateTVChannels() Skipping service with duplicate channel num string (" + copiedOldService.ChannelNumberString() + ") Callsign is " + copiedOldService.Callsign);
                }
                else
                {
                    Functions.WriteLineToLogFileIfSetting(debug, "EPG: UpdateTVChannels() Storing " + copiedOldService.ChannelNumberString() + " : " + copiedOldService.Callsign);
                    OldTVChannelsKeyedByChannelNumberString.Add(copiedOldService.ChannelNumberString(), copiedOldService);
                }
            }

            // Re-populate AllTVChannels from MediaCenter
            Functions.WriteLineToLogFileIfSetting(debug, "EPG: UpdateTVChannels(): Getting newest channels from 7MC...");
            PopulateTVChannels(true);
            Functions.WriteLineToLogFileIfSetting(debug, "EPG: UpdateTVChannels(): Populated from 7MC: there are " + AllTVChannels.Count.ToString() + " channels.");

            // Go through new channels - retrieve isFavourite information and user sort order from old channels
            Functions.WriteLineToLogFileIfSetting(debug, "EPG: UpdateTVChannels(): Merging info from old channels into newer list.");
            List <string> MatchedChannelNumberStrings = new List <string>();

            foreach (TVService newService in AllTVChannels.Values)
            {
                if (OldTVChannelsKeyedByChannelNumberString.ContainsKey(newService.ChannelNumberString()))
                {
                    if (!MatchedChannelNumberStrings.Contains(newService.ChannelNumberString()))
                    {
                        TVService oldService = OldTVChannelsKeyedByChannelNumberString[newService.ChannelNumberString()];

                        // Merge in old user sort and isfavorite information
                        newService.IsFavorite    = oldService.IsFavorite;
                        newService.UserSortOrder = oldService.UserSortOrder;

                        if (newService.MCChannelID != oldService.MCChannelID)
                        {
                            Functions.WriteLineToLogFile("EPG: UpdateTVChannels(): INFORMATION: Service " + newService.Callsign + " changed MC-ID from " + oldService.MCChannelID.ToString() + " to " + newService.MCChannelID.ToString() + " - merging in change.");
                        }
                        if (newService.UniqueId != oldService.UniqueId)
                        {
                            Functions.WriteLineToLogFile("EPG: UpdateTVChannels(): INFORMATION: Service " + newService.Callsign + " changed Unique Service ID from " + oldService.UniqueId + " to " + newService.UniqueId + " - merging in change.");
                        }

                        MatchedChannelNumberStrings.Add(newService.ChannelNumberString());
                    }
                }
                else
                {
                    Functions.WriteLineToLogFileIfSetting(debug, "EPG: UpdateTVChannels(): NEW channel " + newService.Callsign + " was found.  (Chan number " + newService.ChannelNumberString() + ")");
                }
            }

            Functions.WriteLineToLogFileIfSetting(debug, "EPG: UpdateTVChannels(): Merge complete.");

            // Save it
            Functions.WriteLineToLogFileIfSetting(debug, "EPG: UpdateTVChannels(): Saving.");
            SaveChannelsToLocal();

            Functions.WriteLineToLogFileIfSetting(debug, "EPG: UpdateTVChannels(): DONE.");
            return(true);
        }
Exemple #4
0
        // 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);
        }
Exemple #5
0
 void prober_DebugMessage(object sender, FatAttitude.GenericEventArgs <string> e)
 {
     Functions.WriteLineToLogFileIfSetting(Settings.Default.DebugStreaming, e.Value);
 }