Example #1
0
        public Contract_AnimeEpisode GetUserContract(int userid, ISessionWrapper session = null)
        {
            lock (_lock) //Make it atomic on creation
            {
                AnimeEpisode_User rr = GetUserRecord(userid);
                if (rr != null)
                {
                    return(rr.Contract);
                }
                rr                = new AnimeEpisode_User();
                rr.PlayedCount    = 0;
                rr.StoppedCount   = 0;
                rr.WatchedCount   = 0;
                rr.AnimeEpisodeID = this.AnimeEpisodeID;
                rr.AnimeSeriesID  = this.AnimeSeriesID;
                rr.JMMUserID      = userid;
                rr.WatchedDate    = null;

                if (session != null)
                {
                    RepoFactory.AnimeEpisode_User.SaveWithOpenTransaction(session, rr);
                }
                else
                {
                    RepoFactory.AnimeEpisode_User.Save(rr);
                }

                return(rr.Contract);
            }
        }
Example #2
0
        public AnimeEpisode GetLastEpisodeWatched(int userID)
        {
            AnimeEpisode      watchedep         = null;
            AnimeEpisode_User userRecordWatched = null;

            foreach (AnimeEpisode ep in GetAnimeEpisodes())
            {
                AnimeEpisode_User userRecord = ep.GetUserRecord(userID);
                if (userRecord != null && ep.EpisodeTypeEnum == AniDBAPI.enEpisodeType.Episode)
                {
                    if (watchedep == null)
                    {
                        watchedep         = ep;
                        userRecordWatched = userRecord;
                    }

                    if (userRecord.WatchedDate > userRecordWatched.WatchedDate)
                    {
                        watchedep         = ep;
                        userRecordWatched = userRecord;
                    }
                }
            }
            return(watchedep);
        }
Example #3
0
		public Contract_AnimeEpisode ToContract(ISession session, bool getFileCount, int userID, AnimeSeries_User seruser)
		{
			Contract_AnimeEpisode contract = new Contract_AnimeEpisode();
			contract.AniDB_EpisodeID = this.AniDB_EpisodeID;
			contract.AnimeEpisodeID = this.AnimeEpisodeID;
			contract.AnimeSeriesID = this.AnimeSeriesID;
			contract.DateTimeUpdated = this.DateTimeUpdated;

			AnimeEpisode_User epuser = this.GetUserRecord(session, userID);

			if (epuser == null)
			{
				contract.IsWatched = 0;
				contract.PlayedCount = 0;
				contract.StoppedCount = 0;
				contract.WatchedCount = 0;
				contract.WatchedDate = null;
			}
			else
			{
				contract.IsWatched = epuser.WatchedCount > 0 ? 1 : 0;
				contract.PlayedCount = epuser.PlayedCount;
				contract.StoppedCount = epuser.StoppedCount;
				contract.WatchedCount = epuser.WatchedCount;
				contract.WatchedDate = epuser.WatchedDate;
			}

			if (seruser == null)
				contract.UnwatchedEpCountSeries = 0;
			else
				contract.UnwatchedEpCountSeries = seruser.UnwatchedEpisodeCount;

			AniDB_Episode aniEp = this.AniDB_Episode;
			contract.AniDB_AirDate = aniEp.AirDateAsDate;
			contract.AniDB_EnglishName = aniEp.EnglishName;
			contract.AniDB_LengthSeconds = aniEp.LengthSeconds;
			contract.AniDB_Rating = aniEp.Rating;
			contract.AniDB_RomajiName = aniEp.RomajiName;
			contract.AniDB_Votes = aniEp.Votes;

			contract.EpisodeNumber = aniEp.EpisodeNumber;
			contract.EpisodeNameRomaji = aniEp.RomajiName;
			contract.EpisodeNameEnglish = aniEp.EnglishName;
			contract.EpisodeType = aniEp.EpisodeType;


			// find the number of files we actually have for this episode
			if (getFileCount)
				contract.LocalFileCount = this.GetVideoLocals(session).Count;

			contract.ReleaseGroups = new List<Contract_AniDBReleaseGroup>();



			return contract;
		}
