public static void InitCache() { string t = "AnimeEpisodes"; ServerState.Instance.CurrentSetupStatus = string.Format(JMMServer.Properties.Resources.Database_Cache, t, string.Empty); AnimeEpisodeRepository repo = new AnimeEpisodeRepository(); Cache = new PocoCache <int, AnimeEpisode>(repo.InternalGetAll(), a => a.AnimeEpisodeID); Series = Cache.CreateIndex(a => a.AnimeSeriesID); EpisodeIDs = Cache.CreateIndex(a => a.AniDB_EpisodeID); int cnt = 0; List <AnimeEpisode> grps = Cache.Values.Where(a => a.PlexContractVersion < AnimeEpisode.PLEXCONTRACT_VERSION).ToList(); int max = grps.Count; foreach (AnimeEpisode g in grps) { repo.Save(g); cnt++; if (cnt % 10 == 0) { ServerState.Instance.CurrentSetupStatus = string.Format(JMMServer.Properties.Resources.Database_Cache, t, " DbRegen - " + cnt + "/" + max); } } ServerState.Instance.CurrentSetupStatus = string.Format(JMMServer.Properties.Resources.Database_Cache, t, " DbRegen - " + max + "/" + max); }
public void Save(VideoLocal obj, bool updateEpisodes) { lock (obj) { if (obj.VideoLocalID == 0) { obj.Media = null; using (var session = JMMService.SessionFactory.OpenSession()) { // populate the database using (var transaction = session.BeginTransaction()) { session.SaveOrUpdate(obj); transaction.Commit(); } } } using (var session = JMMService.SessionFactory.OpenSession()) { UpdateMediaContracts(obj); using (var transaction = session.BeginTransaction()) { session.SaveOrUpdate(obj); transaction.Commit(); } Cache.Update(obj); } } if (updateEpisodes) { AnimeEpisodeRepository repo = new AnimeEpisodeRepository(); foreach (AnimeEpisode ep in obj.GetAnimeEpisodes()) { repo.Save(ep); } } }
public void CreateAnimeEpisode(ISession session, int animeSeriesID) { // check if there is an existing episode for this EpisodeID AnimeEpisodeRepository repEps = new AnimeEpisodeRepository(); List<AnimeEpisode> existingEps = repEps.GetByAniEpisodeIDAndSeriesID(session, EpisodeID, animeSeriesID); if (existingEps.Count == 0) { AnimeEpisode animeEp = new AnimeEpisode(); animeEp.Populate(this); animeEp.AnimeSeriesID = animeSeriesID; repEps.Save(session, animeEp); } }