public static void FixDuplicateTraktLinks() { AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); // delete all Trakt link duplicates CrossRef_AniDB_TraktRepository repCrossRefTrakt = new CrossRef_AniDB_TraktRepository(); List <CrossRef_AniDB_Trakt> xrefsTraktProcessed = new List <CrossRef_AniDB_Trakt>(); List <CrossRef_AniDB_Trakt> xrefsTraktToBeDeleted = new List <CrossRef_AniDB_Trakt>(); List <CrossRef_AniDB_Trakt> xrefsTrakt = repCrossRefTrakt.GetAll(); foreach (CrossRef_AniDB_Trakt xrefTrakt in xrefsTrakt) { bool deleteXref = false; foreach (CrossRef_AniDB_Trakt xref in xrefsTraktProcessed) { if (xref.TraktID == xrefTrakt.TraktID && xref.TraktSeasonNumber == xrefTrakt.TraktSeasonNumber) { xrefsTraktToBeDeleted.Add(xrefTrakt); deleteXref = true; } } if (!deleteXref) { xrefsTraktProcessed.Add(xrefTrakt); } } foreach (CrossRef_AniDB_Trakt xref in xrefsTraktToBeDeleted) { string msg = ""; AniDB_Anime anime = repAnime.GetByAnimeID(xref.AnimeID); if (anime != null) { msg = anime.MainTitle; } logger.Warn("Deleting Trakt Link because of a duplicate: {0} ({1}) - {2}/{3}", xref.AnimeID, msg, xref.TraktID, xref.TraktSeasonNumber); repCrossRefTrakt.Delete(xref.CrossRef_AniDB_TraktID); } }
protected void Page_Load(object sender, EventArgs e) { Response.ContentType = "text/xml"; try { CrossRef_AniDB_TraktRepository repCrossRef = new CrossRef_AniDB_TraktRepository(); StreamReader reader = new StreamReader(this.Request.InputStream); String xmlData = reader.ReadToEnd(); XmlDocument docXRef = new XmlDocument(); docXRef.LoadXml(xmlData); string uname = Utils.TryGetProperty("DeleteCrossRef_AniDB_TraktRequest", docXRef, "Username"); string aid = Utils.TryGetProperty("DeleteCrossRef_AniDB_TraktRequest", docXRef, "AnimeID"); int animeid = 0; int.TryParse(aid, out animeid); if (string.IsNullOrEmpty(uname) || animeid <= 0) { Response.Write(Constants.ERROR_XML); return; } List <CrossRef_AniDB_Trakt> recs = repCrossRef.GetByAnimeIDUser(animeid, uname); foreach (CrossRef_AniDB_Trakt xref in recs) { repCrossRef.Delete(xref.CrossRef_AniDB_TraktID); } // now send to mirror string uri = string.Format("http://{0}/DeleteCrossRef_AniDB_Trakt.aspx", Constants.MirrorWAIX); XMLService.SendData(uri, xmlData); } catch (Exception ex) { Response.Write(Constants.ERROR_XML); } }