public void Save(AniDB_Character_Seiyuu obj)
		{
			using (var session = JMMService.SessionFactory.OpenSession())
			{
				// populate the database
				using (var transaction = session.BeginTransaction())
				{
					session.SaveOrUpdate(obj);
					transaction.Commit();
				}
			}
		}
示例#2
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();
            }
        }
示例#3
0
        private void CreateCharacters(ISession session, List<Raw_AniDB_Character> chars)
        {
            if (chars == null) return;

            ISessionWrapper sessionWrapper = session.Wrap();

            // delete all the existing cross references just in case one has been removed
            List<AniDB_Anime_Character> animeChars = RepoFactory.AniDB_Anime_Character.GetByAnimeID(sessionWrapper, AnimeID);

            RepoFactory.AniDB_Anime_Character.Delete(animeChars);

            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 = RepoFactory.AniDB_Character_Seiyuu.GetByCharID(session, rawchar.CharID);
                foreach (AniDB_Character_Seiyuu xref in allCharSei)
                    charSeiyuusToDelete.Add(xref);
            }
            RepoFactory.AniDB_Character_Seiyuu.Delete(charSeiyuusToDelete);

            foreach (Raw_AniDB_Character rawchar in chars)
            {
                AniDB_Character chr = RepoFactory.AniDB_Character.GetByCharID(sessionWrapper, 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 = RepoFactory.AniDB_Character_Seiyuu.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 = RepoFactory.AniDB_Seiyuu.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;
                }
            }
            RepoFactory.AniDB_Character.Save(chrsToSave);
            RepoFactory.AniDB_Anime_Character.Save(xrefsToSave);
            RepoFactory.AniDB_Seiyuu.Save(seiyuuToSave.Values.ToList());
            RepoFactory.AniDB_Character_Seiyuu.Save(seiyuuXrefToSave);
        }