Example #4
0
        public void SaveWatchedStatus(bool watched, int userID, DateTime?watchedDate, bool updateWatchedDate)
        {
            AnimeEpisode_UserRepository repEpisodeUsers = new AnimeEpisode_UserRepository();
            AnimeEpisode_User           epUserRecord    = this.GetUserRecord(userID);

            if (watched)
            {
                // lets check if an update is actually required
                if (epUserRecord != null)
                {
                    if (epUserRecord.WatchedDate.HasValue && watchedDate.HasValue &&
                        epUserRecord.WatchedDate.Value.Equals(watchedDate.Value))
                    {
                        // this will happen when we are adding a new file for an episode where we already had another file
                        // and the file/episode was watched already
                        return;
                    }
                }

                if (epUserRecord == null)
                {
                    epUserRecord              = new AnimeEpisode_User();
                    epUserRecord.PlayedCount  = 0;
                    epUserRecord.StoppedCount = 0;
                    epUserRecord.WatchedCount = 0;
                }
                epUserRecord.AnimeEpisodeID = this.AnimeEpisodeID;
                epUserRecord.AnimeSeriesID  = this.AnimeSeriesID;
                epUserRecord.JMMUserID      = userID;
                epUserRecord.WatchedCount++;

                if (watchedDate.HasValue)
                {
                    if (updateWatchedDate)
                    {
                        epUserRecord.WatchedDate = watchedDate.Value;
                    }
                }

                if (!epUserRecord.WatchedDate.HasValue)
                {
                    epUserRecord.WatchedDate = DateTime.Now;
                }

                repEpisodeUsers.Save(epUserRecord);
            }
            else
            {
                if (epUserRecord != null)
                {
                    repEpisodeUsers.Delete(epUserRecord.AnimeEpisode_UserID);
                }
            }
        }
		public void Save(AnimeEpisode_User obj)
		{
			using (var session = JMMService.SessionFactory.OpenSession())
			{
				// populate the database
				using (var transaction = session.BeginTransaction())
				{
					session.SaveOrUpdate(obj);
					transaction.Commit();
				}
			}
		}
Example #6
0
 public Contract_AnimeEpisode GetUserContract(int userid)
 {
     lock (_lock) //Make it atomic on creation
     {
         AnimeEpisode_User rr = GetUserRecord(userid);
         if (rr != null)
         {
             return(rr.Contract);
         }
         rr                = new AnimeEpisode_User();
         rr.PlayedCount    = 0;
         rr.StoppedCount   = 0;
         rr.WatchedCount   = 0;
         rr.AnimeEpisodeID = this.AnimeEpisodeID;
         rr.AnimeSeriesID  = this.AnimeSeriesID;
         rr.JMMUserID      = userid;
         rr.WatchedDate    = null;
         RepoFactory.AnimeEpisode_User.Save(rr);
         return(rr.Contract);
     }
 }
