예제 #1
0
		public Contract_AnimeEpisode ToContract(bool getFileCount, int userID, AnimeSeries_User seruser)
		{
			using (var session = JMMService.SessionFactory.OpenSession())
			{
				return ToContract(session, getFileCount, userID, seruser);
			}
		}
예제 #2
0
 public Contract_AnimeEpisode ToContract(bool getFileCount, int userID, AnimeSeries_User seruser)
 {
     using (var session = JMMService.SessionFactory.OpenSession())
     {
         return(ToContract(session, getFileCount, userID, seruser));
     }
 }
예제 #3
0
        public Contract_AnimeSeries ToContract(AnimeSeries_User userRecord, bool forceimages = false)
        {
            AniDB_Anime anime = this.GetAnime();
            List <CrossRef_AniDB_TvDBV2> tvDBCrossRefs   = this.GetCrossRefTvDBV2();
            CrossRef_AniDB_Other         movieDBCrossRef = this.CrossRefMovieDB;
            List <CrossRef_AniDB_MAL>    malDBCrossRef   = this.CrossRefMAL;
            MovieDB_Movie movie = null;

            if (movieDBCrossRef != null)
            {
                movie = movieDBCrossRef.GetMovieDB_Movie();
            }
            List <TvDB_Series> sers = new List <TvDB_Series>();

            foreach (CrossRef_AniDB_TvDBV2 xref in tvDBCrossRefs)
            {
                TvDB_Series tvser = xref.GetTvDBSeries();
                if (tvser != null)
                {
                    sers.Add(tvser);
                }
                else
                {
                    logger.Warn("You are missing database information for TvDB series: {0} - {1}", xref.TvDBID, xref.TvDBTitle);
                }
            }

            return(this.ToContract(anime, tvDBCrossRefs, movieDBCrossRef, userRecord, sers, malDBCrossRef, false, null, null, null, null, movie, forceimages));
        }
예제 #4
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;
		}
예제 #5
0
		public void Save(AnimeSeries_User obj)
		{
			using (var session = JMMService.SessionFactory.OpenSession())
			{
				// populate the database
				using (var transaction = session.BeginTransaction())
				{
					session.SaveOrUpdate(obj);
					transaction.Commit();
				}
			}

			//logger.Trace("Updating group stats by series from AnimeSeries_UserRepository.Save: {0}", obj.AnimeSeriesID);
			//StatsCache.Instance.UpdateUsingSeries(obj.AnimeSeriesID);
		}
예제 #6
0
        public Contract_AnimeSeries ToContract(AnimeSeries_User userRecord, bool forceimages = false)
        {
            AniDB_Anime anime = this.GetAnime();
            List <CrossRef_AniDB_TvDBV2> tvDBCrossRefs   = this.GetCrossRefTvDBV2();
            CrossRef_AniDB_Other         movieDBCrossRef = this.CrossRefMovieDB;
            List <CrossRef_AniDB_MAL>    malDBCrossRef   = this.CrossRefMAL;

            List <TvDB_Series> sers = new List <TvDB_Series>();

            foreach (CrossRef_AniDB_TvDBV2 xref in tvDBCrossRefs)
            {
                sers.Add(xref.GetTvDBSeries());
            }

            return(this.ToContract(anime, tvDBCrossRefs, movieDBCrossRef, userRecord, sers, malDBCrossRef, false, null, null, null, null, forceimages));
        }
예제 #7
0
        public static HashSet <GroupFilterConditionType> GetConditionTypesChanged(AnimeSeries_User oldcontract,
                                                                                  AnimeSeries_User newcontract)
        {
            HashSet <GroupFilterConditionType> h = new HashSet <GroupFilterConditionType>();

            if (oldcontract == null ||
                oldcontract.UnwatchedEpisodeCount > 0 != newcontract.UnwatchedEpisodeCount > 0)
            {
                h.Add(GroupFilterConditionType.HasUnwatchedEpisodes);
            }
            if (oldcontract == null || oldcontract.WatchedDate != newcontract.WatchedDate)
            {
                h.Add(GroupFilterConditionType.EpisodeWatchedDate);
            }
            if (oldcontract == null || oldcontract.WatchedEpisodeCount > 0 != newcontract.WatchedEpisodeCount > 0)
            {
                h.Add(GroupFilterConditionType.HasWatchedEpisodes);
            }
            return(h);
        }
예제 #8
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);
            }
        }
예제 #9
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);
        }
