Ejemplo n.º 1
0
        internal Dictionary <int, TvdbRating> DownloadRatingsForSeries(string _userId, int _seriesId)
        {
            String xml  = "";
            String link = "";

            try
            {
                link = TvdbLinks.CreateSeriesRatingsLink(m_apiKey, _userId, _seriesId);
                xml  = m_webClient.DownloadString(link);
                Dictionary <int, TvdbRating> retList     = m_xmlHandler.ExtractRatings(xml, TvdbRating.ItemType.Series);
                Dictionary <int, TvdbRating> episodeList = m_xmlHandler.ExtractRatings(xml, TvdbRating.ItemType.Episode);
                if (retList != null && episodeList != null && retList.Count > 0)
                {
                    foreach (KeyValuePair <int, TvdbRating> r in episodeList)
                    {
                        if (!retList.ContainsKey(r.Key))
                        {
                            retList.Add(r.Key, r.Value);
                        }
                    }
                    return(retList);
                }
                else
                {
                    return(null);
                }
            }
            catch (XmlException ex)
            {
                Log.Error("Error parsing the xml file " + link + "\n\n" + xml, ex);
                throw new TvdbInvalidXmlException("Error parsing the xml file " + link + "\n\n" + xml);
            }
            catch (WebException ex)
            {
                Log.Warn("Request not successfull", ex);
                if (ex.Message.Equals("The remote server returned an error: (404) Not Found."))
                {
                    throw new TvdbInvalidApiKeyException("Couldn't connect to Thetvdb.com to retrieve rating of all series " +
                                                         ", it seems like you use an invalid api key");
                }
                else
                {
                    throw new TvdbNotAvailableException("Couldn't connect to Thetvdb.com to retrieve rating of all series " +
                                                        ", check your internet connection and the status of http://thetvdb.com");
                }
            }
        }