public List<MetroContract_Anime_Summary> SearchAnime(int jmmuserID, string queryText, int maxRecords) { List<MetroContract_Anime_Summary> retAnime = new List<MetroContract_Anime_Summary>(); try { using (var session = JMMService.SessionFactory.OpenSession()) { AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); JMMUserRepository repUsers = new JMMUserRepository(); AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); JMMUser user = repUsers.GetByID(session, jmmuserID); if (user == null) return retAnime; List<AniDB_Anime> animes = repAnime.SearchByName(session, queryText); foreach (AniDB_Anime anidb_anime in animes) { if (!user.AllowedAnime(anidb_anime)) continue; AnimeSeries ser = repSeries.GetByAnimeID(anidb_anime.AnimeID); MetroContract_Anime_Summary summ = new MetroContract_Anime_Summary(); summ.AirDateAsSeconds = anidb_anime.AirDateAsSeconds; summ.AnimeID = anidb_anime.AnimeID; if (ser != null) { summ.AnimeName = ser.GetSeriesName(session); summ.AnimeSeriesID = ser.AnimeSeriesID; } else { summ.AnimeName = anidb_anime.MainTitle; summ.AnimeSeriesID = 0; } summ.BeginYear = anidb_anime.BeginYear; summ.EndYear = anidb_anime.EndYear; summ.PosterName = anidb_anime.GetDefaultPosterPathNoBlanks(session); ImageDetails imgDet = anidb_anime.GetDefaultPosterDetailsNoBlanks(session); summ.ImageType = (int)imgDet.ImageType; summ.ImageID = imgDet.ImageID; retAnime.Add(summ); if (retAnime.Count == maxRecords) break; } } } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } return retAnime; }
public MetroContract_Anime_Summary GetAnimeSummary(int animeID) { try { using (var session = JMMService.SessionFactory.OpenSession()) { AnimeEpisodeRepository repEps = new AnimeEpisodeRepository(); AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anime = repAnime.GetByAnimeID(session, animeID); if (anime == null) return null; AnimeSeries ser = repSeries.GetByAnimeID(session, animeID); MetroContract_Anime_Summary summ = new MetroContract_Anime_Summary(); summ.AnimeID = anime.AnimeID; summ.AnimeName = anime.MainTitle; summ.AnimeSeriesID = 0; summ.BeginYear = anime.BeginYear; summ.EndYear = anime.EndYear; summ.PosterName = anime.GetDefaultPosterPathNoBlanks(session); ImageDetails imgDet = anime.GetDefaultPosterDetailsNoBlanks(session); summ.ImageType = (int)imgDet.ImageType; summ.ImageID = imgDet.ImageID; if (ser != null) { summ.AnimeName = ser.GetSeriesName(session); summ.AnimeSeriesID = ser.AnimeSeriesID; } return summ; } } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } return null; }
public List<MetroContract_Anime_Summary> GetAnimeContinueWatching_old(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(); AnimeSeriesRepository repAnimeSer = new AnimeSeriesRepository(); AnimeSeries_UserRepository repSeriesUser = new AnimeSeries_UserRepository(); JMMUserRepository repUsers = new JMMUserRepository(); DateTime start = DateTime.Now; JMMUser user = repUsers.GetByID(session, jmmuserID); if (user == null) return retAnime; // get a list of series that is applicable List<AnimeSeries_User> allSeriesUser = repSeriesUser.GetMostRecentlyWatched(session, jmmuserID); TimeSpan ts = DateTime.Now - start; logger.Info(string.Format("GetAnimeContinueWatching:Series: {0}", ts.TotalMilliseconds)); JMMServiceImplementation imp = new JMMServiceImplementation(); foreach (AnimeSeries_User userRecord in allSeriesUser) { start = DateTime.Now; AnimeSeries series = repAnimeSer.GetByID(session, userRecord.AnimeSeriesID); if (series == null) continue; if (!user.AllowedSeries(session, series)) { logger.Info(string.Format("GetAnimeContinueWatching:Skipping Anime - not allowed: {0}", series.AniDB_ID)); continue; } AnimeSeries_User serUser = series.GetUserRecord(session, jmmuserID); Contract_AnimeEpisode ep = imp.GetNextUnwatchedEpisode(session, userRecord.AnimeSeriesID, jmmuserID); if (ep != null) { AniDB_Anime anidb_anime = series.GetAnime(session); MetroContract_Anime_Summary summ = new MetroContract_Anime_Summary(); summ.AnimeID = series.AniDB_ID; summ.AnimeName = series.GetSeriesName(session); summ.AnimeSeriesID = series.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); ts = DateTime.Now - start; logger.Info(string.Format("GetAnimeContinueWatching:Anime: {0} - {1}", summ.AnimeName, ts.TotalMilliseconds)); // Lets only return the specified amount if (retAnime.Count == maxRecords) return retAnime; } else logger.Info(string.Format("GetAnimeContinueWatching:Skipping Anime - no episodes: {0}", series.AniDB_ID)); } } } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } return retAnime; }
public List<MetroContract_Anime_Summary> GetAnimeContinueWatching(int maxRecords, int jmmuserID) { List<MetroContract_Anime_Summary> retAnime = new List<MetroContract_Anime_Summary>(); try { using (var session = JMMService.SessionFactory.OpenSession()) { GroupFilterRepository repGF = new GroupFilterRepository(); JMMUserRepository repUsers = new JMMUserRepository(); JMMUser user = repUsers.GetByID(session, jmmuserID); if (user == null) return retAnime; // find the locked Continue Watching Filter GroupFilter gf = null; List<GroupFilter> lockedGFs = repGF.GetLockedGroupFilters(session); if (lockedGFs != null) { // if it already exists we can leave foreach (GroupFilter gfTemp in lockedGFs) { if (gfTemp.GroupFilterName.Equals(Constants.GroupFilterName.ContinueWatching, StringComparison.InvariantCultureIgnoreCase)) { gf = gfTemp; break; } } } if (gf == null) return retAnime; // Get all the groups // it is more efficient to just get the full list of groups and then filter them later AnimeGroupRepository repGroups = new AnimeGroupRepository(); List<AnimeGroup> allGrps = repGroups.GetAll(session); // get all the user records AnimeGroup_UserRepository repUserRecords = new AnimeGroup_UserRepository(); List<AnimeGroup_User> userRecords = repUserRecords.GetByUserID(session, jmmuserID); Dictionary<int, AnimeGroup_User> dictUserRecords = new Dictionary<int, AnimeGroup_User>(); foreach (AnimeGroup_User userRec in userRecords) dictUserRecords[userRec.AnimeGroupID] = userRec; // get all the groups in this filter for this user HashSet<int> groups = StatsCache.Instance.StatUserGroupFilter[user.JMMUserID][gf.GroupFilterID]; List<Contract_AnimeGroup> comboGroups = new List<Contract_AnimeGroup>(); foreach (AnimeGroup grp in allGrps) { if (groups.Contains(grp.AnimeGroupID)) { AnimeGroup_User userRec = null; if (dictUserRecords.ContainsKey(grp.AnimeGroupID)) userRec = dictUserRecords[grp.AnimeGroupID]; Contract_AnimeGroup rec = grp.ToContract(userRec); comboGroups.Add(rec); } } // apply sorting List<SortPropOrFieldAndDirection> sortCriteria = GroupFilterHelper.GetSortDescriptions(gf); comboGroups = Sorting.MultiSort<Contract_AnimeGroup>(comboGroups, sortCriteria); if ((StatsCache.Instance.StatUserGroupFilter.ContainsKey(user.JMMUserID)) && (StatsCache.Instance.StatUserGroupFilter[user.JMMUserID].ContainsKey(gf.GroupFilterID))) { AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); foreach (Contract_AnimeGroup grp in comboGroups) { JMMServiceImplementation imp = new JMMServiceImplementation(); foreach (AnimeSeries ser in repSeries.GetByGroupID(session, grp.AnimeGroupID)) { if (!user.AllowedSeries(ser)) continue; AnimeSeries_User serUser = ser.GetUserRecord(session, jmmuserID); Contract_AnimeEpisode ep = imp.GetNextUnwatchedEpisode(session, ser.AnimeSeriesID, jmmuserID); if (ep != 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); // Lets only return the specified amount if (retAnime.Count == maxRecords) return retAnime; } else logger.Info(string.Format("GetAnimeContinueWatching:Skipping Anime - no episodes: {0}", ser.AniDB_ID)); } } } } } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } return retAnime; }
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; }
public List<MetroContract_Anime_Summary> GetSimilarAnimeForAnime(int animeID, int maxRecords, int jmmuserID) { List<Contract_AniDB_Anime_Similar> links = new List<Contract_AniDB_Anime_Similar>(); List<MetroContract_Anime_Summary> retAnime = new List<MetroContract_Anime_Summary>(); try { using (var session = JMMService.SessionFactory.OpenSession()) { AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anime = repAnime.GetByAnimeID(session, animeID); if (anime == null) return retAnime; JMMUserRepository repUsers = new JMMUserRepository(); JMMUser juser = repUsers.GetByID(session, jmmuserID); if (juser == null) return retAnime; AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); // first get the related anime foreach (AniDB_Anime_Relation link in anime.GetRelatedAnime()) { AniDB_Anime animeLink = repAnime.GetByAnimeID(link.RelatedAnimeID); if (animeLink == null) { // try getting it from anidb now animeLink = JMMService.AnidbProcessor.GetAnimeInfoHTTP(session, link.RelatedAnimeID, false, false); } if (animeLink == null) continue; if (!juser.AllowedAnime(animeLink)) continue; // check if this anime has a series AnimeSeries ser = repSeries.GetByAnimeID(link.RelatedAnimeID); MetroContract_Anime_Summary summ = new MetroContract_Anime_Summary(); summ.AnimeID = animeLink.AnimeID; summ.AnimeName = animeLink.MainTitle; summ.AnimeSeriesID = 0; summ.BeginYear = animeLink.BeginYear; summ.EndYear = animeLink.EndYear; //summ.PosterName = animeLink.GetDefaultPosterPathNoBlanks(session); summ.RelationshipType = link.RelationType; ImageDetails imgDet = animeLink.GetDefaultPosterDetailsNoBlanks(session); summ.ImageType = (int)imgDet.ImageType; summ.ImageID = imgDet.ImageID; if (ser != null) { summ.AnimeName = ser.GetSeriesName(session); summ.AnimeSeriesID = ser.AnimeSeriesID; } retAnime.Add(summ); } // now get similar anime foreach (AniDB_Anime_Similar link in anime.GetSimilarAnime(session)) { AniDB_Anime animeLink = repAnime.GetByAnimeID(session, link.SimilarAnimeID); if (animeLink == null) { // try getting it from anidb now animeLink = JMMService.AnidbProcessor.GetAnimeInfoHTTP(session, link.SimilarAnimeID, false, false); } if (animeLink == null) continue; if (!juser.AllowedAnime(animeLink)) continue; // check if this anime has a series AnimeSeries ser = repSeries.GetByAnimeID(session, link.SimilarAnimeID); MetroContract_Anime_Summary summ = new MetroContract_Anime_Summary(); summ.AnimeID = animeLink.AnimeID; summ.AnimeName = animeLink.MainTitle; summ.AnimeSeriesID = 0; summ.BeginYear = animeLink.BeginYear; summ.EndYear = animeLink.EndYear; //summ.PosterName = animeLink.GetDefaultPosterPathNoBlanks(session); summ.RelationshipType = "Recommendation"; ImageDetails imgDet = animeLink.GetDefaultPosterDetailsNoBlanks(session); summ.ImageType = (int)imgDet.ImageType; summ.ImageID = imgDet.ImageID; if (ser != null) { summ.AnimeName = ser.GetSeriesName(session); summ.AnimeSeriesID = ser.AnimeSeriesID; } retAnime.Add(summ); if (retAnime.Count == maxRecords) break; } return retAnime; } } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); return retAnime; } }
public MetroContract_Anime_Summary GetAnimeSummary(int animeID) { try { using (var session = DatabaseFactory.SessionFactory.OpenSession()) { ISessionWrapper sessionWrapper = session.Wrap(); AniDB_Anime anime = RepoFactory.AniDB_Anime.GetByAnimeID(sessionWrapper, animeID); if (anime == null) return null; AnimeSeries ser = RepoFactory.AnimeSeries.GetByAnimeID(animeID); MetroContract_Anime_Summary summ = new MetroContract_Anime_Summary(); summ.AnimeID = anime.AnimeID; summ.AnimeName = anime.MainTitle; summ.AnimeSeriesID = 0; summ.BeginYear = anime.BeginYear; summ.EndYear = anime.EndYear; summ.PosterName = anime.GetDefaultPosterPathNoBlanks(sessionWrapper); ImageDetails imgDet = anime.GetDefaultPosterDetailsNoBlanks(sessionWrapper); summ.ImageType = (int) imgDet.ImageType; summ.ImageID = imgDet.ImageID; if (ser != null) { summ.AnimeName = ser.GetSeriesName(sessionWrapper); summ.AnimeSeriesID = ser.AnimeSeriesID; } return summ; } } catch (Exception ex) { logger.Error( ex,ex.ToString()); } return null; }
public List<MetroContract_Anime_Summary> GetAnimeContinueWatching(int maxRecords, int jmmuserID) { List<MetroContract_Anime_Summary> retAnime = new List<MetroContract_Anime_Summary>(); try { using (var session = DatabaseFactory.SessionFactory.OpenSession()) { ISessionWrapper sessionWrapper = session.Wrap(); JMMUser user = RepoFactory.JMMUser.GetByID(jmmuserID); if (user == null) return retAnime; // find the locked Continue Watching Filter GroupFilter gf = null; List<GroupFilter> lockedGFs = RepoFactory.GroupFilter.GetLockedGroupFilters(); if (lockedGFs != null) { // if it already exists we can leave foreach (GroupFilter gfTemp in lockedGFs) { if (gfTemp.FilterType == (int) GroupFilterType.ContinueWatching) { gf = gfTemp; break; } } } if ((gf == null) || !gf.GroupsIds.ContainsKey(jmmuserID)) return retAnime; IEnumerable<Contract_AnimeGroup> comboGroups = gf.GroupsIds[jmmuserID].Select(a => RepoFactory.AnimeGroup.GetByID(a)) .Where(a => a != null) .Select(a => a.GetUserContract(jmmuserID)); // apply sorting comboGroups= GroupFilterHelper.Sort(comboGroups, gf); foreach (Contract_AnimeGroup grp in comboGroups) { JMMServiceImplementation imp = new JMMServiceImplementation(); foreach (AnimeSeries ser in RepoFactory.AnimeSeries.GetByGroupID(grp.AnimeGroupID)) { if (!user.AllowedSeries(ser)) continue; AnimeSeries_User serUser = ser.GetUserRecord(jmmuserID); Contract_AnimeEpisode ep = imp.GetNextUnwatchedEpisode(sessionWrapper, ser.AnimeSeriesID, jmmuserID); if (ep != null) { AniDB_Anime anidb_anime = ser.GetAnime(); MetroContract_Anime_Summary summ = new MetroContract_Anime_Summary(); summ.AnimeID = ser.AniDB_ID; summ.AnimeName = ser.GetSeriesName(sessionWrapper); 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(sessionWrapper); summ.ImageType = (int) imgDet.ImageType; summ.ImageID = imgDet.ImageID; retAnime.Add(summ); // Lets only return the specified amount if (retAnime.Count == maxRecords) return retAnime; } else logger.Info(string.Format("GetAnimeContinueWatching:Skipping Anime - no episodes: {0}", ser.AniDB_ID)); } } } } catch (Exception ex) { logger.Error( ex,ex.ToString()); } return retAnime; }
public List<MetroContract_Anime_Summary> GetAnimeCalendar(int jmmuserID, int startDateSecs, int endDateSecs, int maxRecords) { List<MetroContract_Anime_Summary> retAnime = new List<MetroContract_Anime_Summary>(); try { using (var session = DatabaseFactory.SessionFactory.OpenSession()) { ISessionWrapper sessionWrapper = session.Wrap(); JMMUser user = RepoFactory.JMMUser.GetByID(jmmuserID); if (user == null) return retAnime; DateTime? startDate = Utils.GetAniDBDateAsDate(startDateSecs); DateTime? endDate = Utils.GetAniDBDateAsDate(endDateSecs); List<AniDB_Anime> animes = RepoFactory.AniDB_Anime.GetForDate(session, startDate.Value, endDate.Value); foreach (AniDB_Anime anidb_anime in animes) { if (!user.AllowedAnime(anidb_anime)) continue; AnimeSeries ser = RepoFactory.AnimeSeries.GetByAnimeID(anidb_anime.AnimeID); MetroContract_Anime_Summary summ = new MetroContract_Anime_Summary(); summ.AirDateAsSeconds = anidb_anime.AirDateAsSeconds; summ.AnimeID = anidb_anime.AnimeID; if (ser != null) { summ.AnimeName = ser.GetSeriesName(sessionWrapper); summ.AnimeSeriesID = ser.AnimeSeriesID; } else { summ.AnimeName = anidb_anime.MainTitle; summ.AnimeSeriesID = 0; } summ.BeginYear = anidb_anime.BeginYear; summ.EndYear = anidb_anime.EndYear; summ.PosterName = anidb_anime.GetDefaultPosterPathNoBlanks(sessionWrapper); ImageDetails imgDet = anidb_anime.GetDefaultPosterDetailsNoBlanks(sessionWrapper); summ.ImageType = (int) imgDet.ImageType; summ.ImageID = imgDet.ImageID; retAnime.Add(summ); if (retAnime.Count == maxRecords) break; } } } catch (Exception ex) { logger.Error( ex,ex.ToString()); } return retAnime; }