Esempio n. 1
0
        public static void PopulateResourceLinks()
        {
            int i      = 0;
            var animes = RepoFactory.AniDB_Anime.GetAll().ToList();

            foreach (var anime in animes)
            {
                if (i % 10 == 0)
                {
                    ServerState.Instance.CurrentSetupStatus = string.Format(
                        Commons.Properties.Resources.Database_Validating, "Populating Resource Links from Cache",
                        $" {i}/{animes.Count}");
                }
                i++;
                try
                {
                    var xmlDocument = APIUtils.LoadAnimeHTTPFromFile(anime.AnimeID);
                    if (xmlDocument == null)
                    {
                        continue;
                    }
                    var resourceLinks = AniDBHTTPHelper.ProcessResources(xmlDocument, anime.AnimeID);
                    anime.CreateResources(resourceLinks);
                }
                catch (Exception e)
                {
                    logger.Error(
                        $"There was an error Populating Resource Links for AniDB_Anime {anime.AnimeID}, Update the Series' AniDB Info for a full stack: {e.Message}");
                }
            }


            using (var session = DatabaseFactory.SessionFactory.OpenStatelessSession())
            {
                i = 0;
                var batches = animes.Batch(50).ToList();
                foreach (var animeBatch in batches)
                {
                    i++;
                    ServerState.Instance.CurrentSetupStatus = string.Format(Commons.Properties.Resources.Database_Validating,
                                                                            "Saving AniDB_Anime batch ", $"{i}/{batches.Count}");
                    try
                    {
                        using (var transaction = session.BeginTransaction())
                        {
                            foreach (var anime in animeBatch)
                            {
                                RepoFactory.AniDB_Anime.SaveWithOpenTransaction(session.Wrap(), anime);
                            }
                            transaction.Commit();
                        }
                    }
                    catch (Exception e)
                    {
                        logger.Error($"There was an error saving anime while Populating Resource Links: {e}");
                    }
                }
            }
        }
Esempio n. 2
0
        public static void FixAniDB_EpisodesWithMissingTitles()
        {
            logger.Info("Checking for Episodes with Missing Titles");
            var episodes = RepoFactory.AniDB_Episode.GetAll()
                           .Where(a => !RepoFactory.AniDB_Episode_Title.GetByEpisodeID(a.EpisodeID).Any() &&
                                  RepoFactory.AnimeSeries.GetByAnimeID(a.AnimeID) != null).ToList();
            var animeIDs = episodes.Select(a => a.AnimeID).Distinct().OrderBy(a => a).ToList();
            int count    = 0;

            logger.Info($"There are {episodes.Count} episodes in {animeIDs.Count} anime with missing titles. Attempting to fill them from HTTP cache");
            foreach (int animeID in animeIDs)
            {
                count++;
                try
                {
                    var anime = RepoFactory.AniDB_Anime.GetByAnimeID(animeID);
                    if (anime == null)
                    {
                        logger.Info($"Anime {animeID} is missing it's AniDB_Anime record. That's a problem. Try importing a file for the anime.");
                        continue;
                    }

                    ServerState.Instance.CurrentSetupStatus = string.Format(
                        Commons.Properties.Resources.Database_Validating,
                        $"Generating Episode Info for {anime.MainTitle}",
                        $" {count}/{animeIDs.Count}");
                    XmlDocument docAnime = APIUtils.LoadAnimeHTTPFromFile(animeID);
                    if (docAnime == null)
                    {
                        continue;
                    }
                    logger.Info($"{anime.MainTitle} has a proper HTTP cache. Attempting to regenerate info from it.");

                    var rawEpisodes = AniDBHTTPHelper.ProcessEpisodes(docAnime, animeID);
                    anime.CreateEpisodes(rawEpisodes);
                    logger.Info($"Recreating Episodes for {anime.MainTitle}");
                    SVR_AnimeSeries series = RepoFactory.AnimeSeries.GetByAnimeID(anime.AnimeID);
                    if (series == null)
                    {
                        continue;
                    }
                    series.CreateAnimeEpisodes();
                }
                catch (Exception e)
                {
                    logger.Error($"Error Populating Episode Titles for Anime ({animeID}): {e}");
                }
            }
            logger.Info("Finished Filling Episode Titles from Cache.");
        }
