public List<Contract_AniDB_Character> GetCharactersForSeiyuu(int aniDB_SeiyuuID) { List<Contract_AniDB_Character> chars = new List<Contract_AniDB_Character>(); try { AniDB_SeiyuuRepository repSeiyuu = new AniDB_SeiyuuRepository(); AniDB_Seiyuu seiyuu = repSeiyuu.GetByID(aniDB_SeiyuuID); if (seiyuu == null) return chars; AniDB_Character_SeiyuuRepository repCharSei = new AniDB_Character_SeiyuuRepository(); List<AniDB_Character_Seiyuu> links = repCharSei.GetBySeiyuuID(seiyuu.SeiyuuID); AniDB_Anime_CharacterRepository repAnimeChar = new AniDB_Anime_CharacterRepository(); AniDB_CharacterRepository repChar = new AniDB_CharacterRepository(); AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); foreach (AniDB_Character_Seiyuu chrSei in links) { AniDB_Character chr = repChar.GetByCharID(chrSei.CharID); if (chr != null) { List<AniDB_Anime_Character> aniChars = repAnimeChar.GetByCharID(chr.CharID); if (aniChars.Count > 0) { AniDB_Anime anime = repAnime.GetByAnimeID(aniChars[0].AnimeID); if (anime != null) { Contract_AniDB_Character contract = chr.ToContract(aniChars[0]); contract.Anime = anime.ToContract(true, null); chars.Add(contract); } } } } } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } return chars; }
public List<Contract_AniDB_Character> GetCharactersForAnime(int animeID) { List<Contract_AniDB_Character> chars = new List<Contract_AniDB_Character>(); try { AniDB_Anime_CharacterRepository repAnimeChar = new AniDB_Anime_CharacterRepository(); AniDB_CharacterRepository repChar = new AniDB_CharacterRepository(); List<AniDB_Anime_Character> animeChars = repAnimeChar.GetByAnimeID(animeID); if (animeChars == null || animeChars.Count == 0) return chars; foreach (AniDB_Anime_Character animeChar in animeChars) { AniDB_Character chr = repChar.GetByCharID(animeChar.CharID); if (chr != null) chars.Add(chr.ToContract(animeChar)); } } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } return chars; }
public List<MetroContract_AniDB_Character> GetCharactersForAnime(int animeID, int maxRecords) { List<MetroContract_AniDB_Character> chars = new List<MetroContract_AniDB_Character>(); try { using (var session = JMMService.SessionFactory.OpenSession()) { AniDB_Anime_CharacterRepository repAnimeChar = new AniDB_Anime_CharacterRepository(); AniDB_CharacterRepository repChar = new AniDB_CharacterRepository(); List<AniDB_Anime_Character> animeChars = repAnimeChar.GetByAnimeID(session, animeID); if (animeChars == null || animeChars.Count == 0) return chars; int cnt = 0; // first get all the main characters foreach (AniDB_Anime_Character animeChar in animeChars.Where(item => item.CharType.Equals("main character in", StringComparison.InvariantCultureIgnoreCase))) { cnt++; AniDB_Character chr = repChar.GetByCharID(animeChar.CharID); if (chr != null) { MetroContract_AniDB_Character contract = new MetroContract_AniDB_Character(); chars.Add(chr.ToContractMetro(session, animeChar)); } if (cnt == maxRecords) break; } // now get the rest foreach (AniDB_Anime_Character animeChar in animeChars.Where(item => !item.CharType.Equals("main character in", StringComparison.InvariantCultureIgnoreCase))) { cnt++; AniDB_Character chr = repChar.GetByCharID(animeChar.CharID); if (chr != null) { MetroContract_AniDB_Character contract = new MetroContract_AniDB_Character(); chars.Add(chr.ToContractMetro(session, animeChar)); } if (cnt == maxRecords) break; } } } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } return chars; }
public List<AniDB_Anime_Character> GetAnimeCharacters(ISession session) { AniDB_Anime_CharacterRepository repRels = new AniDB_Anime_CharacterRepository(); return repRels.GetByAnimeID(session, AnimeID); }
private void CreateCharacters(ISession session, List<Raw_AniDB_Character> chars) { if (chars == null) return; AniDB_CharacterRepository repChars = new AniDB_CharacterRepository(); AniDB_Anime_CharacterRepository repAnimeChars = new AniDB_Anime_CharacterRepository(); AniDB_Character_SeiyuuRepository repCharSeiyuu = new AniDB_Character_SeiyuuRepository(); AniDB_SeiyuuRepository repSeiyuu = new AniDB_SeiyuuRepository(); // delete all the existing cross references just in case one has been removed List<AniDB_Anime_Character> animeChars = repAnimeChars.GetByAnimeID(session, AnimeID); using (var transaction = session.BeginTransaction()) { foreach (AniDB_Anime_Character xref in animeChars) session.Delete(xref); transaction.Commit(); } List<AniDB_Character> chrsToSave = new List<AniDB_Character>(); List<AniDB_Anime_Character> xrefsToSave = new List<AniDB_Anime_Character>(); Dictionary<int, AniDB_Seiyuu> seiyuuToSave = new Dictionary<int, AniDB_Seiyuu>(); List<AniDB_Character_Seiyuu> seiyuuXrefToSave = new List<AniDB_Character_Seiyuu>(); // delete existing relationships to seiyuu's List<AniDB_Character_Seiyuu> charSeiyuusToDelete = new List<AniDB_Character_Seiyuu>(); foreach (Raw_AniDB_Character rawchar in chars) { // delete existing relationships to seiyuu's List<AniDB_Character_Seiyuu> allCharSei = repCharSeiyuu.GetByCharID(session, rawchar.CharID); foreach (AniDB_Character_Seiyuu xref in allCharSei) charSeiyuusToDelete.Add(xref); } using (var transaction = session.BeginTransaction()) { foreach (AniDB_Character_Seiyuu xref in charSeiyuusToDelete) session.Delete(xref); transaction.Commit(); } foreach (Raw_AniDB_Character rawchar in chars) { AniDB_Character chr = repChars.GetByCharID(session, rawchar.CharID); if (chr == null) chr = new AniDB_Character(); chr.PopulateFromHTTP(rawchar); chrsToSave.Add(chr); // create cross ref's between anime and character, but don't actually download anything AniDB_Anime_Character anime_char = new AniDB_Anime_Character(); anime_char.Populate(rawchar); xrefsToSave.Add(anime_char); foreach (Raw_AniDB_Seiyuu rawSeiyuu in rawchar.Seiyuus) { // save the link between character and seiyuu AniDB_Character_Seiyuu acc = repCharSeiyuu.GetByCharIDAndSeiyuuID(session, rawchar.CharID, rawSeiyuu.SeiyuuID); if (acc == null) { acc = new AniDB_Character_Seiyuu(); acc.CharID = chr.CharID; acc.SeiyuuID = rawSeiyuu.SeiyuuID; seiyuuXrefToSave.Add(acc); } // save the seiyuu AniDB_Seiyuu seiyuu = repSeiyuu.GetBySeiyuuID(session, rawSeiyuu.SeiyuuID); if (seiyuu == null) seiyuu = new AniDB_Seiyuu(); seiyuu.PicName = rawSeiyuu.PicName; seiyuu.SeiyuuID = rawSeiyuu.SeiyuuID; seiyuu.SeiyuuName = rawSeiyuu.SeiyuuName; seiyuuToSave[seiyuu.SeiyuuID] = seiyuu; } } using (var transaction = session.BeginTransaction()) { foreach (AniDB_Character chr in chrsToSave) session.SaveOrUpdate(chr); foreach (AniDB_Anime_Character xref in xrefsToSave) session.SaveOrUpdate(xref); foreach (AniDB_Seiyuu seiyuu in seiyuuToSave.Values) session.SaveOrUpdate(seiyuu); foreach (AniDB_Character_Seiyuu xrefSeiyuu in seiyuuXrefToSave) session.SaveOrUpdate(xrefSeiyuu); transaction.Commit(); } }
public JMMServer.Providers.Azure.AnimeFull ToContractAzure(ISession session) { JMMServer.Providers.Azure.AnimeFull contract = new JMMServer.Providers.Azure.AnimeFull(); contract.Detail = new Providers.Azure.AnimeDetail(); contract.Characters = new List<Providers.Azure.AnimeCharacter>(); contract.Comments = new List<Providers.Azure.AnimeComment>(); contract.Detail.AllTags = this.TagsString; contract.Detail.AllCategories = this.TagsString; contract.Detail.AnimeID = this.AnimeID; contract.Detail.AnimeName = this.MainTitle; contract.Detail.AnimeType = this.AnimeTypeDescription; contract.Detail.Description = this.Description; contract.Detail.EndDateLong = Utils.GetAniDBDateAsSeconds(this.EndDate); contract.Detail.StartDateLong = Utils.GetAniDBDateAsSeconds(this.AirDate); contract.Detail.EpisodeCountNormal = this.EpisodeCountNormal; contract.Detail.EpisodeCountSpecial = this.EpisodeCountSpecial; contract.Detail.FanartURL = GetDefaultFanartOnlineURL(session); contract.Detail.OverallRating = this.AniDBRating; contract.Detail.PosterURL = string.Format(Constants.URLS.AniDB_Images, Picname); contract.Detail.TotalVotes = this.AniDBTotalVotes; AniDB_Anime_CharacterRepository repAnimeChar = new AniDB_Anime_CharacterRepository(); AniDB_CharacterRepository repChar = new AniDB_CharacterRepository(); List<AniDB_Anime_Character> animeChars = repAnimeChar.GetByAnimeID(session, AnimeID); if (animeChars != null || animeChars.Count > 0) { // first get all the main characters foreach (AniDB_Anime_Character animeChar in animeChars.Where(item => item.CharType.Equals("main character in", StringComparison.InvariantCultureIgnoreCase))) { AniDB_Character chr = repChar.GetByCharID(session, animeChar.CharID); if (chr != null) contract.Characters.Add(chr.ToContractAzure(animeChar)); } // now get the rest foreach (AniDB_Anime_Character animeChar in animeChars.Where(item => !item.CharType.Equals("main character in", StringComparison.InvariantCultureIgnoreCase))) { AniDB_Character chr = repChar.GetByCharID(session, animeChar.CharID); if (chr != null) contract.Characters.Add(chr.ToContractAzure(animeChar)); } } AniDB_RecommendationRepository repBA = new AniDB_RecommendationRepository(); foreach (AniDB_Recommendation rec in repBA.GetByAnimeID(session, AnimeID)) { JMMServer.Providers.Azure.AnimeComment comment = new JMMServer.Providers.Azure.AnimeComment(); comment.UserID = rec.UserID; comment.UserName = ""; // Comment details comment.CommentText = rec.RecommendationText; comment.IsSpoiler = false; comment.CommentDateLong = 0; comment.ImageURL = string.Empty; AniDBRecommendationType recType = (AniDBRecommendationType)rec.RecommendationType; switch (recType) { case AniDBRecommendationType.ForFans: comment.CommentType = (int)WhatPeopleAreSayingType.AniDBForFans; break; case AniDBRecommendationType.MustSee: comment.CommentType = (int)WhatPeopleAreSayingType.AniDBMustSee; break; case AniDBRecommendationType.Recommended: comment.CommentType = (int)WhatPeopleAreSayingType.AniDBRecommendation; break; } comment.Source = "AniDB"; contract.Comments.Add(comment); } return contract; }