public ILookup <int, AniDB_Anime_Title> GetByAnimeIDs(ISessionWrapper session, ICollection <int> ids)
        {
            if (session == null)
            {
                throw new ArgumentNullException(nameof(session));
            }
            if (ids == null)
            {
                throw new ArgumentNullException(nameof(ids));
            }

            if (ids.Count == 0)
            {
                return(EmptyLookup <int, AniDB_Anime_Title> .Instance);
            }

            lock (globalDBLock)
            {
                var titles = session.CreateCriteria <AniDB_Anime_Title>()
                             .Add(Restrictions.InG(nameof(AniDB_Anime_Title.AnimeID), ids))
                             .List <AniDB_Anime_Title>()
                             .ToLookup(t => t.AnimeID);

                return(titles);
            }
        }
        /// <summary>
        /// Gets other cross references by anime ID.
        /// </summary>
        /// <param name="session">The NHibernate session.</param>
        /// <param name="animeIds">An optional list of anime IDs whose cross references are to be retrieved.
        /// Can be <c>null</c> to get cross references for ALL anime.</param>
        /// <param name="xrefTypes">The types of cross references to find.</param>
        /// <returns>A <see cref="ILookup{TKey,TElement}"/> that maps anime ID to their associated other cross references.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="session"/> is <c>null</c>.</exception>
        public ILookup <int, CrossRef_AniDB_Other> GetByAnimeIDsAndType(ISessionWrapper session,
                                                                        IReadOnlyCollection <int> animeIds,
                                                                        params CrossRefType[] xrefTypes)
        {
            if (session == null)
            {
                throw new ArgumentNullException(nameof(session));
            }

            if (xrefTypes == null || xrefTypes.Length == 0 || animeIds?.Count == 0)
            {
                return(EmptyLookup <int, CrossRef_AniDB_Other> .Instance);
            }

            ICriteria criteria = session.CreateCriteria <CrossRef_AniDB_Other>()
                                 .Add(Restrictions.In(nameof(CrossRef_AniDB_Other.CrossRefType), xrefTypes));

            if (animeIds != null)
            {
                criteria = criteria.Add(Restrictions.InG(nameof(CrossRef_AniDB_Other.AnimeID), animeIds));
            }

            var crossRefs = criteria.List <CrossRef_AniDB_Other>()
                            .ToLookup(cr => cr.AnimeID);

            return(crossRefs);
        }
Exemple #3
0
        public ILookup <int, CrossRef_AniDB_MAL> GetByAnimeIDs(ISessionWrapper session, int[] animeIds)
        {
            if (session == null)
            {
                throw new ArgumentNullException(nameof(session));
            }
            if (animeIds == null)
            {
                throw new ArgumentNullException(nameof(animeIds));
            }

            if (animeIds.Length == 0)
            {
                return(EmptyLookup <int, CrossRef_AniDB_MAL> .Instance);
            }

            var xrefByAnime = session.CreateCriteria <CrossRef_AniDB_MAL>()
                              .Add(Restrictions.In(nameof(CrossRef_AniDB_MAL.AnimeID), animeIds))
                              .AddOrder(Order.Asc(nameof(CrossRef_AniDB_MAL.StartEpisodeType)))
                              .AddOrder(Order.Asc(nameof(CrossRef_AniDB_MAL.StartEpisodeNumber)))
                              .List <CrossRef_AniDB_MAL>()
                              .ToLookup(cr => cr.AnimeID);

            return(xrefByAnime);
        }
Exemple #4
0
 public virtual IReadOnlyList <T> GetAll(ISessionWrapper session)
 {
     lock (globalDBLock)
     {
         return(session.CreateCriteria(typeof(T)).List <T>().ToList());
     }
 }
