Esempio n. 1
0
        /// <summary>
        /// Get all updates since a given interval.
        /// </summary>
        /// <param name="interval">The interval you need to retrieve. 
        /// E.g. if you have last updated your data the same day than you should set Interval.Day. 
        /// The higher the interval the higher the bandwidth costs are.</param>
        /// <param name="compression">Only set compress mode to false when you know what your are doing. 
        /// Disabled compression raises the bandwith costs a lot.</param>
        /// <returns>Returns the update container which consists of all update elements.</returns>
        public async Task<TheTvDbUpdateContainer> GetUpdatesAsync(TheTvDbInterval interval, bool compression = true)
        {
            if (compression)
            {
                var updateContainerStream = await _updateServiceProxy.Retrieve(interval);
                return _updateParser.Parse(updateContainerStream, interval);
            }

            var updateContainerRaw = await _updateServiceProxy.RetrieveUncompressed(interval);
            return _updateParser.ParseUncompressed(updateContainerRaw);
        }
        public async Task<string> RetrieveUncompressed(TheTvDbInterval interval)
        {
            var url = string.Format(UpdateUncompressedUrlFormat, 
                ProxyConfiguration.BaseUrl, 
                ProxyConfiguration.ApiKey, 
                interval.ToApiString());

            var response = await GetAsync(url);
            
            return await response.Content.ReadAsStringAsync();
        }
        public TheTvDbUpdateContainer Parse(Windows.Storage.Streams.IInputStream updateContainerStream, TheTvDbInterval interval)
#endif
        {
            if (updateContainerStream == null) throw new ArgumentNullException(nameof(updateContainerStream));

#if WINDOWS_PORTABLE || WINDOWS_DESKTOP
            using (var archive = new ZipArchive(updateContainerStream, ZipArchiveMode.Read))
#elif WINDOWS_UAP
            using (var archive = new ZipArchive(updateContainerStream.AsStreamForRead(), ZipArchiveMode.Read))
#endif
            {
                var entryName = $"updates_{interval.ToApiString()}.xml";
                var updateContainerRaw = archive.GetEntry(entryName).ReadToEnd();
                return ParseUncompressed(updateContainerRaw);
            }
        }
        public async Task<Windows.Storage.Streams.IInputStream> Retrieve(TheTvDbInterval interval)
#endif
        {
            var url = string.Format(UpdateCompressedUrlFormat, 
                ProxyConfiguration.BaseUrl, 
                ProxyConfiguration.ApiKey, 
                interval.ToApiString());

            var response = await GetAsync(url);

#if WINDOWS_PORTABLE || WINDOWS_DESKTOP
            return await response.Content.ReadAsStreamAsync();
#elif WINDOWS_UAP
            return (await response.Content.ReadAsStreamAsync()).AsInputStream();
#endif
        }
 public TheTvDbUpdateContainer Parse(System.IO.Stream updateContainerStream, TheTvDbInterval interval)
 public async Task<System.IO.Stream> Retrieve(TheTvDbInterval interval)