Example #1
0
        /// <summary>
        /// Gets a list of episodes watched based on the most recently watched series
        /// It will return the next episode to watch in the most recent 10 series
        /// </summary>
        /// <returns></returns>
        public List<Contract_AnimeEpisode> GetEpisodesToWatch_RecentlyWatched(int maxRecords, int jmmuserID)
        {
            List<Contract_AnimeEpisode> retEps = new List<Contract_AnimeEpisode>();
            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 retEps;

                    // 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("GetEpisodesToWatch_RecentlyWatched:Series: {0}", ts.TotalMilliseconds));
                    start = DateTime.Now;

                    foreach (AnimeSeries_User userRecord in allSeriesUser)
                    {
                        AnimeSeries series = repAnimeSer.GetByID(session, userRecord.AnimeSeriesID);
                        if (series == null) continue;

                        if (!user.AllowedSeries(series)) continue;

                        Contract_AnimeEpisode ep = GetNextUnwatchedEpisode(session, userRecord.AnimeSeriesID, jmmuserID);
                        if (ep != null)
                        {
                            retEps.Add(ep);

                            // Lets only return the specified amount
                            if (retEps.Count == maxRecords)
                            {
                                ts = DateTime.Now - start;
                                logger.Info(string.Format("GetEpisodesToWatch_RecentlyWatched:Episodes: {0}", ts.TotalMilliseconds));
                                return retEps;
                            }
                        }
                    }
                    ts = DateTime.Now - start;
                    logger.Info(string.Format("GetEpisodesToWatch_RecentlyWatched:Episodes: {0}", ts.TotalMilliseconds));
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }

            return retEps;
        }
		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;
		}