private static void AnimeFunction(int animeId, DatabaseControl dbControl) { while (true) { var animeObject = PageScraper.GetAnimeInfo(animeId); if (dbControl.AnimeExists(animeId, false)) { dbControl.InsertGenre(animeId, animeObject.Genre); dbControl.InsertAnime(animeObject); if (animeObject.SequelID != 0) { if (animeObject.SequelID != null && dbControl.AnimeExists((int)animeObject.SequelID, false)) { animeId = animeObject.SequelID.Value; continue; } if (animeObject.PrequelID != 0) { if (animeObject.PrequelID != null && dbControl.AnimeExists((int)animeObject.PrequelID, false)) { animeId = animeObject.PrequelID.Value; continue; } } } } else { var oldAnime = dbControl.GetAnimeById(animeId); var updateAnime = new UpdateAnime { Aired = animeObject.Aired == oldAnime.Aired ? null : animeObject.Aired, Episodes = animeObject.Episodes == oldAnime.Episodes ? null : animeObject.Episodes, Status = animeObject.Status == oldAnime.Status ? null : animeObject.Status, Duration = animeObject.Duration == oldAnime.Duration ? null : animeObject.Duration, Rating = animeObject.Rating == oldAnime.Rating ? null : animeObject.Rating, PrequelID = animeObject.PrequelID == oldAnime.PrequelID ? null : animeObject.PrequelID, SequelID = animeObject.SequelID == oldAnime.SequelID ? null : animeObject.SequelID, ID = animeId }; if (updateAnime.Status != null || updateAnime.Aired != null || updateAnime.Duration != null || updateAnime.Rating != null || updateAnime.PrequelID != null || updateAnime.SequelID != null || updateAnime.Episodes != null) { Console.WriteLine("\nAnimeID: " + animeId); if (updateAnime.Status != null) { Console.WriteLine("Status: " + oldAnime.Status + " -> " + updateAnime.Status); } if (updateAnime.Aired != null) { Console.WriteLine("Aired: " + oldAnime.Aired + " -> " + updateAnime.Aired); } if (updateAnime.Duration != null) { Console.WriteLine("Duration: " + oldAnime.Duration + " -> " + updateAnime.Duration); } if (updateAnime.Rating != null) { Console.WriteLine("Rating: " + oldAnime.Rating + " -> " + updateAnime.Rating); } if (updateAnime.PrequelID != null) { Console.WriteLine("Prequel: " + oldAnime.PrequelID + " -> " + updateAnime.PrequelID); } if (updateAnime.SequelID != null) { Console.WriteLine("Sequel: " + oldAnime.SequelID + " -> " + updateAnime.SequelID); } if (updateAnime.Episodes != null) { Console.WriteLine("Episodes: " + oldAnime.Episodes + " -> " + updateAnime.Episodes); } dbControl.UpdateAnime(updateAnime); } } break; } }
public void UpdateAnime(UpdateAnime anime) { _connection.Execute("UpdateAnime", anime, commandType: CommandType.StoredProcedure); }
private static void RunAsyncAnime(IList <string> animeUrlList) { var dbControl = new DatabaseControl(); var check = new UrlChecker(); var AnimeList = check.Check(animeUrlList); var enumerable = AnimeList as IList <Anime> ?? AnimeList.ToList(); var counter = -1; while (enumerable.Count < animeUrlList.Count) { if (counter != enumerable.Count) { Console.WriteLine(enumerable.Count + "/" + animeUrlList.Count); counter = enumerable.Count; } } foreach (var anime in enumerable) { if (dbControl.AnimeExists(anime.ID, false)) { dbControl.InsertGenre(anime.ID, anime.Genre); dbControl.InsertAnime(anime); } else { var oldAnime = dbControl.GetAnimeById(anime.ID); var updateAnime = new UpdateAnime { Aired = anime.Aired == oldAnime.Aired ? null : anime.Aired, Episodes = anime.Episodes == oldAnime.Episodes ? null : anime.Episodes, Status = anime.Status == oldAnime.Status ? null : anime.Status, Duration = anime.Duration == oldAnime.Duration ? null : anime.Duration, Rating = anime.Rating == oldAnime.Rating ? null : anime.Rating, PrequelID = anime.PrequelID == oldAnime.PrequelID ? null : anime.PrequelID, SequelID = anime.SequelID == oldAnime.SequelID ? null : anime.SequelID, ID = anime.ID }; if (updateAnime.Status != null || updateAnime.Aired != null || updateAnime.Duration != null || updateAnime.Rating != null || updateAnime.PrequelID != null || updateAnime.SequelID != null || updateAnime.Episodes != null) { Console.WriteLine("\nAnimeID: " + anime.ID); if (updateAnime.Status != null) { Console.WriteLine("Status: " + oldAnime.Status + " -> " + updateAnime.Status); } if (updateAnime.Aired != null) { Console.WriteLine("Aired: " + oldAnime.Aired + " -> " + updateAnime.Aired); } if (updateAnime.Duration != null) { Console.WriteLine("Duration: " + oldAnime.Duration + " -> " + updateAnime.Duration); } if (updateAnime.Rating != null) { Console.WriteLine("Rating: " + oldAnime.Rating + " -> " + updateAnime.Rating); } if (updateAnime.PrequelID != null) { Console.WriteLine("Prequel: " + oldAnime.PrequelID + " -> " + updateAnime.PrequelID); } if (updateAnime.SequelID != null) { Console.WriteLine("Sequel: " + oldAnime.SequelID + " -> " + updateAnime.SequelID); } if (updateAnime.Episodes != null) { Console.WriteLine("Episodes: " + oldAnime.Episodes + " -> " + updateAnime.Episodes); } dbControl.UpdateAnime(updateAnime); } } } Console.ReadLine(); }