public virtual enHelperActivityType Process()
        {
            string appPath  = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            string filePath = Path.Combine(appPath, "Anime_HTTP");

            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }

            string fileName         = string.Format("AnimeDoc_{0}.xml", animeID);
            string fileNameWithPath = Path.Combine(filePath, fileName);

            if (!CacheOnly)
            {
                JMMService.LastAniDBMessage     = DateTime.Now;
                JMMService.LastAniDBHTTPMessage = DateTime.Now;
            }

            XmlDocument docAnime = null;

            if (CacheOnly)
            {
                xmlResult = AzureWebAPI.Get_AnimeXML(animeID);
                if (!string.IsNullOrEmpty(xmlResult))
                {
                    docAnime = new XmlDocument();
                    docAnime.LoadXml(xmlResult);
                }
            }
            else
            {
                if (!ForceFromAniDB)
                {
                    //Disable usage of Azure API for this type of data

                    /*xmlResult = AzureWebAPI.Get_AnimeXML(animeID);
                     *                  if (string.IsNullOrEmpty(xmlResult))
                     *                  {
                     *                          docAnime = AniDBHTTPHelper.GetAnimeXMLFromAPI(animeID, ref xmlResult);
                     *                  }
                     *                  else
                     *                  {
                     *                          docAnime = new XmlDocument();
                     *                          docAnime.LoadXml(xmlResult);
                     *                  }*/

                    docAnime = AniDBHTTPHelper.GetAnimeXMLFromAPI(animeID, ref xmlResult);
                }
                else
                {
                    docAnime = AniDBHTTPHelper.GetAnimeXMLFromAPI(animeID, ref xmlResult);
                    //XmlDocument docAnime = LoadAnimeHTTPFromFile(animeID);
                }
            }

            if (xmlResult.Trim().Length > 0)
            {
                WriteAnimeHTTPToFile(animeID, xmlResult);
            }

            if (CheckForBan(xmlResult))
            {
                return(enHelperActivityType.NoSuchAnime);
            }

            if (docAnime != null)
            {
                anime           = AniDBHTTPHelper.ProcessAnimeDetails(docAnime, animeID);
                episodes        = AniDBHTTPHelper.ProcessEpisodes(docAnime, animeID);
                titles          = AniDBHTTPHelper.ProcessTitles(docAnime, animeID);
                tags            = AniDBHTTPHelper.ProcessTags(docAnime, animeID);
                characters      = AniDBHTTPHelper.ProcessCharacters(docAnime, animeID);
                relations       = AniDBHTTPHelper.ProcessRelations(docAnime, animeID);
                similarAnime    = AniDBHTTPHelper.ProcessSimilarAnime(docAnime, animeID);
                recommendations = AniDBHTTPHelper.ProcessRecommendations(docAnime, animeID);
                return(enHelperActivityType.GotAnimeInfoHTTP);
            }
            else
            {
                return(enHelperActivityType.NoSuchAnime);
            }
        }
예제 #2
0
        public virtual enHelperActivityType Process()
        {
            if (!CacheOnly)
            {
                ShokoService.LastAniDBMessage     = DateTime.Now;
                ShokoService.LastAniDBHTTPMessage = DateTime.Now;
            }

            XmlDocument docAnime = null;

            if (CacheOnly)
            {
                xmlResult = AzureWebAPI.Get_AnimeXML(animeID);
                if (!string.IsNullOrEmpty(xmlResult))
                {
                    docAnime = new XmlDocument();
                    docAnime.LoadXml(xmlResult);
                }
            }
            else
            {
                if (!ForceFromAniDB)
                {
                    //Disable usage of Azure API for this type of data

                    /*xmlResult = AzureWebAPI.Get_AnimeXML(animeID);
                     *                  if (string.IsNullOrEmpty(xmlResult))
                     *                  {
                     *                          docAnime = AniDBHTTPHelper.GetAnimeXMLFromAPI(animeID, ref xmlResult);
                     *                  }
                     *                  else
                     *                  {
                     *                          docAnime = new XmlDocument();
                     *                          docAnime.LoadXml(xmlResult);
                     *                  }*/

                    //logger.Info("Trying to load Anime HTTP info from cache file...");
                    docAnime = LoadAnimeHTTPFromFile(animeID);
                    if (docAnime == null)
                    {
                        //logger.Info("No Anime HTTP info found in cache file, loading from HTTP API");
                        docAnime = AniDBHTTPHelper.GetAnimeXMLFromAPI(animeID, ref xmlResult);
                    }
                }
                else
                {
                    docAnime = AniDBHTTPHelper.GetAnimeXMLFromAPI(animeID, ref xmlResult);
                }
            }

            if (CheckForBan(xmlResult))
            {
                return(enHelperActivityType.NoSuchAnime);
            }

            if (xmlResult.Trim().Length > 0)
            {
                WriteAnimeHTTPToFile(animeID, xmlResult);
            }

            if (docAnime != null)
            {
                anime           = AniDBHTTPHelper.ProcessAnimeDetails(docAnime, animeID);
                episodes        = AniDBHTTPHelper.ProcessEpisodes(docAnime, animeID);
                titles          = AniDBHTTPHelper.ProcessTitles(docAnime, animeID);
                tags            = AniDBHTTPHelper.ProcessTags(docAnime, animeID);
                characters      = AniDBHTTPHelper.ProcessCharacters(docAnime, animeID);
                relations       = AniDBHTTPHelper.ProcessRelations(docAnime, animeID);
                similarAnime    = AniDBHTTPHelper.ProcessSimilarAnime(docAnime, animeID);
                recommendations = AniDBHTTPHelper.ProcessRecommendations(docAnime, animeID);
                return(enHelperActivityType.GotAnimeInfoHTTP);
            }
            else
            {
                return(enHelperActivityType.NoSuchAnime);
            }
        }