Exemple #5
0
        public ILookup <int, CrossRef_AniDB_TvDBV2> GetByAnimeIDs(ISessionWrapper session, IReadOnlyCollection <int> animeIds)
        {
            if (session == null)
            {
                throw new ArgumentNullException(nameof(session));
            }
            if (animeIds == null)
            {
                throw new ArgumentNullException(nameof(animeIds));
            }

            if (animeIds.Count == 0)
            {
                return(EmptyLookup <int, CrossRef_AniDB_TvDBV2> .Instance);
            }

            var xrefs = session
                        .CreateCriteria(typeof(CrossRef_AniDB_TvDBV2))
                        .Add(Restrictions.InG("AnimeID", animeIds))
                        .AddOrder(Order.Asc("AniDBStartEpisodeType"))
                        .AddOrder(Order.Asc("AniDBStartEpisodeNumber"))
                        .List <CrossRef_AniDB_TvDBV2>()
                        .ToLookup(cr => cr.AnimeID);

            return(xrefs);
        }
Exemple #6
0
 public TvDB_Series GetByTvDBID(ISessionWrapper session, int id)
 {
     return(session
            .CreateCriteria(typeof(TvDB_Series))
            .Add(Restrictions.Eq("SeriesID", id))
            .UniqueResult <TvDB_Series>());
 }
        public MovieDB_Movie GetByOnlineID(ISessionWrapper session, int id)
        {
            MovieDB_Movie cr = session
                               .CreateCriteria(typeof(MovieDB_Movie))
                               .Add(Restrictions.Eq("MovieId", id))
                               .UniqueResult <MovieDB_Movie>();

            return(cr);
        }
Exemple #8
0
        public List <TvDB_ImageFanart> GetBySeriesID(ISessionWrapper session, int seriesID)
        {
            var objs = session
                       .CreateCriteria(typeof(TvDB_ImageFanart))
                       .Add(Restrictions.Eq("SeriesID", seriesID))
                       .List <TvDB_ImageFanart>();

            return(new List <TvDB_ImageFanart>(objs));
        }
        public List <AniDB_Anime_Staff> GetByAnimeID(ISessionWrapper session, int id)
        {
            var cats = session
                       .CreateCriteria(typeof(AniDB_Anime_Staff))
                       .Add(Restrictions.Eq("AnimeID", id))
                       .List <AniDB_Anime_Staff>();

            return(new List <AniDB_Anime_Staff>(cats));
        }
        public AniDB_Character GetByCharID(ISessionWrapper session, int id)
        {
            AniDB_Character cr = session
                                 .CreateCriteria(typeof(AniDB_Character))
                                 .Add(Restrictions.Eq("CharID", id))
                                 .UniqueResult <AniDB_Character>();

            return(cr);
        }
        public List <AniDB_Recommendation> GetByAnimeID(ISessionWrapper session, int id)
        {
            var votes = session
                        .CreateCriteria(typeof(AniDB_Recommendation))
                        .Add(Restrictions.Eq("AnimeID", id))
                        .List <AniDB_Recommendation>();

            return(new List <AniDB_Recommendation>(votes));
        }
        public List <MovieDB_Fanart> GetByMovieID(ISessionWrapper session, int id)
        {
            var objs = session
                       .CreateCriteria(typeof(MovieDB_Fanart))
                       .Add(Restrictions.Eq("MovieId", id))
                       .List <MovieDB_Fanart>();

            return(new List <MovieDB_Fanart>(objs));
        }
Exemple #13
0
        public List <TvDB_Episode> GetBySeriesID(ISessionWrapper session, int seriesID)
        {
            var objs = session
                       .CreateCriteria(typeof(TvDB_Episode))
                       .Add(Restrictions.Eq("SeriesID", seriesID))
                       .List <TvDB_Episode>();

            return(objs.ToList());
        }
        public AniDB_Anime_DefaultImage GetByAnimeIDAndImagezSizeType(ISessionWrapper session, int animeid, int imageType)
        {
            AniDB_Anime_DefaultImage cr = session
                                          .CreateCriteria(typeof(AniDB_Anime_DefaultImage))
                                          .Add(Restrictions.Eq("AnimeID", animeid))
                                          .Add(Restrictions.Eq("ImageType", imageType))
                                          .UniqueResult <AniDB_Anime_DefaultImage>();

            return(cr);
        }
