public List<Contract_AnimeEpisode> GetEpisodesRecentlyAddedSummary(int maxRecords, int jmmuserID) { List<Contract_AnimeEpisode> retEps = new List<Contract_AnimeEpisode>(); try { AnimeEpisodeRepository repEps = new AnimeEpisodeRepository(); AnimeEpisode_UserRepository repEpUser = new AnimeEpisode_UserRepository(); AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); JMMUserRepository repUsers = new JMMUserRepository(); VideoLocalRepository repVids = new VideoLocalRepository(); using (var session = JMMService.SessionFactory.OpenSession()) { JMMUser user = repUsers.GetByID(session, jmmuserID); if (user == null) return retEps; DateTime start = DateTime.Now; string sql = "Select ae.AnimeSeriesID, max(vl.DateTimeCreated) as MaxDate " + "From VideoLocal vl " + "INNER JOIN CrossRef_File_Episode xref ON vl.Hash = xref.Hash " + "INNER JOIN AnimeEpisode ae ON ae.AniDB_EpisodeID = xref.EpisodeID " + "GROUP BY ae.AnimeSeriesID " + "ORDER BY MaxDate desc "; ArrayList results = DatabaseHelper.GetData(sql); TimeSpan ts2 = DateTime.Now - start; logger.Info("GetEpisodesRecentlyAddedSummary:RawData in {0} ms", ts2.TotalMilliseconds); start = DateTime.Now; int numEps = 0; foreach (object[] res in results) { int animeSeriesID = int.Parse(res[0].ToString()); AnimeSeries ser = repSeries.GetByID(session, animeSeriesID); if (ser == null) continue; if (!user.AllowedSeries(ser)) continue; List<VideoLocal> vids = repVids.GetMostRecentlyAddedForAnime(session, 1, ser.AniDB_ID); if (vids.Count == 0) continue; List<AnimeEpisode> eps = vids[0].GetAnimeEpisodes(session); if (eps.Count == 0) continue; Contract_AnimeEpisode epContract = eps[0].ToContract(session, jmmuserID); if (epContract != null) { retEps.Add(epContract); numEps++; // Lets only return the specified amount if (retEps.Count == maxRecords) { ts2 = DateTime.Now - start; logger.Info("GetEpisodesRecentlyAddedSummary:Episodes in {0} ms", ts2.TotalMilliseconds); start = DateTime.Now; return retEps; } } } ts2 = DateTime.Now - start; logger.Info("GetEpisodesRecentlyAddedSummary:Episodes in {0} ms", ts2.TotalMilliseconds); start = DateTime.Now; } } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } return retEps; }
public List<MetroContract_Anime_Summary> GetAnimeWithNewEpisodes(int maxRecords, int jmmuserID) { List<MetroContract_Anime_Summary> retAnime = new List<MetroContract_Anime_Summary>(); try { using (var session = JMMService.SessionFactory.OpenSession()) { 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); if (user == null) return retAnime; string sql = "Select ae.AnimeSeriesID, max(vl.DateTimeCreated) as MaxDate " + "From VideoLocal vl " + "INNER JOIN CrossRef_File_Episode xref ON vl.Hash = xref.Hash " + "INNER JOIN AnimeEpisode ae ON ae.AniDB_EpisodeID = xref.EpisodeID " + "GROUP BY ae.AnimeSeriesID " + "ORDER BY MaxDate desc "; ArrayList results = DatabaseHelper.GetData(sql); int numEps = 0; foreach (object[] res in results) { int animeSeriesID = int.Parse(res[0].ToString()); AnimeSeries ser = repSeries.GetByID(session, animeSeriesID); if (ser == null) continue; if (!user.AllowedSeries(session, ser)) continue; AnimeSeries_User serUser = ser.GetUserRecord(session, jmmuserID); List<VideoLocal> vids = repVids.GetMostRecentlyAddedForAnime(session, 1, ser.AniDB_ID); if (vids.Count == 0) continue; List<AnimeEpisode> eps = vids[0].GetAnimeEpisodes(session); if (eps.Count == 0) continue; Contract_AnimeEpisode epContract = eps[0].ToContract(session, jmmuserID); if (epContract != null) { AniDB_Anime anidb_anime = ser.GetAnime(session); MetroContract_Anime_Summary summ = new MetroContract_Anime_Summary(); summ.AnimeID = ser.AniDB_ID; summ.AnimeName = ser.GetSeriesName(session); summ.AnimeSeriesID = ser.AnimeSeriesID; summ.BeginYear = anidb_anime.BeginYear; summ.EndYear = anidb_anime.EndYear; //summ.PosterName = anidb_anime.GetDefaultPosterPathNoBlanks(session); if (serUser != null) summ.UnwatchedEpisodeCount = serUser.UnwatchedEpisodeCount; else summ.UnwatchedEpisodeCount = 0; ImageDetails imgDet = anidb_anime.GetDefaultPosterDetailsNoBlanks(session); summ.ImageType = (int)imgDet.ImageType; summ.ImageID = imgDet.ImageID; retAnime.Add(summ); numEps++; // Lets only return the specified amount if (retAnime.Count == maxRecords) return retAnime; } } } } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } return retAnime; }