public static void InitCache()
        {
            string t = "AniDB_Anime";

            ServerState.Instance.CurrentSetupStatus = string.Format(JMMServer.Properties.Resources.Database_Cache, t, string.Empty);
            AniDB_AnimeRepository repo = new AniDB_AnimeRepository();

            using (var session = JMMService.SessionFactory.OpenSession())
            {
                List <AniDB_Anime> ls =
                    repo.GetAll(session).Where(a => a.ContractVersion < AniDB_Anime.CONTRACT_VERSION).ToList();
                int max = ls.Count;
                int cnt = 0;
                foreach (AniDB_Anime a in ls)
                {
                    repo.Save(session, a);
                    cnt++;
                    if (cnt % 10 == 0)
                    {
                        ServerState.Instance.CurrentSetupStatus = string.Format(JMMServer.Properties.Resources.Database_Cache, t,
                                                                                " DbRegen - " + cnt + "/" + max);
                    }
                }
                ServerState.Instance.CurrentSetupStatus = string.Format(JMMServer.Properties.Resources.Database_Cache, t,
                                                                        " DbRegen - " + max + "/" + max);
            }
        }
		public override void ProcessCommand()
		{
			logger.Info("Processing CommandRequest_MALUploadStatusToMAL");

			try
			{
				if (string.IsNullOrEmpty(ServerSettings.MAL_Username) || string.IsNullOrEmpty(ServerSettings.MAL_Password))
					return;

				// find the latest eps to update
				AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
				List<AniDB_Anime> animes = repAnime.GetAll();

				foreach (AniDB_Anime anime in animes)
				{
					CommandRequest_MALUpdatedWatchedStatus cmd = new CommandRequest_MALUpdatedWatchedStatus(anime.AnimeID);
					cmd.Save();
				}
			}
			catch (Exception ex)
			{
				logger.Error("Error processing CommandRequest_MALUploadStatusToMAL: {0}", ex.ToString());
				return;
			}
		}
Exemple #3
0
		void btnUploadAzureCache_Click(object sender, RoutedEventArgs e)
		{
			AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
			List<AniDB_Anime> allAnime = repAnime.GetAll();
			int cnt = 0;
			foreach (AniDB_Anime anime in allAnime)
			{
				cnt++;
				logger.Info(string.Format("Uploading anime {0} of {1} - {2}", cnt, allAnime.Count, anime.MainTitle));

				try
				{
					CommandRequest_Azure_SendAnimeFull cmdAzure = new CommandRequest_Azure_SendAnimeFull(anime.AnimeID);
					cmdAzure.Save();
				}
				catch { }
			}
		}
Exemple #4
0
		private void SendToAzureXML()
		{
			
			DateTime dt = DateTime.Now.AddYears(-2);
			AniDB_AnimeRepository rep = new AniDB_AnimeRepository();
			List<AniDB_Anime> allAnime = rep.GetAll();

			int sentAnime = 0;
			foreach (AniDB_Anime anime in rep.GetAll())
			{
				if (!anime.EndDate.HasValue) continue;

				if (anime.EndDate.Value > dt) continue;

				sentAnime++;
				CommandRequest_Azure_SendAnimeXML cmd = new CommandRequest_Azure_SendAnimeXML(anime.AnimeID);
				cmd.Save();
			}

			logger.Info(string.Format("Sent Anime XML to Cache: {0} out of {1}", sentAnime, allAnime.Count));
		}
Exemple #5
0
		private void GenerateAzureList()
		{

			// get a lst of anime's that we already have
			AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
			List<AniDB_Anime> allAnime = repAnime.GetAll();
			Dictionary<int, int> localAnimeIDs = new Dictionary<int, int>();
			foreach (AniDB_Anime anime in allAnime)
			{
				localAnimeIDs[anime.AnimeID] = anime.AnimeID;
			}

			// loop through the list of valid anime id's and add the ones we don't have yet
			Dictionary<int, int> validAnimeIDs = new Dictionary<int, int>();

			string line;
			System.IO.StreamReader file =
			   new System.IO.StreamReader(@"e:\animetitles.txt");
			while ((line = file.ReadLine()) != null)
			{
				string[] titlesArray = line.Split('|');

				try
				{
					int aid = int.Parse(titlesArray[0]);
					if (!localAnimeIDs.ContainsKey(aid))
						validAnimeIDs[aid] = aid;
				}
				catch { }
			}

			file.Close();

			string aids = "";
			var shuffledList = validAnimeIDs.Values.OrderBy(a => Guid.NewGuid());
			int i = 0;
			foreach (int animeID in shuffledList)
			{
				i++;
				if (!string.IsNullOrEmpty(aids)) aids += ",";
				aids += animeID;

				if (i == 250)
				{
					logger.Info(aids);
					aids = "";
					i = 0;
				}
			}

			logger.Info(aids);
		}
