From d5135fc7f6fb379c83f3b9cd42517a8beb035471 Mon Sep 17 00:00:00 2001 From: Paul McLeish Date: Thu, 1 Sep 2016 14:00:00 +1000 Subject: [PATCH 1/2] Performance improvements for AniDB_Anime cache initialisation * AniDB_AnimeRepository now uses a stateless session. Using the standard ISession have a large amount of overhead due to change tracking, etc. * The above change required the introduction of an ISessionWrapper to provide the common functionality from both ISession and IStatelessSession for performing SELECT queries. * Also switched to processing anime in batches instead of one by one to reduce the number of round-trips to the database. --- JMMServer/AniDBHelper.cs | 15 +- JMMServer/Collections/EmptyLookup.cs | 21 + JMMServer/Collections/EnumerableExtensions.cs | 55 + JMMServer/Collections/LazyLookup.cs | 60 + .../Commands/AniDB/CommandRequest_GetFile.cs | 3 +- .../CommandRequest_MovieDBSearchAnime.cs | 9 +- .../Trakt/CommandRequest_TraktSearchAnime.cs | 9 +- JMMServer/Databases/DatabaseFixes.cs | 6 +- JMMServer/Entities/AniDB_Anime.cs | 477 ++-- JMMServer/Entities/AniDB_Anime_Character.cs | 5 +- .../Entities/AniDB_Anime_DefaultImage.cs | 96 +- JMMServer/Entities/AniDB_Character.cs | 38 +- JMMServer/Entities/AnimeEpisode.cs | 5 +- JMMServer/Entities/AnimeGroup.cs | 41 +- JMMServer/Entities/AnimeGroup_User.cs | 6 +- JMMServer/Entities/AnimeSeries.cs | 26 +- JMMServer/Entities/CrossRef_AniDB_Other.cs | 5 +- JMMServer/Entities/CrossRef_AniDB_TvDB.cs | 5 +- JMMServer/Entities/CrossRef_AniDB_TvDBV2.cs | 8 +- JMMServer/Entities/IImageEntity.cs | 6 + JMMServer/Entities/MovieDB_Fanart.cs | 2 +- JMMServer/Entities/MovieDB_Poster.cs | 2 +- JMMServer/Entities/Trakt_ImageFanart.cs | 2 +- JMMServer/Entities/Trakt_ImagePoster.cs | 2 +- JMMServer/Entities/TvDB_ImageFanart.cs | 2 +- JMMServer/Entities/TvDB_ImagePoster.cs | 2 +- JMMServer/Entities/TvDB_ImageWideBanner.cs | 2 +- JMMServer/Entities/VideoLocal.cs | 5 +- JMMServer/Importer.cs | 4 +- JMMServer/JMMServer.csproj | 9 + JMMServer/JMMServiceImplementation.cs | 80 +- JMMServer/JMMServiceImplementationMetro.cs | 117 +- JMMServer/PlexAndKodi/CommonImplementation.cs | 2428 +++++++++-------- JMMServer/PlexAndKodi/Helper.cs | 1870 ++++++------- JMMServer/Providers/MovieDB/MovieDBHelper.cs | 6 +- JMMServer/Providers/TvDB/TvDBHelper.cs | 7 +- JMMServer/Repositories/AdhocRepository.cs | 348 ++- .../Repositories/AniDB_AnimeRepository.cs | 190 +- .../AniDB_Anime_CharacterRepository.cs | 3 +- .../AniDB_Anime_DefaultImageRepository.cs | 5 +- .../AniDB_Anime_RelationRepository.cs | 5 +- .../Repositories/AniDB_Anime_TagRepository.cs | 30 +- .../AniDB_Anime_TitleRepository.cs | 28 +- .../Repositories/AniDB_CharacterRepository.cs | 80 +- .../Repositories/AniDB_EpisodeRepository.cs | 5 +- .../Repositories/AniDB_FileRepository.cs | 5 +- .../AniDB_RecommendationRepository.cs | 5 +- JMMServer/Repositories/AniDB_TagRepository.cs | 32 +- .../Repositories/AniDB_VoteRepository.cs | 23 +- .../Repositories/AnimeEpisodeRepository.cs | 3 +- .../AnimeEpisode_UserRepository.cs | 3 +- .../Repositories/AnimeGroupRepository.cs | 10 +- .../Repositories/AnimeSeriesRepository.cs | 5 +- .../AnimeSeries_UserRepository.cs | 3 +- .../CrossRef_AniDB_OtherRepository.cs | 5 +- .../CrossRef_AniDB_TvDBV2Repository.cs | 5 +- .../CrossRef_File_EpisodeRepository.cs | 5 +- JMMServer/Repositories/CustomTagRepository.cs | 32 +- JMMServer/Repositories/JMMUserRepository.cs | 5 +- .../Repositories/MovieDB_FanartRepository.cs | 9 +- .../Repositories/MovieDB_MovieRepository.cs | 5 +- .../Repositories/MovieDB_PosterRepository.cs | 9 +- .../NHibernate/ISessionWrapper.cs | 21 + .../NHibernate/SessionExtensions.cs | 12 + .../Repositories/NHibernate/SessionWrapper.cs | 49 + .../NHibernate/StatelessSessionExtensions.cs | 12 + .../NHibernate/StatelessSessionWrapper.cs | 49 + .../Trakt_ImageFanartRepository.cs | 5 +- .../Trakt_ImagePosterRepository.cs | 5 +- .../Repositories/TvDB_EpisodeRepository.cs | 5 +- .../TvDB_ImageFanartRepository.cs | 9 +- .../TvDB_ImagePosterRepository.cs | 9 +- .../TvDB_ImageWideBannerRepository.cs | 5 +- .../Repositories/TvDB_SeriesRepository.cs | 5 +- .../Repositories/VideoLocalRepository.cs | 5 +- 75 files changed, 3739 insertions(+), 2746 deletions(-) create mode 100644 JMMServer/Collections/EmptyLookup.cs create mode 100644 JMMServer/Collections/EnumerableExtensions.cs create mode 100644 JMMServer/Collections/LazyLookup.cs create mode 100644 JMMServer/Entities/IImageEntity.cs create mode 100644 JMMServer/Repositories/NHibernate/ISessionWrapper.cs create mode 100644 JMMServer/Repositories/NHibernate/SessionExtensions.cs create mode 100644 JMMServer/Repositories/NHibernate/SessionWrapper.cs create mode 100644 JMMServer/Repositories/NHibernate/StatelessSessionExtensions.cs create mode 100644 JMMServer/Repositories/NHibernate/StatelessSessionWrapper.cs diff --git a/JMMServer/AniDBHelper.cs b/JMMServer/AniDBHelper.cs index 949d4abb0..317e206da 100644 --- a/JMMServer/AniDBHelper.cs +++ b/JMMServer/AniDBHelper.cs @@ -12,6 +12,7 @@ using JMMServer.Commands.Azure; using JMMServer.Entities; using JMMServer.Repositories; +using JMMServer.Repositories.NHibernate; using NHibernate; using NLog; @@ -1096,20 +1097,21 @@ public AniDB_Anime GetAnimeInfoHTTP(ISession session, int animeID, bool forceRef AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anime = null; + ISessionWrapper sessionWrapper = session.Wrap(); bool skip = true; if (forceRefresh) skip = false; else { - anime = repAnime.GetByAnimeID(session, animeID); + anime = repAnime.GetByAnimeID(sessionWrapper, animeID); if (anime == null) skip = false; } if (skip) { if (anime == null) - anime = repAnime.GetByAnimeID(session, animeID); + anime = repAnime.GetByAnimeID(sessionWrapper, animeID); return anime; } @@ -1144,10 +1146,11 @@ private AniDB_Anime SaveResultsForAnimeXML(ISession session, int animeID, bool d { AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anime = null; + ISessionWrapper sessionWrapper = session.Wrap(); logger.Trace("cmdResult.Anime: {0}", getAnimeCmd.Anime); - anime = repAnime.GetByAnimeID(session, animeID); + anime = repAnime.GetByAnimeID(sessionWrapper, animeID); if (anime == null) anime = new AniDB_Anime(); anime.PopulateAndSaveFromHTTP(session, getAnimeCmd.Anime, getAnimeCmd.Episodes, getAnimeCmd.Titles, @@ -1163,7 +1166,7 @@ private AniDB_Anime SaveResultsForAnimeXML(ISession session, int animeID, bool d // create AnimeEpisode records for all episodes in this anime // only if we have a series AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); - AnimeSeries ser = repSeries.GetByAnimeID(session, animeID); + AnimeSeries ser = repSeries.GetByAnimeID(sessionWrapper, animeID); repAnime.Save(anime); if (ser != null) { @@ -1181,9 +1184,9 @@ private AniDB_Anime SaveResultsForAnimeXML(ISession session, int animeID, bool d //StatsCache.Instance.UpdateAnimeContract(session, anime.AnimeID); // download character images - foreach (AniDB_Anime_Character animeChar in anime.GetAnimeCharacters(session)) + foreach (AniDB_Anime_Character animeChar in anime.GetAnimeCharacters(session.Wrap())) { - AniDB_Character chr = animeChar.GetCharacter(session); + AniDB_Character chr = animeChar.GetCharacter(sessionWrapper); if (chr == null) continue; if (ServerSettings.AniDB_DownloadCharacters) diff --git a/JMMServer/Collections/EmptyLookup.cs b/JMMServer/Collections/EmptyLookup.cs new file mode 100644 index 000000000..6eb9b0bc6 --- /dev/null +++ b/JMMServer/Collections/EmptyLookup.cs @@ -0,0 +1,21 @@ +using System.Collections; +using System.Collections.Generic; +using System.Linq; + +namespace JMMServer.Collections +{ + public class EmptyLookup : ILookup + { + public static readonly EmptyLookup Instance = new EmptyLookup(); + + public bool Contains(TKey key) => false; + + public IEnumerator> GetEnumerator() => Enumerable.Empty>().GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => Enumerable.Empty>().GetEnumerator(); + + public IEnumerable this[TKey key] => Enumerable.Empty(); + + public int Count => 0; + } +} \ No newline at end of file diff --git a/JMMServer/Collections/EnumerableExtensions.cs b/JMMServer/Collections/EnumerableExtensions.cs new file mode 100644 index 000000000..749834101 --- /dev/null +++ b/JMMServer/Collections/EnumerableExtensions.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace JMMServer.Collections +{ + public static class EnumerableExtensions + { + public static ILookup ToLazyLookup(this IEnumerable source, Func keySelector, + IEqualityComparer comparer = null) + { + return LazyLookup.Create(source, keySelector, comparer); + } + + public static ILookup ToLazyLookup(this IEnumerable source, Func keySelector, + Func elementSelector, IEqualityComparer comparer = null) + { + return LazyLookup.Create(source, keySelector, elementSelector, comparer); + } + + public static IEnumerable Batch(this IEnumerable source, int size) + { + TSource[] bucket = null; + var count = 0; + + foreach (var item in source) + { + if (bucket == null) + { + bucket = new TSource[size]; + } + + bucket[count++] = item; + + if (count != size) + { + continue; + } + + yield return bucket; + + bucket = null; + count = 0; + } + + // Return the last bucket with remaining elements + if (bucket != null && count > 0) + { + Array.Resize(ref bucket, count); + + yield return bucket; + } + } + } +} \ No newline at end of file diff --git a/JMMServer/Collections/LazyLookup.cs b/JMMServer/Collections/LazyLookup.cs new file mode 100644 index 000000000..ce86485c5 --- /dev/null +++ b/JMMServer/Collections/LazyLookup.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JMMServer.Collections +{ + public class LazyLookup : ILookup + { + private readonly Lazy> _lookup; + + public LazyLookup(Lazy> lookup) + { + if (lookup == null) + throw new ArgumentNullException(nameof(lookup)); + + _lookup = lookup; + } + + public static LazyLookup Create(IEnumerable source, Func keySelector, + IEqualityComparer comparer = null) + { + if (source == null) + throw new ArgumentNullException(nameof(source)); + if (keySelector == null) + throw new ArgumentNullException(nameof(keySelector)); + + var lazyLookup = new Lazy>(() => source.ToLookup(keySelector, comparer), false); + + return new LazyLookup(lazyLookup); + } + + public static LazyLookup Create(IEnumerable source, Func keySelector, + Func elementSelector, IEqualityComparer comparer = null) + { + if (source == null) + throw new ArgumentNullException(nameof(source)); + if (keySelector == null) + throw new ArgumentNullException(nameof(keySelector)); + if (elementSelector == null) + throw new ArgumentNullException(nameof(elementSelector)); + + var lazyLookup = new Lazy>(() => source.ToLookup(keySelector, elementSelector, comparer), false); + + return new LazyLookup(lazyLookup); + } + + public bool Contains(TKey key) => _lookup.Value.Contains(key); + + public IEnumerator> GetEnumerator() => _lookup.Value.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => _lookup.Value.GetEnumerator(); + + public IEnumerable this[TKey key] => _lookup.Value[key]; + + public int Count => _lookup.Value.Count; + } +} \ No newline at end of file diff --git a/JMMServer/Commands/AniDB/CommandRequest_GetFile.cs b/JMMServer/Commands/AniDB/CommandRequest_GetFile.cs index 18881d6ad..b45159ef2 100644 --- a/JMMServer/Commands/AniDB/CommandRequest_GetFile.cs +++ b/JMMServer/Commands/AniDB/CommandRequest_GetFile.cs @@ -7,6 +7,7 @@ using JMMServer.Commands.AniDB; using JMMServer.Entities; using JMMServer.Repositories; +using JMMServer.Repositories.NHibernate; namespace JMMServer.Commands { @@ -123,7 +124,7 @@ public override void ProcessCommand() { using (var session = JMMService.SessionFactory.OpenSession()) { - anime.UpdateContractDetailed(session); + anime.UpdateContractDetailed(session.Wrap()); } } AnimeSeries series = repo.GetByAnimeID(aniFile.AnimeID); diff --git a/JMMServer/Commands/CommandRequest_MovieDBSearchAnime.cs b/JMMServer/Commands/CommandRequest_MovieDBSearchAnime.cs index 9cf033f4d..64d03b68c 100644 --- a/JMMServer/Commands/CommandRequest_MovieDBSearchAnime.cs +++ b/JMMServer/Commands/CommandRequest_MovieDBSearchAnime.cs @@ -6,6 +6,7 @@ using JMMServer.Entities; using JMMServer.Providers.MovieDB; using JMMServer.Repositories; +using JMMServer.Repositories.NHibernate; using NHibernate; namespace JMMServer.Commands @@ -51,6 +52,8 @@ public override void ProcessCommand() { using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); + // first check if the user wants to use the web cache if (ServerSettings.WebCache_TvDB_Get) { @@ -64,7 +67,7 @@ public override void ProcessCommand() if (crossRef != null) { int movieID = int.Parse(crossRef.CrossRefID); - MovieDB_Movie movie = repMovies.GetByOnlineID(session, movieID); + MovieDB_Movie movie = repMovies.GetByOnlineID(sessionWrapper, movieID); if (movie == null) { // update the info from online @@ -87,7 +90,7 @@ public override void ProcessCommand() string searchCriteria = ""; AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); - AniDB_Anime anime = repAnime.GetByAnimeID(session, AnimeID); + AniDB_Anime anime = repAnime.GetByAnimeID(sessionWrapper, AnimeID); if (anime == null) return; searchCriteria = anime.MainTitle; @@ -100,7 +103,7 @@ public override void ProcessCommand() if (results.Count == 0) { - foreach (AniDB_Anime_Title title in anime.GetTitles(session)) + foreach (AniDB_Anime_Title title in anime.GetTitles(sessionWrapper)) { if (title.TitleType.ToUpper() != Constants.AnimeTitleType.Official.ToUpper()) continue; diff --git a/JMMServer/Commands/Trakt/CommandRequest_TraktSearchAnime.cs b/JMMServer/Commands/Trakt/CommandRequest_TraktSearchAnime.cs index 67a692605..d2a91503c 100644 --- a/JMMServer/Commands/Trakt/CommandRequest_TraktSearchAnime.cs +++ b/JMMServer/Commands/Trakt/CommandRequest_TraktSearchAnime.cs @@ -9,6 +9,7 @@ using JMMServer.Providers.TraktTV; using JMMServer.Providers.TraktTV.Contracts; using JMMServer.Repositories; +using JMMServer.Repositories.NHibernate; using NHibernate; namespace JMMServer.Commands @@ -55,6 +56,8 @@ public override void ProcessCommand() { using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); + // first check if the user wants to use the web cache if (ServerSettings.WebCache_Trakt_Get) { @@ -92,7 +95,7 @@ public override void ProcessCommand() // lets try to see locally if we have a tvDB link for this anime // Trakt allows the use of TvDB ID's or their own Trakt ID's CrossRef_AniDB_TvDBV2Repository repCrossRefTvDB = new CrossRef_AniDB_TvDBV2Repository(); - List xrefTvDBs = repCrossRefTvDB.GetByAnimeID(session, AnimeID); + List xrefTvDBs = repCrossRefTvDB.GetByAnimeID(sessionWrapper, AnimeID); if (xrefTvDBs != null && xrefTvDBs.Count > 0) { foreach (CrossRef_AniDB_TvDBV2 tvXRef in xrefTvDBs) @@ -149,7 +152,7 @@ public override void ProcessCommand() // finally lets try searching Trakt directly string searchCriteria = ""; AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); - AniDB_Anime anime = repAnime.GetByAnimeID(session, AnimeID); + AniDB_Anime anime = repAnime.GetByAnimeID(sessionWrapper, AnimeID); if (anime == null) return; searchCriteria = anime.MainTitle; @@ -162,7 +165,7 @@ public override void ProcessCommand() if (results.Count == 0) { - foreach (AniDB_Anime_Title title in anime.GetTitles(session)) + foreach (AniDB_Anime_Title title in anime.GetTitles(sessionWrapper)) { if (title.TitleType.ToUpper() != Constants.AnimeTitleType.Official.ToUpper()) continue; diff --git a/JMMServer/Databases/DatabaseFixes.cs b/JMMServer/Databases/DatabaseFixes.cs index 1bd4007f3..c37200b41 100644 --- a/JMMServer/Databases/DatabaseFixes.cs +++ b/JMMServer/Databases/DatabaseFixes.cs @@ -4,6 +4,7 @@ using AniDBAPI; using JMMServer.Entities; using JMMServer.Repositories; +using JMMServer.Repositories.NHibernate; using NLog; namespace JMMServer.Databases @@ -212,6 +213,7 @@ public static void MigrateTvDBLinks_V1_to_V2() using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); List xrefsTvDB = repCrossRefTvDB.GetAll(); foreach (CrossRef_AniDB_TvDB xrefTvDB in xrefsTvDB) { @@ -221,7 +223,7 @@ public static void MigrateTvDBLinks_V1_to_V2() xrefNew.TvDBID = xrefTvDB.TvDBID; xrefNew.TvDBSeasonNumber = xrefTvDB.TvDBSeasonNumber; - TvDB_Series ser = xrefTvDB.GetTvDBSeries(session); + TvDB_Series ser = xrefTvDB.GetTvDBSeries(sessionWrapper); if (ser != null) xrefNew.TvDBTitle = ser.SeriesName; @@ -265,7 +267,7 @@ public static void MigrateTvDBLinks_V1_to_V2() xrefNew.AniDBStartEpisodeType = (int) enEpisodeType.Special; xrefNew.AniDBStartEpisodeNumber = 1; - TvDB_Series ser = xrefTvDB.GetTvDBSeries(session); + TvDB_Series ser = xrefTvDB.GetTvDBSeries(sessionWrapper); if (ser != null) xrefNew.TvDBTitle = ser.SeriesName; diff --git a/JMMServer/Entities/AniDB_Anime.cs b/JMMServer/Entities/AniDB_Anime.cs index 393a5c6e0..79b324f4c 100644 --- a/JMMServer/Entities/AniDB_Anime.cs +++ b/JMMServer/Entities/AniDB_Anime.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Text; @@ -7,12 +8,14 @@ using AniDBAPI; using JMMContracts; +using JMMServer.Collections; using JMMServer.Commands; using JMMServer.ImageDownload; using JMMServer.LZ4; using JMMServer.Properties; using JMMServer.Providers.Azure; using JMMServer.Repositories; +using JMMServer.Repositories.NHibernate; using NHibernate; using NHibernate.Criterion; using NLog; @@ -209,11 +212,11 @@ public List GetTvDBEpisodes() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetTvDBEpisodes(session); + return GetTvDBEpisodes(session.Wrap()); } } - public List GetTvDBEpisodes(ISession session) + public List GetTvDBEpisodes(ISessionWrapper session) { List tvDBEpisodes = new List(); @@ -234,11 +237,11 @@ public Dictionary GetDictTvDBEpisodes() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetDictTvDBEpisodes(session); + return GetDictTvDBEpisodes(session.Wrap()); } } - public Dictionary GetDictTvDBEpisodes(ISession session) + public Dictionary GetDictTvDBEpisodes(ISessionWrapper session) { if (dictTvDBEpisodes == null) { @@ -275,11 +278,11 @@ public Dictionary GetDictTvDBSeasons() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetDictTvDBSeasons(session); + return GetDictTvDBSeasons(session.Wrap()); } } - public Dictionary GetDictTvDBSeasons(ISession session) + public Dictionary GetDictTvDBSeasons(ISessionWrapper session) { if (dictTvDBSeasons == null) { @@ -318,11 +321,11 @@ public Dictionary GetDictTvDBSeasonsSpecials() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetDictTvDBSeasonsSpecials(session); + return GetDictTvDBSeasonsSpecials(session.Wrap()); } } - public Dictionary GetDictTvDBSeasonsSpecials(ISession session) + public Dictionary GetDictTvDBSeasonsSpecials(ISessionWrapper session) { if (dictTvDBSeasonsSpecials == null) { @@ -379,11 +382,11 @@ public List GetCrossRefTvDBV2() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetCrossRefTvDBV2(session); + return GetCrossRefTvDBV2(session.Wrap()); } } - public List GetCrossRefTvDBV2(ISession session) + public List GetCrossRefTvDBV2(ISessionWrapper session) { CrossRef_AniDB_TvDBV2Repository repCrossRef = new CrossRef_AniDB_TvDBV2Repository(); return repCrossRef.GetByAnimeID(session, this.AnimeID); @@ -421,11 +424,11 @@ public List GetTvDBSeries() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetTvDBSeries(session); + return GetTvDBSeries(session.Wrap()); } } - public List GetTvDBSeries(ISession session) + public List GetTvDBSeries(ISessionWrapper session) { TvDB_SeriesRepository repSeries = new TvDB_SeriesRepository(); @@ -446,11 +449,11 @@ public List GetTvDBImageFanarts() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetTvDBImageFanarts(session); + return GetTvDBImageFanarts(session.Wrap()); } } - public List GetTvDBImageFanarts(ISession session) + public List GetTvDBImageFanarts(ISessionWrapper session) { List ret = new List(); @@ -471,11 +474,11 @@ public List GetTvDBImagePosters() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetTvDBImagePosters(session); + return GetTvDBImagePosters(session.Wrap()); } } - public List GetTvDBImagePosters(ISession session) + public List GetTvDBImagePosters(ISessionWrapper session) { List ret = new List(); @@ -496,11 +499,11 @@ public List GetTvDBImageWideBanners() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetTvDBImageWideBanners(session); + return GetTvDBImageWideBanners(session.Wrap()); } } - public List GetTvDBImageWideBanners(ISession session) + public List GetTvDBImageWideBanners(ISessionWrapper session) { List ret = new List(); @@ -519,14 +522,14 @@ public CrossRef_AniDB_Other GetCrossRefMovieDB() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetCrossRefMovieDB(session); + return GetCrossRefMovieDB(session.Wrap()); } } - public CrossRef_AniDB_Other GetCrossRefMovieDB(ISession session) + public CrossRef_AniDB_Other GetCrossRefMovieDB(ISessionWrapper criteriaFactory) { CrossRef_AniDB_OtherRepository repCrossRef = new CrossRef_AniDB_OtherRepository(); - return repCrossRef.GetByAnimeIDAndType(session, this.AnimeID, CrossRefType.MovieDB); + return repCrossRef.GetByAnimeIDAndType(criteriaFactory, this.AnimeID, CrossRefType.MovieDB); } @@ -534,28 +537,28 @@ public MovieDB_Movie GetMovieDBMovie() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetMovieDBMovie(session); + return GetMovieDBMovie(session.Wrap()); } } - public MovieDB_Movie GetMovieDBMovie(ISession session) + public MovieDB_Movie GetMovieDBMovie(ISessionWrapper criteriaFactory) { - CrossRef_AniDB_Other xref = GetCrossRefMovieDB(session); + CrossRef_AniDB_Other xref = GetCrossRefMovieDB(criteriaFactory); if (xref == null) return null; MovieDB_MovieRepository repMovies = new MovieDB_MovieRepository(); - return repMovies.GetByOnlineID(session, Int32.Parse(xref.CrossRefID)); + return repMovies.GetByOnlineID(criteriaFactory, Int32.Parse(xref.CrossRefID)); } public List GetMovieDBFanarts() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetMovieDBFanarts(session); + return GetMovieDBFanarts(session.Wrap()); } } - public List GetMovieDBFanarts(ISession session) + public List GetMovieDBFanarts(ISessionWrapper session) { CrossRef_AniDB_Other xref = GetCrossRefMovieDB(session); if (xref == null) return new List(); @@ -568,11 +571,11 @@ public List GetMovieDBPosters() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetMovieDBPosters(session); + return GetMovieDBPosters(session.Wrap()); } } - public List GetMovieDBPosters(ISession session) + public List GetMovieDBPosters(ISessionWrapper session) { CrossRef_AniDB_Other xref = GetCrossRefMovieDB(session); if (xref == null) return new List(); @@ -585,14 +588,14 @@ public AniDB_Anime_DefaultImage GetDefaultPoster() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetDefaultPoster(session); + return GetDefaultPoster(session.Wrap()); } } - public AniDB_Anime_DefaultImage GetDefaultPoster(ISession session) + public AniDB_Anime_DefaultImage GetDefaultPoster(ISessionWrapper criteriaFactory) { AniDB_Anime_DefaultImageRepository repDefaults = new AniDB_Anime_DefaultImageRepository(); - return repDefaults.GetByAnimeIDAndImagezSizeType(session, this.AnimeID, (int) ImageSizeType.Poster); + return repDefaults.GetByAnimeIDAndImagezSizeType(criteriaFactory, this.AnimeID, (int) ImageSizeType.Poster); } public string PosterPathNoDefault @@ -604,15 +607,17 @@ public string PosterPathNoDefault } } + + public string GetDefaultPosterPathNoBlanks() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetDefaultPosterPathNoBlanks(session); + return GetDefaultPosterPathNoBlanks(session.Wrap()); } } - public string GetDefaultPosterPathNoBlanks(ISession session) + public string GetDefaultPosterPathNoBlanks(ISessionWrapper session) { AniDB_Anime_DefaultImage defaultPoster = GetDefaultPoster(session); if (defaultPoster == null) @@ -662,11 +667,11 @@ public ImageDetails GetDefaultPosterDetailsNoBlanks() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetDefaultPosterDetailsNoBlanks(session); + return GetDefaultPosterDetailsNoBlanks(session.Wrap()); } } - public ImageDetails GetDefaultPosterDetailsNoBlanks(ISession session) + public ImageDetails GetDefaultPosterDetailsNoBlanks(ISessionWrapper session) { ImageDetails details = new ImageDetails() {ImageType = JMMImageType.AniDB_Cover, ImageID = this.AnimeID}; AniDB_Anime_DefaultImage defaultPoster = GetDefaultPoster(session); @@ -730,25 +735,25 @@ public AniDB_Anime_DefaultImage GetDefaultFanart() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetDefaultFanart(session); + return GetDefaultFanart(session.Wrap()); } } - public AniDB_Anime_DefaultImage GetDefaultFanart(ISession session) + public AniDB_Anime_DefaultImage GetDefaultFanart(ISessionWrapper factory) { AniDB_Anime_DefaultImageRepository repDefaults = new AniDB_Anime_DefaultImageRepository(); - return repDefaults.GetByAnimeIDAndImagezSizeType(session, this.AnimeID, (int) ImageSizeType.Fanart); + return repDefaults.GetByAnimeIDAndImagezSizeType(factory, this.AnimeID, (int) ImageSizeType.Fanart); } public ImageDetails GetDefaultFanartDetailsNoBlanks() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetDefaultFanartDetailsNoBlanks(session); + return GetDefaultFanartDetailsNoBlanks(session.Wrap()); } } - public ImageDetails GetDefaultFanartDetailsNoBlanks(ISession session) + public ImageDetails GetDefaultFanartDetailsNoBlanks(ISessionWrapper session) { Random fanartRandom = new Random(); @@ -840,11 +845,11 @@ public string GetDefaultFanartOnlineURL() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetDefaultFanartOnlineURL(session); + return GetDefaultFanartOnlineURL(session.Wrap()); } } - public string GetDefaultFanartOnlineURL(ISession session) + public string GetDefaultFanartOnlineURL(ISessionWrapper session) { Random fanartRandom = new Random(); @@ -911,70 +916,70 @@ public AniDB_Anime_DefaultImage GetDefaultWideBanner() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetDefaultWideBanner(session); + return GetDefaultWideBanner(session.Wrap()); } } - public AniDB_Anime_DefaultImage GetDefaultWideBanner(ISession session) + public AniDB_Anime_DefaultImage GetDefaultWideBanner(ISessionWrapper session) { AniDB_Anime_DefaultImageRepository repDefaults = new AniDB_Anime_DefaultImageRepository(); return repDefaults.GetByAnimeIDAndImagezSizeType(session, this.AnimeID, (int) ImageSizeType.WideBanner); } - public ImageDetails GetDefaultWideBannerDetailsNoBlanks(ISession session) - { - Random bannerRandom = new Random(); - - ImageDetails details = null; - if (GetDefaultWideBanner() == null) - { - // get a random banner (only tvdb) - if (this.AnimeTypeEnum == enAnimeType.Movie) - { - // MovieDB doesn't have banners - return null; - } - else - { - List banners = GetTvDBImageWideBanners(session); - if (banners.Count == 0) return null; - - TvDB_ImageWideBanner tvBanner = banners[bannerRandom.Next(0, banners.Count)]; - details = new ImageDetails() - { - ImageType = JMMImageType.TvDB_Banner, - ImageID = tvBanner.TvDB_ImageWideBannerID - }; - return details; - } - } - else - { - ImageEntityType imageType = (ImageEntityType) GetDefaultWideBanner().ImageParentType; - - switch (imageType) - { - case ImageEntityType.TvDB_Banner: - - TvDB_ImageWideBannerRepository repTvBanner = new TvDB_ImageWideBannerRepository(); - TvDB_ImageWideBanner tvBanner = repTvBanner.GetByID(session, - GetDefaultWideBanner(session).ImageParentID); - if (tvBanner != null) - details = new ImageDetails() - { - ImageType = JMMImageType.TvDB_Banner, - ImageID = tvBanner.TvDB_ImageWideBannerID - }; - - return details; - - } - } - - return null; - } - - public string AnimeTypeRAW + public ImageDetails GetDefaultWideBannerDetailsNoBlanks(ISessionWrapper session) + { + Random bannerRandom = new Random(); + + ImageDetails details = null; + if (GetDefaultWideBanner() == null) + { + // get a random banner (only tvdb) + if (this.AnimeTypeEnum == enAnimeType.Movie) + { + // MovieDB doesn't have banners + return null; + } + else + { + List banners = GetTvDBImageWideBanners(session); + if (banners.Count == 0) return null; + + TvDB_ImageWideBanner tvBanner = banners[bannerRandom.Next(0, banners.Count)]; + details = new ImageDetails() + { + ImageType = JMMImageType.TvDB_Banner, + ImageID = tvBanner.TvDB_ImageWideBannerID + }; + return details; + } + } + else + { + ImageEntityType imageType = (ImageEntityType) GetDefaultWideBanner().ImageParentType; + + switch (imageType) + { + case ImageEntityType.TvDB_Banner: + + TvDB_ImageWideBannerRepository repTvBanner = new TvDB_ImageWideBannerRepository(); + TvDB_ImageWideBanner tvBanner = repTvBanner.GetByID(session, + GetDefaultWideBanner(session).ImageParentID); + if (tvBanner != null) + details = new ImageDetails() + { + ImageType = JMMImageType.TvDB_Banner, + ImageID = tvBanner.TvDB_ImageWideBannerID + }; + + return details; + + } + } + + return null; + } + + public string AnimeTypeRAW { get { @@ -1058,11 +1063,11 @@ public List GetTags() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetTags(session); + return GetTags(session.Wrap()); } } - public List GetTags(ISession session) + public List GetTags(ISessionWrapper session) { AniDB_TagRepository repTag = new AniDB_TagRepository(); @@ -1096,19 +1101,19 @@ public List GetAniDBTags(ISession session) } */ - public List GetCustomTagsForAnime(ISession session) + public List GetCustomTagsForAnime(ISessionWrapper session) { CustomTagRepository repTags = new CustomTagRepository(); return repTags.GetByAnimeID(session, AnimeID); } - public List GetAniDBTags(ISession session) + public List GetAniDBTags(ISessionWrapper session) { AniDB_TagRepository repTags = new AniDB_TagRepository(); return repTags.GetByAnimeID(session, AnimeID); } - public List GetAnimeTags(ISession session) + public List GetAnimeTags(ISessionWrapper session) { AniDB_Anime_TagRepository repAnimeTags = new AniDB_Anime_TagRepository(); return repAnimeTags.GetByAnimeID(session, AnimeID); @@ -1118,11 +1123,11 @@ public List GetRelatedAnime() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetRelatedAnime(session); + return GetRelatedAnime(session.Wrap()); } } - public List GetRelatedAnime(ISession session) + public List GetRelatedAnime(ISessionWrapper session) { AniDB_Anime_RelationRepository repRels = new AniDB_Anime_RelationRepository(); return repRels.GetByAnimeID(session, AnimeID); @@ -1156,11 +1161,11 @@ public List GetAllRelatedAnime() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetAllRelatedAnime(session); + return GetAllRelatedAnime(session.Wrap()); } } - public List GetAllRelatedAnime(ISession session) + public List GetAllRelatedAnime(ISessionWrapper session) { List relList = new List(); List relListIDs = new List(); @@ -1174,11 +1179,11 @@ public List GetAnimeCharacters() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetAnimeCharacters(session); + return GetAnimeCharacters(session.Wrap()); } } - public List GetAnimeCharacters(ISession session) + public List GetAnimeCharacters(ISessionWrapper session) { AniDB_Anime_CharacterRepository repRels = new AniDB_Anime_CharacterRepository(); return repRels.GetByAnimeID(session, AnimeID); @@ -1245,11 +1250,11 @@ public List GetTitles() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetTitles(session); + return GetTitles(session.Wrap()); } } - public List GetTitles(ISession session) + public List GetTitles(ISessionWrapper session) { AniDB_Anime_TitleRepository repTitles = new AniDB_Anime_TitleRepository(); return repTitles.GetByAnimeID(session, AnimeID); @@ -1306,11 +1311,11 @@ public string GetFormattedTitle() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetFormattedTitle(session); + return GetFormattedTitle(session.Wrap()); } } - public string GetFormattedTitle(ISession session) + public string GetFormattedTitle(ISessionWrapper session) { List thisTitles = this.GetTitles(session); return GetFormattedTitle(thisTitles); @@ -1415,7 +1420,7 @@ public List AniDBEpisodes } } - public List GetAniDBEpisodes(ISession session) + public List GetAniDBEpisodes(ISessionWrapper session) { AniDB_EpisodeRepository repEps = new AniDB_EpisodeRepository(); return repEps.GetByAnimeID(session, AnimeID); @@ -1479,54 +1484,55 @@ public void PopulateAndSaveFromHTTP(ISession session, Raw_AniDB_Anime animeInfo, logger.Trace(String.Format("PopulateAndSaveFromHTTP: for {0} - {1}", animeInfo.AnimeID, animeInfo.MainTitle)); logger.Trace("------------------------------------------------"); - DateTime start0 = DateTime.Now; - + Stopwatch taskTimer = new Stopwatch(); + Stopwatch totalTimer = Stopwatch.StartNew(); + Populate(animeInfo); // save now for FK purposes AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); repAnime.Save(session, this); - DateTime start = DateTime.Now; + taskTimer.Start(); CreateEpisodes(session, eps); - TimeSpan ts = DateTime.Now - start; - logger.Trace(String.Format("CreateEpisodes in : {0}", ts.TotalMilliseconds)); - start = DateTime.Now; + taskTimer.Stop(); + logger.Trace("CreateEpisodes in : " + taskTimer.ElapsedMilliseconds); + taskTimer.Restart(); CreateTitles(session, titles); - ts = DateTime.Now - start; - logger.Trace(String.Format("CreateTitles in : {0}", ts.TotalMilliseconds)); - start = DateTime.Now; + taskTimer.Stop(); + logger.Trace("CreateTitles in : " + taskTimer.ElapsedMilliseconds); + taskTimer.Restart(); CreateTags(session, tags); - ts = DateTime.Now - start; - logger.Trace(String.Format("CreateTags in : {0}", ts.TotalMilliseconds)); - start = DateTime.Now; + taskTimer.Stop(); + logger.Trace("CreateTags in : " + taskTimer.ElapsedMilliseconds); + taskTimer.Restart(); CreateCharacters(session, chars); - ts = DateTime.Now - start; - logger.Trace(String.Format("CreateCharacters in : {0}", ts.TotalMilliseconds)); - start = DateTime.Now; + taskTimer.Stop(); + logger.Trace("CreateCharacters in : " + taskTimer.ElapsedMilliseconds); + taskTimer.Restart(); CreateRelations(session, rels, downloadRelations); - ts = DateTime.Now - start; - logger.Trace(String.Format("CreateRelations in : {0}", ts.TotalMilliseconds)); - start = DateTime.Now; + taskTimer.Stop(); + logger.Trace("CreateRelations in : " + taskTimer.ElapsedMilliseconds); + taskTimer.Restart(); CreateSimilarAnime(session, sims); - ts = DateTime.Now - start; - logger.Trace(String.Format("CreateSimilarAnime in : {0}", ts.TotalMilliseconds)); - start = DateTime.Now; + taskTimer.Stop(); + logger.Trace("CreateSimilarAnime in : " + taskTimer.ElapsedMilliseconds); + taskTimer.Restart(); CreateRecommendations(session, recs); - ts = DateTime.Now - start; - logger.Trace(String.Format("CreateRecommendations in : {0}", ts.TotalMilliseconds)); - start = DateTime.Now; + taskTimer.Stop(); + logger.Trace("CreateRecommendations in : " + taskTimer.ElapsedMilliseconds); + taskTimer.Restart(); repAnime.Save(this); - ts = DateTime.Now - start0; - logger.Trace(String.Format("TOTAL TIME in : {0}", ts.TotalMilliseconds)); + totalTimer.Stop(); + logger.Trace("TOTAL TIME in : " + totalTimer.ElapsedMilliseconds); logger.Trace("------------------------------------------------"); } @@ -1696,10 +1702,11 @@ private void CreateTags(ISession session, List tags) // find all the current links, and then later remove the ones that are no longer relevant List currentTags = repTagsXRefs.GetByAnimeID(AnimeID); List newTagIDs = new List(); + ISessionWrapper sessionWrapper = session.Wrap(); foreach (Raw_AniDB_Tag rawtag in tags) { - AniDB_Tag tag = repTags.GetByTagID(rawtag.TagID, session); + AniDB_Tag tag = repTags.GetByTagID(rawtag.TagID, sessionWrapper); if (tag == null) tag = new AniDB_Tag(); tag.Populate(rawtag); @@ -1707,7 +1714,7 @@ private void CreateTags(ISession session, List tags) newTagIDs.Add(tag.TagID); - AniDB_Anime_Tag anime_tag = repTagsXRefs.GetByAnimeIDAndTagID(session, rawtag.AnimeID, rawtag.TagID); + AniDB_Anime_Tag anime_tag = repTagsXRefs.GetByAnimeIDAndTagID(sessionWrapper, rawtag.AnimeID, rawtag.TagID); if (anime_tag == null) anime_tag = new AniDB_Anime_Tag(); anime_tag.Populate(rawtag); @@ -1748,9 +1755,10 @@ private void CreateCharacters(ISession session, List chars) AniDB_Anime_CharacterRepository repAnimeChars = new AniDB_Anime_CharacterRepository(); AniDB_Character_SeiyuuRepository repCharSeiyuu = new AniDB_Character_SeiyuuRepository(); AniDB_SeiyuuRepository repSeiyuu = new AniDB_SeiyuuRepository(); + ISessionWrapper sessionWrapper = session.Wrap(); // delete all the existing cross references just in case one has been removed - List animeChars = repAnimeChars.GetByAnimeID(session, AnimeID); + List animeChars = repAnimeChars.GetByAnimeID(sessionWrapper, AnimeID); using (var transaction = session.BeginTransaction()) { @@ -1786,7 +1794,7 @@ private void CreateCharacters(ISession session, List chars) foreach (Raw_AniDB_Character rawchar in chars) { - AniDB_Character chr = repChars.GetByCharID(session, rawchar.CharID); + AniDB_Character chr = repChars.GetByCharID(sessionWrapper, rawchar.CharID); if (chr == null) chr = new AniDB_Character(); @@ -1991,7 +1999,23 @@ public override string ToString() return sb.ToString(); } - private Contract_AniDBAnime GenerateContract(ISession session, List titles) + private Contract_AniDBAnime GenerateContract(ISessionWrapper session, List titles) + { + List characters = GetCharactersContract(); + Contract_AniDBAnime contract = GenerateContract(titles, null, characters); + AniDB_Anime_DefaultImage defFanart = GetDefaultFanart(session); + AniDB_Anime_DefaultImage defPoster = GetDefaultPoster(session); + AniDB_Anime_DefaultImage defBanner = GetDefaultWideBanner(session); + + contract.DefaultImageFanart = defFanart?.ToContract(session); + contract.DefaultImagePoster = defPoster?.ToContract(session); + contract.DefaultImageWideBanner = defBanner?.ToContract(session); + + return contract; + } + + private Contract_AniDBAnime GenerateContract(List titles, DefaultAnimeImages defaultImages, + List characters) { Contract_AniDBAnime contract = new Contract_AniDBAnime(); contract.AirDate = this.AirDate; @@ -2002,12 +2026,12 @@ private Contract_AniDBAnime GenerateContract(ISession session, List( this.AllTags.Split(new char[] {'|'}, StringSplitOptions.RemoveEmptyEntries) .Select(a => a.Trim()) - .Where(a => !string.IsNullOrEmpty(a)).Distinct(StringComparer.InvariantCultureIgnoreCase), StringComparer.InvariantCultureIgnoreCase); + .Where(a => !string.IsNullOrEmpty(a)), StringComparer.InvariantCultureIgnoreCase); contract.AllTitles = new HashSet( this.AllTitles.Split(new char[] {'|'}, StringSplitOptions.RemoveEmptyEntries) .Select(a => a.Trim()) - .Where(a => !string.IsNullOrEmpty(a)).Distinct(StringComparer.InvariantCultureIgnoreCase), StringComparer.InvariantCultureIgnoreCase); + .Where(a => !string.IsNullOrEmpty(a)), StringComparer.InvariantCultureIgnoreCase); contract.AnimeID = this.AnimeID; contract.AnimeNfo = this.AnimeNfo; contract.AnimePlanetID = this.AnimePlanetID; @@ -2037,13 +2061,15 @@ private Contract_AniDBAnime GenerateContract(ISession session, List GetCharactersContract() { AniDB_Character chr = repChar.GetByCharID(animeChar.CharID); if (chr != null) - chars.Add(chr.ToContract(animeChar)); + chars.Add(chr.ToContract(animeChar.CharType)); } } catch (Exception ex) @@ -2073,7 +2099,133 @@ public List GetCharactersContract() return chars; } - public void UpdateContractDetailed(ISession session) + public static void UpdateContractDetailedBatch(ISessionWrapper session, IReadOnlyCollection animeColl) + { + if (session == null) + throw new ArgumentNullException(nameof(session)); + if (animeColl == null) + throw new ArgumentNullException(nameof(animeColl)); + + var repTitles = new AniDB_Anime_TitleRepository(); + var repAnimeTags = new AniDB_Anime_TagRepository(); + var repTags = new AniDB_TagRepository(); + var repCustomTags = new CustomTagRepository(); + var repAdHoc = new AdhocRepository(); + var repVotes = new AniDB_VoteRepository(); + var repAnime = new AniDB_AnimeRepository(); + var repChars = new AniDB_CharacterRepository(); + int[] animeIds = animeColl.Select(a => a.AnimeID).ToArray(); + + var titlesByAnime = repTitles.GetByAnimeIDs(session, animeIds); + var animeTagsByAnime = repAnimeTags.GetByAnimeIDs(session, animeIds); + var tagsByAnime = repTags.GetByAnimeIDs(session, animeIds); + var custTagsByAnime = repCustomTags.GetByAnimeIDs(session, animeIds); + var voteByAnime = repVotes.GetByAnimeIDs(session, animeIds); + var audioLangByAnime = repAdHoc.GetAudioLanguageStatsByAnime(session, animeIds); + var subtitleLangByAnime = repAdHoc.GetSubtitleLanguageStatsByAnime(session, animeIds); + var vidQualByAnime = repAdHoc.GetAllVideoQualityByAnime(session, animeIds); + var epVidQualByAnime = repAdHoc.GetEpisodeVideoQualityStatsByAnime(session, animeIds); + var defImagesByAnime = repAnime.GetDefaultImagesByAnime(session, animeIds); + var charsByAnime = repChars.GetCharacterAndSeiyuuByAnime(session, animeIds); + + foreach (AniDB_Anime anime in animeColl) + { + var contract = new Contract_AniDB_AnimeDetailed(); + var animeTitles = titlesByAnime[anime.AnimeID]; + DefaultAnimeImages defImages; + + defImagesByAnime.TryGetValue(anime.AnimeID, out defImages); + + var characterContracts = (charsByAnime[anime.AnimeID] ?? Enumerable.Empty()) + .Select(ac => ac.ToContract()) + .ToList(); + + contract.AniDBAnime = anime.GenerateContract(animeTitles.ToList(), defImages, characterContracts); + + // Anime titles + contract.AnimeTitles = titlesByAnime[anime.AnimeID] + .Select(t => new Contract_AnimeTitle + { + AnimeID = t.AnimeID, + Language = t.Language, + Title = t.Title, + TitleType = t.TitleType + }).ToList(); + + // Anime tags + var dictAnimeTags = animeTagsByAnime[anime.AnimeID] + .ToDictionary(t => t.TagID); + + contract.Tags = tagsByAnime[anime.AnimeID].Select(t => + { + AniDB_Anime_Tag animeTag = null; + Contract_AnimeTag ctag = new Contract_AnimeTag + { + GlobalSpoiler = t.GlobalSpoiler, + LocalSpoiler = t.LocalSpoiler, + TagDescription = t.TagDescription, + TagID = t.TagID, + TagName = t.TagName, + Weight = dictAnimeTags.TryGetValue(t.TagID, out animeTag) ? animeTag.Weight : 0 + }; + + return ctag; + }).ToList(); + + // Custom tags + contract.CustomTags = custTagsByAnime[anime.AnimeID] + .Select(t => t.ToContract()) + .ToList(); + + // Vote + AniDB_Vote vote; + + if (voteByAnime.TryGetValue(anime.AnimeID, out vote)) + { + contract.UserVote = vote.ToContract(); + } + + LanguageStat langStat; + + // Subtitle languages + contract.Stat_AudioLanguages = new HashSet(StringComparer.InvariantCultureIgnoreCase); + + if (audioLangByAnime.TryGetValue(anime.AnimeID, out langStat)) + { + contract.Stat_AudioLanguages.UnionWith(langStat.LanguageNames); + } + + // Audio languages + contract.Stat_SubtitleLanguages = new HashSet(StringComparer.InvariantCultureIgnoreCase); + + if (subtitleLangByAnime.TryGetValue(anime.AnimeID, out langStat)) + { + contract.Stat_SubtitleLanguages.UnionWith(langStat.LanguageNames); + } + + // Anime video quality + HashSet vidQual; + + contract.Stat_AllVideoQuality = vidQualByAnime.TryGetValue(anime.AnimeID, out vidQual) ? vidQual + : new HashSet(StringComparer.InvariantCultureIgnoreCase); + + // Episode video quality + AnimeVideoQualityStat vidQualStat; + + contract.Stat_AllVideoQuality_Episodes = new HashSet(StringComparer.InvariantCultureIgnoreCase); + + if (epVidQualByAnime.TryGetValue(anime.AnimeID, out vidQualStat) && vidQualStat.VideoQualityEpisodeCount.Count > 0) + { + contract.Stat_AllVideoQuality_Episodes.UnionWith(vidQualStat.VideoQualityEpisodeCount + .Where(kvp => kvp.Value >= anime.EpisodeCountNormal) + .Select(kvp => kvp.Key)); + } + + anime.Contract = contract; + } + } + + public void UpdateContractDetailed(ISessionWrapper session) { AniDB_Anime_TitleRepository repTitles = new AniDB_Anime_TitleRepository(); List animeTitles = repTitles.GetByAnimeID(session, AnimeID); @@ -2198,11 +2350,11 @@ public AnimeFull ToContractAzure() { using (var session = JMMService.SessionFactory.OpenSession()) { - return ToContractAzure(session); + return ToContractAzure(session.Wrap()); } } - public AnimeFull ToContractAzure(ISession session) + public AnimeFull ToContractAzure(ISessionWrapper session) { AnimeFull contract = new AnimeFull(); contract.Detail = new AnimeDetail(); @@ -2311,8 +2463,9 @@ public AnimeSeries CreateAnimeSeriesAndGroup(ISession session) AnimeSeries ser = new AnimeSeries(); ser.Populate(this); + ISessionWrapper sessionWrapper = session.Wrap(); JMMUserRepository repUsers = new JMMUserRepository(); - List allUsers = repUsers.GetAll(session); + List allUsers = repUsers.GetAll(sessionWrapper); // create the AnimeGroup record // check if there are any existing groups we could add this series to @@ -2320,7 +2473,7 @@ public AnimeSeries CreateAnimeSeriesAndGroup(ISession session) if (ServerSettings.AutoGroupSeries) { - List grps = AnimeGroup.GetRelatedGroupsFromAnimeID(session, ser.AniDB_ID, true); + List grps = AnimeGroup.GetRelatedGroupsFromAnimeID(sessionWrapper, ser.AniDB_ID, true); // only use if there is just one result @@ -2459,7 +2612,7 @@ public AnimeSeries CreateAnimeSeriesAndGroup(ISession session) return ser; } - public static void GetRelatedAnimeRecursive(ISession session, int animeID, ref List relList, + public static void GetRelatedAnimeRecursive(ISessionWrapper session, int animeID, ref List relList, ref List relListIDs, ref List searchedIDs) { AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); diff --git a/JMMServer/Entities/AniDB_Anime_Character.cs b/JMMServer/Entities/AniDB_Anime_Character.cs index 75592a0cd..cd97533bd 100644 --- a/JMMServer/Entities/AniDB_Anime_Character.cs +++ b/JMMServer/Entities/AniDB_Anime_Character.cs @@ -1,6 +1,7 @@ using AniDBAPI; using JMMContracts; using JMMServer.Repositories; +using JMMServer.Repositories.NHibernate; using NHibernate; namespace JMMServer.Entities @@ -25,11 +26,11 @@ public AniDB_Character GetCharacter() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetCharacter(session); + return GetCharacter(session.Wrap()); } } - public AniDB_Character GetCharacter(ISession session) + public AniDB_Character GetCharacter(ISessionWrapper session) { AniDB_CharacterRepository repChar = new AniDB_CharacterRepository(); return repChar.GetByCharID(session, CharID); diff --git a/JMMServer/Entities/AniDB_Anime_DefaultImage.cs b/JMMServer/Entities/AniDB_Anime_DefaultImage.cs index 51e3960b1..bfb3a7d55 100644 --- a/JMMServer/Entities/AniDB_Anime_DefaultImage.cs +++ b/JMMServer/Entities/AniDB_Anime_DefaultImage.cs @@ -1,5 +1,6 @@ using JMMContracts; using JMMServer.Repositories; +using JMMServer.Repositories.NHibernate; using NHibernate; namespace JMMServer.Entities @@ -16,90 +17,95 @@ public Contract_AniDB_Anime_DefaultImage ToContract() { using (var session = JMMService.SessionFactory.OpenSession()) { - return ToContract(session); + return ToContract(session.Wrap()); } } - public Contract_AniDB_Anime_DefaultImage ToContract(ISession session) + public Contract_AniDB_Anime_DefaultImage ToContract(IImageEntity parentImage) { - Contract_AniDB_Anime_DefaultImage contract = new Contract_AniDB_Anime_DefaultImage(); + var contract = new Contract_AniDB_Anime_DefaultImage + { + AniDB_Anime_DefaultImageID = AniDB_Anime_DefaultImageID, + AnimeID = AnimeID, + ImageParentID = ImageParentID, + ImageParentType = ImageParentType, + ImageType = ImageType + }; - contract.AniDB_Anime_DefaultImageID = this.AniDB_Anime_DefaultImageID; - contract.AnimeID = this.AnimeID; - contract.ImageParentID = this.ImageParentID; - contract.ImageParentType = this.ImageParentType; - contract.ImageType = this.ImageType; + JMMImageType imgType = (JMMImageType)ImageParentType; - contract.MovieFanart = null; - contract.MoviePoster = null; - contract.TVPoster = null; - contract.TVFanart = null; - contract.TVWideBanner = null; - contract.TraktFanart = null; - contract.TraktPoster = null; + switch (imgType) + { + case JMMImageType.TvDB_Banner: + contract.TVWideBanner = (parentImage as TvDB_ImageWideBanner)?.ToContract(); + break; + case JMMImageType.TvDB_Cover: + contract.TVPoster = (parentImage as TvDB_ImagePoster)?.ToContract(); + break; + case JMMImageType.TvDB_FanArt: + contract.TVFanart = (parentImage as TvDB_ImageFanart)?.ToContract(); + break; + case JMMImageType.MovieDB_Poster: + contract.MoviePoster = (parentImage as MovieDB_Poster)?.ToContract(); + break; + case JMMImageType.MovieDB_FanArt: + contract.MovieFanart = (parentImage as MovieDB_Fanart)?.ToContract(); + break; + case JMMImageType.Trakt_Fanart: + contract.TraktFanart = (parentImage as Trakt_ImageFanart)?.ToContract(); + break; + case JMMImageType.Trakt_Poster: + contract.TraktPoster = (parentImage as Trakt_ImagePoster)?.ToContract(); + break; + } + + return contract; + } - JMMImageType imgType = (JMMImageType) ImageParentType; + public Contract_AniDB_Anime_DefaultImage ToContract(ISessionWrapper session) + { + JMMImageType imgType = (JMMImageType)ImageParentType; + IImageEntity parentImage = null; switch (imgType) { case JMMImageType.TvDB_Banner: - TvDB_ImageWideBannerRepository repBanners = new TvDB_ImageWideBannerRepository(); - TvDB_ImageWideBanner banner = repBanners.GetByID(session, ImageParentID); - if (banner != null) contract.TVWideBanner = banner.ToContract(); + parentImage = repBanners.GetByID(session, ImageParentID); break; - case JMMImageType.TvDB_Cover: - TvDB_ImagePosterRepository repPosters = new TvDB_ImagePosterRepository(); - TvDB_ImagePoster poster = repPosters.GetByID(session, ImageParentID); - if (poster != null) contract.TVPoster = poster.ToContract(); + parentImage = repPosters.GetByID(session, ImageParentID); break; - case JMMImageType.TvDB_FanArt: - TvDB_ImageFanartRepository repFanart = new TvDB_ImageFanartRepository(); - TvDB_ImageFanart fanart = repFanart.GetByID(session, ImageParentID); - if (fanart != null) contract.TVFanart = fanart.ToContract(); + parentImage = repFanart.GetByID(session, ImageParentID); break; - case JMMImageType.MovieDB_Poster: - MovieDB_PosterRepository repMoviePosters = new MovieDB_PosterRepository(); - MovieDB_Poster moviePoster = repMoviePosters.GetByID(session, ImageParentID); - if (moviePoster != null) contract.MoviePoster = moviePoster.ToContract(); + parentImage = repMoviePosters.GetByID(session, ImageParentID); break; - case JMMImageType.MovieDB_FanArt: - MovieDB_FanartRepository repMovieFanart = new MovieDB_FanartRepository(); - MovieDB_Fanart movieFanart = repMovieFanart.GetByID(session, ImageParentID); - if (movieFanart != null) contract.MovieFanart = movieFanart.ToContract(); + parentImage = repMovieFanart.GetByID(session, ImageParentID); break; - case JMMImageType.Trakt_Fanart: - Trakt_ImageFanartRepository repTraktFanart = new Trakt_ImageFanartRepository(); - Trakt_ImageFanart traktFanart = repTraktFanart.GetByID(session, ImageParentID); - if (traktFanart != null) contract.TraktFanart = traktFanart.ToContract(); - + parentImage = repTraktFanart.GetByID(session, ImageParentID); break; - case JMMImageType.Trakt_Poster: - Trakt_ImagePosterRepository repTraktPoster = new Trakt_ImagePosterRepository(); - Trakt_ImagePoster traktPoster = repTraktPoster.GetByID(session, ImageParentID); - if (traktPoster != null) contract.TraktPoster = traktPoster.ToContract(); + parentImage = repTraktPoster.GetByID(session, ImageParentID); break; } - return contract; + return ToContract(parentImage); } } } \ No newline at end of file diff --git a/JMMServer/Entities/AniDB_Character.cs b/JMMServer/Entities/AniDB_Character.cs index 02e4c7dce..a5b9d3f18 100644 --- a/JMMServer/Entities/AniDB_Character.cs +++ b/JMMServer/Entities/AniDB_Character.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; using AniDBAPI; using JMMContracts; @@ -69,28 +70,35 @@ public void PopulateFromUDP(Raw_AniDB_Character rawChar) } } - public Contract_AniDB_Character ToContract(AniDB_Anime_Character charRel) + public Contract_AniDB_Character ToContract(string charType, AniDB_Seiyuu seiyuu) { - Contract_AniDB_Character contract = new Contract_AniDB_Character(); + var contract = new Contract_AniDB_Character + { + AniDB_CharacterID = AniDB_CharacterID, + CharID = CharID, + PicName = PicName, + CreatorListRaw = CreatorListRaw, + CharName = CharName, + CharKanjiName = CharKanjiName, + CharDescription = CharDescription, + CharType = charType + }; - contract.AniDB_CharacterID = this.AniDB_CharacterID; - contract.CharID = this.CharID; - contract.PicName = this.PicName; - contract.CreatorListRaw = this.CreatorListRaw; - contract.CharName = this.CharName; - contract.CharKanjiName = this.CharKanjiName; - contract.CharDescription = this.CharDescription; - - contract.CharType = charRel.CharType; - - contract.Seiyuu = null; - AniDB_Seiyuu seiyuu = this.GetSeiyuu(); if (seiyuu != null) + { contract.Seiyuu = seiyuu.ToContract(); + } return contract; } + public Contract_AniDB_Character ToContract(string charType) + { + AniDB_Seiyuu seiyuu = GetSeiyuu(); + + return ToContract(charType, seiyuu); + } + public MetroContract_AniDB_Character ToContractMetro(ISession session, AniDB_Anime_Character charRel) { MetroContract_AniDB_Character contract = new MetroContract_AniDB_Character(); diff --git a/JMMServer/Entities/AnimeEpisode.cs b/JMMServer/Entities/AnimeEpisode.cs index 8ed26bbac..85640d9c2 100644 --- a/JMMServer/Entities/AnimeEpisode.cs +++ b/JMMServer/Entities/AnimeEpisode.cs @@ -7,6 +7,7 @@ using JMMContracts.PlexAndKodi; using JMMServer.LZ4; using JMMServer.Repositories; +using JMMServer.Repositories.NHibernate; using NHibernate; using Stream = JMMContracts.PlexAndKodi.Stream; @@ -97,11 +98,11 @@ public AnimeSeries GetAnimeSeries() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetAnimeSeries(session); + return GetAnimeSeries(session.Wrap()); } } - public AnimeSeries GetAnimeSeries(ISession session) + public AnimeSeries GetAnimeSeries(ISessionWrapper session) { AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); return repSeries.GetByID(session, this.AnimeSeriesID); diff --git a/JMMServer/Entities/AnimeGroup.cs b/JMMServer/Entities/AnimeGroup.cs index 12e26b18d..4998b591e 100644 --- a/JMMServer/Entities/AnimeGroup.cs +++ b/JMMServer/Entities/AnimeGroup.cs @@ -8,6 +8,7 @@ using JMMContracts.PlexAndKodi; using JMMServer.LZ4; using JMMServer.Repositories; +using JMMServer.Repositories.NHibernate; using NHibernate; using NLog; @@ -74,11 +75,11 @@ public string GetPosterPathNoBlanks() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetPosterPathNoBlanks(session); + return GetPosterPathNoBlanks(session.Wrap()); } } - public string GetPosterPathNoBlanks(ISession session) + public string GetPosterPathNoBlanks(ISessionWrapper session) { List allPosters = GetPosterFilenames(session); string posterName = ""; @@ -96,11 +97,11 @@ private List GetPosterFilenames() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetPosterFilenames(session); + return GetPosterFilenames(session.Wrap()); } } - private List GetPosterFilenames(ISession session) + private List GetPosterFilenames(ISessionWrapper session) { List allPosters = new List(); @@ -200,11 +201,11 @@ public static List GetRelatedGroupsFromAnimeID(int animeid, bool for { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetRelatedGroupsFromAnimeID(session, animeid, forceRecursive); + return GetRelatedGroupsFromAnimeID(session.Wrap(), animeid, forceRecursive); } } - public static List GetRelatedGroupsFromAnimeID(ISession session, int animeid, + public static List GetRelatedGroupsFromAnimeID(ISessionWrapper session, int animeid, bool forceRecursive = false) { AniDB_AnimeRepository repAniAnime = new AniDB_AnimeRepository(); @@ -471,11 +472,11 @@ public List GetChildGroups() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetChildGroups(session); + return GetChildGroups(session.Wrap()); } } - public List GetChildGroups(ISession session) + public List GetChildGroups(ISessionWrapper session) { AnimeGroupRepository repGroups = new AnimeGroupRepository(); return repGroups.GetByParentID(session, this.AnimeGroupID); @@ -496,11 +497,11 @@ public List GetAllChildGroups() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetAllChildGroups(session); + return GetAllChildGroups(session.Wrap()); } } - public List GetAllChildGroups(ISession session) + public List GetAllChildGroups(ISessionWrapper session) { List grpList = new List(); AnimeGroup.GetAnimeGroupsRecursive(session, this.AnimeGroupID, ref grpList); @@ -523,11 +524,11 @@ public List GetSeries() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetSeries(session); + return GetSeries(session.Wrap()); } } - public List GetSeries(ISession session) + public List GetSeries(ISessionWrapper session) { AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); List seriesList = repSeries.GetByGroupID(this.AnimeGroupID); @@ -561,11 +562,11 @@ public List GetAllSeries(bool skipSorting=false) { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetAllSeries(session, skipSorting); + return GetAllSeries(session.Wrap(), skipSorting); } } - public List GetAllSeries(ISession session, bool skipSorting=false) + public List GetAllSeries(ISessionWrapper session, bool skipSorting = false) { List seriesList = new List(); AnimeGroup.GetAnimeSeriesRecursive(session, this.AnimeGroupID, ref seriesList); @@ -600,10 +601,12 @@ public List Tags using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); + // get a list of all the unique tags for this all the series in this group foreach (AnimeSeries ser in GetAllSeries()) { - foreach (AniDB_Anime_Tag aac in ser.GetAnime().GetAnimeTags(session)) + foreach (AniDB_Anime_Tag aac in ser.GetAnime().GetAnimeTags(sessionWrapper)) { if (!animeTagIDs.Contains(aac.AniDB_Anime_TagID)) { @@ -616,7 +619,7 @@ public List Tags AniDB_TagRepository repTag = new AniDB_TagRepository(); foreach (AniDB_Anime_Tag animeTag in animeTags.OrderByDescending(a=>a.Weight)) { - AniDB_Tag tag = repTag.GetByTagID(animeTag.TagID, session); + AniDB_Tag tag = repTag.GetByTagID(animeTag.TagID, sessionWrapper); if (tag != null) tags.Add(tag); } } @@ -981,7 +984,7 @@ public static HashSet GetConditionTypesChanged(Contrac return h; } - public HashSet UpdateContract(ISession session, bool updatestats) + public HashSet UpdateContract(ISessionWrapper session, bool updatestats) { Contract_AnimeGroup contract = (Contract_AnimeGroup) Contract?.DeepCopy(); if (contract == null) @@ -1290,7 +1293,7 @@ public void UpdateGroupFilters(HashSet types, JMMUser } - public static void GetAnimeGroupsRecursive(ISession session, int animeGroupID, ref List groupList) + public static void GetAnimeGroupsRecursive(ISessionWrapper session, int animeGroupID, ref List groupList) { AnimeGroupRepository rep = new AnimeGroupRepository(); AnimeGroup grp = rep.GetByID(session, animeGroupID); @@ -1305,7 +1308,7 @@ public static void GetAnimeGroupsRecursive(ISession session, int animeGroupID, r } } - public static void GetAnimeSeriesRecursive(ISession session, int animeGroupID, ref List seriesList) + public static void GetAnimeSeriesRecursive(ISessionWrapper session, int animeGroupID, ref List seriesList) { AnimeGroupRepository rep = new AnimeGroupRepository(); AnimeGroup grp = rep.GetByID(session, animeGroupID); diff --git a/JMMServer/Entities/AnimeGroup_User.cs b/JMMServer/Entities/AnimeGroup_User.cs index 3cded1ce6..67e640d1f 100644 --- a/JMMServer/Entities/AnimeGroup_User.cs +++ b/JMMServer/Entities/AnimeGroup_User.cs @@ -4,6 +4,7 @@ using JMMServer.LZ4; using JMMServer.PlexAndKodi; using JMMServer.Repositories; +using JMMServer.Repositories.NHibernate; using NLog; namespace JMMServer.Entities @@ -128,12 +129,13 @@ public void UpdatePlexKodiContracts() { using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); AnimeGroupRepository repo = new AnimeGroupRepository(); AnimeGroup grp = repo.GetByID(AnimeGroupID); if (grp == null) return; - List series = grp.GetAllSeries(session); - PlexContract = Helper.GenerateFromAnimeGroup(session, grp, JMMUserID, series); + List series = grp.GetAllSeries(sessionWrapper); + PlexContract = Helper.GenerateFromAnimeGroup(sessionWrapper, grp, JMMUserID, series); } } diff --git a/JMMServer/Entities/AnimeSeries.cs b/JMMServer/Entities/AnimeSeries.cs index 538afaa59..9e053bd84 100644 --- a/JMMServer/Entities/AnimeSeries.cs +++ b/JMMServer/Entities/AnimeSeries.cs @@ -7,6 +7,7 @@ using JMMServer.ImageDownload; using JMMServer.LZ4; using JMMServer.Repositories; +using JMMServer.Repositories.NHibernate; using NHibernate; using NLog; using NutzCode.InMemoryIndex; @@ -79,11 +80,11 @@ public string GetSeriesName() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetSeriesName(session); + return GetSeriesName(session.Wrap()); } } - public string GetSeriesName(ISession session) + public string GetSeriesName(ISessionWrapper session) { string seriesName = ""; if (!string.IsNullOrEmpty(SeriesNameOverride)) @@ -185,11 +186,11 @@ public List GetAnimeEpisodes() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetAnimeEpisodes(session); + return GetAnimeEpisodes(session.Wrap()); } } - public List GetAnimeEpisodes(ISession session) + public List GetAnimeEpisodes(ISessionWrapper session) { AnimeEpisodeRepository repEpisodes = new AnimeEpisodeRepository(); return repEpisodes.GetBySeriesID(session, AnimeSeriesID); @@ -240,11 +241,11 @@ public List GetCrossRefTvDBV2() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetCrossRefTvDBV2(session); + return GetCrossRefTvDBV2(session.Wrap()); } } - public List GetCrossRefTvDBV2(ISession session) + public List GetCrossRefTvDBV2(ISessionWrapper session) { CrossRef_AniDB_TvDBV2Repository repCrossRef = new CrossRef_AniDB_TvDBV2Repository(); return repCrossRef.GetByAnimeID(session, this.AniDB_ID); @@ -254,11 +255,11 @@ public List GetTvDBSeries() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetTvDBSeries(session); + return GetTvDBSeries(session.Wrap()); } } - public List GetTvDBSeries(ISession session) + public List GetTvDBSeries(ISessionWrapper session) { List sers = new List(); @@ -427,11 +428,11 @@ public AniDB_Anime GetAnime() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetAnime(session); + return GetAnime(session.Wrap()); } } - public AniDB_Anime GetAnime(ISession session) + public AniDB_Anime GetAnime(ISessionWrapper session) { AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anidb_anime = repAnime.GetByAnimeID(session, this.AniDB_ID); @@ -488,10 +489,11 @@ public void CreateAnimeEpisodes() public void CreateAnimeEpisodes(ISession session) { - AniDB_Anime anime = GetAnime(session); + ISessionWrapper sessionWrapper = session.Wrap(); + AniDB_Anime anime = GetAnime(session.Wrap()); if (anime == null) return; - foreach (AniDB_Episode ep in anime.GetAniDBEpisodes(session)) + foreach (AniDB_Episode ep in anime.GetAniDBEpisodes(sessionWrapper)) { ep.CreateAnimeEpisode(session, this.AnimeSeriesID); } diff --git a/JMMServer/Entities/CrossRef_AniDB_Other.cs b/JMMServer/Entities/CrossRef_AniDB_Other.cs index b72dfe576..0e7d549f5 100644 --- a/JMMServer/Entities/CrossRef_AniDB_Other.cs +++ b/JMMServer/Entities/CrossRef_AniDB_Other.cs @@ -1,5 +1,6 @@ using JMMContracts; using JMMServer.Repositories; +using JMMServer.Repositories.NHibernate; using NHibernate; namespace JMMServer.Entities @@ -16,11 +17,11 @@ public MovieDB_Movie GetMovieDB_Movie() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetMovieDB_Movie(session); + return GetMovieDB_Movie(session.Wrap()); } } - public MovieDB_Movie GetMovieDB_Movie(ISession session) + public MovieDB_Movie GetMovieDB_Movie(ISessionWrapper session) { if (CrossRefType != (int) JMMServer.CrossRefType.MovieDB) return null; diff --git a/JMMServer/Entities/CrossRef_AniDB_TvDB.cs b/JMMServer/Entities/CrossRef_AniDB_TvDB.cs index fd315dced..d536db411 100644 --- a/JMMServer/Entities/CrossRef_AniDB_TvDB.cs +++ b/JMMServer/Entities/CrossRef_AniDB_TvDB.cs @@ -1,5 +1,6 @@ using JMMContracts; using JMMServer.Repositories; +using JMMServer.Repositories.NHibernate; using NHibernate; namespace JMMServer.Entities @@ -17,11 +18,11 @@ public TvDB_Series GetTvDBSeries() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetTvDBSeries(session); + return GetTvDBSeries(session.Wrap()); } } - public TvDB_Series GetTvDBSeries(ISession session) + public TvDB_Series GetTvDBSeries(ISessionWrapper session) { TvDB_SeriesRepository repTvSeries = new TvDB_SeriesRepository(); return repTvSeries.GetByTvDBID(session, TvDBID); diff --git a/JMMServer/Entities/CrossRef_AniDB_TvDBV2.cs b/JMMServer/Entities/CrossRef_AniDB_TvDBV2.cs index addcd1883..ef01fe1bc 100644 --- a/JMMServer/Entities/CrossRef_AniDB_TvDBV2.cs +++ b/JMMServer/Entities/CrossRef_AniDB_TvDBV2.cs @@ -1,5 +1,7 @@ -using JMMContracts; +using System; +using JMMContracts; using JMMServer.Repositories; +using JMMServer.Repositories.NHibernate; using NHibernate; namespace JMMServer.Entities @@ -22,11 +24,11 @@ public TvDB_Series GetTvDBSeries() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetTvDBSeries(session); + return GetTvDBSeries(session.Wrap()); } } - public TvDB_Series GetTvDBSeries(ISession session) + public TvDB_Series GetTvDBSeries(ISessionWrapper session) { TvDB_SeriesRepository repTvSeries = new TvDB_SeriesRepository(); return repTvSeries.GetByTvDBID(session, TvDBID); diff --git a/JMMServer/Entities/IImageEntity.cs b/JMMServer/Entities/IImageEntity.cs new file mode 100644 index 000000000..05b61a196 --- /dev/null +++ b/JMMServer/Entities/IImageEntity.cs @@ -0,0 +1,6 @@ +namespace JMMServer.Entities +{ + public interface IImageEntity + { + } +} \ No newline at end of file diff --git a/JMMServer/Entities/MovieDB_Fanart.cs b/JMMServer/Entities/MovieDB_Fanart.cs index 42017e43a..8d83db0c6 100644 --- a/JMMServer/Entities/MovieDB_Fanart.cs +++ b/JMMServer/Entities/MovieDB_Fanart.cs @@ -6,7 +6,7 @@ namespace JMMServer.Entities { - public class MovieDB_Fanart + public class MovieDB_Fanart : IImageEntity { private static Logger logger = LogManager.GetCurrentClassLogger(); diff --git a/JMMServer/Entities/MovieDB_Poster.cs b/JMMServer/Entities/MovieDB_Poster.cs index ae751bec3..5df5aa8bb 100644 --- a/JMMServer/Entities/MovieDB_Poster.cs +++ b/JMMServer/Entities/MovieDB_Poster.cs @@ -6,7 +6,7 @@ namespace JMMServer.Entities { - public class MovieDB_Poster + public class MovieDB_Poster : IImageEntity { private static Logger logger = LogManager.GetCurrentClassLogger(); diff --git a/JMMServer/Entities/Trakt_ImageFanart.cs b/JMMServer/Entities/Trakt_ImageFanart.cs index e38e0f564..e7a5b3358 100644 --- a/JMMServer/Entities/Trakt_ImageFanart.cs +++ b/JMMServer/Entities/Trakt_ImageFanart.cs @@ -5,7 +5,7 @@ namespace JMMServer.Entities { - public class Trakt_ImageFanart + public class Trakt_ImageFanart : IImageEntity { private static Logger logger = LogManager.GetCurrentClassLogger(); diff --git a/JMMServer/Entities/Trakt_ImagePoster.cs b/JMMServer/Entities/Trakt_ImagePoster.cs index 2cf594d14..0fb830b71 100644 --- a/JMMServer/Entities/Trakt_ImagePoster.cs +++ b/JMMServer/Entities/Trakt_ImagePoster.cs @@ -5,7 +5,7 @@ namespace JMMServer.Entities { - public class Trakt_ImagePoster + public class Trakt_ImagePoster : IImageEntity { private static Logger logger = LogManager.GetCurrentClassLogger(); diff --git a/JMMServer/Entities/TvDB_ImageFanart.cs b/JMMServer/Entities/TvDB_ImageFanart.cs index 3aa59b906..4b0639fd5 100644 --- a/JMMServer/Entities/TvDB_ImageFanart.cs +++ b/JMMServer/Entities/TvDB_ImageFanart.cs @@ -7,7 +7,7 @@ namespace JMMServer.Entities { - public class TvDB_ImageFanart + public class TvDB_ImageFanart : IImageEntity { private static Logger logger = LogManager.GetCurrentClassLogger(); diff --git a/JMMServer/Entities/TvDB_ImagePoster.cs b/JMMServer/Entities/TvDB_ImagePoster.cs index 674c653c4..c89036536 100644 --- a/JMMServer/Entities/TvDB_ImagePoster.cs +++ b/JMMServer/Entities/TvDB_ImagePoster.cs @@ -7,7 +7,7 @@ namespace JMMServer.Entities { - public class TvDB_ImagePoster + public class TvDB_ImagePoster : IImageEntity { private static Logger logger = LogManager.GetCurrentClassLogger(); diff --git a/JMMServer/Entities/TvDB_ImageWideBanner.cs b/JMMServer/Entities/TvDB_ImageWideBanner.cs index 9395f109d..1b40f2951 100644 --- a/JMMServer/Entities/TvDB_ImageWideBanner.cs +++ b/JMMServer/Entities/TvDB_ImageWideBanner.cs @@ -7,7 +7,7 @@ namespace JMMServer.Entities { - public class TvDB_ImageWideBanner + public class TvDB_ImageWideBanner : IImageEntity { private static Logger logger = LogManager.GetCurrentClassLogger(); diff --git a/JMMServer/Entities/VideoLocal.cs b/JMMServer/Entities/VideoLocal.cs index d1f8efcc2..33f635355 100644 --- a/JMMServer/Entities/VideoLocal.cs +++ b/JMMServer/Entities/VideoLocal.cs @@ -21,6 +21,7 @@ using Directory = Pri.LongPath.Directory; using File = Pri.LongPath.File; using FileInfo = Pri.LongPath.FileInfo; +using JMMServer.Repositories.NHibernate; namespace JMMServer.Entities { @@ -139,11 +140,11 @@ public AniDB_File GetAniDBFile() { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetAniDBFile(session); + return GetAniDBFile(session.Wrap()); } } - public AniDB_File GetAniDBFile(ISession session) + public AniDB_File GetAniDBFile(ISessionWrapper session) { AniDB_FileRepository repAniFile = new AniDB_FileRepository(); return repAniFile.GetByHash(session, Hash); diff --git a/JMMServer/Importer.cs b/JMMServer/Importer.cs index d564fd766..fd0710b36 100644 --- a/JMMServer/Importer.cs +++ b/JMMServer/Importer.cs @@ -13,6 +13,7 @@ using JMMServer.Providers.TraktTV; using JMMServer.Providers.TvDB; using JMMServer.Repositories; +using JMMServer.Repositories.NHibernate; using NLog; using CrossRef_File_Episode = JMMServer.Entities.CrossRef_File_Episode; @@ -143,6 +144,7 @@ public static void SyncHashes() AniDB_FileRepository repFiles=new AniDB_FileRepository(); using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); List allfiles = repVidLocals.GetAll().ToList(); List missfiles = allfiles.Where( a => @@ -153,7 +155,7 @@ public static void SyncHashes() //Check if we can populate md5,sha and crc from AniDB_Files foreach (VideoLocal v in missfiles.ToList()) { - AniDB_File file = repFiles.GetByHash(session,v.ED2KHash); + AniDB_File file = repFiles.GetByHash(sessionWrapper,v.ED2KHash); if (file != null) { if (!string.IsNullOrEmpty(file.CRC) && !string.IsNullOrEmpty(file.SHA1) && diff --git a/JMMServer/JMMServer.csproj b/JMMServer/JMMServer.csproj index e4cccf23e..9509eea29 100644 --- a/JMMServer/JMMServer.csproj +++ b/JMMServer/JMMServer.csproj @@ -259,9 +259,13 @@ + + + + @@ -539,6 +543,11 @@ + + + + + diff --git a/JMMServer/JMMServiceImplementation.cs b/JMMServer/JMMServiceImplementation.cs index a6d7f4001..46e825efd 100644 --- a/JMMServer/JMMServiceImplementation.cs +++ b/JMMServer/JMMServiceImplementation.cs @@ -25,6 +25,7 @@ using NHibernate; using NLog; using JMMServer.Commands.TvDB; +using JMMServer.Repositories.NHibernate; namespace JMMServer { @@ -56,12 +57,13 @@ public List GetAllGroupsAboveGroupInclusive(int animeGroupI { using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); AnimeGroupRepository repGroups = new AnimeGroupRepository(); int? grpid = animeGroupID; while (grpid.HasValue) { grpid = null; - AnimeGroup grp = repGroups.GetByID(session, animeGroupID); + AnimeGroup grp = repGroups.GetByID(sessionWrapper, animeGroupID); if (grp != null) { grps.Add(grp.GetUserContract(userID)); @@ -85,8 +87,9 @@ public List GetAllGroupsAboveSeries(int animeSeriesID, int { using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); - AnimeSeries series = repSeries.GetByID(session, animeSeriesID); + AnimeSeries series = repSeries.GetByID(sessionWrapper, animeSeriesID); if (series == null) return grps; @@ -207,10 +210,11 @@ public List GetAnimeGroupsForFilter(int groupFilterID, int { using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); AnimeGroupRepository repGroups = new AnimeGroupRepository(); GroupFilterRepository repGF = new GroupFilterRepository(); JMMUserRepository repUsers = new JMMUserRepository(); - JMMUser user = repUsers.GetByID(session, userID); + JMMUser user = repUsers.GetByID(sessionWrapper, userID); if (user == null) return retGroups; GroupFilter gf; gf = repGF.GetByID(session, groupFilterID); @@ -285,12 +289,13 @@ public Contract_GroupFilterExtended GetGroupFilterExtended(int groupFilterID, in { using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); GroupFilterRepository repGF = new GroupFilterRepository(); GroupFilter gf = repGF.GetByID(session, groupFilterID); if (gf == null) return null; JMMUserRepository repUsers = new JMMUserRepository(); - JMMUser user = repUsers.GetByID(session, userID); + JMMUser user = repUsers.GetByID(sessionWrapper, userID); if (user == null) return null; Contract_GroupFilterExtended contract = gf.ToContractExtended(session, user); @@ -1502,10 +1507,11 @@ public Contract_AnimeSeries_SaveResponse CreateSeriesFromAnime(int animeID, int? { using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); AnimeGroupRepository repGroups = new AnimeGroupRepository(); if (animeGroupID.HasValue) { - AnimeGroup grp = repGroups.GetByID(session, animeGroupID.Value); + AnimeGroup grp = repGroups.GetByID(sessionWrapper, animeGroupID.Value); if (grp == null) { response.ErrorMessage = "Could not find the specified group"; @@ -1515,7 +1521,7 @@ public Contract_AnimeSeries_SaveResponse CreateSeriesFromAnime(int animeID, int? // make sure a series doesn't already exists for this anime AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); - AnimeSeries ser = repSeries.GetByAnimeID(session, animeID); + AnimeSeries ser = repSeries.GetByAnimeID(sessionWrapper, animeID); if (ser != null) { response.ErrorMessage = "A series already exists for this anime"; @@ -1524,7 +1530,7 @@ public Contract_AnimeSeries_SaveResponse CreateSeriesFromAnime(int animeID, int? // make sure the anime exists first AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); - AniDB_Anime anime = repAnime.GetByAnimeID(session, animeID); + AniDB_Anime anime = repAnime.GetByAnimeID(sessionWrapper, animeID); if (anime == null) anime = JMMService.AnidbProcessor.GetAnimeInfoHTTP(session, animeID, false, false); @@ -1596,10 +1602,11 @@ public string UpdateAnimeData(int animeID) // we can usually tell this if the Resolution == '0x0' VideoLocalRepository repVids = new VideoLocalRepository(); AniDB_FileRepository repFiles = new AniDB_FileRepository(); + ISessionWrapper sessionWrapper = session.Wrap(); - foreach (VideoLocal vid in repVids.GetByAniDBAnimeID(session, animeID)) + foreach (VideoLocal vid in repVids.GetByAniDBAnimeID(sessionWrapper, animeID)) { - AniDB_File aniFile = vid.GetAniDBFile(session); + AniDB_File aniFile = vid.GetAniDBFile(sessionWrapper); if (aniFile == null) continue; if (aniFile.File_VideoResolution.Equals("0x0", StringComparison.InvariantCultureIgnoreCase)) @@ -1762,7 +1769,7 @@ public Contract_AniDBAnime GetAnime(int animeID) { using (var session = JMMService.SessionFactory.OpenSession()) { - AniDB_Anime anime = repAnime.GetByAnimeID(session, animeID); + AniDB_Anime anime = repAnime.GetByAnimeID(session.Wrap(), animeID); return anime?.Contract.AniDBAnime; } } @@ -4445,6 +4452,7 @@ public Contract_AniDB_AnimeCrossRefs GetCrossRefDetails(int animeID) { using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); TvDB_SeriesRepository repSeries = new TvDB_SeriesRepository(); AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anime = repAnime.GetByAnimeID(animeID); @@ -4460,17 +4468,17 @@ public Contract_AniDB_AnimeCrossRefs GetCrossRefDetails(int animeID) { result.CrossRef_AniDB_TvDB.Add(xref.ToContract()); - TvDB_Series ser = repSeries.GetByTvDBID(session, xref.TvDBID); + TvDB_Series ser = repSeries.GetByTvDBID(sessionWrapper, xref.TvDBID); if (ser != null) result.TvDBSeries.Add(ser.ToContract()); foreach (TvDB_Episode ep in anime.GetTvDBEpisodes()) result.TvDBEpisodes.Add(ep.ToContract()); - foreach (TvDB_ImageFanart fanart in repFanart.GetBySeriesID(session, xref.TvDBID)) + foreach (TvDB_ImageFanart fanart in repFanart.GetBySeriesID(sessionWrapper, xref.TvDBID)) result.TvDBImageFanarts.Add(fanart.ToContract()); - foreach (TvDB_ImagePoster poster in repPosters.GetBySeriesID(session, xref.TvDBID)) + foreach (TvDB_ImagePoster poster in repPosters.GetBySeriesID(sessionWrapper, xref.TvDBID)) result.TvDBImagePosters.Add(poster.ToContract()); foreach (TvDB_ImageWideBanner banner in repBanners.GetBySeriesID(xref.TvDBID)) @@ -6040,11 +6048,11 @@ public Contract_AnimeEpisode GetNextUnwatchedEpisode(int animeSeriesID, int user { using (var session = JMMService.SessionFactory.OpenSession()) { - return GetNextUnwatchedEpisode(session, animeSeriesID, userID); + return GetNextUnwatchedEpisode(session.Wrap(), animeSeriesID, userID); } } - public Contract_AnimeEpisode GetNextUnwatchedEpisode(ISession session, int animeSeriesID, int userID) + public Contract_AnimeEpisode GetNextUnwatchedEpisode(ISessionWrapper session, int animeSeriesID, int userID) { try { @@ -6255,10 +6263,11 @@ public List GetContinueWatchingFilter(int userID, int max { using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); GroupFilterRepository repGF = new GroupFilterRepository(); AnimeGroup_UserRepository repGroupsUser = new AnimeGroup_UserRepository(); JMMUserRepository repUsers = new JMMUserRepository(); - JMMUser user = repUsers.GetByID(session, userID); + JMMUser user = repUsers.GetByID(sessionWrapper, userID); if (user == null) return retEps; // find the locked Continue Watching Filter @@ -6319,7 +6328,7 @@ public List GetContinueWatchingFilter(int userID, int max if (!useSeries) continue; - Contract_AnimeEpisode ep = GetNextUnwatchedEpisode(session, ser.AnimeSeriesID, userID); + Contract_AnimeEpisode ep = GetNextUnwatchedEpisode(sessionWrapper, ser.AnimeSeriesID, userID); if (ep != null) { retEps.Add(ep); @@ -6354,6 +6363,7 @@ public List GetEpisodesToWatch_RecentlyWatched(int maxRec { using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); AnimeEpisodeRepository repEps = new AnimeEpisodeRepository(); AnimeSeriesRepository repAnimeSer = new AnimeSeriesRepository(); AnimeSeries_UserRepository repSeriesUser = new AnimeSeries_UserRepository(); @@ -6361,7 +6371,7 @@ public List GetEpisodesToWatch_RecentlyWatched(int maxRec DateTime start = DateTime.Now; - JMMUser user = repUsers.GetByID(session, jmmuserID); + JMMUser user = repUsers.GetByID(sessionWrapper, jmmuserID); if (user == null) return retEps; // get a list of series that is applicable @@ -6373,12 +6383,12 @@ public List GetEpisodesToWatch_RecentlyWatched(int maxRec foreach (AnimeSeries_User userRecord in allSeriesUser) { - AnimeSeries series = repAnimeSer.GetByID(session, userRecord.AnimeSeriesID); + AnimeSeries series = repAnimeSer.GetByID(sessionWrapper, userRecord.AnimeSeriesID); if (series == null) continue; if (!user.AllowedSeries(series)) continue; - Contract_AnimeEpisode ep = GetNextUnwatchedEpisode(session, userRecord.AnimeSeriesID, jmmuserID); + Contract_AnimeEpisode ep = GetNextUnwatchedEpisode(sessionWrapper, userRecord.AnimeSeriesID, jmmuserID); if (ep != null) { retEps.Add(ep); @@ -6459,12 +6469,13 @@ public List GetEpisodesRecentlyAdded(int maxRecords, int { using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); AnimeEpisodeRepository repEps = new AnimeEpisodeRepository(); AnimeEpisode_UserRepository repEpUser = new AnimeEpisode_UserRepository(); JMMUserRepository repUsers = new JMMUserRepository(); VideoLocalRepository repVids = new VideoLocalRepository(); - JMMUser user = repUsers.GetByID(session, jmmuserID); + JMMUser user = repUsers.GetByID(sessionWrapper, jmmuserID); if (user == null) return retEps; List vids = repVids.GetMostRecentlyAdded(session, maxRecords); @@ -6473,7 +6484,7 @@ public List GetEpisodesRecentlyAdded(int maxRecords, int { foreach (AnimeEpisode ep in vid.GetAnimeEpisodes(session)) { - if (user.AllowedSeries(ep.GetAnimeSeries(session))) + if (user.AllowedSeries(ep.GetAnimeSeries(sessionWrapper))) { Contract_AnimeEpisode epContract = ep.GetUserContract(jmmuserID); if (epContract != null) @@ -6510,7 +6521,8 @@ public List GetEpisodesRecentlyAddedSummary(int maxRecord using (var session = JMMService.SessionFactory.OpenSession()) { - JMMUser user = repUsers.GetByID(session, jmmuserID); + ISessionWrapper sessionWrapper = session.Wrap(); + JMMUser user = repUsers.GetByID(sessionWrapper, jmmuserID); if (user == null) return retEps; DateTime start = DateTime.Now; @@ -6532,7 +6544,7 @@ public List GetEpisodesRecentlyAddedSummary(int maxRecord { int animeSeriesID = int.Parse(res[0].ToString()); - AnimeSeries ser = repSeries.GetByID(session, animeSeriesID); + AnimeSeries ser = repSeries.GetByID(sessionWrapper, animeSeriesID); if (ser == null) continue; if (!user.AllowedSeries(ser)) continue; @@ -6579,10 +6591,11 @@ public List GetSeriesRecentlyAdded(int maxRecords, int jmm { using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); JMMUserRepository repUsers = new JMMUserRepository(); AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); - JMMUser user = repUsers.GetByID(session, jmmuserID); + JMMUser user = repUsers.GetByID(sessionWrapper, jmmuserID); if (user == null) return retSeries; List series = repSeries.GetMostRecentlyAdded(session, maxRecords); @@ -7359,7 +7372,7 @@ public List GetCharactersForSeiyuu(int aniDB_SeiyuuID) AniDB_Anime anime = repAnime.GetByAnimeID(aniChars[0].AnimeID); if (anime != null) { - Contract_AniDB_Character contract = chr.ToContract(aniChars[0]); + Contract_AniDB_Character contract = chr.ToContract(aniChars[0].CharType); contract.Anime = anime.Contract.AniDBAnime; chars.Add(contract); } @@ -8724,10 +8737,8 @@ public List OnlineAnimeTitleSearch(string titleQuery) // try the local database first // if not download the data from AniDB now - AniDB_Anime anime = - anime = - JMMService.AnidbProcessor.GetAnimeInfoHTTP(aid, false, - ServerSettings.AniDB_DownloadRelatedAnime); + AniDB_Anime anime = JMMService.AnidbProcessor.GetAnimeInfoHTTP(aid, false, + ServerSettings.AniDB_DownloadRelatedAnime); if (anime != null) { Contract_AnimeSearch res = new Contract_AnimeSearch(); @@ -8755,12 +8766,13 @@ public List OnlineAnimeTitleSearch(string titleQuery) else { // title search so look at the web cache - List titles = - JMMServer.Providers.Azure.AzureWebAPI.Get_AnimeTitle(titleQuery); + List titles = Providers.Azure.AzureWebAPI.Get_AnimeTitle(titleQuery); using (var session = JMMService.SessionFactory.OpenSession()) { - foreach (JMMServer.Providers.Azure.AnimeIDTitle tit in titles) + ISessionWrapper sessionWrapper = session.Wrap(); + + foreach (Providers.Azure.AnimeIDTitle tit in titles) { Contract_AnimeSearch res = new Contract_AnimeSearch(); res.AnimeID = tit.AnimeID; @@ -8775,7 +8787,7 @@ public List OnlineAnimeTitleSearch(string titleQuery) { res.SeriesExists = true; res.AnimeSeriesID = ser.AnimeSeriesID; - res.AnimeSeriesName = ser.GetAnime(session).GetFormattedTitle(session); + res.AnimeSeriesName = ser.GetAnime(sessionWrapper).GetFormattedTitle(sessionWrapper); } else { diff --git a/JMMServer/JMMServiceImplementationMetro.cs b/JMMServer/JMMServiceImplementationMetro.cs index 95ea377dd..e670eaac0 100644 --- a/JMMServer/JMMServiceImplementationMetro.cs +++ b/JMMServer/JMMServiceImplementationMetro.cs @@ -13,6 +13,7 @@ using JMMServer.Providers.TraktTV.Contracts; using JMMServer.Providers.TvDB; using JMMServer.Repositories; +using JMMServer.Repositories.NHibernate; using NLog; namespace JMMServer @@ -79,9 +80,10 @@ public MetroContract_CommunityLinks GetCommunityLinks(int animeID) { using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); - AniDB_Anime anime = repAnime.GetByAnimeID(session, animeID); + AniDB_Anime anime = repAnime.GetByAnimeID(sessionWrapper, animeID); if (anime == null) return null; //AniDB @@ -100,7 +102,7 @@ public MetroContract_CommunityLinks GetCommunityLinks(int animeID) } // TvDB - List tvdbRef = anime.GetCrossRefTvDBV2(session); + List tvdbRef = anime.GetCrossRefTvDBV2(sessionWrapper); if (tvdbRef != null && tvdbRef.Count > 0) { contract.TvDB_ID = tvdbRef[0].TvDBID.ToString(); @@ -181,13 +183,14 @@ public List GetEpisodesRecentlyAddedSummary(int maxRecord { using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); AnimeEpisodeRepository repEps = new AnimeEpisodeRepository(); AnimeEpisode_UserRepository repEpUser = new AnimeEpisode_UserRepository(); AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); JMMUserRepository repUsers = new JMMUserRepository(); VideoLocalRepository repVids = new VideoLocalRepository(); - JMMUser user = repUsers.GetByID(session, jmmuserID); + JMMUser user = repUsers.GetByID(sessionWrapper, jmmuserID); if (user == null) return retEps; string sql = "Select ae.AnimeSeriesID, max(vl.DateTimeCreated) as MaxDate " + @@ -203,7 +206,7 @@ public List GetEpisodesRecentlyAddedSummary(int maxRecord { int animeSeriesID = int.Parse(res[0].ToString()); - AnimeSeries ser = repSeries.GetByID(session, animeSeriesID); + AnimeSeries ser = repSeries.GetByID(sessionWrapper, animeSeriesID); if (ser == null) continue; if (!user.AllowedSeries(session, ser)) continue; @@ -242,13 +245,14 @@ public List GetAnimeWithNewEpisodes(int maxRecords, { using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); AnimeEpisodeRepository repEps = new AnimeEpisodeRepository(); AnimeEpisode_UserRepository repEpUser = new AnimeEpisode_UserRepository(); AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); JMMUserRepository repUsers = new JMMUserRepository(); VideoLocalRepository repVids = new VideoLocalRepository(); - JMMUser user = repUsers.GetByID(session, jmmuserID); + JMMUser user = repUsers.GetByID(sessionWrapper, jmmuserID); if (user == null) return retAnime; string sql = "Select ae.AnimeSeriesID, max(vl.DateTimeCreated) as MaxDate " + @@ -264,7 +268,7 @@ public List GetAnimeWithNewEpisodes(int maxRecords, { int animeSeriesID = int.Parse(res[0].ToString()); - AnimeSeries ser = repSeries.GetByID(session, animeSeriesID); + AnimeSeries ser = repSeries.GetByID(sessionWrapper, animeSeriesID); if (ser == null) continue; if (!user.AllowedSeries(session, ser)) continue; @@ -280,11 +284,11 @@ public List GetAnimeWithNewEpisodes(int maxRecords, Contract_AnimeEpisode epContract = eps[0].GetUserContract(jmmuserID); if (epContract != null) { - AniDB_Anime anidb_anime = ser.GetAnime(session); + AniDB_Anime anidb_anime = ser.GetAnime(sessionWrapper); MetroContract_Anime_Summary summ = new MetroContract_Anime_Summary(); summ.AnimeID = ser.AniDB_ID; - summ.AnimeName = ser.GetSeriesName(session); + summ.AnimeName = ser.GetSeriesName(sessionWrapper); summ.AnimeSeriesID = ser.AnimeSeriesID; summ.BeginYear = anidb_anime.BeginYear; summ.EndYear = anidb_anime.EndYear; @@ -294,7 +298,7 @@ public List GetAnimeWithNewEpisodes(int maxRecords, else summ.UnwatchedEpisodeCount = 0; - ImageDetails imgDet = anidb_anime.GetDefaultPosterDetailsNoBlanks(session); + ImageDetails imgDet = anidb_anime.GetDefaultPosterDetailsNoBlanks(sessionWrapper); summ.ImageType = (int) imgDet.ImageType; summ.ImageID = imgDet.ImageID; @@ -322,6 +326,7 @@ public List GetAnimeContinueWatching_old(int maxRec { using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); AnimeEpisodeRepository repEps = new AnimeEpisodeRepository(); AnimeSeriesRepository repAnimeSer = new AnimeSeriesRepository(); AnimeSeries_UserRepository repSeriesUser = new AnimeSeries_UserRepository(); @@ -329,7 +334,7 @@ public List GetAnimeContinueWatching_old(int maxRec DateTime start = DateTime.Now; - JMMUser user = repUsers.GetByID(session, jmmuserID); + JMMUser user = repUsers.GetByID(sessionWrapper, jmmuserID); if (user == null) return retAnime; // get a list of series that is applicable @@ -344,7 +349,7 @@ public List GetAnimeContinueWatching_old(int maxRec { start = DateTime.Now; - AnimeSeries series = repAnimeSer.GetByID(session, userRecord.AnimeSeriesID); + AnimeSeries series = repAnimeSer.GetByID(sessionWrapper, userRecord.AnimeSeriesID); if (series == null) continue; if (!user.AllowedSeries(session, series)) @@ -356,15 +361,15 @@ public List GetAnimeContinueWatching_old(int maxRec AnimeSeries_User serUser = series.GetUserRecord(session, jmmuserID); - Contract_AnimeEpisode ep = imp.GetNextUnwatchedEpisode(session, userRecord.AnimeSeriesID, + Contract_AnimeEpisode ep = imp.GetNextUnwatchedEpisode(sessionWrapper, userRecord.AnimeSeriesID, jmmuserID); if (ep != null) { - AniDB_Anime anidb_anime = series.GetAnime(session); + AniDB_Anime anidb_anime = series.GetAnime(sessionWrapper); MetroContract_Anime_Summary summ = new MetroContract_Anime_Summary(); summ.AnimeID = series.AniDB_ID; - summ.AnimeName = series.GetSeriesName(session); + summ.AnimeName = series.GetSeriesName(sessionWrapper); summ.AnimeSeriesID = series.AnimeSeriesID; summ.BeginYear = anidb_anime.BeginYear; summ.EndYear = anidb_anime.EndYear; @@ -375,7 +380,7 @@ public List GetAnimeContinueWatching_old(int maxRec else summ.UnwatchedEpisodeCount = 0; - ImageDetails imgDet = anidb_anime.GetDefaultPosterDetailsNoBlanks(session); + ImageDetails imgDet = anidb_anime.GetDefaultPosterDetailsNoBlanks(sessionWrapper); summ.ImageType = (int) imgDet.ImageType; summ.ImageID = imgDet.ImageID; @@ -409,10 +414,11 @@ public List GetAnimeContinueWatching(int maxRecords { using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); GroupFilterRepository repGF = new GroupFilterRepository(); AnimeGroup_UserRepository repGU = new AnimeGroup_UserRepository(); JMMUserRepository repUsers = new JMMUserRepository(); - JMMUser user = repUsers.GetByID(session, jmmuserID); + JMMUser user = repUsers.GetByID(sessionWrapper, jmmuserID); if (user == null) return retAnime; // find the locked Continue Watching Filter @@ -451,14 +457,14 @@ public List GetAnimeContinueWatching(int maxRecords AnimeSeries_User serUser = ser.GetUserRecord(session, jmmuserID); - Contract_AnimeEpisode ep = imp.GetNextUnwatchedEpisode(session, ser.AnimeSeriesID, jmmuserID); + Contract_AnimeEpisode ep = imp.GetNextUnwatchedEpisode(sessionWrapper, ser.AnimeSeriesID, jmmuserID); if (ep != null) { - AniDB_Anime anidb_anime = ser.GetAnime(session); + AniDB_Anime anidb_anime = ser.GetAnime(sessionWrapper); MetroContract_Anime_Summary summ = new MetroContract_Anime_Summary(); summ.AnimeID = ser.AniDB_ID; - summ.AnimeName = ser.GetSeriesName(session); + summ.AnimeName = ser.GetSeriesName(sessionWrapper); summ.AnimeSeriesID = ser.AnimeSeriesID; summ.BeginYear = anidb_anime.BeginYear; summ.EndYear = anidb_anime.EndYear; @@ -469,7 +475,7 @@ public List GetAnimeContinueWatching(int maxRecords else summ.UnwatchedEpisodeCount = 0; - ImageDetails imgDet = anidb_anime.GetDefaultPosterDetailsNoBlanks(session); + ImageDetails imgDet = anidb_anime.GetDefaultPosterDetailsNoBlanks(sessionWrapper); summ.ImageType = (int) imgDet.ImageType; summ.ImageID = imgDet.ImageID; @@ -502,12 +508,12 @@ public List GetAnimeCalendar(int jmmuserID, int sta { using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); JMMUserRepository repUsers = new JMMUserRepository(); AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); - - JMMUser user = repUsers.GetByID(session, jmmuserID); + JMMUser user = repUsers.GetByID(sessionWrapper, jmmuserID); if (user == null) return retAnime; DateTime? startDate = Utils.GetAniDBDateAsDate(startDateSecs); @@ -526,7 +532,7 @@ public List GetAnimeCalendar(int jmmuserID, int sta summ.AnimeID = anidb_anime.AnimeID; if (ser != null) { - summ.AnimeName = ser.GetSeriesName(session); + summ.AnimeName = ser.GetSeriesName(sessionWrapper); summ.AnimeSeriesID = ser.AnimeSeriesID; } else @@ -536,9 +542,9 @@ public List GetAnimeCalendar(int jmmuserID, int sta } summ.BeginYear = anidb_anime.BeginYear; summ.EndYear = anidb_anime.EndYear; - summ.PosterName = anidb_anime.GetDefaultPosterPathNoBlanks(session); + summ.PosterName = anidb_anime.GetDefaultPosterPathNoBlanks(sessionWrapper); - ImageDetails imgDet = anidb_anime.GetDefaultPosterDetailsNoBlanks(session); + ImageDetails imgDet = anidb_anime.GetDefaultPosterDetailsNoBlanks(sessionWrapper); summ.ImageType = (int) imgDet.ImageType; summ.ImageID = imgDet.ImageID; @@ -562,12 +568,12 @@ public List SearchAnime(int jmmuserID, string query { using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); JMMUserRepository repUsers = new JMMUserRepository(); AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); - - JMMUser user = repUsers.GetByID(session, jmmuserID); + JMMUser user = repUsers.GetByID(sessionWrapper, jmmuserID); if (user == null) return retAnime; @@ -584,7 +590,7 @@ public List SearchAnime(int jmmuserID, string query summ.AnimeID = anidb_anime.AnimeID; if (ser != null) { - summ.AnimeName = ser.GetSeriesName(session); + summ.AnimeName = ser.GetSeriesName(sessionWrapper); summ.AnimeSeriesID = ser.AnimeSeriesID; } else @@ -594,9 +600,9 @@ public List SearchAnime(int jmmuserID, string query } summ.BeginYear = anidb_anime.BeginYear; summ.EndYear = anidb_anime.EndYear; - summ.PosterName = anidb_anime.GetDefaultPosterPathNoBlanks(session); + summ.PosterName = anidb_anime.GetDefaultPosterPathNoBlanks(sessionWrapper); - ImageDetails imgDet = anidb_anime.GetDefaultPosterDetailsNoBlanks(session); + ImageDetails imgDet = anidb_anime.GetDefaultPosterDetailsNoBlanks(sessionWrapper); summ.ImageType = (int) imgDet.ImageType; summ.ImageID = imgDet.ImageID; @@ -619,19 +625,20 @@ public MetroContract_Anime_Detail GetAnimeDetail(int animeID, int jmmuserID, int { using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); - AniDB_Anime anime = repAnime.GetByAnimeID(session, animeID); + AniDB_Anime anime = repAnime.GetByAnimeID(sessionWrapper, animeID); if (anime == null) return null; - AnimeSeries ser = repSeries.GetByAnimeID(session, animeID); + AnimeSeries ser = repSeries.GetByAnimeID(sessionWrapper, animeID); MetroContract_Anime_Detail ret = new MetroContract_Anime_Detail(); ret.AnimeID = anime.AnimeID; if (ser != null) - ret.AnimeName = ser.GetSeriesName(session); + ret.AnimeName = ser.GetSeriesName(sessionWrapper); else ret.AnimeName = anime.MainTitle; @@ -643,11 +650,11 @@ public MetroContract_Anime_Detail GetAnimeDetail(int animeID, int jmmuserID, int ret.BeginYear = anime.BeginYear; ret.EndYear = anime.EndYear; - ImageDetails imgDet = anime.GetDefaultPosterDetailsNoBlanks(session); + ImageDetails imgDet = anime.GetDefaultPosterDetailsNoBlanks(sessionWrapper); ret.PosterImageType = (int) imgDet.ImageType; ret.PosterImageID = imgDet.ImageID; - ImageDetails imgDetFan = anime.GetDefaultFanartDetailsNoBlanks(session); + ImageDetails imgDetFan = anime.GetDefaultFanartDetailsNoBlanks(sessionWrapper); if (imgDetFan != null) { ret.FanartImageType = (int) imgDetFan.ImageType; @@ -688,10 +695,10 @@ public MetroContract_Anime_Detail GetAnimeDetail(int animeID, int jmmuserID, int Dictionary dictEpUsers = new Dictionary(); foreach ( AnimeEpisode_User userRecord in - repEpUser.GetByUserIDAndSeriesID(session, jmmuserID, ser.AnimeSeriesID)) + repEpUser.GetByUserIDAndSeriesID(sessionWrapper, jmmuserID, ser.AnimeSeriesID)) dictEpUsers[userRecord.AnimeEpisodeID] = userRecord; - foreach (AnimeEpisode animeep in repEps.GetBySeriesID(session, ser.AnimeSeriesID)) + foreach (AnimeEpisode animeep in repEps.GetBySeriesID(sessionWrapper, ser.AnimeSeriesID)) { if (!dictEpUsers.ContainsKey(animeep.AnimeEpisodeID)) { @@ -705,7 +712,7 @@ AnimeEpisode_User userRecord in } AniDB_EpisodeRepository repAniEps = new AniDB_EpisodeRepository(); - List aniEpList = repAniEps.GetByAnimeID(session, ser.AniDB_ID); + List aniEpList = repAniEps.GetByAnimeID(sessionWrapper, ser.AniDB_ID); Dictionary dictAniEps = new Dictionary(); foreach (AniDB_Episode aniep in aniEpList) dictAniEps[aniep.EpisodeID] = aniep; @@ -806,14 +813,15 @@ public MetroContract_Anime_Summary GetAnimeSummary(int animeID) { using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); AnimeEpisodeRepository repEps = new AnimeEpisodeRepository(); AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); - AniDB_Anime anime = repAnime.GetByAnimeID(session, animeID); + AniDB_Anime anime = repAnime.GetByAnimeID(sessionWrapper, animeID); if (anime == null) return null; - AnimeSeries ser = repSeries.GetByAnimeID(session, animeID); + AnimeSeries ser = repSeries.GetByAnimeID(sessionWrapper, animeID); MetroContract_Anime_Summary summ = new MetroContract_Anime_Summary(); summ.AnimeID = anime.AnimeID; @@ -822,15 +830,15 @@ public MetroContract_Anime_Summary GetAnimeSummary(int animeID) summ.BeginYear = anime.BeginYear; summ.EndYear = anime.EndYear; - summ.PosterName = anime.GetDefaultPosterPathNoBlanks(session); + summ.PosterName = anime.GetDefaultPosterPathNoBlanks(sessionWrapper); - ImageDetails imgDet = anime.GetDefaultPosterDetailsNoBlanks(session); + ImageDetails imgDet = anime.GetDefaultPosterDetailsNoBlanks(sessionWrapper); summ.ImageType = (int) imgDet.ImageType; summ.ImageID = imgDet.ImageID; if (ser != null) { - summ.AnimeName = ser.GetSeriesName(session); + summ.AnimeName = ser.GetSeriesName(sessionWrapper); summ.AnimeSeriesID = ser.AnimeSeriesID; } @@ -1056,10 +1064,11 @@ public List GetCharactersForAnime(int animeID, in { using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); AniDB_Anime_CharacterRepository repAnimeChar = new AniDB_Anime_CharacterRepository(); AniDB_CharacterRepository repChar = new AniDB_CharacterRepository(); - List animeChars = repAnimeChar.GetByAnimeID(session, animeID); + List animeChars = repAnimeChar.GetByAnimeID(sessionWrapper, animeID); if (animeChars == null || animeChars.Count == 0) return chars; int cnt = 0; @@ -1172,10 +1181,11 @@ public List GetAniDBRecommendationsForAnime(int animeID, { using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); AniDB_RecommendationRepository repBA = new AniDB_RecommendationRepository(); int cnt = 0; - foreach (AniDB_Recommendation rec in repBA.GetByAnimeID(session, animeID)) + foreach (AniDB_Recommendation rec in repBA.GetByAnimeID(sessionWrapper, animeID)) { MetroContract_Comment shout = new MetroContract_Comment(); @@ -1229,12 +1239,13 @@ public List GetSimilarAnimeForAnime(int animeID, in { using (var session = JMMService.SessionFactory.OpenSession()) { + ISessionWrapper sessionWrapper = session.Wrap(); AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); - AniDB_Anime anime = repAnime.GetByAnimeID(session, animeID); + AniDB_Anime anime = repAnime.GetByAnimeID(sessionWrapper, animeID); if (anime == null) return retAnime; JMMUserRepository repUsers = new JMMUserRepository(); - JMMUser juser = repUsers.GetByID(session, jmmuserID); + JMMUser juser = repUsers.GetByID(sessionWrapper, jmmuserID); if (juser == null) return retAnime; AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); @@ -1268,13 +1279,13 @@ public List GetSimilarAnimeForAnime(int animeID, in summ.RelationshipType = link.RelationType; - ImageDetails imgDet = animeLink.GetDefaultPosterDetailsNoBlanks(session); + ImageDetails imgDet = animeLink.GetDefaultPosterDetailsNoBlanks(sessionWrapper); summ.ImageType = (int) imgDet.ImageType; summ.ImageID = imgDet.ImageID; if (ser != null) { - summ.AnimeName = ser.GetSeriesName(session); + summ.AnimeName = ser.GetSeriesName(sessionWrapper); summ.AnimeSeriesID = ser.AnimeSeriesID; } @@ -1284,7 +1295,7 @@ public List GetSimilarAnimeForAnime(int animeID, in // now get similar anime foreach (AniDB_Anime_Similar link in anime.GetSimilarAnime(session)) { - AniDB_Anime animeLink = repAnime.GetByAnimeID(session, link.SimilarAnimeID); + AniDB_Anime animeLink = repAnime.GetByAnimeID(sessionWrapper, link.SimilarAnimeID); if (animeLink == null) { @@ -1297,7 +1308,7 @@ public List GetSimilarAnimeForAnime(int animeID, in if (!juser.AllowedAnime(animeLink)) continue; // check if this anime has a series - AnimeSeries ser = repSeries.GetByAnimeID(session, link.SimilarAnimeID); + AnimeSeries ser = repSeries.GetByAnimeID(sessionWrapper, link.SimilarAnimeID); MetroContract_Anime_Summary summ = new MetroContract_Anime_Summary(); summ.AnimeID = animeLink.AnimeID; @@ -1310,13 +1321,13 @@ public List GetSimilarAnimeForAnime(int animeID, in summ.RelationshipType = "Recommendation"; - ImageDetails imgDet = animeLink.GetDefaultPosterDetailsNoBlanks(session); + ImageDetails imgDet = animeLink.GetDefaultPosterDetailsNoBlanks(sessionWrapper); summ.ImageType = (int) imgDet.ImageType; summ.ImageID = imgDet.ImageID; if (ser != null) { - summ.AnimeName = ser.GetSeriesName(session); + summ.AnimeName = ser.GetSeriesName(sessionWrapper); summ.AnimeSeriesID = ser.AnimeSeriesID; } diff --git a/JMMServer/PlexAndKodi/CommonImplementation.cs b/JMMServer/PlexAndKodi/CommonImplementation.cs index 9adbf4532..8040aa6de 100644 --- a/JMMServer/PlexAndKodi/CommonImplementation.cs +++ b/JMMServer/PlexAndKodi/CommonImplementation.cs @@ -1,1210 +1,1218 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.IO; -using System.Linq; -using System.ServiceModel.Web; -using System.Text; -using AniDBAPI; -using FluentNHibernate.Conventions; -using JMMContracts; -using JMMContracts.PlexAndKodi; -using JMMServer.Commands; -using JMMServer.Entities; -using JMMServer.PlexAndKodi.Kodi; -using JMMServer.Properties; -using JMMServer.Repositories; -using NLog; -using Directory = JMMContracts.PlexAndKodi.Directory; - -// ReSharper disable FunctionComplexityOverflow - -namespace JMMServer.PlexAndKodi -{ - public class CommonImplementation - { - public static Logger logger = LogManager.GetCurrentClassLogger(); - - - public System.IO.Stream GetSupportImage(string name) - { - if (string.IsNullOrEmpty(name)) - return new MemoryStream(); - name = Path.GetFileNameWithoutExtension(name); - System.Resources.ResourceManager man = Resources.ResourceManager; - byte[] dta = (byte[]) man.GetObject(name); - if ((dta == null) || (dta.Length == 0)) - return new MemoryStream(); - if (WebOperationContext.Current != null) - WebOperationContext.Current.OutgoingResponse.ContentType = "image/png"; - MemoryStream ms = new MemoryStream(dta); - ms.Seek(0, SeekOrigin.Begin); - return ms; - } - - public MediaContainer GetFilters(IProvider prov, string uid) - { - prov.AddResponseHeaders(); - int t = 0; - int.TryParse(uid, out t); - JMMUser user = t > 0 ? Helper.GetJMMUser(uid) : Helper.GetUser(uid); - if (user == null) - return new MediaContainer() {ErrorString = "User not found"}; - int userid = user.JMMUserID; - - BreadCrumbs info = prov.UseBreadCrumbs - ? new BreadCrumbs {Key = prov.ConstructFiltersUrl(userid), Title = "Anime"} - : null; - BaseObject ret = - new BaseObject(prov.NewMediaContainer(MediaContainerTypes.Show, "Anime", false, false, info)); - if (!ret.Init()) - return new MediaContainer(); //Normal OPTION VERB - List