public List<Contract_AnimeEpisode> GetContinueWatchingFilter(int userID, int maxRecords) { List<Contract_AnimeEpisode> retEps = new List<Contract_AnimeEpisode>(); try { using (var session = JMMService.SessionFactory.OpenSession()) { GroupFilterRepository repGF = new GroupFilterRepository(); JMMUserRepository repUsers = new JMMUserRepository(); JMMUser user = repUsers.GetByID(session, userID); if (user == null) return retEps; // 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.FilterType == (int)GroupFilterType.ContinueWatching) { gf = gfTemp; break; } } } if (gf == null) return retEps; // 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, userID); 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) { List<AnimeSeries> sers = repSeries.GetByGroupID(session, grp.AnimeGroupID); // sort the series by air date List<SortPropOrFieldAndDirection> sortCriteria2 = new List<SortPropOrFieldAndDirection>(); sortCriteria2.Add(new SortPropOrFieldAndDirection("AirDate", false, SortType.eDateTime)); sers = Sorting.MultiSort<AnimeSeries>(sers, sortCriteria2); List<int> seriesWatching = new List<int>(); foreach (AnimeSeries ser in sers) { if (!user.AllowedSeries(ser)) continue; bool useSeries = true; if (seriesWatching.Count > 0) { if (ser.GetAnime().AnimeType == (int)enAnimeType.TVSeries) { // make sure this series is not a sequel to an existing series we have already added foreach (AniDB_Anime_Relation rel in ser.GetAnime().GetRelatedAnime()) { if (rel.RelationType.ToLower().Trim().Equals("sequel") || rel.RelationType.ToLower().Trim().Equals("prequel")) useSeries = false; } } } if (!useSeries) continue; Contract_AnimeEpisode ep = GetNextUnwatchedEpisode(session, ser.AnimeSeriesID, userID); if (ep != null) { retEps.Add(ep); // Lets only return the specified amount if (retEps.Count == maxRecords) return retEps; if (ser.GetAnime().AnimeType == (int)enAnimeType.TVSeries) seriesWatching.Add(ser.AniDB_ID); } } } } } } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } return retEps; }
public List<AnimeSeries> GetSeries(ISession session) { AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); List<AnimeSeries> seriesList = repSeries.GetByGroupID(this.AnimeGroupID); return seriesList; }
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<Contract_AnimeEpisode> GetContinueWatchingFilter(int userID, int maxRecords) { List<Contract_AnimeEpisode> retEps = new List<Contract_AnimeEpisode>(); try { using (var session = JMMService.SessionFactory.OpenSession()) { GroupFilterRepository repGF = new GroupFilterRepository(); JMMUserRepository repUsers = new JMMUserRepository(); JMMUser user = repUsers.GetByID(session, userID); if (user == null) return retEps; // 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 retEps; // 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, userID); 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) { foreach (AnimeSeries ser in repSeries.GetByGroupID(session, grp.AnimeGroupID)) { if (!user.AllowedSeries(ser)) continue; Contract_AnimeEpisode ep = GetNextUnwatchedEpisode(session, ser.AnimeSeriesID, userID); if (ep != null) { retEps.Add(ep); // Lets only return the specified amount if (retEps.Count == maxRecords) return retEps; } } } } } } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } return retEps; }