예제 #10
0
        public Contract_AnimeSeries ToContract(AniDB_Anime animeRec, List <CrossRef_AniDB_TvDBV2> tvDBCrossRefs, CrossRef_AniDB_Other movieDBCrossRef,
                                               AnimeSeries_User userRecord, List <TvDB_Series> tvseries, List <CrossRef_AniDB_MAL> malDBCrossRef, bool passedDefaultImages, AniDB_Anime_DefaultImage defPoster,
                                               AniDB_Anime_DefaultImage defFanart, AniDB_Anime_DefaultImage defWideBanner, List <AniDB_Anime_Title> titles, bool forceimages = false)
        {
            Contract_AnimeSeries contract = new Contract_AnimeSeries();

            contract.AniDB_ID                  = this.AniDB_ID;
            contract.AnimeGroupID              = this.AnimeGroupID;
            contract.AnimeSeriesID             = this.AnimeSeriesID;
            contract.DateTimeUpdated           = this.DateTimeUpdated;
            contract.DateTimeCreated           = this.DateTimeCreated;
            contract.DefaultAudioLanguage      = this.DefaultAudioLanguage;
            contract.DefaultSubtitleLanguage   = this.DefaultSubtitleLanguage;
            contract.LatestLocalEpisodeNumber  = this.LatestLocalEpisodeNumber;
            contract.EpisodeAddedDate          = this.EpisodeAddedDate;
            contract.MissingEpisodeCount       = this.MissingEpisodeCount;
            contract.MissingEpisodeCountGroups = this.MissingEpisodeCountGroups;
            contract.SeriesNameOverride        = this.SeriesNameOverride;



            if (userRecord == null)
            {
                contract.PlayedCount           = 0;
                contract.StoppedCount          = 0;
                contract.UnwatchedEpisodeCount = 0;
                contract.WatchedCount          = 0;
                contract.WatchedDate           = null;
                contract.WatchedEpisodeCount   = 0;
            }
            else
            {
                contract.PlayedCount           = userRecord.PlayedCount;
                contract.StoppedCount          = userRecord.StoppedCount;
                contract.UnwatchedEpisodeCount = userRecord.UnwatchedEpisodeCount;
                contract.WatchedCount          = userRecord.WatchedCount;
                contract.WatchedDate           = userRecord.WatchedDate;
                contract.WatchedEpisodeCount   = userRecord.WatchedEpisodeCount;
            }

            // get AniDB data
            contract.AniDBAnime = null;
            if (animeRec != null)
            {
                Contract_AniDBAnime animecontract = animeRec.ToContract(false, titles);

                AniDB_Anime_DefaultImage defaultPoster = null;
                if (passedDefaultImages)
                {
                    defaultPoster = defPoster;
                }
                else
                {
                    defaultPoster = animeRec.GetDefaultPoster();
                }

                if (defaultPoster == null)
                {
                    animecontract.DefaultImagePoster = null;
                }
                else
                {
                    animecontract.DefaultImagePoster = defaultPoster.ToContract();
                }

                if ((animecontract.DefaultImagePoster == null) && (forceimages))
                {
                    ImageDetails im = animeRec.GetDefaultPosterDetailsNoBlanks();
                    if (im != null)
                    {
                        animecontract.DefaultImagePoster           = new Contract_AniDB_Anime_DefaultImage();
                        animecontract.DefaultImagePoster.AnimeID   = im.ImageID;
                        animecontract.DefaultImagePoster.ImageType = (int)im.ImageType;
                    }
                }
                AniDB_Anime_DefaultImage defaultFanart = null;
                if (passedDefaultImages)
                {
                    defaultFanart = defFanart;
                }
                else
                {
                    defaultFanart = animeRec.GetDefaultFanart();
                }

                if (defaultFanart == null)
                {
                    animecontract.DefaultImageFanart = null;
                }
                else
                {
                    animecontract.DefaultImageFanart = defaultFanart.ToContract();
                }

                if ((animecontract.DefaultImagePoster == null) && (forceimages))
                {
                    ImageDetails im = animeRec.GetDefaultFanartDetailsNoBlanks();
                    if (im != null)
                    {
                        animecontract.DefaultImageFanart           = new Contract_AniDB_Anime_DefaultImage();
                        animecontract.DefaultImageFanart.AnimeID   = im.ImageID;
                        animecontract.DefaultImageFanart.ImageType = (int)im.ImageType;
                    }
                }

                AniDB_Anime_DefaultImage defaultWideBanner = null;
                if (passedDefaultImages)
                {
                    defaultWideBanner = defWideBanner;
                }
                else
                {
                    defaultWideBanner = animeRec.GetDefaultWideBanner();
                }

                if (defaultWideBanner == null)
                {
                    animecontract.DefaultImageWideBanner = null;
                }
                else
                {
                    animecontract.DefaultImageWideBanner = defaultWideBanner.ToContract();
                }

                contract.AniDBAnime = animecontract;
            }

            contract.CrossRefAniDBTvDBV2 = new List <Contract_CrossRef_AniDB_TvDBV2>();
            foreach (CrossRef_AniDB_TvDBV2 tvXref in tvDBCrossRefs)
            {
                contract.CrossRefAniDBTvDBV2.Add(tvXref.ToContract());
            }


            contract.TvDB_Series = new List <Contract_TvDB_Series>();
            foreach (TvDB_Series ser in tvseries)
            {
                contract.TvDB_Series.Add(ser.ToContract());
            }

            contract.CrossRefAniDBMovieDB = null;
            if (movieDBCrossRef != null)
            {
                contract.CrossRefAniDBMovieDB = movieDBCrossRef.ToContract();
            }

            contract.CrossRefAniDBMAL = new List <Contract_CrossRef_AniDB_MAL>();
            if (malDBCrossRef != null)
            {
                foreach (CrossRef_AniDB_MAL xref in malDBCrossRef)
                {
                    contract.CrossRefAniDBMAL.Add(xref.ToContract());
                }
            }

            return(contract);
        }
