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