示例#1
0
        public static XmlDocument GetAnimeXMLFromAPI(int animeID)
        {
            try
            {
                if (ShokoService.AnidbProcessor.IsHttpBanned)
                {
                    logger.Info("GetAnimeXMLFromAPI: banned, not getting");
                    return(null);
                }
                ShokoService.LastAniDBMessage     = DateTime.Now;
                ShokoService.LastAniDBHTTPMessage = DateTime.Now;

                var      anime      = Repo.Instance.AniDB_AnimeUpdate.GetByAnimeID(animeID);
                DateTime?prevUpdate = anime?.UpdatedAt;

                string uri = string.Format(AnimeURL, animeID);
                Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(ServerSettings.Instance.Culture);
                DateTime start = DateTime.Now;
                string   msg   = string.Format(Resources.AniDB_GettingAnimeXML, animeID) + "; prevUpdate: " + prevUpdate;
                ShokoService.LogToSystem(Constants.DBLogType.APIAniDBHTTP, msg);

                string rawXML = APIUtils.DownloadWebPage(uri);

                // Putting this here for no chance of error. It is ALWAYS created or updated when AniDB is called!
                var update = Repo.Instance.AniDB_AnimeUpdate.GetByAnimeID(animeID);
                using (var upd = Repo.Instance.AniDB_AnimeUpdate.BeginAddOrUpdate(() => Repo.Instance.AniDB_AnimeUpdate.GetByAnimeID(animeID), () => new AniDB_AnimeUpdate {
                    AnimeID = animeID
                }))
                {
                    upd.Entity.UpdatedAt = DateTime.Now;
                    upd.Commit();
                }

                TimeSpan ts      = DateTime.Now - start;
                string   content = rawXML;
                if (content.Length > 100)
                {
                    content = content.Substring(0, 100);
                }
                msg = string.Format(Resources.AniDB_GotAnimeXML, animeID, ts.TotalMilliseconds,
                                    content);
                ShokoService.LogToSystem(Constants.DBLogType.APIAniDBHTTP, msg);

                XmlDocument docAnime = null;
                if (0 < rawXML.Trim().Length&& !CheckForBan(rawXML))
                {
                    APIUtils.WriteAnimeHTTPToFile(animeID, rawXML);

                    docAnime = new XmlDocument();
                    docAnime.LoadXml(rawXML);
                }

                return(docAnime);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error in AniDBHTTPHelper.GetAnimeXMLFromAPI: {0}");
                return(null);
            }
        }
示例#2
0
        public static string GetMyListXMLFromAPI(string username, string password)
        {
            try
            {
                if (ShokoService.AnidbProcessor.IsHttpBanned)
                {
                    logger.Info("GetMyListXMLFromAPI: banned, not getting");
                    return(null);
                }
                ShokoService.LastAniDBMessage     = DateTime.Now;
                ShokoService.LastAniDBHTTPMessage = DateTime.Now;

                string uri    = string.Format(MyListURL, username, password);
                string rawXML = APIUtils.DownloadWebPage(uri);

                if (0 == rawXML.Trim().Length || CheckForBan(rawXML))
                {
                    rawXML = null;
                }

                return(rawXML);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error in AniDBHTTPHelper.GetMyListXMLFromAPI: {0}");
                return(null);
            }
        }
示例#3
0
        public static XmlDocument GetVotesXMLFromAPI(string username, string password)
        {
            try
            {
                if (ShokoService.AnidbProcessor.IsHttpBanned)
                {
                    logger.Info("GetVotesXMLFromAPI: banned, not getting");
                    return(null);
                }
                ShokoService.LastAniDBMessage     = DateTime.Now;
                ShokoService.LastAniDBHTTPMessage = DateTime.Now;

                string      uri      = string.Format(VotesURL, username, password);
                string      rawXML   = APIUtils.DownloadWebPage(uri);
                XmlDocument docAnime = null;
                if (0 < rawXML.Trim().Length&& !CheckForBan(rawXML))
                {
                    docAnime = new XmlDocument();
                    docAnime.LoadXml(rawXML);
                }
                return(docAnime);
            }
            catch
            {
                //BaseConfig.MyAnimeLog.Write("Error in AniDBHTTPHelper.GetAnimeXMLFromAPI: {0}", ex);
                return(null);
            }
        }