public TheTvDbUpdateContainer ParseUncompressed(string updateContainerRaw)
        {
            if (updateContainerRaw == null) throw new ArgumentNullException(nameof(updateContainerRaw));

            // If xml cannot be created return null
            XDocument doc;
            try
            {
                doc = XDocument.Parse(updateContainerRaw);
            }
            catch (XmlException e)
            {
                throw new TheTvDbParseException("Search series collection string cannot be parsed into a xml document.", e);
            }

            var updateContainerXml = doc.Element("Data");
            if (updateContainerXml == null) throw new TheTvDbParseException("Error while parsing update xml document. Xml Element 'Data' is missing.");

            var updateContainer = new TheTvDbUpdateContainer();

            uint lastUpdatedEpoch;
            var lastUpdatedRaw = updateContainerXml.Attribute("time").Value;
            if (uint.TryParse(lastUpdatedRaw, out lastUpdatedEpoch))
            {
                updateContainer.LastUpdated = lastUpdatedEpoch.ToDateTime();
            }

            updateContainer.SeriesUpdates = updateContainerXml.Elements("Series")
                .Select(ParseSeriesUpdate)
                .ToList();

            updateContainer.EpisodeUpdates = updateContainerXml.Elements("Episode")
                .Select(ParseEpisodeUpdate)
                .ToList();

            updateContainer.BannerUpdates = updateContainerXml.Elements("Banner")
                .Select(ParseBannerUpdate)
                .ToList();

            return updateContainer;
        }
Ejemplo n.º 2
0
        private TheTvDbUpdateContainer GetCacheUpdates(TheTvDbUpdateContainer updates)
        {
            var seriesCacheUpdates =
                updates.SeriesUpdates.Where(
                    seriesUpdate => _cache.Series.Any(p => p.SeriesId == seriesUpdate.SeriesId)).ToList();

            var episodeCacheUpdates =
                updates.EpisodeUpdates.Where(
                    episodeUpdate => _cache.Series.Any(p => p.SeriesId == episodeUpdate.SeriesId)).ToList();

            var bannerCacheUpdates =
                updates.BannerUpdates.Where(
                    bannerUpdate => _cache.Series.Any(p => p.SeriesId == bannerUpdate.SeriesId)).ToList();

            return new TheTvDbUpdateContainer
            {
                SeriesUpdates = seriesCacheUpdates,
                EpisodeUpdates = episodeCacheUpdates,
                BannerUpdates = bannerCacheUpdates,
                LastUpdated = updates.LastUpdated
            };
        }