Esempio n. 3
0
        public ActionResult UpdateMissingAniDBXML()
        {
            try
            {
                var allAnime = RepoFactory.AniDB_Anime.GetAll().Select(a => a.AnimeID).OrderBy(a => a).ToList();
                logger.Info($"Starting the check for {allAnime.Count} anime XML files");
                int updatedAnime = 0;
                for (var i = 0; i < allAnime.Count; i++)
                {
                    var animeID = allAnime[i];
                    if (i % 10 == 1)
                    {
                        logger.Info($"Checking anime {i + 1}/{allAnime.Count} for XML file");
                    }

                    var xml = APIUtils.LoadAnimeHTTPFromFile(animeID);
                    if (xml == null)
                    {
                        CommandRequest_GetAnimeHTTP cmd = new CommandRequest_GetAnimeHTTP(animeID, true, false);
                        cmd.Save();
                        updatedAnime++;
                        continue;
                    }

                    var rawAnime = AniDBHTTPHelper.ProcessAnimeDetails(xml, animeID);
                    if (rawAnime == null)
                    {
                        CommandRequest_GetAnimeHTTP cmd = new CommandRequest_GetAnimeHTTP(animeID, true, false);
                        cmd.Save();
                        updatedAnime++;
                    }
                }
                logger.Info($"Updating {updatedAnime} anime");
            }
            catch (Exception e)
            {
                logger.Error($"Error checking and queuing AniDB XML Updates: {e}");
                return(APIStatus.InternalError(e.Message));
            }
            return(APIStatus.OK());
        }
Esempio n. 4
0
        public ActionResult UpdateMissingAniDBXML()
        {
            try
            {
                var allAnime = RepoFactory.AniDB_Anime.GetAll().Select(a => a.AnimeID).OrderBy(a => a).ToList();
                Logger.LogInformation($"Starting the check for {allAnime.Count} anime XML files");
                int updatedAnime = 0;
                for (var i = 0; i < allAnime.Count; i++)
                {
                    var animeID = allAnime[i];
                    if (i % 10 == 1)
                    {
                        Logger.LogInformation($"Checking anime {i + 1}/{allAnime.Count} for XML file");
                    }

                    var xml = APIUtils.LoadAnimeHTTPFromFile(animeID);
                    if (xml == null)
                    {
                        Series.QueueAniDBRefresh(animeID, true, false, false);
                        updatedAnime++;
                        continue;
                    }

                    var rawAnime = AniDBHTTPHelper.ProcessAnimeDetails(xml, animeID);
                    if (rawAnime == null)
                    {
                        Series.QueueAniDBRefresh(animeID, true, false, false);
                        updatedAnime++;
                    }
                }
                Logger.LogInformation($"Updating {updatedAnime} anime");
            }
            catch (Exception e)
            {
                Logger.LogError(e, $"Error checking and queuing AniDB XML Updates: {e}");
                return(InternalError(e.Message));
            }
            return(Ok());
        }
        public static void FixAniDB_EpisodesWithMissingTitles()
        {
            var specials = RepoFactory.AniDB_Episode.GetAll().Where(a => string.IsNullOrEmpty(a.GetEnglishTitle()))
                           .Select(a => a.AnimeID).Distinct().OrderBy(a => a).ToList();
            int count = 0;

            foreach (int animeID in specials)
            {
                count++;
                try
                {
                    var anime = RepoFactory.AniDB_Anime.GetByAnimeID(animeID);
                    if (anime == null)
                    {
                        continue;
                    }

                    ServerState.Instance.CurrentSetupStatus = string.Format(
                        Commons.Properties.Resources.Database_Validating,
                        $"Generating Episode Info for {anime.MainTitle}",
                        $" {count}/{specials.Count}");
                    XmlDocument docAnime = APIUtils.LoadAnimeHTTPFromFile(animeID);
                    if (docAnime == null)
                    {
                        continue;
                    }

                    var episodes = AniDBHTTPHelper.ProcessEpisodes(docAnime, animeID);
                    anime.CreateEpisodes(episodes);
                    // we don't need to save the AniDB_Anime, since nothing has changed in it
                }
                catch (Exception e)
                {
                    logger.Error($"Error Populating Episode Titles for Anime ({animeID}): {e}");
                }
            }
        }