Example #1
0
        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;
        }
Example #2
0
		public AniDB_Seiyuu GetSeiyuu(ISession session)
		{
			AniDB_Character_SeiyuuRepository repCharSeiyuu = new AniDB_Character_SeiyuuRepository();
			List<AniDB_Character_Seiyuu> charSeiyuus = repCharSeiyuu.GetByCharID(session, CharID);

			if (charSeiyuus.Count > 0)
			{
				// just use the first creator
				AniDB_SeiyuuRepository repCreators = new AniDB_SeiyuuRepository();
				return repCreators.GetBySeiyuuID(session, charSeiyuus[0].SeiyuuID);
			}

			return null;
		}
Example #3
0
        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();
            }
        }