Exemple #1
0
        /// <summary>
        /// Takes Bleb channel names and populates the TvChannels table
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="blebChannelNames"></param>
        /// <param name="days"></param>
        /// <param name="channelHandler"></param>
        /// <param name="handler"></param>
        /// <returns></returns>
        public void ImportChannels(TvProgramBroadCastListingImport tag, IEnumerable<string> blebChannelNames, AddTvChannelSourceInfoHandler channelHandler)
        {
            var importer = new BlebXmltvProvider();

            var channelNames = blebChannelNames.ToArray();

            int[] days = new[] { 0 };
            var results = importer.GetFeedResults(blebChannelNames, days).Result;

            if (results.channel.Length != channelNames.Length) throw new InvalidOperationException("Got wrong number of result channels so can't import pair them up with names");

            // look through the response and create each channel
            for (int i = 0; i < channelNames.Length; i++) {
                var channel = results.channel[i];

                channelHandler(tag, new AddTvChannelInfo {
                    DisplayName = channel.displayname.Trim(),
                    SourceName = channelNames[i],
                    Uri = channel.id
                });
            }
        }
Exemple #2
0
        /// <summary>
        /// Performs an update for the specified channels for the specified days!
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="channels"></param>
        /// <param name="days"></param>
        /// <param name="handler"></param>
        /// <returns></returns>
        public void ImportPrograms(TvProgramBroadCastListingImport tag, IEnumerable<TvChannelListingSource> channels, IEnumerable<int> days, AddTvBroadCastListingInfoHandler handler)
        {
            var importer = new BlebXmltvProvider();

            // get a list of the source names to pass to the importer
            var blebChannelNames = channels.Select(x => x.SourceChannelName);

            var results = importer.GetFeedResults(blebChannelNames, days).Result;

            // create a dictionary of channel URI -> TvChannel for the importer to find the TvChannelId from the URI
            var channelUriLookup = channels.ToDictionary(x => x.SourceChannelUri, x => x);

            // add each program
            if (results.programme != null) {
                AddPrograms(tag, handler, channelUriLookup, results.programme);
            }
        }