Example #7
0
        public void IncrementEpisodeStats(int animeEpisodeID, int userID, int statCountType)
        {
            try
            {
                AnimeEpisodeRepository repEpisodes = new AnimeEpisodeRepository();
                AnimeEpisode ep = repEpisodes.GetByID(animeEpisodeID);
                if (ep == null) return;

                AnimeEpisode_UserRepository repEpisodeUsers = new AnimeEpisode_UserRepository();
                AnimeEpisode_User epUserRecord = ep.GetUserRecord(userID);

                if (epUserRecord == null)
                {
                    epUserRecord = new AnimeEpisode_User();
                    epUserRecord.PlayedCount = 0;
                    epUserRecord.StoppedCount = 0;
                    epUserRecord.WatchedCount = 0;
                }
                epUserRecord.AnimeEpisodeID = ep.AnimeEpisodeID;
                epUserRecord.AnimeSeriesID = ep.AnimeSeriesID;
                epUserRecord.JMMUserID = userID;
                //epUserRecord.WatchedDate = DateTime.Now;

                switch ((StatCountType)statCountType)
                {
                    case StatCountType.Played: epUserRecord.PlayedCount++; break;
                    case StatCountType.Stopped: epUserRecord.StoppedCount++; break;
                    case StatCountType.Watched: epUserRecord.WatchedCount++; break;
                }

                repEpisodeUsers.Save(epUserRecord);

                AnimeSeries ser = ep.GetAnimeSeries();
                if (ser == null) return;

                AnimeSeries_UserRepository repSeriesUser = new AnimeSeries_UserRepository();
                AnimeSeries_User userRecord = ser.GetUserRecord(userID);
                if (userRecord == null)
                    userRecord = new AnimeSeries_User(userID, ser.AnimeSeriesID);

                switch ((StatCountType)statCountType)
                {
                    case StatCountType.Played: userRecord.PlayedCount++; break;
                    case StatCountType.Stopped: userRecord.StoppedCount++; break;
                    case StatCountType.Watched: userRecord.WatchedCount++; break;
                }

                repSeriesUser.Save(userRecord);
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
        }
Example #8
0
        public void UpdateStats(bool watchedStats, bool missingEpsStats, bool updateAllGroupsAbove)
        {
            DateTime start        = DateTime.Now;
            DateTime startOverall = DateTime.Now;

            logger.Info("Starting Updating STATS for SERIES {0} ({1} - {2} - {3})", this.ToString(), watchedStats, missingEpsStats, updateAllGroupsAbove);

            AnimeSeries_UserRepository      repSeriesUser  = new AnimeSeries_UserRepository();
            AnimeEpisode_UserRepository     repEpisodeUser = new AnimeEpisode_UserRepository();
            VideoLocalRepository            repVids        = new VideoLocalRepository();
            CrossRef_File_EpisodeRepository repXrefs       = new CrossRef_File_EpisodeRepository();

            JMMUserRepository repUsers = new JMMUserRepository();
            List <JMMUser>    allUsers = repUsers.GetAll();

            DateTime            startEps = DateTime.Now;
            List <AnimeEpisode> eps      = GetAnimeEpisodes();
            TimeSpan            tsEps    = DateTime.Now - startEps;

            logger.Trace("Got episodes for SERIES {0} in {1}ms", this.ToString(), tsEps.TotalMilliseconds);

            DateTime                     startVids = DateTime.Now;
            List <VideoLocal>            vidsTemp  = repVids.GetByAniDBAnimeID(this.AniDB_ID);
            List <CrossRef_File_Episode> crossRefs = repXrefs.GetByAnimeID(this.AniDB_ID);

            Dictionary <int, List <CrossRef_File_Episode> > dictCrossRefs = new Dictionary <int, List <CrossRef_File_Episode> >();

            foreach (CrossRef_File_Episode xref in crossRefs)
            {
                if (!dictCrossRefs.ContainsKey(xref.EpisodeID))
                {
                    dictCrossRefs[xref.EpisodeID] = new List <CrossRef_File_Episode>();
                }
                dictCrossRefs[xref.EpisodeID].Add(xref);
            }

            Dictionary <string, VideoLocal> dictVids = new Dictionary <string, VideoLocal>();

            foreach (VideoLocal vid in vidsTemp)
            {
                dictVids[vid.Hash] = vid;
            }

            TimeSpan tsVids = DateTime.Now - startVids;

            logger.Trace("Got video locals for SERIES {0} in {1}ms", this.ToString(), tsVids.TotalMilliseconds);


            if (watchedStats)
            {
                foreach (JMMUser juser in allUsers)
                {
                    //this.WatchedCount = 0;
                    AnimeSeries_User userRecord = GetUserRecord(juser.JMMUserID);
                    if (userRecord == null)
                    {
                        userRecord = new AnimeSeries_User(juser.JMMUserID, this.AnimeSeriesID);
                    }

                    // reset stats
                    userRecord.UnwatchedEpisodeCount = 0;
                    userRecord.WatchedEpisodeCount   = 0;
                    userRecord.WatchedCount          = 0;
                    userRecord.WatchedDate           = null;

                    DateTime startUser = DateTime.Now;
                    List <AnimeEpisode_User>            epUserRecords   = repEpisodeUser.GetByUserID(juser.JMMUserID);
                    Dictionary <int, AnimeEpisode_User> dictUserRecords = new Dictionary <int, AnimeEpisode_User>();
                    foreach (AnimeEpisode_User usrec in epUserRecords)
                    {
                        dictUserRecords[usrec.AnimeEpisodeID] = usrec;
                    }
                    TimeSpan tsUser = DateTime.Now - startUser;
                    logger.Trace("Got user records for SERIES {0}/{1} in {2}ms", this.ToString(), juser.Username, tsUser.TotalMilliseconds);

                    foreach (AnimeEpisode ep in eps)
                    {
                        // if the episode doesn't have any files then it won't count towards watched/unwatched counts
                        List <VideoLocal> epVids = new List <VideoLocal>();

                        if (dictCrossRefs.ContainsKey(ep.AniDB_EpisodeID))
                        {
                            foreach (CrossRef_File_Episode xref in dictCrossRefs[ep.AniDB_EpisodeID])
                            {
                                if (xref.EpisodeID == ep.AniDB_EpisodeID)
                                {
                                    if (dictVids.ContainsKey(xref.Hash))
                                    {
                                        epVids.Add(dictVids[xref.Hash]);
                                    }
                                }
                            }
                        }
                        if (epVids.Count == 0)
                        {
                            continue;
                        }

                        if (ep.EpisodeTypeEnum == AniDBAPI.enEpisodeType.Episode || ep.EpisodeTypeEnum == AniDBAPI.enEpisodeType.Special)
                        {
                            AnimeEpisode_User epUserRecord = null;
                            if (dictUserRecords.ContainsKey(ep.AnimeEpisodeID))
                            {
                                epUserRecord = dictUserRecords[ep.AnimeEpisodeID];
                            }

                            if (epUserRecord != null && epUserRecord.WatchedDate.HasValue)
                            {
                                userRecord.WatchedEpisodeCount++;
                            }
                            else
                            {
                                userRecord.UnwatchedEpisodeCount++;
                            }

                            if (epUserRecord != null)
                            {
                                if (userRecord.WatchedDate.HasValue)
                                {
                                    if (epUserRecord.WatchedDate > userRecord.WatchedDate)
                                    {
                                        userRecord.WatchedDate = epUserRecord.WatchedDate;
                                    }
                                }
                                else
                                {
                                    userRecord.WatchedDate = epUserRecord.WatchedDate;
                                }

                                userRecord.WatchedCount += epUserRecord.WatchedCount;
                            }
                        }
                    }
                    repSeriesUser.Save(userRecord);
                }
            }

            TimeSpan ts = DateTime.Now - start;

            logger.Trace("Updated WATCHED stats for SERIES {0} in {1}ms", this.ToString(), ts.TotalMilliseconds);
            start = DateTime.Now;



            if (missingEpsStats)
            {
                enAnimeType animeType   = enAnimeType.TVSeries;
                AniDB_Anime aniDB_Anime = this.GetAnime();
                if (aniDB_Anime != null)
                {
                    animeType = aniDB_Anime.AnimeTypeEnum;
                }

                MissingEpisodeCount       = 0;
                MissingEpisodeCountGroups = 0;

                // get all the group status records
                AniDB_GroupStatusRepository repGrpStat  = new AniDB_GroupStatusRepository();
                List <AniDB_GroupStatus>    grpStatuses = repGrpStat.GetByAnimeID(this.AniDB_ID);

                // find all the episodes for which the user has a file
                // from this we can determine what their latest episode number is
                // find out which groups the user is collecting

                List <int> userReleaseGroups = new List <int>();
                foreach (AnimeEpisode ep in eps)
                {
                    List <VideoLocal> vids = new List <VideoLocal>();
                    if (dictCrossRefs.ContainsKey(ep.AniDB_EpisodeID))
                    {
                        foreach (CrossRef_File_Episode xref in dictCrossRefs[ep.AniDB_EpisodeID])
                        {
                            if (xref.EpisodeID == ep.AniDB_EpisodeID)
                            {
                                if (dictVids.ContainsKey(xref.Hash))
                                {
                                    vids.Add(dictVids[xref.Hash]);
                                }
                            }
                        }
                    }

                    //List<VideoLocal> vids = ep.VideoLocals;
                    foreach (VideoLocal vid in vids)
                    {
                        AniDB_File anifile = vid.GetAniDBFile();
                        if (anifile != null)
                        {
                            if (!userReleaseGroups.Contains(anifile.GroupID))
                            {
                                userReleaseGroups.Add(anifile.GroupID);
                            }
                        }
                    }
                }

                int         latestLocalEpNumber = 0;
                EpisodeList epReleasedList      = new EpisodeList(animeType);
                EpisodeList epGroupReleasedList = new EpisodeList(animeType);

                foreach (AnimeEpisode ep in eps)
                {
                    //List<VideoLocal> vids = ep.VideoLocals;
                    if (ep.EpisodeTypeEnum != AniDBAPI.enEpisodeType.Episode)
                    {
                        continue;
                    }

                    List <VideoLocal> vids = new List <VideoLocal>();
                    if (dictCrossRefs.ContainsKey(ep.AniDB_EpisodeID))
                    {
                        foreach (CrossRef_File_Episode xref in dictCrossRefs[ep.AniDB_EpisodeID])
                        {
                            if (xref.EpisodeID == ep.AniDB_EpisodeID)
                            {
                                if (dictVids.ContainsKey(xref.Hash))
                                {
                                    vids.Add(dictVids[xref.Hash]);
                                }
                            }
                        }
                    }



                    AniDB_Episode aniEp     = ep.AniDB_Episode;
                    int           thisEpNum = aniEp.EpisodeNumber;

                    if (thisEpNum > latestLocalEpNumber && vids.Count > 0)
                    {
                        latestLocalEpNumber = thisEpNum;
                    }

                    // does this episode have a file released
                    // does this episode have a file released by the group the user is collecting
                    bool epReleased      = false;
                    bool epReleasedGroup = false;
                    foreach (AniDB_GroupStatus gs in grpStatuses)
                    {
                        if (gs.LastEpisodeNumber >= thisEpNum)
                        {
                            epReleased = true;
                        }
                        if (userReleaseGroups.Contains(gs.GroupID) && gs.HasGroupReleasedEpisode(thisEpNum))
                        {
                            epReleasedGroup = true;
                        }
                    }


                    try
                    {
                        epReleasedList.Add(ep, (!epReleased || vids.Count != 0));
                        epGroupReleasedList.Add(ep, (!epReleasedGroup || vids.Count != 0));
                    }
                    catch (Exception e)
                    {
                        logger.Trace("Error {0}", e.ToString());
                        throw;
                    }
                }
                foreach (EpisodeList.StatEpisodes eplst in epReleasedList)
                {
                    if (!eplst.Available)
                    {
                        MissingEpisodeCount++;
                    }
                }
                foreach (EpisodeList.StatEpisodes eplst in epGroupReleasedList)
                {
                    if (!eplst.Available)
                    {
                        MissingEpisodeCountGroups++;
                    }
                }

                this.LatestLocalEpisodeNumber = latestLocalEpNumber;
            }

            ts = DateTime.Now - start;
            logger.Trace("Updated MISSING EPS stats for SERIES {0} in {1}ms", this.ToString(), ts.TotalMilliseconds);
            start = DateTime.Now;

            AnimeSeriesRepository rep = new AnimeSeriesRepository();

            rep.Save(this);

            if (updateAllGroupsAbove)
            {
                foreach (AnimeGroup grp in AllGroupsAbove)
                {
                    grp.UpdateStats(watchedStats, missingEpsStats);
                }
            }

            ts = DateTime.Now - start;
            logger.Trace("Updated GROUPS ABOVE stats for SERIES {0} in {1}ms", this.ToString(), ts.TotalMilliseconds);
            start = DateTime.Now;

            TimeSpan tsOverall = DateTime.Now - startOverall;

            logger.Info("Finished Updating STATS for SERIES {0} in {1}ms ({2} - {3} - {4})", this.ToString(), tsOverall.TotalMilliseconds,
                        watchedStats, missingEpsStats, updateAllGroupsAbove);
        }
Example #9
0
		public void SaveWatchedStatus(bool watched, int userID, DateTime? watchedDate, bool updateWatchedDate)
		{
			AnimeEpisode_UserRepository repEpisodeUsers = new AnimeEpisode_UserRepository();
			AnimeEpisode_User epUserRecord = this.GetUserRecord(userID);

			if (watched)
			{
				// lets check if an update is actually required
				if (epUserRecord != null)
				{
					if (epUserRecord.WatchedDate.HasValue && watchedDate.HasValue &&
						epUserRecord.WatchedDate.Value.Equals(watchedDate.Value))
					{
						// this will happen when we are adding a new file for an episode where we already had another file
						// and the file/episode was watched already
						return;
					}
				}

				if (epUserRecord == null)
				{
					epUserRecord = new AnimeEpisode_User();
					epUserRecord.PlayedCount = 0;
					epUserRecord.StoppedCount = 0;
					epUserRecord.WatchedCount = 0;
				}
				epUserRecord.AnimeEpisodeID = this.AnimeEpisodeID;
				epUserRecord.AnimeSeriesID = this.AnimeSeriesID;
				epUserRecord.JMMUserID = userID;
				epUserRecord.WatchedCount++;

				if (watchedDate.HasValue)
				{
					if (updateWatchedDate)
						epUserRecord.WatchedDate = watchedDate.Value;
				}

				if (!epUserRecord.WatchedDate.HasValue) epUserRecord.WatchedDate = DateTime.Now;

				repEpisodeUsers.Save(epUserRecord);
			}
			else
			{
				if (epUserRecord != null)
					repEpisodeUsers.Delete(epUserRecord.AnimeEpisode_UserID);
			}
		}
Example #10
0
		public Contract_AnimeEpisode ToContract(AniDB_Episode aniEp, List<VideoLocal> epVids, AnimeEpisode_User epuser, AnimeSeries_User seruser)
		{
			Contract_AnimeEpisode contract = new Contract_AnimeEpisode();
			contract.AniDB_EpisodeID = this.AniDB_EpisodeID;
			contract.AnimeEpisodeID = this.AnimeEpisodeID;
			contract.AnimeSeriesID = this.AnimeSeriesID;
			contract.DateTimeUpdated = this.DateTimeUpdated;

			if (epuser == null)
			{
				contract.IsWatched = 0;
				contract.PlayedCount = 0;
				contract.StoppedCount = 0;
				contract.WatchedCount = 0;
				contract.WatchedDate = null;
			}
			else
			{
				contract.IsWatched = epuser.WatchedCount > 0 ? 1 : 0;
				contract.PlayedCount = epuser.PlayedCount;
				contract.StoppedCount = epuser.StoppedCount;
				contract.WatchedCount = epuser.WatchedCount;
				contract.WatchedDate = epuser.WatchedDate;
			}

			if (seruser == null)
				contract.UnwatchedEpCountSeries = 0;
			else
				contract.UnwatchedEpCountSeries = seruser.UnwatchedEpisodeCount;
			
			contract.AniDB_AirDate = aniEp.AirDateAsDate;
			contract.AniDB_EnglishName = aniEp.EnglishName;
			contract.AniDB_LengthSeconds = aniEp.LengthSeconds;
			contract.AniDB_Rating = aniEp.Rating;
			contract.AniDB_RomajiName = aniEp.RomajiName;
			contract.AniDB_Votes = aniEp.Votes;

			contract.EpisodeNumber = aniEp.EpisodeNumber;
			contract.EpisodeNameRomaji = aniEp.RomajiName;
			contract.EpisodeNameEnglish = aniEp.EnglishName;
			contract.EpisodeType = aniEp.EpisodeType;


			// find the number of files we actually have for this episode
			//contract.LocalFileCount = VideoLocals.Count;
			contract.LocalFileCount = epVids.Count;

			contract.ReleaseGroups = new List<Contract_AniDBReleaseGroup>(); 



			return contract;
		}
Example #11
0
        public Contract_AnimeEpisode ToContract(AniDB_Episode aniEp, List <VideoLocal> epVids, AnimeEpisode_User epuser, AnimeSeries_User seruser)
        {
            Contract_AnimeEpisode contract = new Contract_AnimeEpisode();

            contract.AniDB_EpisodeID = this.AniDB_EpisodeID;
            contract.AnimeEpisodeID  = this.AnimeEpisodeID;
            contract.AnimeSeriesID   = this.AnimeSeriesID;
            contract.DateTimeUpdated = this.DateTimeUpdated;

            if (epuser == null)
            {
                contract.IsWatched    = 0;
                contract.PlayedCount  = 0;
                contract.StoppedCount = 0;
                contract.WatchedCount = 0;
                contract.WatchedDate  = null;
            }
            else
            {
                contract.IsWatched    = epuser.WatchedCount > 0 ? 1 : 0;
                contract.PlayedCount  = epuser.PlayedCount;
                contract.StoppedCount = epuser.StoppedCount;
                contract.WatchedCount = epuser.WatchedCount;
                contract.WatchedDate  = epuser.WatchedDate;
            }

            if (seruser == null)
            {
                contract.UnwatchedEpCountSeries = 0;
            }
            else
            {
                contract.UnwatchedEpCountSeries = seruser.UnwatchedEpisodeCount;
            }

            contract.AniDB_AirDate       = aniEp.AirDateAsDate;
            contract.AniDB_EnglishName   = aniEp.EnglishName;
            contract.AniDB_LengthSeconds = aniEp.LengthSeconds;
            contract.AniDB_Rating        = aniEp.Rating;
            contract.AniDB_RomajiName    = aniEp.RomajiName;
            contract.AniDB_Votes         = aniEp.Votes;

            contract.EpisodeNumber      = aniEp.EpisodeNumber;
            contract.EpisodeNameRomaji  = aniEp.RomajiName;
            contract.EpisodeNameEnglish = aniEp.EnglishName;
            contract.EpisodeType        = aniEp.EpisodeType;


            // find the number of files we actually have for this episode
            //contract.LocalFileCount = VideoLocals.Count;
            contract.LocalFileCount = epVids.Count;

            contract.ReleaseGroups = new List <Contract_AniDBReleaseGroup>();



            return(contract);
        }
Example #12
0
        public Contract_AnimeEpisode GetUserContract(int userid, ISessionWrapper session = null)
        {
            lock(_lock) //Make it atomic on creation
            {
                AnimeEpisode_User rr = GetUserRecord(userid);
                if (rr != null)
                    return rr.Contract;
                rr = new AnimeEpisode_User();
                rr.PlayedCount = 0;
                rr.StoppedCount = 0;
                rr.WatchedCount = 0;
                rr.AnimeEpisodeID = this.AnimeEpisodeID;
                rr.AnimeSeriesID = this.AnimeSeriesID;
                rr.JMMUserID = userid;
                rr.WatchedDate = null;

                if (session != null)
                {
                    RepoFactory.AnimeEpisode_User.SaveWithOpenTransaction(session, rr);
                }
                else
                {
                    RepoFactory.AnimeEpisode_User.Save(rr);
                }

                return rr.Contract;
            }
        }