public static void LinkAniDBMovieDB(int animeID, int movieDBID, bool fromWebCache) { // check if we have this information locally // if not download it now MovieDB_MovieRepository repMovies = new MovieDB_MovieRepository(); MovieDB_Movie movie = repMovies.GetByOnlineID(movieDBID); if (movie == null) { // we download the series info here just so that we have the basic info in the // database before the queued task runs later UpdateMovieInfo(movieDBID, false); movie = repMovies.GetByOnlineID(movieDBID); if (movie == null) { return; } } // download and update series info and images UpdateMovieInfo(movieDBID, true); CrossRef_AniDB_OtherRepository repCrossRef = new CrossRef_AniDB_OtherRepository(); CrossRef_AniDB_Other xref = repCrossRef.GetByAnimeIDAndType(animeID, CrossRefType.MovieDB); if (xref == null) { xref = new CrossRef_AniDB_Other(); } xref.AnimeID = animeID; if (fromWebCache) { xref.CrossRefSource = (int)CrossRefSource.WebCache; } else { xref.CrossRefSource = (int)CrossRefSource.User; } xref.CrossRefType = (int)CrossRefType.MovieDB; xref.CrossRefID = movieDBID.ToString(); repCrossRef.Save(xref); AniDB_Anime.UpdateStatsByAnimeID(animeID); logger.Trace("Changed moviedb association: {0}", animeID); CommandRequest_WebCacheSendXRefAniDBOther req = new CommandRequest_WebCacheSendXRefAniDBOther(xref.CrossRef_AniDB_OtherID); req.Save(); }
public static void RemoveLinkAniDBMovieDB(int animeID) { CrossRef_AniDB_OtherRepository repCrossRef = new CrossRef_AniDB_OtherRepository(); CrossRef_AniDB_Other xref = repCrossRef.GetByAnimeIDAndType(animeID, CrossRefType.MovieDB); if (xref == null) { return; } repCrossRef.Delete(xref.CrossRef_AniDB_OtherID); CommandRequest_WebCacheDeleteXRefAniDBOther req = new CommandRequest_WebCacheDeleteXRefAniDBOther(animeID, CrossRefType.MovieDB); req.Save(); }
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; } }