示例#1
0
 /// <summary>
 /// Load previously stored information on (except series information) from cache
 /// </summary>
 /// <returns>true if cache could be loaded successfully, false otherwise</returns>
 public bool InitCache()
 {
   if (_cacheProvider != null)
   {
     if (!_cacheProvider.Initialised)
     {
       TvdbData data = _cacheProvider.InitCache();
       if (data != null)
       {//cache provider was initialised successfully
         _loadedData = data;
         return true;
       }
       //couldn't init the cache provider
       return false;
     }
     return _loadedData != null;
   }
   return false;
 }
 /// <summary>
 /// Saves cache settings
 /// </summary>
 /// <param name="content">settings</param>
 public void SaveToCache(TvdbData content)
 {
   SaveToCache(content.LanguageList);
   SaveToCache(content.LastUpdated);
 }
    /// <summary>
    /// Initialises the cache, should do the following things
    /// - initialise connections used for this cache provider (db connections, network shares,...)
    /// - create folder structure / db tables / ...  if they are not created already
    /// - if this is the first time the cache has been initialised (built), mark last_updated with the
    ///   current date
    /// </summary>
    /// <returns>Tvdb Data object</returns>
    public TvdbData InitCache()
    {
      try
      {
        if (!Directory.Exists(_rootFolder))
          Directory.CreateDirectory(_rootFolder);

        TvdbData data = LoadUserDataFromCache();
        if (data == null)
        {
          //the cache has never been initialised before -> do it now
          data = new TvdbData { LanguageList = new List<TvdbLanguage>(), LastUpdated = DateTime.Now };
          SaveToCache(data);
        }
        Initialised = true;
        return data;
      }
      catch (Exception ex)
      {
        Log.Error("Couldn't initialise cache: " + ex);
        return null;
      }
    }
 /// <summary>
 /// Load the cached data
 /// </summary>
 /// <returns>TvdbData object</returns>
 public TvdbData LoadUserDataFromCache()
 {
   List<TvdbLanguage> languages = LoadLanguageListFromCache();
   DateTime lastUpdated = LoadLastUpdatedFromCache();
   TvdbData data = new TvdbData(languages) { LastUpdated = lastUpdated };
   return data;
 }
示例#5
0
    /// <summary>
    /// Loads the settings data from cache 
    /// </summary>
    /// <returns>The loaded TvdbData object</returns>
    public TvdbData LoadUserDataFromCache()
    {
      String fName = _rootFolder + Path.DirectorySeparatorChar + "data.xml";
      if (File.Exists(fName))
      {
        String xmlData = File.ReadAllText(fName);
        XDocument xml = XDocument.Parse(xmlData);

        var info = from dataNode in xml.Descendants("Data")
                   select new
                   {
                     lu = dataNode.Element("LastUpdated").Value
                   };
        if (info.Count() == 1)
        {
          TvdbData data = new TvdbData();
          DateTime lastUpdated = new DateTime();
          try
          {
            lastUpdated = Util.UnixToDotNet(info.First().lu);
          }
          catch (FormatException ex)
          {
            Log.Warn("Couldn't parse date of last update", ex);
          }
          data.LastUpdated = lastUpdated;
          data.LanguageList = LoadLanguageListFromCache();
          //if (data.SeriesList == null) data.SeriesList = new List<TvdbSeries>();
          return data;
        }

      }

      return null;

    }
示例#6
0
    /// <summary>
    /// Saves cache settings
    /// </summary>
    /// <param name="content">settings</param>
    public void SaveToCache(TvdbData content)
    {
      if (content == null)
        return;
      SaveToCache(content.LanguageList);

      //store additional information
      //- time of last update
      //- more to come (eventually)
      XElement xml = new XElement("Data");
      xml.Add(new XElement("LastUpdated", Util.DotNetToUnix(content.LastUpdated)));
      String data = xml.ToString();
      File.WriteAllText(_rootFolder + Path.DirectorySeparatorChar + "data.xml", data);
    }