Exemple #15
0
        public virtual void Populate(ISessionWrapper session, bool displayname = true)
        {
            if (displayname)
            {
                ServerState.Instance.CurrentSetupStatus = string.Format(Properties.Resources.Database_Cache, typeof(T).Name, string.Empty);
            }

            Cache = new PocoCache <S, T>(session.CreateCriteria(typeof(T)).List <T>(), SelectKey);
            PopulateIndexes();
        }
        public CrossRef_AniDB_Other GetByAnimeIDAndType(ISessionWrapper session, int animeID, CrossRefType xrefType)
        {
            CrossRef_AniDB_Other cr = session
                                      .CreateCriteria(typeof(CrossRef_AniDB_Other))
                                      .Add(Restrictions.Eq("AnimeID", animeID))
                                      .Add(Restrictions.Eq("CrossRefType", (int)xrefType))
                                      .UniqueResult <CrossRef_AniDB_Other>();

            return(cr);
        }
Exemple #17
0
        public List <CrossRef_AniDB_TvDBV2> GetByAnimeID(ISessionWrapper session, int id)
        {
            var xrefs = session
                        .CreateCriteria(typeof(CrossRef_AniDB_TvDBV2))
                        .Add(Restrictions.Eq("AnimeID", id))
                        .AddOrder(Order.Asc("AniDBStartEpisodeType"))
                        .AddOrder(Order.Asc("AniDBStartEpisodeNumber"))
                        .List <CrossRef_AniDB_TvDBV2>();

            return(new List <CrossRef_AniDB_TvDBV2>(xrefs));
        }
Exemple #18
0
        public virtual void Populate(ISessionWrapper session, bool displayname = true)
        {
            if (displayname)
            {
                ServerState.Instance.ServerStartingStatus = string.Format(
                    Resources.Database_Cache, typeof(T).Name.Replace("SVR_", string.Empty),
                    string.Empty);
            }

            // This is only called from main thread, so we don't need to lock
            Cache = new PocoCache <S, T>(session.CreateCriteria(typeof(T)).List <T>(), SelectKey);
            PopulateIndexes();
        }
        public AniDB_AnimeUpdate GetByAnimeID(ISessionWrapper session, int id)
        {
            var cats = session
                       .CreateCriteria(typeof(AniDB_AnimeUpdate))
                       .Add(Restrictions.Eq("AnimeID", id))
                       .List <AniDB_AnimeUpdate>();

            var cat = cats.FirstOrDefault();

            cats.Remove(cat);
            if (cats.Count > 1)
            {
                cats.ForEach(Delete);
            }

            return(cat);
        }
        public Dictionary <int, AniDB_Vote> GetByAnimeIDs(ISessionWrapper session, IReadOnlyCollection <int> animeIDs)
        {
            if (session == null)
            {
                throw new ArgumentNullException(nameof(session));
            }
            if (animeIDs == null)
            {
                throw new ArgumentNullException(nameof(animeIDs));
            }

            var votesByAnime = session
                               .CreateCriteria <AniDB_Vote>()
                               .Add(Restrictions.InG(nameof(AniDB_Vote.EntityID), animeIDs))
                               .Add(Restrictions.In(nameof(AniDB_Vote.VoteType), new[] { (int)AniDBVoteType.Anime, (int)AniDBVoteType.AnimeTemp }))
                               .List <AniDB_Vote>()
                               .GroupBy(v => v.EntityID)
                               .ToDictionary(g => g.Key, g => g.FirstOrDefault());

            return(votesByAnime);
        }
Exemple #21
0
 public virtual IReadOnlyList <T> GetAll(ISessionWrapper session)
 {
     return(new List <T>(session.CreateCriteria(typeof(T)).List <T>()));
 }