Exemple #6
0
        public List<Contract_AnimeSeries> GetSeriesWithMissingEpisodes(int maxRecords, int jmmuserID)
        {
            DateTime start = DateTime.Now;
            AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
            AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
            JMMUserRepository repUsers = new JMMUserRepository();

            // get all the series
            List<Contract_AnimeSeries> seriesContractList = new List<Contract_AnimeSeries>();

            try
            {
                JMMUser user = repUsers.GetByID(jmmuserID);
                if (user == null) return seriesContractList;

                List<AnimeSeries> series = repSeries.GetWithMissingEpisodes();

                List<AniDB_Anime> animes = repAnime.GetAll();
                Dictionary<int, AniDB_Anime> dictAnimes = new Dictionary<int, AniDB_Anime>();
                foreach (AniDB_Anime anime in animes)
                    dictAnimes[anime.AnimeID] = anime;

                // tvdb
                CrossRef_AniDB_TvDBV2Repository repCrossRef = new CrossRef_AniDB_TvDBV2Repository();
                List<CrossRef_AniDB_TvDBV2> allCrossRefs = repCrossRef.GetAll();
                Dictionary<int, List<CrossRef_AniDB_TvDBV2>> dictCrossRefsV2 = new Dictionary<int, List<CrossRef_AniDB_TvDBV2>>();
                foreach (CrossRef_AniDB_TvDBV2 xref in allCrossRefs)
                {
                    if (!dictCrossRefsV2.ContainsKey(xref.AnimeID))
                        dictCrossRefsV2[xref.AnimeID] = new List<CrossRef_AniDB_TvDBV2>();
                    dictCrossRefsV2[xref.AnimeID].Add(xref);
                }

                // moviedb
                CrossRef_AniDB_OtherRepository repOtherCrossRef = new CrossRef_AniDB_OtherRepository();
                List<CrossRef_AniDB_Other> allOtherCrossRefs = repOtherCrossRef.GetAll();
                Dictionary<int, CrossRef_AniDB_Other> dictMovieCrossRefs = new Dictionary<int, CrossRef_AniDB_Other>();
                foreach (CrossRef_AniDB_Other xref in allOtherCrossRefs)
                {
                    if (xref.CrossRefType == (int)CrossRefType.MovieDB)
                        dictMovieCrossRefs[xref.AnimeID] = xref;
                }

                // MAL
                CrossRef_AniDB_MALRepository repMALCrossRef = new CrossRef_AniDB_MALRepository();
                List<CrossRef_AniDB_MAL> allMALCrossRefs = repMALCrossRef.GetAll();
                Dictionary<int, List<CrossRef_AniDB_MAL>> dictMALCrossRefs = new Dictionary<int, List<CrossRef_AniDB_MAL>>();
                foreach (CrossRef_AniDB_MAL xref in allMALCrossRefs)
                {
                    if (!dictMALCrossRefs.ContainsKey(xref.AnimeID))
                        dictMALCrossRefs[xref.AnimeID] = new List<CrossRef_AniDB_MAL>();
                    dictMALCrossRefs[xref.AnimeID].Add(xref);
                }

                // user records
                AnimeSeries_UserRepository repSeriesUser = new AnimeSeries_UserRepository();
                List<AnimeSeries_User> userRecordList = repSeriesUser.GetByUserID(jmmuserID);
                Dictionary<int, AnimeSeries_User> dictUserRecords = new Dictionary<int, AnimeSeries_User>();
                foreach (AnimeSeries_User serUser in userRecordList)
                    dictUserRecords[serUser.AnimeSeriesID] = serUser;

                int i = 1;
                foreach (AnimeSeries aser in series)
                {
                    if (!dictAnimes.ContainsKey(aser.AniDB_ID)) continue;

                    AniDB_Anime anime = dictAnimes[aser.AniDB_ID];
                    if (!user.AllowedAnime(anime)) continue;

                    List<CrossRef_AniDB_TvDBV2> xrefs = new List<CrossRef_AniDB_TvDBV2>();
                    if (dictCrossRefsV2.ContainsKey(aser.AniDB_ID)) xrefs = dictCrossRefsV2[aser.AniDB_ID];

                    CrossRef_AniDB_Other xrefMovie = null;
                    if (dictMovieCrossRefs.ContainsKey(aser.AniDB_ID)) xrefMovie = dictMovieCrossRefs[aser.AniDB_ID];

                    AnimeSeries_User userRec = null;
                    if (dictUserRecords.ContainsKey(aser.AnimeSeriesID))
                        userRec = dictUserRecords[aser.AnimeSeriesID];

                    List<CrossRef_AniDB_MAL> xrefMAL = null;
                    if (dictMALCrossRefs.ContainsKey(aser.AniDB_ID))
                        xrefMAL = dictMALCrossRefs[aser.AniDB_ID];

                    List<TvDB_Series> sers = new List<TvDB_Series>();
                    foreach (CrossRef_AniDB_TvDBV2 xref in xrefs)
                        sers.Add(xref.GetTvDBSeries());
                    MovieDB_Movie movie = null;
                    if (xrefMovie != null)
                        movie = xrefMovie.GetMovieDB_Movie();
                    seriesContractList.Add(aser.ToContract(dictAnimes[aser.AniDB_ID], xrefs, xrefMovie, userRec,
                        sers, xrefMAL, false, null, null, null, null,movie));

                    if (i == maxRecords) break;

                    i++;
                }

                TimeSpan ts = DateTime.Now - start;
                logger.Info("GetSeriesWithMissingEpisodes in {0} ms", ts.TotalMilliseconds);
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
            return seriesContractList;
        }
Exemple #7
0
        public List<Contract_AnimeRating> GetAnimeRatings(int collectionState, int watchedState, int ratingVotedState, int userID)
        {
            List<Contract_AnimeRating> contracts = new List<Contract_AnimeRating>();

            try
            {
                AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
                List<AnimeSeries> series = repSeries.GetAll();
                Dictionary<int, AnimeSeries> dictSeries = new Dictionary<int, AnimeSeries>();
                foreach (AnimeSeries ser in series)
                    dictSeries[ser.AniDB_ID] = ser;

                RatingCollectionState _collectionState = (RatingCollectionState)collectionState;
                RatingWatchedState _watchedState = (RatingWatchedState)watchedState;
                RatingVotedState _ratingVotedState = (RatingVotedState)ratingVotedState;

                DateTime start = DateTime.Now;

                AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();

                /*
                // build a dictionary of categories
                AniDB_CategoryRepository repCats = new AniDB_CategoryRepository();
                AniDB_Anime_CategoryRepository repAnimeCat = new AniDB_Anime_CategoryRepository();

                List<AniDB_Category> allCatgeories = repCats.GetAll();
                Dictionary<int, AniDB_Category> allCatgeoriesDict = new Dictionary<int, AniDB_Category>();
                foreach (AniDB_Category cat in allCatgeories)
                    allCatgeoriesDict[cat.CategoryID] = cat;

                List<AniDB_Anime_Category> allAnimeCatgeories = repAnimeCat.GetAll();
                Dictionary<int, List<AniDB_Anime_Category>> allAnimeCatgeoriesDict = new Dictionary<int, List<AniDB_Anime_Category>>(); //
                foreach (AniDB_Anime_Category aniCat in allAnimeCatgeories)
                {
                    if (!allAnimeCatgeoriesDict.ContainsKey(aniCat.AnimeID))
                        allAnimeCatgeoriesDict[aniCat.AnimeID] = new List<AniDB_Anime_Category>();

                    allAnimeCatgeoriesDict[aniCat.AnimeID].Add(aniCat);
                }

                // build a dictionary of titles
                AniDB_Anime_TitleRepository repTitles = new AniDB_Anime_TitleRepository();

                List<AniDB_Anime_Title> allTitles = repTitles.GetAll();
                Dictionary<int, List<AniDB_Anime_Title>> allTitlesDict = new Dictionary<int, List<AniDB_Anime_Title>>();
                foreach (AniDB_Anime_Title title in allTitles)
                {
                    if (!allTitlesDict.ContainsKey(title.AnimeID))
                        allTitlesDict[title.AnimeID] = new List<AniDB_Anime_Title>();

                    allTitlesDict[title.AnimeID].Add(title);
                }

                // build a dictionary of tags
                AniDB_TagRepository repTags = new AniDB_TagRepository();
                AniDB_Anime_TagRepository repAnimeTag = new AniDB_Anime_TagRepository();

                List<AniDB_Tag> allTags = repTags.GetAll();
                Dictionary<int, AniDB_Tag> allTagsDict = new Dictionary<int, AniDB_Tag>();
                foreach (AniDB_Tag tag in allTags)
                    allTagsDict[tag.TagID] = tag;

                List<AniDB_Anime_Tag> allAnimeTags = repAnimeTag.GetAll();
                Dictionary<int, List<AniDB_Anime_Tag>> allAnimeTagsDict = new Dictionary<int, List<AniDB_Anime_Tag>>(); //
                foreach (AniDB_Anime_Tag aniTag in allAnimeTags)
                {
                    if (!allAnimeTagsDict.ContainsKey(aniTag.AnimeID))
                        allAnimeTagsDict[aniTag.AnimeID] = new List<AniDB_Anime_Tag>();

                    allAnimeTagsDict[aniTag.AnimeID].Add(aniTag);
                }

                // build a dictionary of languages
                AdhocRepository rep = new AdhocRepository();
                Dictionary<int, LanguageStat> dictAudioStats = rep.GetAudioLanguageStatsForAnime();
                Dictionary<int, LanguageStat> dictSubtitleStats = rep.GetSubtitleLanguageStatsForAnime();

                Dictionary<int, string> dictAnimeVideoQualStats = rep.GetAllVideoQualityByAnime();
                Dictionary<int, AnimeVideoQualityStat> dictAnimeEpisodeVideoQualStats = rep.GetEpisodeVideoQualityStatsByAnime();
                 * */

                List<AniDB_Anime> animes = repAnime.GetAll();

                // user votes
                AniDB_VoteRepository repVotes = new AniDB_VoteRepository();
                List<AniDB_Vote> allVotes = repVotes.GetAll();

                JMMUserRepository repUsers = new JMMUserRepository();
                JMMUser user = repUsers.GetByID(userID);
                if (user == null) return contracts;

                int i = 0;

                foreach (AniDB_Anime anime in animes)
                {
                    i++;

                    // evaluate collection states
                    if (_collectionState == RatingCollectionState.AllEpisodesInMyCollection)
                    {
                        if (!anime.FinishedAiring) continue;
                        if (!dictSeries.ContainsKey(anime.AnimeID)) continue;
                        if (dictSeries[anime.AnimeID].MissingEpisodeCount > 0) continue;
                    }

                    if (_collectionState == RatingCollectionState.InMyCollection)
                        if (!dictSeries.ContainsKey(anime.AnimeID)) continue;

                    if (_collectionState == RatingCollectionState.NotInMyCollection)
                        if (dictSeries.ContainsKey(anime.AnimeID)) continue;

                    if (!user.AllowedAnime(anime)) continue;

                    // evaluate watched states
                    if (_watchedState == RatingWatchedState.AllEpisodesWatched)
                    {
                        if (!dictSeries.ContainsKey(anime.AnimeID)) continue;
                        AnimeSeries_User userRec = dictSeries[anime.AnimeID].GetUserRecord(userID);
                        if (userRec == null) continue;
                        if (userRec.UnwatchedEpisodeCount > 0) continue;
                    }

                    if (_watchedState == RatingWatchedState.NotWatched)
                    {
                        if (dictSeries.ContainsKey(anime.AnimeID))
                        {
                            AnimeSeries_User userRec = dictSeries[anime.AnimeID].GetUserRecord(userID);
                            if (userRec != null)
                            {
                                if (userRec.UnwatchedEpisodeCount == 0) continue;
                            }
                        }
                    }

                    // evaluate voted states
                    if (_ratingVotedState == RatingVotedState.Voted)
                    {
                        bool voted = false;
                        foreach (AniDB_Vote vote in allVotes)
                        {
                            if (vote.EntityID == anime.AnimeID && (vote.VoteType == (int)AniDBVoteType.Anime || vote.VoteType == (int)AniDBVoteType.AnimeTemp))
                            {
                                voted = true;
                                break;
                            }
                        }

                        if (!voted) continue;
                    }

                    if (_ratingVotedState == RatingVotedState.NotVoted)
                    {
                        bool voted = false;
                        foreach (AniDB_Vote vote in allVotes)
                        {
                            if (vote.EntityID == anime.AnimeID && (vote.VoteType == (int)AniDBVoteType.Anime || vote.VoteType == (int)AniDBVoteType.AnimeTemp))
                            {
                                voted = true;
                                break;
                            }
                        }

                        if (voted) continue;
                    }

                    Contract_AnimeRating contract = new Contract_AnimeRating();
                    contract.AnimeID = anime.AnimeID;

                    Contract_AniDB_AnimeDetailed contractAnimeDetailed = new Contract_AniDB_AnimeDetailed();

                    contractAnimeDetailed.AnimeTitles = new List<Contract_AnimeTitle>();
                    contractAnimeDetailed.Tags = new List<Contract_AnimeTag>();
                    contractAnimeDetailed.CustomTags = new List<Contract_CustomTag>();
                    contractAnimeDetailed.UserVote = null;

                    contractAnimeDetailed.AniDBAnime = anime.ToContract();

                    // get user vote
                    foreach (AniDB_Vote vote in allVotes)
                    {
                        if (vote.EntityID == anime.AnimeID && (vote.VoteType == (int)AniDBVoteType.Anime || vote.VoteType == (int)AniDBVoteType.AnimeTemp))
                        {
                            contractAnimeDetailed.UserVote = vote.ToContract();
                            break;
                        }
                    }

                    contract.AnimeDetailed = contractAnimeDetailed;

                    if (dictSeries.ContainsKey(anime.AnimeID))
                    {
                        contract.AnimeSeries = dictSeries[anime.AnimeID].ToContract(dictSeries[anime.AnimeID].GetUserRecord(userID));
                    }

                    contracts.Add(contract);

                }
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
            return contracts;
        }
Exemple #8
0
        public List<Contract_AnimeSeries> GetAllSeries(int userID)
        {
            AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
            AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
            AniDB_Anime_TitleRepository repTitles = new AniDB_Anime_TitleRepository();

            //TODO: Custom Tags: Do I need to add custom tags for searches

            // get all the series
            List<Contract_AnimeSeries> seriesContractList = new List<Contract_AnimeSeries>();

            try
            {

                DateTime start = DateTime.Now;
                DateTime start2 = DateTime.Now;

                List<AnimeSeries> series = repSeries.GetAll();

                List<AniDB_Anime> animes = repAnime.GetAll();
                Dictionary<int, AniDB_Anime> dictAnimes = new Dictionary<int, AniDB_Anime>();
                foreach (AniDB_Anime anime in animes)
                    dictAnimes[anime.AnimeID] = anime;

                TimeSpan ts2 = DateTime.Now - start2; logger.Info("GetAllSeries:Anime:RawData in {0} ms", ts2.TotalMilliseconds); start2 = DateTime.Now;

                // tvdb - cross refs
                CrossRef_AniDB_TvDBV2Repository repCrossRef = new CrossRef_AniDB_TvDBV2Repository();
                List<CrossRef_AniDB_TvDBV2> allCrossRefs = repCrossRef.GetAll();
                Dictionary<int, List<CrossRef_AniDB_TvDBV2>> dictCrossRefsV2 = new Dictionary<int, List<CrossRef_AniDB_TvDBV2>>();
                foreach (CrossRef_AniDB_TvDBV2 xref in allCrossRefs)
                {
                    if (!dictCrossRefsV2.ContainsKey(xref.AnimeID))
                        dictCrossRefsV2[xref.AnimeID] = new List<CrossRef_AniDB_TvDBV2>();
                    dictCrossRefsV2[xref.AnimeID].Add(xref);
                }

                ts2 = DateTime.Now - start2; logger.Info("GetAllSeries:TvDB CrossRefs:RawData in {0} ms", ts2.TotalMilliseconds); start2 = DateTime.Now;

                // tvdb - series info
                TvDB_SeriesRepository repTvSeries = new TvDB_SeriesRepository();
                List<TvDB_Series> allTvSeries = repTvSeries.GetAll();
                Dictionary<int, TvDB_Series> dictTvSeries = new Dictionary<int, TvDB_Series>();
                foreach (TvDB_Series tvs in allTvSeries)
                    dictTvSeries[tvs.SeriesID] = tvs;

                ts2 = DateTime.Now - start2; logger.Info("GetAllSeries:TvDB:RawData in {0} ms", ts2.TotalMilliseconds); start2 = DateTime.Now;

                // moviedb
                CrossRef_AniDB_OtherRepository repOtherCrossRef = new CrossRef_AniDB_OtherRepository();
                List<CrossRef_AniDB_Other> allOtherCrossRefs = repOtherCrossRef.GetAll();
                Dictionary<int, CrossRef_AniDB_Other> dictMovieCrossRefs = new Dictionary<int, CrossRef_AniDB_Other>();
                foreach (CrossRef_AniDB_Other xref in allOtherCrossRefs)
                {
                    if (xref.CrossRefType == (int)CrossRefType.MovieDB)
                        dictMovieCrossRefs[xref.AnimeID] = xref;
                }
                ts2 = DateTime.Now - start2; logger.Info("GetAllSeries:MovieDB:RawData in {0} ms", ts2.TotalMilliseconds); start2 = DateTime.Now;

                // MAL
                CrossRef_AniDB_MALRepository repMALCrossRef = new CrossRef_AniDB_MALRepository();
                List<CrossRef_AniDB_MAL> allMALCrossRefs = repMALCrossRef.GetAll();
                Dictionary<int, List<CrossRef_AniDB_MAL>> dictMALCrossRefs = new Dictionary<int, List<CrossRef_AniDB_MAL>>();
                foreach (CrossRef_AniDB_MAL xref in allMALCrossRefs)
                {
                    if (!dictMALCrossRefs.ContainsKey(xref.AnimeID))
                        dictMALCrossRefs[xref.AnimeID] = new List<CrossRef_AniDB_MAL>();
                    dictMALCrossRefs[xref.AnimeID].Add(xref);
                }
                ts2 = DateTime.Now - start2; logger.Info("GetAllSeries:MAL:RawData in {0} ms", ts2.TotalMilliseconds); start2 = DateTime.Now;

                // user records
                AnimeSeries_UserRepository repSeriesUser = new AnimeSeries_UserRepository();
                List<AnimeSeries_User> userRecordList = repSeriesUser.GetByUserID(userID);
                Dictionary<int, AnimeSeries_User> dictUserRecords = new Dictionary<int, AnimeSeries_User>();
                foreach (AnimeSeries_User serUser in userRecordList)
                    dictUserRecords[serUser.AnimeSeriesID] = serUser;

                ts2 = DateTime.Now - start2; logger.Info("GetAllSeries:UserRecs:RawData in {0} ms", ts2.TotalMilliseconds); start2 = DateTime.Now;

                // default images
                AniDB_Anime_DefaultImageRepository repDefImages = new AniDB_Anime_DefaultImageRepository();
                List<AniDB_Anime_DefaultImage> allDefaultImages = repDefImages.GetAll();

                ts2 = DateTime.Now - start2; logger.Info("GetAllSeries:DefaultImages:RawData in {0} ms", ts2.TotalMilliseconds); start2 = DateTime.Now;

                // titles
                List<AniDB_Anime_Title> allTitles = repTitles.GetAllForLocalSeries();
                Dictionary<int, List<AniDB_Anime_Title>> dictTitles = new Dictionary<int, List<AniDB_Anime_Title>>();
                foreach (AniDB_Anime_Title atit in allTitles)
                {
                    if (!dictTitles.ContainsKey(atit.AnimeID))
                        dictTitles[atit.AnimeID] = new List<AniDB_Anime_Title>();

                    dictTitles[atit.AnimeID].Add(atit);
                }

                ts2 = DateTime.Now - start2; logger.Info("GetAllSeries:Titles:RawData in {0} ms", ts2.TotalMilliseconds); start2 = DateTime.Now;

                TimeSpan ts = DateTime.Now - start;
                logger.Info("GetAllSeries:RawData in {0} ms", ts.TotalMilliseconds);

                Dictionary<int, AniDB_Anime_DefaultImage> dictDefaultsPosters = new Dictionary<int, AniDB_Anime_DefaultImage>();
                Dictionary<int, AniDB_Anime_DefaultImage> dictDefaultsFanart = new Dictionary<int, AniDB_Anime_DefaultImage>();
                Dictionary<int, AniDB_Anime_DefaultImage> dictDefaultsWideBanner = new Dictionary<int, AniDB_Anime_DefaultImage>();

                start = DateTime.Now;

                foreach (AniDB_Anime_DefaultImage defaultImage in allDefaultImages)
                {
                    ImageSizeType sizeType = (ImageSizeType)defaultImage.ImageType;

                    if (sizeType == ImageSizeType.Fanart)
                        dictDefaultsFanart[defaultImage.AnimeID] = defaultImage;

                    if (sizeType == ImageSizeType.Poster)
                        dictDefaultsPosters[defaultImage.AnimeID] = defaultImage;

                    if (sizeType == ImageSizeType.WideBanner)
                        dictDefaultsWideBanner[defaultImage.AnimeID] = defaultImage;
                }

                foreach (AnimeSeries aser in series)
                {
                    if (!dictAnimes.ContainsKey(aser.AniDB_ID)) continue;

                    List<CrossRef_AniDB_TvDBV2> xrefs = new List<CrossRef_AniDB_TvDBV2>();
                    if (dictCrossRefsV2.ContainsKey(aser.AniDB_ID)) xrefs = dictCrossRefsV2[aser.AniDB_ID];

                    List<TvDB_Series> tvseriesV2 = new List<TvDB_Series>();
                    if (xrefs != null)
                    {
                        foreach (CrossRef_AniDB_TvDBV2 xref in xrefs)
                        {
                            if (dictTvSeries.ContainsKey(xref.TvDBID))
                                tvseriesV2.Add(dictTvSeries[xref.TvDBID]);
                        }
                    }

                    CrossRef_AniDB_Other xrefMovie = null;
                    if (dictMovieCrossRefs.ContainsKey(aser.AniDB_ID)) xrefMovie = dictMovieCrossRefs[aser.AniDB_ID];

                    List<CrossRef_AniDB_MAL> xrefMAL = null;
                    if (dictMALCrossRefs.ContainsKey(aser.AniDB_ID))
                        xrefMAL = dictMALCrossRefs[aser.AniDB_ID];

                    MovieDB_Movie movie = null;
                    if (xrefMovie != null)
                        movie = xrefMovie.GetMovieDB_Movie();

                    AnimeSeries_User userRec = null;
                    if (dictUserRecords.ContainsKey(aser.AnimeSeriesID))
                        userRec = dictUserRecords[aser.AnimeSeriesID];

                    List<AniDB_Anime_Title> titles = null;
                    if (dictTitles.ContainsKey(aser.AniDB_ID))
                        titles = dictTitles[aser.AniDB_ID];

                    AniDB_Anime_DefaultImage defPoster = null;
                    AniDB_Anime_DefaultImage defFanart = null;
                    AniDB_Anime_DefaultImage defWideBanner = null;

                    if (dictDefaultsPosters.ContainsKey(aser.AniDB_ID)) defPoster = dictDefaultsPosters[aser.AniDB_ID];
                    if (dictDefaultsFanart.ContainsKey(aser.AniDB_ID)) defFanart = dictDefaultsFanart[aser.AniDB_ID];
                    if (dictDefaultsWideBanner.ContainsKey(aser.AniDB_ID)) defWideBanner = dictDefaultsWideBanner[aser.AniDB_ID];

                    seriesContractList.Add(aser.ToContract(dictAnimes[aser.AniDB_ID], xrefs, xrefMovie, userRec, tvseriesV2, xrefMAL, true, defPoster, defFanart, defWideBanner, titles, movie));
                }

                ts = DateTime.Now - start;
                logger.Info("GetAllSeries:ProcessedData in {0} ms", ts.TotalMilliseconds);
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
            return seriesContractList;
        }
Exemple #9
0
        public List<Contract_AnimeEpisode> GetAllEpisodesWithMultipleFiles(int userID, bool onlyFinishedSeries, bool ignoreVariations)
        {
            List<Contract_AnimeEpisode> eps = new List<Contract_AnimeEpisode>();
            try
            {
                AnimeEpisodeRepository repEps = new AnimeEpisodeRepository();
                AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
                AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();

                Dictionary<int, int> dictSeriesAnime = new Dictionary<int, int>();
                Dictionary<int, bool> dictAnimeFinishedAiring = new Dictionary<int, bool>();
                Dictionary<int, bool> dictSeriesFinishedAiring = new Dictionary<int, bool>();

                if (onlyFinishedSeries)
                {
                    List<AnimeSeries> allSeries = repSeries.GetAll();
                    foreach (AnimeSeries ser in allSeries)
                        dictSeriesAnime[ser.AnimeSeriesID] = ser.AniDB_ID;

                    List<AniDB_Anime> allAnime = repAnime.GetAll();
                    foreach (AniDB_Anime anime in allAnime)
                        dictAnimeFinishedAiring[anime.AnimeID] = anime.FinishedAiring;

                    foreach (KeyValuePair<int, int> kvp in dictSeriesAnime)
                    {
                        if (dictAnimeFinishedAiring.ContainsKey(kvp.Value))
                            dictSeriesFinishedAiring[kvp.Key] = dictAnimeFinishedAiring[kvp.Value];
                    }
                }

                foreach (AnimeEpisode ep in repEps.GetEpisodesWithMultipleFiles(ignoreVariations))
                {
                    if (onlyFinishedSeries)
                    {
                        bool finishedAiring = false;
                        if (dictSeriesFinishedAiring.ContainsKey(ep.AnimeSeriesID))
                            finishedAiring = dictSeriesFinishedAiring[ep.AnimeSeriesID];

                        if (!finishedAiring) continue;

                    }

                    eps.Add(ep.ToContract(true, userID, null));
                }

                return eps;
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return eps;
            }
        }
Exemple #10
0
        public List<Contract_AniDB_AnimeDetailed> GetAllAnimeDetailed()
        {
            List<Contract_AniDB_AnimeDetailed> contracts = new List<Contract_AniDB_AnimeDetailed>();
            int countElements = 0;
            try
            {
                DateTime start = DateTime.Now;

                AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();

                // build a dictionary of titles
                AniDB_Anime_TitleRepository repTitles = new AniDB_Anime_TitleRepository();

                List<AniDB_Anime_Title> allTitles = repTitles.GetAll();
                Dictionary<int, List<AniDB_Anime_Title>> allTitlesDict = new Dictionary<int, List<AniDB_Anime_Title>>();
                foreach (AniDB_Anime_Title title in allTitles)
                {
                    if (!allTitlesDict.ContainsKey(title.AnimeID))
                        allTitlesDict[title.AnimeID] = new List<AniDB_Anime_Title>();

                    allTitlesDict[title.AnimeID].Add(title);
                }

                // build a dictionary of tags
                AniDB_TagRepository repTags = new AniDB_TagRepository();
                AniDB_Anime_TagRepository repAnimeTag = new AniDB_Anime_TagRepository();

                List<AniDB_Tag> allTags = repTags.GetAll();
                Dictionary<int, AniDB_Tag> allTagsDict = new Dictionary<int, AniDB_Tag>();
                foreach (AniDB_Tag tag in allTags)
                    allTagsDict[tag.TagID] = tag;

                List<AniDB_Anime_Tag> allAnimeTags = repAnimeTag.GetAll();
                Dictionary<int, List<AniDB_Anime_Tag>> allAnimeTagsDict = new Dictionary<int, List<AniDB_Anime_Tag>>(); //
                foreach (AniDB_Anime_Tag aniTag in allAnimeTags)
                {
                    if (!allAnimeTagsDict.ContainsKey(aniTag.AnimeID))
                        allAnimeTagsDict[aniTag.AnimeID] = new List<AniDB_Anime_Tag>();

                    allAnimeTagsDict[aniTag.AnimeID].Add(aniTag);
                }

                // build a dictionary of custom tags
                CustomTagRepository repCustomTags = new CustomTagRepository();
                CrossRef_CustomTagRepository repXRefCustomTags = new CrossRef_CustomTagRepository();

                List<CustomTag> allCustomTags = repCustomTags.GetAll();
                Dictionary<int, CustomTag> allCustomTagsDict = new Dictionary<int, CustomTag>();
                foreach (CustomTag tag in allCustomTags)
                    allCustomTagsDict[tag.CustomTagID] = tag;

                List<CrossRef_CustomTag> allCustomTagsXRefs = repXRefCustomTags.GetAll();
                Dictionary<int, List<CrossRef_CustomTag>> allCustomTagsXRefDict = new Dictionary<int, List<CrossRef_CustomTag>>(); //
                foreach (CrossRef_CustomTag aniTag in allCustomTagsXRefs)
                {
                    if (!allCustomTagsXRefDict.ContainsKey(aniTag.CrossRefID))
                        allCustomTagsXRefDict[aniTag.CrossRefID] = new List<CrossRef_CustomTag>();

                    allCustomTagsXRefDict[aniTag.CrossRefID].Add(aniTag);
                }

                // build a dictionary of languages
                AdhocRepository rep = new AdhocRepository();
                Dictionary<int, LanguageStat> dictAudioStats = rep.GetAudioLanguageStatsForAnime();
                Dictionary<int, LanguageStat> dictSubtitleStats = rep.GetSubtitleLanguageStatsForAnime();

                Dictionary<int, string> dictAnimeVideoQualStats = rep.GetAllVideoQualityByAnime();
                Dictionary<int, AnimeVideoQualityStat> dictAnimeEpisodeVideoQualStats = rep.GetEpisodeVideoQualityStatsByAnime();

                List<AniDB_Anime> animes = repAnime.GetAll();

                // user votes
                AniDB_VoteRepository repVotes = new AniDB_VoteRepository();
                List<AniDB_Vote> allVotes = repVotes.GetAll();

                int i = 0;

                foreach (AniDB_Anime anime in animes)
                {
                    i++;
                    //if (i >= 10) continue;

                    countElements++;

                    Contract_AniDB_AnimeDetailed contract = new Contract_AniDB_AnimeDetailed();

                    contract.AnimeTitles = new List<Contract_AnimeTitle>();
                    contract.Tags = new List<Contract_AnimeTag>();
                    contract.CustomTags = new List<Contract_CustomTag>();
                    contract.UserVote = null;

                    contract.AniDBAnime = anime.ToContract();

                    if (dictAnimeVideoQualStats.ContainsKey(anime.AnimeID))
                        contract.Stat_AllVideoQuality = dictAnimeVideoQualStats[anime.AnimeID];
                    else contract.Stat_AllVideoQuality = "";

                    contract.Stat_AllVideoQuality_Episodes = "";

                    // All Video Quality Episodes
                    // Try to determine if this anime has all the episodes available at a certain video quality
                    // e.g.  the series has all episodes in blu-ray
                    if (dictAnimeEpisodeVideoQualStats.ContainsKey(anime.AnimeID))
                    {
                        AnimeVideoQualityStat stat = dictAnimeEpisodeVideoQualStats[anime.AnimeID];
                        foreach (KeyValuePair<string, int> kvp in stat.VideoQualityEpisodeCount)
                        {
                            if (kvp.Value >= anime.EpisodeCountNormal)
                            {
                                if (contract.Stat_AllVideoQuality_Episodes.Length > 0) contract.Stat_AllVideoQuality_Episodes += ",";
                                contract.Stat_AllVideoQuality_Episodes += kvp.Key;
                            }
                        }
                    }

                    List<string> audioLanguageList = new List<string>();
                    List<string> subtitleLanguageList = new List<string>();

                    // get audio languages
                    if (dictAudioStats.ContainsKey(anime.AnimeID))
                    {
                        foreach (string lanName in dictAudioStats[anime.AnimeID].LanguageNames)
                        {
                            if (!audioLanguageList.Contains(lanName)) audioLanguageList.Add(lanName);
                        }
                    }

                    // get subtitle languages
                    if (dictSubtitleStats.ContainsKey(anime.AnimeID))
                    {
                        foreach (string lanName in dictSubtitleStats[anime.AnimeID].LanguageNames)
                        {
                            if (!subtitleLanguageList.Contains(lanName)) subtitleLanguageList.Add(lanName);
                        }
                    }

                    contract.Stat_AudioLanguages = "";
                    foreach (string audioLan in audioLanguageList)
                    {
                        if (contract.Stat_AudioLanguages.Length > 0) contract.Stat_AudioLanguages += ",";
                        contract.Stat_AudioLanguages += audioLan;
                    }

                    contract.Stat_SubtitleLanguages = "";
                    foreach (string subLan in subtitleLanguageList)
                    {
                        if (contract.Stat_SubtitleLanguages.Length > 0) contract.Stat_SubtitleLanguages += ",";
                        contract.Stat_SubtitleLanguages += subLan;
                    }

                    if (allTitlesDict.ContainsKey(anime.AnimeID))
                    {
                        foreach (AniDB_Anime_Title title in allTitlesDict[anime.AnimeID])
                        {
                            Contract_AnimeTitle ctitle = new Contract_AnimeTitle();
                            ctitle.AnimeID = title.AnimeID;
                            ctitle.Language = title.Language;
                            ctitle.Title = title.Title;
                            ctitle.TitleType = title.TitleType;
                            contract.AnimeTitles.Add(ctitle);
                            countElements++;
                        }
                    }

                    if (allAnimeTagsDict.ContainsKey(anime.AnimeID))
                    {
                        List<AniDB_Anime_Tag> aniTags = allAnimeTagsDict[anime.AnimeID];
                        foreach (AniDB_Anime_Tag aniTag in aniTags)
                        {
                            if (allTagsDict.ContainsKey(aniTag.TagID))
                            {
                                AniDB_Tag tag = allTagsDict[aniTag.TagID];

                                Contract_AnimeTag ctag = new Contract_AnimeTag();
                                ctag.Weight = aniTag.Weight;
                                ctag.GlobalSpoiler = tag.GlobalSpoiler;
                                ctag.LocalSpoiler = tag.LocalSpoiler;
                                //ctag.Spoiler = tag.Spoiler;
                                //ctag.TagCount = tag.TagCount;
                                ctag.TagDescription = tag.TagDescription;
                                ctag.TagID = tag.TagID;
                                ctag.TagName = tag.TagName;
                                contract.Tags.Add(ctag);
                                countElements++;
                            }
                        }
                    }

                    //TODO - Custom Tags: add custom tags

                    if (allCustomTagsXRefDict.ContainsKey(anime.AnimeID))
                    {
                        List<CrossRef_CustomTag> aniTags = allCustomTagsXRefDict[anime.AnimeID];
                        foreach (CrossRef_CustomTag aniTag in aniTags)
                        {
                            if (allCustomTagsDict.ContainsKey(aniTag.CustomTagID))
                            {
                                contract.CustomTags.Add(allCustomTagsDict[aniTag.CustomTagID].ToContract());
                                countElements++;
                            }
                        }
                    }

                    // get user vote
                    foreach (AniDB_Vote vote in allVotes)
                    {
                        if (vote.EntityID == anime.AnimeID && (vote.VoteType == (int)AniDBVoteType.Anime || vote.VoteType == (int)AniDBVoteType.AnimeTemp))
                        {
                            contract.UserVote = vote.ToContract();
                            break;
                        }
                    }

                    contracts.Add(contract);

                }

                TimeSpan ts = DateTime.Now - start;
                logger.Info("GetAllAnimeDetailed in {0} ms {1}", ts.TotalMilliseconds, countElements);
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
            return contracts;
        }
Exemple #11
0
        public List<Contract_AniDBAnime> GetAllAnime()
        {
            List<Contract_AniDBAnime> contracts = new List<Contract_AniDBAnime>();

            try
            {
                using (var session = JMMService.SessionFactory.OpenSession())
                {
                    DateTime start = DateTime.Now;

                    AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
                    List<AniDB_Anime> animes = repAnime.GetAll(session);

                    AniDB_Anime_DefaultImageRepository repDefaults = new AniDB_Anime_DefaultImageRepository();
                    List<AniDB_Anime_DefaultImage> allDefaultImages = repDefaults.GetAll(session);

                    Dictionary<int, AniDB_Anime_DefaultImage> dictDefaultsPosters = new Dictionary<int, AniDB_Anime_DefaultImage>();
                    Dictionary<int, AniDB_Anime_DefaultImage> dictDefaultsFanart = new Dictionary<int, AniDB_Anime_DefaultImage>();
                    Dictionary<int, AniDB_Anime_DefaultImage> dictDefaultsWideBanner = new Dictionary<int, AniDB_Anime_DefaultImage>();

                    foreach (AniDB_Anime_DefaultImage defaultImage in allDefaultImages)
                    {
                        ImageSizeType sizeType = (ImageSizeType)defaultImage.ImageType;

                        if (sizeType == ImageSizeType.Fanart)
                            dictDefaultsFanart[defaultImage.AnimeID] = defaultImage;

                        if (sizeType == ImageSizeType.Poster)
                            dictDefaultsPosters[defaultImage.AnimeID] = defaultImage;

                        if (sizeType == ImageSizeType.WideBanner)
                            dictDefaultsWideBanner[defaultImage.AnimeID] = defaultImage;
                    }

                    foreach (AniDB_Anime anime in animes)
                    {
                        Contract_AniDBAnime contract = anime.ToContract();

                        if (dictDefaultsFanart.ContainsKey(anime.AnimeID))
                            contract.DefaultImageFanart = dictDefaultsFanart[anime.AnimeID].ToContract();
                        else contract.DefaultImageFanart = null;

                        if (dictDefaultsPosters.ContainsKey(anime.AnimeID))
                            contract.DefaultImagePoster = dictDefaultsPosters[anime.AnimeID].ToContract();
                        else contract.DefaultImagePoster = null;

                        if (dictDefaultsWideBanner.ContainsKey(anime.AnimeID))
                            contract.DefaultImageWideBanner = dictDefaultsWideBanner[anime.AnimeID].ToContract();
                        else contract.DefaultImageWideBanner = null;

                        contracts.Add(contract);
                        //anime.ToContractDetailed();
                    }

                    TimeSpan ts = DateTime.Now - start;
                    logger.Info("GetAllAnimein {0} ms", ts.TotalMilliseconds);
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
            return contracts;
        }
Exemple #12
0
		public void InitStats()
		{
			try
			{

				DateTime start = DateTime.Now;

				ClearAllData();

				#region Get the data
				AnimeGroupRepository repGroups = new AnimeGroupRepository();
				AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
				AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
				AniDB_CategoryRepository repCats = new AniDB_CategoryRepository();
				AniDB_Anime_CategoryRepository repAnimeCat = new AniDB_Anime_CategoryRepository();
				AniDB_Anime_TitleRepository repTitles = new AniDB_Anime_TitleRepository();

				List<AnimeGroup> allGrps = repGroups.GetAll();

				Dictionary<int, AnimeGroup> allGroupsDict = new Dictionary<int, AnimeGroup>();
				foreach (AnimeGroup agrp in allGrps)
					allGroupsDict[agrp.AnimeGroupID] = agrp;
				TimeSpan ts = DateTime.Now - start;
				logger.Info("Get All GROUPS (Database) in {0} ms", ts.TotalMilliseconds);
				

				// anime
				start = DateTime.Now;
				List<AniDB_Anime> allAnime = repAnime.GetAll();
				Dictionary<int, AniDB_Anime> allAnimeDict = new Dictionary<int, AniDB_Anime>();
				foreach (AniDB_Anime anime in allAnime)
					allAnimeDict[anime.AnimeID] = anime;

				ts = DateTime.Now - start;
				logger.Info("Get All ANIME (Database) in {0} ms", ts.TotalMilliseconds);

				// categories
				start = DateTime.Now;
				List<AniDB_Category> allCatgeories = repCats.GetAll();
				Dictionary<int, AniDB_Category> allCatgeoriesDict = new Dictionary<int, AniDB_Category>();
				foreach (AniDB_Category cat in allCatgeories)
					allCatgeoriesDict[cat.CategoryID] = cat;


				List<AniDB_Anime_Category> allAnimeCatgeories = repAnimeCat.GetAll();
				Dictionary<int, List<int>> allAnimeCatgeoriesDict = new Dictionary<int, List<int>>(); // animeid / list of category id's
				foreach (AniDB_Anime_Category aniCat in allAnimeCatgeories)
				{
					if (!allAnimeCatgeoriesDict.ContainsKey(aniCat.AnimeID))
						allAnimeCatgeoriesDict[aniCat.AnimeID] = new List<int>();

					allAnimeCatgeoriesDict[aniCat.AnimeID].Add(aniCat.CategoryID);
				}
				ts = DateTime.Now - start;
				logger.Info("Get All CATEGORIES (Database) in {0} ms", ts.TotalMilliseconds);

				// titles
				start = DateTime.Now;
				List<AniDB_Anime_Title> allTitles = repTitles.GetAll();
				Dictionary<int, List<AniDB_Anime_Title>> allTitlesDict = new Dictionary<int, List<AniDB_Anime_Title>>(); // animeid / list of titles
				foreach (AniDB_Anime_Title aniTitle in allTitles)
				{
					if (!allTitlesDict.ContainsKey(aniTitle.AnimeID))
						allTitlesDict[aniTitle.AnimeID] = new List<AniDB_Anime_Title>();

					allTitlesDict[aniTitle.AnimeID].Add(aniTitle);
				}
				ts = DateTime.Now - start;
				logger.Info("Get All TITLES (Database) in {0} ms", ts.TotalMilliseconds);

				// user votes
				start = DateTime.Now;
				AniDB_VoteRepository repVotes = new AniDB_VoteRepository();
				List<AniDB_Vote> allVotes = repVotes.GetAll();
				ts = DateTime.Now - start;
				logger.Info("Get All VOTES (Database) in {0} ms", ts.TotalMilliseconds);

				// video quality
				start = DateTime.Now;
				AdhocRepository rep = new AdhocRepository();
				Dictionary<int, string> allVidQuality = rep.GetAllVideoQualityByGroup();

				ts = DateTime.Now - start;
				logger.Info("Get VIDEO QUALITY STATS (Database) in {0} ms", ts.TotalMilliseconds);

				// video quality episode stats
				start = DateTime.Now;
				Dictionary<int, AnimeVideoQualityStat> dictStats = rep.GetEpisodeVideoQualityStatsByAnime();
				ts = DateTime.Now - start;
				logger.Info("Get VIDEO QUALITY EPISODE STATS (Database) in {0} ms", ts.TotalMilliseconds);

				// audio and subtitle language stats
				start = DateTime.Now;
				Dictionary<int, LanguageStat> dictAudioStats = rep.GetAudioLanguageStatsForAnime();
				Dictionary<int, LanguageStat> dictSubtitleStats = rep.GetSubtitleLanguageStatsForAnime();
				ts = DateTime.Now - start;
				logger.Info("Get LANGUAGE STATS (Database) in {0} ms", ts.TotalMilliseconds);

				start = DateTime.Now;
				List<AnimeSeries> allSeries = repSeries.GetAll();
				ts = DateTime.Now - start;
				logger.Info("Get All Series (Database) in {0} ms", ts.TotalMilliseconds);

				// TvDB
				start = DateTime.Now;
				CrossRef_AniDB_TvDBV2Repository repCrossRef = new CrossRef_AniDB_TvDBV2Repository();
				List<CrossRef_AniDB_TvDBV2> allCrossRefs = repCrossRef.GetAll();
				List<int> animeWithTvDBCrossRef = new List<int>();
				foreach (CrossRef_AniDB_TvDBV2 xref in allCrossRefs)
				{
					if (!animeWithTvDBCrossRef.Contains(xref.AnimeID)) animeWithTvDBCrossRef.Add(xref.AnimeID);
				}
				ts = DateTime.Now - start;
				logger.Info("Get All AniDB->TvDB Cross Refs (Database) in {0} ms", ts.TotalMilliseconds);

				// MovieDB
				start = DateTime.Now;
				CrossRef_AniDB_OtherRepository repOtherCrossRef = new CrossRef_AniDB_OtherRepository();
				List<CrossRef_AniDB_Other> allOtherCrossRefs = repOtherCrossRef.GetAll();
				List<int> animeWithMovieCrossRef = new List<int>();
				foreach (CrossRef_AniDB_Other xref in allOtherCrossRefs)
				{
					if (!animeWithMovieCrossRef.Contains(xref.AnimeID) && xref.CrossRefType == (int)CrossRefType.MovieDB)
						animeWithMovieCrossRef.Add(xref.AnimeID);
				}
				ts = DateTime.Now - start;
				logger.Info("Get All AniDB->MovieDB Cross Refs (Database) in {0} ms", ts.TotalMilliseconds);


				// MAL
				start = DateTime.Now;
				CrossRef_AniDB_MALRepository repMALCrossRef = new CrossRef_AniDB_MALRepository();
				List<CrossRef_AniDB_MAL> allMALCrossRefs = repMALCrossRef.GetAll();
				List<int> animeWithMALCrossRef = new List<int>();
				foreach (CrossRef_AniDB_MAL xref in allMALCrossRefs)
				{
					if (!animeWithMALCrossRef.Contains(xref.AnimeID))
						animeWithMALCrossRef.Add(xref.AnimeID);
				}
				ts = DateTime.Now - start;
				logger.Info("Get All AniDB->MAL Cross Refs (Database) in {0} ms", ts.TotalMilliseconds);

				#endregion

				start = DateTime.Now;
			    var session = JMMService.SessionFactory.OpenSession();
				foreach (AnimeGroup ag in allGrps)
				{
					// get all the series for this group
					List<AnimeSeries> seriesForGroup = new List<AnimeSeries>();
					GetAnimeSeriesRecursive(ag, ref seriesForGroup, allSeries, allGroupsDict);
                    /*
					if (ag.AnimeGroupID == 915)
					{
						Console.Write("");
					}

                    */
					DateTime? Stat_AirDate_Min = null;
					DateTime? Stat_AirDate_Max = null;
					DateTime? Stat_EndDate = new DateTime(1980, 1, 1);
					DateTime? Stat_SeriesCreatedDate = null;
					bool isComplete = false;
					bool hasFinishedAiring = false;
					bool isCurrentlyAiring = false;

					List<int> categoryIDList = new List<int>();
					List<string> audioLanguageList = new List<string>();
					List<string> subtitleLanguageList = new List<string>();
					string Stat_AllTitles = "";
					string Stat_AllCategories = "";
					string Stat_AllVideoQualityEpisodes = "";
					

					decimal totalVotesPerm = 0, totalVotesTemp = 0, totalVotes = 0;
					int countVotesPerm = 0, countVotesTemp = 0, countVotes = 0;

					bool hasTvDB = true;
					bool hasMAL = true;
					bool hasMovieDB = true;
					bool hasMovieDBOrTvDB = true;

					int seriesCount = 0;
					int epCount = 0;

					foreach (AnimeSeries series in seriesForGroup)
					{
						seriesCount++;
						if (allAnimeDict.ContainsKey(series.AniDB_ID))
						{
							AniDB_Anime thisAnime = allAnimeDict[series.AniDB_ID];

							epCount = epCount + thisAnime.EpisodeCountNormal;

							// All Video Quality Episodes
							// Try to determine if this anime has all the episodes available at a certain video quality
							// e.g.  the series has all episodes in blu-ray
							if (dictStats.ContainsKey(series.AniDB_ID))
							{
								if (series.AniDB_ID == 7656)
								{
									Debug.Print("");
								}

								AnimeVideoQualityStat stat = dictStats[series.AniDB_ID];
								foreach (KeyValuePair<string, int> kvp in stat.VideoQualityEpisodeCount)
								{
									if (kvp.Value >= thisAnime.EpisodeCountNormal)
									{
										if (Stat_AllVideoQualityEpisodes.Length > 0) Stat_AllVideoQualityEpisodes += ",";
										Stat_AllVideoQualityEpisodes += kvp.Key;
									}
								}
							}

							// Calculate Air Date 
							DateTime? thisDate = thisAnime.AirDate;
							if (thisDate.HasValue)
							{
								if (Stat_AirDate_Min.HasValue)
								{
									if (thisDate.Value < Stat_AirDate_Min.Value) Stat_AirDate_Min = thisDate;
								}
								else
									Stat_AirDate_Min = thisDate;

								if (Stat_AirDate_Max.HasValue)
								{
									if (thisDate.Value > Stat_AirDate_Max.Value) Stat_AirDate_Max = thisDate;
								}
								else
									Stat_AirDate_Max = thisDate;
							}

							// calculate end date
							// if the end date is NULL it actually means it is ongoing, so this is the max possible value
							thisDate = thisAnime.EndDate;
							if (thisDate.HasValue && Stat_EndDate.HasValue)
							{
								if (thisDate.Value > Stat_EndDate.Value) Stat_EndDate = thisDate;
							}
							else
								Stat_EndDate = null;

							// Calculate Series Created Date 
							thisDate = series.DateTimeCreated;
							if (thisDate.HasValue)
							{
								if (Stat_SeriesCreatedDate.HasValue)
								{
									if (thisDate.Value < Stat_SeriesCreatedDate.Value) Stat_SeriesCreatedDate = thisDate;
								}
								else
									Stat_SeriesCreatedDate = thisDate;
							}
                            /*
							if (series.AniDB_ID == 2369)
								Debug.Write("Test");
                            */
							// Note - only one series has to be finished airing to qualify
							if (thisAnime.EndDate.HasValue && thisAnime.EndDate.Value < DateTime.Now)
								hasFinishedAiring = true;

							// Note - only one series has to be currently airing to qualify
							if (!thisAnime.EndDate.HasValue || thisAnime.EndDate.Value > DateTime.Now)
								isCurrentlyAiring = true;

							// We evaluate IsComplete as true if
							// 1. series has finished airing
							// 2. user has all episodes locally
							// Note - only one series has to be complete for the group to be considered complete
							if (thisAnime.EndDate.HasValue)
							{
								if (thisAnime.EndDate.Value < DateTime.Now && series.MissingEpisodeCount == 0 && series.MissingEpisodeCountGroups == 0)
								{
									isComplete = true;
								}
							}

							// get categories
							if (allAnimeCatgeoriesDict.ContainsKey(series.AniDB_ID))
							{
								foreach (int catID in allAnimeCatgeoriesDict[series.AniDB_ID])
								{
									if (!categoryIDList.Contains(catID)) categoryIDList.Add(catID);
								}
							}

							// get audio languages
							if (dictAudioStats.ContainsKey(series.AniDB_ID))
							{
								foreach (string lanName in dictAudioStats[series.AniDB_ID].LanguageNames)
								{
									if (!audioLanguageList.Contains(lanName)) audioLanguageList.Add(lanName);
								}
							}

							// get subtitle languages
							if (dictSubtitleStats.ContainsKey(series.AniDB_ID))
							{
								foreach (string lanName in dictSubtitleStats[series.AniDB_ID].LanguageNames)
								{
									if (!subtitleLanguageList.Contains(lanName)) subtitleLanguageList.Add(lanName);
								}
							}

							// get titles
							if (allTitlesDict.ContainsKey(series.AniDB_ID))
							{
								foreach (AniDB_Anime_Title title in allTitlesDict[series.AniDB_ID])
								{
									if (Stat_AllTitles.Length > 0) Stat_AllTitles += ",";
									Stat_AllTitles += title.Title;
								}
							}

							// get votes
							foreach (AniDB_Vote vote in allVotes)
							{
								if (vote.EntityID == series.AniDB_ID && (vote.VoteType == (int)AniDBVoteType.Anime || vote.VoteType == (int)AniDBVoteType.AnimeTemp))
								{
									countVotes++;
									totalVotes += (decimal)vote.VoteValue;

									if (vote.VoteType == (int)AniDBVoteType.Anime)
									{
										countVotesPerm++;
										totalVotesPerm += (decimal)vote.VoteValue;
									}
									if (vote.VoteType == (int)AniDBVoteType.AnimeTemp)
									{
										countVotesTemp++;
										totalVotesTemp += (decimal)vote.VoteValue;
									}

									break;
								}
							}
						}

						// for the group, if any of the series don't have a tvdb link
						// we will consider the group as not having a tvdb link
						if (!animeWithTvDBCrossRef.Contains(series.AniDB_ID)) hasTvDB = false;
						if (!animeWithMovieCrossRef.Contains(series.AniDB_ID)) hasMovieDB = false;
						if (!animeWithMALCrossRef.Contains(series.AniDB_ID)) hasMAL = false;

						if (!animeWithTvDBCrossRef.Contains(series.AniDB_ID) && !animeWithMovieCrossRef.Contains(series.AniDB_ID)) hasMovieDBOrTvDB = false;
					}

					if (allVidQuality.ContainsKey(ag.AnimeGroupID))
						StatGroupVideoQuality[ag.AnimeGroupID] = allVidQuality[ag.AnimeGroupID];
					else
						StatGroupVideoQuality[ag.AnimeGroupID] = "";

					StatGroupVideoQualityEpisodes[ag.AnimeGroupID] = Stat_AllVideoQualityEpisodes;

					StatGroupIsComplete[ag.AnimeGroupID] = isComplete;
					StatGroupIsFinishedAiring[ag.AnimeGroupID] = hasFinishedAiring;
					StatGroupIsCurrentlyAiring[ag.AnimeGroupID] = isCurrentlyAiring;
					StatGroupSeriesCount[ag.AnimeGroupID] = seriesCount;
					StatGroupEpisodeCount[ag.AnimeGroupID] = epCount;

					StatGroupTitles[ag.AnimeGroupID] = Stat_AllTitles;
					StatGroupAirDate_Max[ag.AnimeGroupID] = Stat_AirDate_Max;
					StatGroupAirDate_Min[ag.AnimeGroupID] = Stat_AirDate_Min;
					StatGroupEndDate[ag.AnimeGroupID] = Stat_EndDate;
					StatGroupSeriesCreatedDate[ag.AnimeGroupID] = Stat_SeriesCreatedDate;
					StatGroupHasTvDB[ag.AnimeGroupID] = hasTvDB;
					StatGroupHasMAL[ag.AnimeGroupID] = hasMAL;
					StatGroupHasMovieDB[ag.AnimeGroupID] = hasMovieDB;
					StatGroupHasMovieDBOrTvDB[ag.AnimeGroupID] = hasMovieDBOrTvDB;

					decimal? Stat_UserVoteOverall = null;
					if (countVotes > 0) 
						Stat_UserVoteOverall = totalVotes / (decimal)countVotes / (decimal)100;
					StatGroupUserVoteOverall[ag.AnimeGroupID] = Stat_UserVoteOverall;

					decimal? Stat_UserVotePermanent = null;
					if (countVotesPerm > 0)
						Stat_UserVotePermanent = totalVotesPerm / (decimal)countVotesPerm / (decimal)100;
					StatGroupUserVotePermanent[ag.AnimeGroupID] = Stat_UserVotePermanent;

					decimal? Stat_UserVoteTemporary = null;
					if (countVotesTemp > 0)
						Stat_UserVoteTemporary = totalVotesTemp / (decimal)countVotesTemp / (decimal)100;
					StatGroupUserVoteTemporary[ag.AnimeGroupID] = Stat_UserVoteTemporary;

					StatGroupAniDBRating[ag.AnimeGroupID] = ag.AniDBRating;

					Stat_AllCategories = "";

					foreach (int catID in categoryIDList)
					{
						if (!allCatgeoriesDict.ContainsKey(catID)) continue;

						string catName = allCatgeoriesDict[catID].CategoryName;
						if (Stat_AllCategories.Length > 0)
							Stat_AllCategories += "|";

						Stat_AllCategories += catName;
					}
					this.StatGroupCategories[ag.AnimeGroupID] = Stat_AllCategories;

					string Stat_AudioLanguages = "";
					foreach (string audioLan in audioLanguageList)
					{
						if (Stat_AudioLanguages.Length > 0) Stat_AudioLanguages += ",";
						Stat_AudioLanguages += audioLan;
					}
					this.StatGroupAudioLanguages[ag.AnimeGroupID] = Stat_AudioLanguages;

					string Stat_SubtitleLanguages = "";
					foreach (string subLan in subtitleLanguageList)
					{
						if (Stat_SubtitleLanguages.Length > 0) Stat_SubtitleLanguages += ",";
						Stat_SubtitleLanguages += subLan;
					}
					this.StatGroupSubtitleLanguages[ag.AnimeGroupID] = Stat_SubtitleLanguages;

                    UpdateGroupFilterUsingGroup(ag.AnimeGroupID);
                    UpdatePlexAnimeGroup(session, ag, allSeries);
				}


				ts = DateTime.Now - start;
				logger.Info("GetAllGroups (Contracts) in {0} ms", ts.TotalMilliseconds);

				//UpdateAllAnimeContracts();

			}
			catch (Exception ex)
			{
				logger.ErrorException(ex.ToString(), ex);
			}
		}
		public List<Contract_AnimeRating> GetAnimeRatings(int collectionState, int watchedState, int ratingVotedState, int userID)
		{
			List<Contract_AnimeRating> contracts = new List<Contract_AnimeRating>();

			try
			{
				AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
				List<AnimeSeries> series = repSeries.GetAll();
				Dictionary<int, AnimeSeries> dictSeries = new Dictionary<int, AnimeSeries>();
				foreach (AnimeSeries ser in series)
					dictSeries[ser.AniDB_ID] = ser;

				RatingCollectionState _collectionState = (RatingCollectionState)collectionState;
				RatingWatchedState _watchedState = (RatingWatchedState)watchedState;
				RatingVotedState _ratingVotedState = (RatingVotedState)ratingVotedState;

				DateTime start = DateTime.Now;

				AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();

				/*
				// build a dictionary of categories
				AniDB_CategoryRepository repCats = new AniDB_CategoryRepository();
				AniDB_Anime_CategoryRepository repAnimeCat = new AniDB_Anime_CategoryRepository();

				List<AniDB_Category> allCatgeories = repCats.GetAll();
				Dictionary<int, AniDB_Category> allCatgeoriesDict = new Dictionary<int, AniDB_Category>();
				foreach (AniDB_Category cat in allCatgeories)
					allCatgeoriesDict[cat.CategoryID] = cat;


				List<AniDB_Anime_Category> allAnimeCatgeories = repAnimeCat.GetAll();
				Dictionary<int, List<AniDB_Anime_Category>> allAnimeCatgeoriesDict = new Dictionary<int, List<AniDB_Anime_Category>>(); // 
				foreach (AniDB_Anime_Category aniCat in allAnimeCatgeories)
				{
					if (!allAnimeCatgeoriesDict.ContainsKey(aniCat.AnimeID))
						allAnimeCatgeoriesDict[aniCat.AnimeID] = new List<AniDB_Anime_Category>();

					allAnimeCatgeoriesDict[aniCat.AnimeID].Add(aniCat);
				}

				// build a dictionary of titles
				AniDB_Anime_TitleRepository repTitles = new AniDB_Anime_TitleRepository();


				List<AniDB_Anime_Title> allTitles = repTitles.GetAll();
				Dictionary<int, List<AniDB_Anime_Title>> allTitlesDict = new Dictionary<int, List<AniDB_Anime_Title>>();
				foreach (AniDB_Anime_Title title in allTitles)
				{
					if (!allTitlesDict.ContainsKey(title.AnimeID))
						allTitlesDict[title.AnimeID] = new List<AniDB_Anime_Title>();

					allTitlesDict[title.AnimeID].Add(title);
				}


				// build a dictionary of tags
				AniDB_TagRepository repTags = new AniDB_TagRepository();
				AniDB_Anime_TagRepository repAnimeTag = new AniDB_Anime_TagRepository();

				List<AniDB_Tag> allTags = repTags.GetAll();
				Dictionary<int, AniDB_Tag> allTagsDict = new Dictionary<int, AniDB_Tag>();
				foreach (AniDB_Tag tag in allTags)
					allTagsDict[tag.TagID] = tag;


				List<AniDB_Anime_Tag> allAnimeTags = repAnimeTag.GetAll();
				Dictionary<int, List<AniDB_Anime_Tag>> allAnimeTagsDict = new Dictionary<int, List<AniDB_Anime_Tag>>(); // 
				foreach (AniDB_Anime_Tag aniTag in allAnimeTags)
				{
					if (!allAnimeTagsDict.ContainsKey(aniTag.AnimeID))
						allAnimeTagsDict[aniTag.AnimeID] = new List<AniDB_Anime_Tag>();

					allAnimeTagsDict[aniTag.AnimeID].Add(aniTag);
				}

				// build a dictionary of languages
				AdhocRepository rep = new AdhocRepository();
				Dictionary<int, LanguageStat> dictAudioStats = rep.GetAudioLanguageStatsForAnime();
				Dictionary<int, LanguageStat> dictSubtitleStats = rep.GetSubtitleLanguageStatsForAnime();

				Dictionary<int, string> dictAnimeVideoQualStats = rep.GetAllVideoQualityByAnime();
				Dictionary<int, AnimeVideoQualityStat> dictAnimeEpisodeVideoQualStats = rep.GetEpisodeVideoQualityStatsByAnime();
				 * */

				List<AniDB_Anime> animes = repAnime.GetAll();

				// user votes
				AniDB_VoteRepository repVotes = new AniDB_VoteRepository();
				List<AniDB_Vote> allVotes = repVotes.GetAll();

				JMMUserRepository repUsers = new JMMUserRepository();
				JMMUser user = repUsers.GetByID(userID);
				if (user == null) return contracts;

				int i = 0;



				foreach (AniDB_Anime anime in animes)
				{
					i++;

					// evaluate collection states
					if (_collectionState == RatingCollectionState.AllEpisodesInMyCollection)
					{
						if (!anime.FinishedAiring) continue;
						if (!dictSeries.ContainsKey(anime.AnimeID)) continue;
						if (dictSeries[anime.AnimeID].MissingEpisodeCount > 0) continue;
					}

					if (_collectionState == RatingCollectionState.InMyCollection)
						if (!dictSeries.ContainsKey(anime.AnimeID)) continue;

					if (_collectionState == RatingCollectionState.NotInMyCollection)
						if (dictSeries.ContainsKey(anime.AnimeID)) continue;

					if (!user.AllowedAnime(anime)) continue;

					// evaluate watched states
					if (_watchedState == RatingWatchedState.AllEpisodesWatched)
					{
						if (!dictSeries.ContainsKey(anime.AnimeID)) continue;
						AnimeSeries_User userRec = dictSeries[anime.AnimeID].GetUserRecord(userID);
						if (userRec == null) continue;
						if (userRec.UnwatchedEpisodeCount > 0) continue;
					}

					if (_watchedState == RatingWatchedState.NotWatched)
					{
						if (dictSeries.ContainsKey(anime.AnimeID))
						{
							AnimeSeries_User userRec = dictSeries[anime.AnimeID].GetUserRecord(userID);
							if (userRec != null)
							{
								if (userRec.UnwatchedEpisodeCount == 0) continue;
							}
						}
					}

					// evaluate voted states
					if (_ratingVotedState == RatingVotedState.Voted)
					{
						bool voted = false;
						foreach (AniDB_Vote vote in allVotes)
						{
							if (vote.EntityID == anime.AnimeID && (vote.VoteType == (int)AniDBVoteType.Anime || vote.VoteType == (int)AniDBVoteType.AnimeTemp))
							{
								voted = true;
								break;
							}
						}

						if (!voted) continue;
					}

					if (_ratingVotedState == RatingVotedState.NotVoted)
					{
						bool voted = false;
						foreach (AniDB_Vote vote in allVotes)
						{
							if (vote.EntityID == anime.AnimeID && (vote.VoteType == (int)AniDBVoteType.Anime || vote.VoteType == (int)AniDBVoteType.AnimeTemp))
							{
								voted = true;
								break;
							}
						}

						if (voted) continue;
					}

					Contract_AnimeRating contract = new Contract_AnimeRating();
					contract.AnimeID = anime.AnimeID;


					Contract_AniDB_AnimeDetailed contractAnimeDetailed = new Contract_AniDB_AnimeDetailed();

					contractAnimeDetailed.AnimeTitles = new List<Contract_AnimeTitle>();
					contractAnimeDetailed.Categories = new List<Contract_AnimeCategory>();
					contractAnimeDetailed.Tags = new List<Contract_AnimeTag>();
					contractAnimeDetailed.UserVote = null;

					contractAnimeDetailed.AniDBAnime = anime.ToContract();

					/*
					if (dictAnimeVideoQualStats.ContainsKey(anime.AnimeID))
						contractAnimeDetailed.Stat_AllVideoQuality = dictAnimeVideoQualStats[anime.AnimeID];
					else contractAnimeDetailed.Stat_AllVideoQuality = "";

					contractAnimeDetailed.Stat_AllVideoQuality_Episodes = "";

					// All Video Quality Episodes
					// Try to determine if this anime has all the episodes available at a certain video quality
					// e.g.  the series has all episodes in blu-ray
					if (dictAnimeEpisodeVideoQualStats.ContainsKey(anime.AnimeID))
					{
						AnimeVideoQualityStat stat = dictAnimeEpisodeVideoQualStats[anime.AnimeID];
						foreach (KeyValuePair<string, int> kvp in stat.VideoQualityEpisodeCount)
						{
							if (kvp.Value >= anime.EpisodeCountNormal)
							{
								if (contractAnimeDetailed.Stat_AllVideoQuality_Episodes.Length > 0) contractAnimeDetailed.Stat_AllVideoQuality_Episodes += ",";
								contractAnimeDetailed.Stat_AllVideoQuality_Episodes += kvp.Key;
							}
						}
					}

					List<string> audioLanguageList = new List<string>();
					List<string> subtitleLanguageList = new List<string>();

					// get audio languages
					if (dictAudioStats.ContainsKey(anime.AnimeID))
					{
						foreach (string lanName in dictAudioStats[anime.AnimeID].LanguageNames)
						{
							if (!audioLanguageList.Contains(lanName)) audioLanguageList.Add(lanName);
						}
					}

					// get subtitle languages
					if (dictSubtitleStats.ContainsKey(anime.AnimeID))
					{
						foreach (string lanName in dictSubtitleStats[anime.AnimeID].LanguageNames)
						{
							if (!subtitleLanguageList.Contains(lanName)) subtitleLanguageList.Add(lanName);
						}
					}

					contractAnimeDetailed.Stat_AudioLanguages = "";
					foreach (string audioLan in audioLanguageList)
					{
						if (contractAnimeDetailed.Stat_AudioLanguages.Length > 0) contractAnimeDetailed.Stat_AudioLanguages += ",";
						contractAnimeDetailed.Stat_AudioLanguages += audioLan;
					}

					contractAnimeDetailed.Stat_SubtitleLanguages = "";
					foreach (string subLan in subtitleLanguageList)
					{
						if (contractAnimeDetailed.Stat_SubtitleLanguages.Length > 0) contractAnimeDetailed.Stat_SubtitleLanguages += ",";
						contractAnimeDetailed.Stat_SubtitleLanguages += subLan;
					}


					if (allTitlesDict.ContainsKey(anime.AnimeID))
					{
						foreach (AniDB_Anime_Title title in allTitlesDict[anime.AnimeID])
						{
							Contract_AnimeTitle ctitle = new Contract_AnimeTitle();
							ctitle.AnimeID = title.AnimeID;
							ctitle.Language = title.Language;
							ctitle.Title = title.Title;
							ctitle.TitleType = title.TitleType;
							contractAnimeDetailed.AnimeTitles.Add(ctitle);
						}
					}


					if (allAnimeCatgeoriesDict.ContainsKey(anime.AnimeID))
					{
						List<AniDB_Anime_Category> aniCats = allAnimeCatgeoriesDict[anime.AnimeID];
						foreach (AniDB_Anime_Category aniCat in aniCats)
						{
							if (allCatgeoriesDict.ContainsKey(aniCat.CategoryID))
							{
								AniDB_Category cat = allCatgeoriesDict[aniCat.CategoryID];

								Contract_AnimeCategory ccat = new Contract_AnimeCategory();
								ccat.CategoryDescription = cat.CategoryDescription;
								ccat.CategoryID = cat.CategoryID;
								ccat.CategoryName = cat.CategoryName;
								ccat.IsHentai = cat.IsHentai;
								ccat.ParentID = cat.ParentID;
								ccat.Weighting = aniCat.Weighting;
								contractAnimeDetailed.Categories.Add(ccat);

							}
						}
					}

					if (allAnimeTagsDict.ContainsKey(anime.AnimeID))
					{
						List<AniDB_Anime_Tag> aniTags = allAnimeTagsDict[anime.AnimeID];
						foreach (AniDB_Anime_Tag aniTag in aniTags)
						{
							if (allTagsDict.ContainsKey(aniTag.TagID))
							{
								AniDB_Tag tag = allTagsDict[aniTag.TagID];

								Contract_AnimeTag ctag = new Contract_AnimeTag();
								ctag.Approval = aniTag.Approval;
								ctag.GlobalSpoiler = tag.GlobalSpoiler;
								ctag.LocalSpoiler = tag.LocalSpoiler;
								ctag.Spoiler = tag.Spoiler;
								ctag.TagCount = tag.TagCount;
								ctag.TagDescription = tag.TagDescription;
								ctag.TagID = tag.TagID;
								ctag.TagName = tag.TagName;
								contractAnimeDetailed.Tags.Add(ctag);
							}
						}
					}*/

					// get user vote
					foreach (AniDB_Vote vote in allVotes)
					{
						if (vote.EntityID == anime.AnimeID && (vote.VoteType == (int)AniDBVoteType.Anime || vote.VoteType == (int)AniDBVoteType.AnimeTemp))
						{
							contractAnimeDetailed.UserVote = vote.ToContract();
							break;
						}
					}

					contract.AnimeDetailed = contractAnimeDetailed;

					if (dictSeries.ContainsKey(anime.AnimeID))
					{
						contract.AnimeSeries = dictSeries[anime.AnimeID].ToContract(dictSeries[anime.AnimeID].GetUserRecord(userID));
					}

					contracts.Add(contract);

				}
			}
			catch (Exception ex)
			{
				logger.ErrorException(ex.ToString(), ex);
			}
			return contracts;
		}
Exemple #14
0
		public static void RunImport_UpdateAllAniDB()
		{
			AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
			foreach (AniDB_Anime anime in repAnime.GetAll())
			{
				CommandRequest_GetAnimeHTTP cmd = new CommandRequest_GetAnimeHTTP(anime.AnimeID, true, false);
				cmd.Save();
			}
		}
Exemple #15
0
		public static void RunImport_GetImages()
		{
			// AniDB posters
			AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
			foreach (AniDB_Anime anime in repAnime.GetAll())
			{
				if (anime.AnimeID == 8580)
					Console.Write("");

				if (string.IsNullOrEmpty(anime.PosterPath)) continue;

				bool fileExists = File.Exists(anime.PosterPath);
				if (!fileExists)
				{
					CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(anime.AniDB_AnimeID, JMMImageType.AniDB_Cover, false);
					cmd.Save();
				}
			}

			// TvDB Posters
			if (ServerSettings.TvDB_AutoPosters)
			{
				TvDB_ImagePosterRepository repTvPosters = new TvDB_ImagePosterRepository();
				Dictionary<int, int> postersCount = new Dictionary<int, int>();

				// build a dictionary of series and how many images exist
				List<TvDB_ImagePoster> allPosters = repTvPosters.GetAll();
				foreach (TvDB_ImagePoster tvPoster in allPosters)
				{
					if (string.IsNullOrEmpty(tvPoster.FullImagePath)) continue;
					bool fileExists = File.Exists(tvPoster.FullImagePath);

					if (fileExists)
					{
						if (postersCount.ContainsKey(tvPoster.SeriesID))
							postersCount[tvPoster.SeriesID] = postersCount[tvPoster.SeriesID] + 1;
						else
							postersCount[tvPoster.SeriesID] = 1;
					}
				}

				foreach (TvDB_ImagePoster tvPoster in allPosters)
				{
					if (string.IsNullOrEmpty(tvPoster.FullImagePath)) continue;
					bool fileExists = File.Exists(tvPoster.FullImagePath);

					int postersAvailable = 0;
					if (postersCount.ContainsKey(tvPoster.SeriesID))
						postersAvailable = postersCount[tvPoster.SeriesID];

					if (!fileExists && postersAvailable < ServerSettings.TvDB_AutoPostersAmount)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(tvPoster.TvDB_ImagePosterID, JMMImageType.TvDB_Cover, false);
						cmd.Save();
					}
				}
			}

			// TvDB Fanart
			if (ServerSettings.TvDB_AutoFanart)
			{
				Dictionary<int, int> fanartCount = new Dictionary<int, int>();
				TvDB_ImageFanartRepository repTvFanart = new TvDB_ImageFanartRepository();

				List<TvDB_ImageFanart> allFanart = repTvFanart.GetAll();
				foreach (TvDB_ImageFanart tvFanart in allFanart)
				{
					// build a dictionary of series and how many images exist
					if (string.IsNullOrEmpty(tvFanart.FullImagePath)) continue;
					bool fileExists = File.Exists(tvFanart.FullImagePath);

					if (fileExists)
					{
						if (fanartCount.ContainsKey(tvFanart.SeriesID))
							fanartCount[tvFanart.SeriesID] = fanartCount[tvFanart.SeriesID] + 1;
						else
							fanartCount[tvFanart.SeriesID] = 1;
					}
				}

				foreach (TvDB_ImageFanart tvFanart in allFanart)
				{
					if (string.IsNullOrEmpty(tvFanart.FullImagePath)) continue;
					bool fileExists = File.Exists(tvFanart.FullImagePath);

					int fanartAvailable = 0;
					if (fanartCount.ContainsKey(tvFanart.SeriesID))
						fanartAvailable = fanartCount[tvFanart.SeriesID];

					if (!fileExists && fanartAvailable < ServerSettings.TvDB_AutoFanartAmount)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(tvFanart.TvDB_ImageFanartID, JMMImageType.TvDB_FanArt, false);
						cmd.Save();
						fanartCount[tvFanart.SeriesID] = fanartAvailable + 1;
					}
				}
			}

			// TvDB Wide Banners
			if (ServerSettings.TvDB_AutoWideBanners)
			{
				TvDB_ImageWideBannerRepository repTvBanners = new TvDB_ImageWideBannerRepository();
				Dictionary<int, int> fanartCount = new Dictionary<int, int>();

				// build a dictionary of series and how many images exist
				List<TvDB_ImageWideBanner> allBanners = repTvBanners.GetAll();
				foreach (TvDB_ImageWideBanner tvBanner in allBanners)
				{
					if (string.IsNullOrEmpty(tvBanner.FullImagePath)) continue;
					bool fileExists = File.Exists(tvBanner.FullImagePath);

					if (fileExists)
					{
						if (fanartCount.ContainsKey(tvBanner.SeriesID))
							fanartCount[tvBanner.SeriesID] = fanartCount[tvBanner.SeriesID] + 1;
						else
							fanartCount[tvBanner.SeriesID] = 1;
					}
				}

				foreach (TvDB_ImageWideBanner tvBanner in allBanners)
				{
					if (string.IsNullOrEmpty(tvBanner.FullImagePath)) continue;
					bool fileExists = File.Exists(tvBanner.FullImagePath);

					int bannersAvailable = 0;
					if (fanartCount.ContainsKey(tvBanner.SeriesID))
						bannersAvailable = fanartCount[tvBanner.SeriesID];

					if (!fileExists && bannersAvailable < ServerSettings.TvDB_AutoWideBannersAmount)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(tvBanner.TvDB_ImageWideBannerID, JMMImageType.TvDB_Banner, false);
						cmd.Save();
					}
				}
			}

			// TvDB Episodes
			TvDB_EpisodeRepository repTvEpisodes = new TvDB_EpisodeRepository();
			foreach (TvDB_Episode tvEpisode in repTvEpisodes.GetAll())
			{
				if (string.IsNullOrEmpty(tvEpisode.FullImagePath)) continue;
				bool fileExists = File.Exists(tvEpisode.FullImagePath);
				if (!fileExists)
				{
					CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(tvEpisode.TvDB_EpisodeID, JMMImageType.TvDB_Episode, false);
					cmd.Save();
				}
			}

			// MovieDB Posters
			if (ServerSettings.MovieDB_AutoPosters)
			{
				MovieDB_PosterRepository repMoviePosters = new MovieDB_PosterRepository();
				Dictionary<int, int> postersCount = new Dictionary<int, int>();

				// build a dictionary of series and how many images exist
				List<MovieDB_Poster> allPosters = repMoviePosters.GetAll();
				foreach (MovieDB_Poster moviePoster in allPosters)
				{
					if (string.IsNullOrEmpty(moviePoster.FullImagePath)) continue;
					bool fileExists = File.Exists(moviePoster.FullImagePath);

					if (fileExists)
					{
						if (postersCount.ContainsKey(moviePoster.MovieId))
							postersCount[moviePoster.MovieId] = postersCount[moviePoster.MovieId] + 1;
						else
							postersCount[moviePoster.MovieId] = 1;
					}
				}

				foreach (MovieDB_Poster moviePoster in allPosters)
				{
					if (string.IsNullOrEmpty(moviePoster.FullImagePath)) continue;
					bool fileExists = File.Exists(moviePoster.FullImagePath);

					int postersAvailable = 0;
					if (postersCount.ContainsKey(moviePoster.MovieId))
						postersAvailable = postersCount[moviePoster.MovieId];

					if (!fileExists && postersAvailable < ServerSettings.MovieDB_AutoPostersAmount)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(moviePoster.MovieDB_PosterID, JMMImageType.MovieDB_Poster, false);
						cmd.Save();
					}
				}
			}

			// MovieDB Fanart
			if (ServerSettings.MovieDB_AutoFanart)
			{
				MovieDB_FanartRepository repMovieFanarts = new MovieDB_FanartRepository();
				Dictionary<int, int> fanartCount = new Dictionary<int, int>();

				// build a dictionary of series and how many images exist
				List<MovieDB_Fanart> allFanarts = repMovieFanarts.GetAll();
				foreach (MovieDB_Fanart movieFanart in allFanarts)
				{
					if (string.IsNullOrEmpty(movieFanart.FullImagePath)) continue;
					bool fileExists = File.Exists(movieFanart.FullImagePath);

					if (fileExists)
					{
						if (fanartCount.ContainsKey(movieFanart.MovieId))
							fanartCount[movieFanart.MovieId] = fanartCount[movieFanart.MovieId] + 1;
						else
							fanartCount[movieFanart.MovieId] = 1;
					}
				}

				foreach (MovieDB_Fanart movieFanart in repMovieFanarts.GetAll())
				{
					if (string.IsNullOrEmpty(movieFanart.FullImagePath)) continue;
					bool fileExists = File.Exists(movieFanart.FullImagePath);

					int fanartAvailable = 0;
					if (fanartCount.ContainsKey(movieFanart.MovieId))
						fanartAvailable = fanartCount[movieFanart.MovieId];

					if (!fileExists && fanartAvailable < ServerSettings.MovieDB_AutoFanartAmount)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(movieFanart.MovieDB_FanartID, JMMImageType.MovieDB_FanArt, false);
						cmd.Save();
					}
				}
			}

			// Trakt Posters
			if (ServerSettings.Trakt_DownloadPosters)
			{
				Trakt_ImagePosterRepository repTraktPosters = new Trakt_ImagePosterRepository();
				foreach (Trakt_ImagePoster traktPoster in repTraktPosters.GetAll())
				{
					if (string.IsNullOrEmpty(traktPoster.FullImagePath)) continue;
					bool fileExists = File.Exists(traktPoster.FullImagePath);
					if (!fileExists)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(traktPoster.Trakt_ImagePosterID, JMMImageType.Trakt_Poster, false);
						cmd.Save();
					}
				}
			}

			// Trakt Fanart
			if (ServerSettings.Trakt_DownloadFanart)
			{
				Trakt_ImageFanartRepository repTraktFanarts = new Trakt_ImageFanartRepository();
				foreach (Trakt_ImageFanart traktFanart in repTraktFanarts.GetAll())
				{
					if (string.IsNullOrEmpty(traktFanart.FullImagePath)) continue;
					bool fileExists = File.Exists(traktFanart.FullImagePath);
					if (!fileExists)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(traktFanart.Trakt_ImageFanartID, JMMImageType.Trakt_Fanart, false);
						cmd.Save();
					}
				}
			}

			// Trakt Episode
			if (ServerSettings.Trakt_DownloadEpisodes)
			{
				Trakt_EpisodeRepository repTraktEpisodes = new Trakt_EpisodeRepository();
				foreach (Trakt_Episode traktEp in repTraktEpisodes.GetAll())
				{
					if (string.IsNullOrEmpty(traktEp.FullImagePath)) continue;
					bool fileExists = File.Exists(traktEp.FullImagePath);
					if (!fileExists)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(traktEp.Trakt_EpisodeID, JMMImageType.Trakt_Episode, false);
						cmd.Save();
					}
				}
			}

			// AniDB Characters
			if (ServerSettings.AniDB_DownloadCharacters)
			{
				AniDB_CharacterRepository repChars = new AniDB_CharacterRepository();
				foreach (AniDB_Character chr in repChars.GetAll())
				{
					if (string.IsNullOrEmpty(chr.PosterPath)) continue;
					bool fileExists = File.Exists(chr.PosterPath);
					if (!fileExists)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(chr.AniDB_CharacterID, JMMImageType.AniDB_Character, false);
						cmd.Save();
					}
				}
			}

			// AniDB Creators
			if (ServerSettings.AniDB_DownloadCreators)
			{
				AniDB_SeiyuuRepository repSeiyuu = new AniDB_SeiyuuRepository();
				foreach (AniDB_Seiyuu seiyuu in repSeiyuu.GetAll())
				{
					if (string.IsNullOrEmpty(seiyuu.PosterPath)) continue;
					bool fileExists = File.Exists(seiyuu.PosterPath);
					if (!fileExists)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(seiyuu.AniDB_SeiyuuID, JMMImageType.AniDB_Creator, false);
						cmd.Save();
					}
				}
			}
		}