예제 #11
0
        /// <summary>
        /// Update the stats for this group based on the child series
        /// Assumes that all the AnimeSeries have had their stats updated already
        /// </summary>
        public void UpdateStats(bool watchedStats, bool missingEpsStats)
        {
            List <AnimeSeries> seriesList = GetAllSeries();

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

            if (watchedStats)
            {
                foreach (JMMUser juser in allUsers)
                {
                    AnimeGroup_User userRecord = GetUserRecord(juser.JMMUserID);
                    if (userRecord == null)
                    {
                        userRecord = new AnimeGroup_User(juser.JMMUserID, this.AnimeGroupID);
                    }

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

                    foreach (AnimeSeries ser in seriesList)
                    {
                        AnimeSeries_User serUserRecord = ser.GetUserRecord(juser.JMMUserID);
                        if (serUserRecord != null)
                        {
                            userRecord.WatchedCount          += serUserRecord.WatchedCount;
                            userRecord.UnwatchedEpisodeCount += serUserRecord.UnwatchedEpisodeCount;
                            userRecord.PlayedCount           += serUserRecord.PlayedCount;
                            userRecord.StoppedCount          += serUserRecord.StoppedCount;
                            userRecord.WatchedEpisodeCount   += serUserRecord.WatchedEpisodeCount;

                            if (serUserRecord.WatchedDate.HasValue)
                            {
                                if (userRecord.WatchedDate.HasValue)
                                {
                                    if (serUserRecord.WatchedDate > userRecord.WatchedDate)
                                    {
                                        userRecord.WatchedDate = serUserRecord.WatchedDate;
                                    }
                                }
                                else
                                {
                                    userRecord.WatchedDate = serUserRecord.WatchedDate;
                                }
                            }
                        }
                    }

                    // now update the stats for the groups
                    logger.Trace("Updating stats for {0}", this.ToString());
                    AnimeGroup_UserRepository rep = new AnimeGroup_UserRepository();
                    rep.Save(userRecord);
                }
            }

            if (missingEpsStats)
            {
                this.MissingEpisodeCount       = 0;
                this.MissingEpisodeCountGroups = 0;

                foreach (AnimeSeries ser in seriesList)
                {
                    this.MissingEpisodeCount       += ser.MissingEpisodeCount;
                    this.MissingEpisodeCountGroups += ser.MissingEpisodeCountGroups;
                }

                AnimeGroupRepository repGrp = new AnimeGroupRepository();
                repGrp.Save(this);
            }
        }
예제 #12
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);
        }
예제 #13
0
        public static HashSet<GroupFilterConditionType> GetConditionTypesChanged(AnimeSeries_User oldcontract,
            AnimeSeries_User newcontract)
        {
            HashSet<GroupFilterConditionType> h = new HashSet<GroupFilterConditionType>();

            if (oldcontract == null ||
                oldcontract.UnwatchedEpisodeCount > 0 != newcontract.UnwatchedEpisodeCount > 0)
                h.Add(GroupFilterConditionType.HasUnwatchedEpisodes);
            if (oldcontract == null || oldcontract.WatchedDate != newcontract.WatchedDate)
                h.Add(GroupFilterConditionType.EpisodeWatchedDate);
            if (oldcontract == null || oldcontract.WatchedEpisodeCount > 0 != newcontract.WatchedEpisodeCount > 0)
                h.Add(GroupFilterConditionType.HasWatchedEpisodes);
            return h;
        }
예제 #14
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;
		}