Esempio n. 1
0
        public static bool LoadMovieCache([NotNull] FileInfo loadFrom, iMovieSource 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 = ProcessMovieXml(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);
            }
        }
Esempio n. 2
0
        private static bool ProcessMovieXml(XElement x, iMovieSource cache)
        {
            try
            {
                string?time = x.Attribute("time")?.Value;
                if (time != null)
                {
                    cache.LatestUpdateTimeIs(time);
                }
                else
                {
                    Logger.Error("Could not obtain update time from XML");
                }

                foreach (CachedMovieInfo si in x.Descendants("Movie").Select(seriesXml => new CachedMovieInfo(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.Update(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);
        }