protected void Page_Load(object sender, EventArgs e) { Response.ContentType = "text/xml"; try { string aid = Utils.GetParam("AnimeID"); int animeid = 0; int.TryParse(aid, out animeid); if (animeid <= 0) { Response.Write(Constants.ERROR_XML); return; } string xtype = Utils.GetParam("CrossRefType"); int xrefType = 0; int.TryParse(xtype, out xrefType); if (xrefType <= 0) { Response.Write(Constants.ERROR_XML); return; } string uname = Utils.GetParam("uname"); if (uname.Trim().Length == 0) { Response.Write(Constants.ERROR_XML); return; } CrossRef_AniDB_OtherRepository repCrossRef = new CrossRef_AniDB_OtherRepository(); CrossRef_AniDB_Other xref = null; // check for user specific List <CrossRef_AniDB_Other> recs; if (xref == null) { recs = repCrossRef.GetByAnimeIDAndTypeAndUser(animeid, uname, (CrossRefType)xrefType); if (recs.Count > 0) { xref = recs[0]; // should only be one } } // check for other users (anonymous) if (xref == null) { // check for other users (anonymous) recs = repCrossRef.GetByAnimeIDAndType(animeid, (CrossRefType)xrefType); if (recs.Count == 0) { Response.Write(Constants.ERROR_XML); return; } // find the most popular result List <CrossRefStatOther> results = new List <CrossRefStatOther>(); foreach (CrossRef_AniDB_Other xrefloc in recs) { bool found = false; foreach (CrossRefStatOther stat in results) { if (stat.CrossRefID.Equals(xrefloc.CrossRefID, StringComparison.InvariantCultureIgnoreCase)) { found = true; stat.ResultCount++; } } if (!found) { CrossRefStatOther stat = new CrossRefStatOther(); stat.ResultCount = 1; stat.CrossRefID = xrefloc.CrossRefID; stat.CrossRef = xrefloc; results.Add(stat); } } CrossRefStatOther mostPopular = null; foreach (CrossRefStatOther stat in results) { if (mostPopular == null) { mostPopular = stat; } else { if (stat.ResultCount > mostPopular.ResultCount) { mostPopular = stat; } } } xref = mostPopular.CrossRef; } CrossRef_AniDB_OtherResult result = new CrossRef_AniDB_OtherResult(xref); string ret = Utils.ConvertToXML(result, typeof(CrossRef_AniDB_OtherResult)); Response.Write(ret); } catch (Exception ex) { Response.Write(ex.ToString()); return; } }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_MovieDBSearchAnime: {0}", AnimeID); try { using (var session = JMMService.SessionFactory.OpenSession()) { // first check if the user wants to use the web cache if (ServerSettings.WebCache_TvDB_Get) { try { MovieDB_MovieRepository repMovies = new MovieDB_MovieRepository(); CrossRef_AniDB_OtherResult crossRef = XMLService.Get_CrossRef_AniDB_Other(AnimeID, CrossRefType.MovieDB); if (crossRef != null) { int movieID = int.Parse(crossRef.CrossRefID); MovieDB_Movie movie = repMovies.GetByOnlineID(session, movieID); if (movie == null) { // update the info from online MovieDBHelper.UpdateMovieInfo(session, movieID, true); movie = repMovies.GetByOnlineID(movieID); } if (movie != null) { // since we are using the web cache result, let's save it MovieDBHelper.LinkAniDBMovieDB(AnimeID, movieID, true); return; } } } catch (Exception) { } } string searchCriteria = ""; AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anime = repAnime.GetByAnimeID(session, AnimeID); if (anime == null) { return; } searchCriteria = anime.MainTitle; // if not wanting to use web cache, or no match found on the web cache go to TvDB directly List <MovieDB_Movie_Result> results = MovieDBHelper.Search(searchCriteria); logger.Trace("Found {0} moviedb results for {1} on TheTvDB", results.Count, searchCriteria); if (ProcessSearchResults(session, results, searchCriteria)) { return; } if (results.Count == 0) { foreach (AniDB_Anime_Title title in anime.GetTitles(session)) { if (title.TitleType.ToUpper() != Constants.AnimeTitleType.Official.ToUpper()) { continue; } if (searchCriteria.ToUpper() == title.Title.ToUpper()) { continue; } results = MovieDBHelper.Search(title.Title); logger.Trace("Found {0} moviedb results for search on {1}", results.Count, title.Title); if (ProcessSearchResults(session, results, title.Title)) { return; } } } } } catch (Exception ex) { logger.Error("Error processing CommandRequest_TvDBSearchAnime: {0} - {1}", AnimeID, ex.ToString()); return; } }