Beispiel #1
0
        public static bool LoadTvCache([NotNull] FileInfo loadFrom, iTVSource cache)
        {
            Logger.Info("Loading Cache from: {0}", loadFrom.FullName);
            if (!loadFrom.Exists)
            {
                return(true); // that's ok
            }

            try
            {
                XElement x = XElement.Load(loadFrom.FullName);
                bool     r = ProcessSeriesXml(x, cache);
                if (r)
                {
                    cache.UpdatesDoneOk();
                }

                return(r);
            }
            catch (Exception e)
            {
                Logger.Warn(e, "Problem on Startup loading File");
                LoadErr = loadFrom.Name + " : " + e.Message;
                return(false);
            }
        }
Beispiel #2
0
        private static void ProcessXmlBannerCache([NotNull] XElement r, iTVSource localCache)
        {
            //this is a wrapper that provides the seriesId and the Banners List as provided from the website
            //
            //
            // <BannersCache>
            //      <BannersItem Expiry='xx'>
            //          <SeriesId>123</SeriesId>
            //          <Banners>
            //              <Banner>

            foreach (XElement bannersXml in r.Descendants("BannersItem"))
            {
                int seriesId = bannersXml.ExtractInt("SeriesId") ?? -1;

                localCache.AddBanners(seriesId, bannersXml.Descendants("Banners").Descendants("Banner")
                                      .Select(banner => new Banner(seriesId, banner)));
            }
        }
Beispiel #3
0
        private static bool ProcessSeriesXml([NotNull] XElement x, [NotNull] iTVSource cache)
        {
            // Will have one or more cachedSeries, and episodes
            // all wrapped in <Data> </Data>

            // e.g.:
            //<Data>
            // <Series>
            //  <id>...</id>
            //  etc.
            // </Series>
            // <Episode>
            //  <id>...</id>
            //  blah blah
            // </Episode>
            // <Episode>
            //  <id>...</id>
            //  blah blah
            // </Episode>
            // ...
            //</Data>

            try
            {
                string?time = x.Attribute("time")?.Value;
                if (time != null)
                {
                    cache.LatestUpdateTimeIs(time);
                }
                else
                {
                    Logger.Error("Could not obtain update time from XML");
                }

                foreach (CachedSeriesInfo si in x.Descendants("Series").Select(seriesXml => new CachedSeriesInfo(seriesXml)))
                {
                    // The <cachedSeries> returned by GetSeries have
                    // less info than other results from
                    // thetvdb.com, so we need to smartly merge
                    // in a <Series> if we already have some/all
                    // info on it (depending on which one came
                    // first).
                    cache.UpdateSeries(si);
                }

                foreach (XElement episodeXml in x.Descendants("Episode"))
                {
                    Episode e = new Episode(episodeXml);
                    if (e.Ok())
                    {
                        cache.AddOrUpdateEpisode(e);
                    }
                    else
                    {
                        Logger.Error($"problem with XML recieved {episodeXml}");
                    }
                }

                foreach (XElement banners in x.Descendants("BannersCache"))
                {
                    //this wil not be found in a standard response from the TVDB website
                    //will only be in the response when we are reading from the cache
                    ProcessXmlBannerCache(banners, cache);
                }
            }
            catch (XmlException e)
            {
                string message = "Error processing data from Cache (top level).";
                message += "\r\n" + x;
                message += "\r\n" + e.Message;

                Logger.Error(message);
                Logger.Error(x.ToString());
                throw new CacheLoadException(message);
            }
            return(true);
        }