Beispiel #1
0
 /// <summary>
 /// Write the user data to file
 /// </summary>
 /// <param name="_user">User to store</param>
 /// <param name="_path">Path on disk</param>
 /// <returns>true if the file could be stored, false otherwise</returns>
 internal bool WriteUserData(TvdbUser _user, String _path)
 {
     String fileContent = CreateUserData(_user);
       try
       {
     FileInfo info = new FileInfo(_path);
     if (!info.Directory.Exists) info.Directory.Create();
     File.WriteAllText(info.FullName, fileContent);
     return true;
       }
       catch (Exception)
       {
     return false;
       }
 }
Beispiel #2
0
        /// <summary>
        /// Extract user data from
        /// </summary>
        /// <param name="_data"></param>
        /// <returns></returns>
        internal List<TvdbUser> ExtractUser(String _data)
        {
            //Stopwatch watch = new Stopwatch();
              //watch.Start();
              XDocument xml = XDocument.Parse(_data);
              List<TvdbBanner> retList = new List<TvdbBanner>();
              var allUsers = from episode in xml.Descendants("User")
                     select new
                     {

                       Identifier = episode.Element("Identifier").Value,
                       Name = episode.Element("Name").Value,
                       Favorites = episode.Element("Favorites"),
                       Preferred = episode.Element("PreferredLanguage")
                     };

              List<TvdbUser> userList = new List<TvdbUser>();
              foreach (var a in allUsers)
              {
            TvdbUser user = new TvdbUser();
            user.UserIdentifier = a.Identifier;
            user.UserName = a.Name;
            user.UserPreferredLanguage = a.Preferred.HasAttributes ?
                                     Util.ParseLanguage(a.Preferred.FirstAttribute.NextAttribute.Value) :
                                     TvdbLanguage.DefaultLanguage;
            List<int> favList = new List<int>();
            foreach (String f in a.Favorites.Value.Split(','))
            {
              int val;
              if (Int32.TryParse(f, out val))
              {
            favList.Add(val);
              }
            }
            user.UserFavorites = favList;
            userList.Add(user);
              }
              //watch.Stop();
              //Log.Debug("Extracted " + userList.Count + " actors in " + watch.ElapsedMilliseconds + " milliseconds");
              return userList;
        }
Beispiel #3
0
        /// <summary>
        /// Create the xml content to save a TvdbUser to file
        /// </summary>
        /// <param name="_user">User to store</param>
        /// <returns>xml content</returns>
        internal String CreateUserData(TvdbUser _user)
        {
            XElement xml = new XElement("Data");

              StringBuilder favBuilder = new StringBuilder();
              if (_user.UserFavorites != null && _user.UserFavorites.Count > 0)
              {
            foreach (int f in _user.UserFavorites)
            {
              favBuilder.Append(f);
              favBuilder.Append(",");
            }
              }

              XElement preferred = new XElement("PreferredLanguage");
              if (_user.UserPreferredLanguage != null)
              {
            preferred.Add(new XAttribute("Id", _user.UserPreferredLanguage.Id));
            preferred.Add(new XAttribute("Abbriviation", _user.UserPreferredLanguage.Abbriviation));
            preferred.Add(new XAttribute("Name", _user.UserPreferredLanguage.Name));
              }

              xml.Add(new XElement("User",
                  new XElement("Name", _user.UserName),
                  new XElement("Identifier", _user.UserIdentifier),
                  new XElement("Favorites", favBuilder.ToString()),
                  preferred
             ));

              return xml.ToString();
        }
Beispiel #4
0
 private void cmdSetUser_Click(object sender, EventArgs e)
 {
     TvdbUser user = new TvdbUser();
       user.UserIdentifier = txtUserId.Text;
       user.UserName = "******";
       m_tvdbHandler.UserInfo = user;
       cmdGetAllSeriesRatings.Enabled = true;
       cmdGetRatingsForSeries.Enabled = true;
 }
 /// <summary>
 /// Saves the user data to cache
 /// </summary>
 /// <param name="_user"></param>
 public void SaveToCache(TvdbUser _user)
 {
     if (_user != null)
       {
     if (!Directory.Exists(m_rootFolder)) Directory.CreateDirectory(m_rootFolder);
     m_filestream = new FileStream(m_rootFolder + Path.DirectorySeparatorChar + "user_" + _user.UserIdentifier + ".ser", FileMode.Create);
     m_formatter.Serialize(m_filestream, _user);
     m_filestream.Close();
       }
 }
Beispiel #6
0
        /// <summary>
        /// Initialise the form
        /// </summary>
        /// <param name="_userId"></param>
        public void InitialiseForm(String _userId, ICacheProvider _provider)
        {
            //m_tvdbHandler = new Tvdb(new BinaryCacheProvider(@"cachefile.bin"), Resources.API_KEY);new XmlCacheProvider("XmlCache")

              m_tvdbHandler = new TvdbHandler(_provider, Resources.API_KEY);
              m_tvdbHandler.InitCache();

              List<TvdbLanguage> m_languages = m_tvdbHandler.Languages;

              foreach (TvdbLanguage l in m_languages)
              {
            if (l.Abbriviation.Equals("en")) m_currentLanguage = l;
            cbLanguage.Items.Add(l);
              }
              lblCurrentLanguage.Text = "[" + m_currentLanguage.ToString() + "]";

              //enable/disable community features
              if (_userId != null)
              {
            TvdbUser user = new TvdbUser("user", _userId);
            m_tvdbHandler.UserInfo = user;
            List<TvdbSeries> favList = null;
            try
            {
              user.UserPreferredLanguage = m_tvdbHandler.GetPreferredLanguage();
              favList = m_tvdbHandler.GetUserFavorites(user.UserPreferredLanguage);
            }
            catch (TvdbInvalidApiKeyException ex)
            {
              MessageBox.Show(ex.Message);
            }
            catch (TvdbNotAvailableException ex)
            {
              MessageBox.Show(ex.Message);
            }

            if (favList != null)
            {
              foreach (TvdbSeries s in favList)
              {
            if (s != null)
            {
              cbUserFavourites.Items.Add(s);
            }
              }
            }
              }
              else
              {
            cbUserFavourites.Text = "No userinfo set";
            cbUserFavourites.Enabled = false;
              }

              cmdAddRemoveFavorites.Enabled = false;
              cmdSendSeriesRating.Enabled = false;
              raterSeriesYourRating.Enabled = false;
        }
Beispiel #7
0
 /// <summary>
 /// Saves the user data to cache
 /// </summary>
 /// <param name="_user">TvdbUser object</param>
 public void SaveToCache(TvdbUser _user)
 {
     if (_user != null)
       {
     if (!Directory.Exists(m_rootFolder)) Directory.CreateDirectory(m_rootFolder);
     m_xmlWriter.WriteUserData(_user, m_rootFolder + Path.DirectorySeparatorChar + "user_" + _user.UserIdentifier + ".xml");
       }
 }