protected void Page_Load(object sender, EventArgs e)
        {
            Response.ContentType = "text/xml";

            try
            {
                CrossRef_AniDB_TvDBRepository repCrossRef = new CrossRef_AniDB_TvDBRepository();

                StreamReader reader  = new StreamReader(this.Request.InputStream);
                String       xmlData = reader.ReadToEnd();

                XmlDocument docXRef = new XmlDocument();
                docXRef.LoadXml(xmlData);

                string uname = Utils.TryGetProperty("DeleteCrossRef_AniDB_TvDBRequest", docXRef, "Username");

                string aid     = Utils.TryGetProperty("DeleteCrossRef_AniDB_TvDBRequest", 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_TvDB> recs = repCrossRef.GetByAnimeIDUser(animeid, uname);
                foreach (CrossRef_AniDB_TvDB xref in recs)
                {
                    repCrossRef.Delete(xref.CrossRef_AniDB_TvDBID);
                }

                // now send to mirror
                string uri = string.Format("http://{0}/DeleteCrossRef_AniDB_TvDB.aspx", Constants.MirrorWAIX);
                XMLService.SendData(uri, xmlData);
            }
            catch (Exception ex)
            {
                Response.Write(Constants.ERROR_XML);
            }
        }
예제 #2
0
        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 uname = Utils.GetParam("uname");
                if (uname.Trim().Length == 0)
                {
                    Response.Write(Constants.ERROR_XML);
                    return;
                }

                CrossRef_AniDB_TvDBRepository repCrossRef = new CrossRef_AniDB_TvDBRepository();
                CrossRef_AniDB_TvDB           xref        = null;

                // check for admin approved
                List <CrossRef_AniDB_TvDB> recs = repCrossRef.GetByAnimeIDApproved(animeid);
                if (recs.Count > 0)
                {
                    xref = recs[0];                                 // should only be one
                }
                // check for user specific
                if (xref == null)
                {
                    recs = repCrossRef.GetByAnimeIDUser(animeid, uname);
                    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.GetByAnimeID(animeid);
                    if (recs.Count == 0)
                    {
                        Response.Write(Constants.ERROR_XML);
                        return;
                    }

                    // find the most popular result

                    List <CrossRefStat> results = new List <CrossRefStat>();
                    foreach (CrossRef_AniDB_TvDB xrefloc in recs)
                    {
                        bool found = false;
                        foreach (CrossRefStat stat in results)
                        {
                            if (stat.TvDBID == xrefloc.TvDBID && stat.TvDBSeason == xrefloc.TvDBSeasonNumber)
                            {
                                found = true;
                                stat.ResultCount++;
                            }
                        }
                        if (!found)
                        {
                            CrossRefStat stat = new CrossRefStat();
                            stat.ResultCount = 1;
                            stat.TvDBID      = xrefloc.TvDBID;
                            stat.TvDBSeason  = xrefloc.TvDBSeasonNumber;
                            stat.CrossRef    = xrefloc;
                            results.Add(stat);
                        }
                    }

                    CrossRefStat mostPopular = null;
                    foreach (CrossRefStat stat in results)
                    {
                        if (mostPopular == null)
                        {
                            mostPopular = stat;
                        }
                        else
                        {
                            if (stat.ResultCount > mostPopular.ResultCount)
                            {
                                mostPopular = stat;
                            }
                        }
                    }

                    xref = mostPopular.CrossRef;
                }

                CrossRef_AniDB_TvDBResult result = new CrossRef_AniDB_TvDBResult(xref);
                string ret = Utils.ConvertToXML(result, typeof(CrossRef_AniDB_TvDBResult));
                Response.Write(ret);
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
                return;
            }
        }
예제 #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.ContentType = "text/xml";

            try
            {
                CrossRef_AniDB_TvDBRepository repCrossRef = new CrossRef_AniDB_TvDBRepository();

                StreamReader reader  = new StreamReader(this.Request.InputStream);
                String       xmlData = reader.ReadToEnd();

                XmlDocument docXRef = new XmlDocument();
                docXRef.LoadXml(xmlData);

                string uname = Utils.TryGetProperty("AddCrossRef_AniDB_TvDB_Request", docXRef, "Username");
                string sname = Utils.TryGetProperty("AddCrossRef_AniDB_TvDB_Request", docXRef, "SeriesName");

                string aid     = Utils.TryGetProperty("AddCrossRef_AniDB_TvDB_Request", docXRef, "AnimeID");
                int    animeid = 0;
                int.TryParse(aid, out animeid);

                string tvid   = Utils.TryGetProperty("AddCrossRef_AniDB_TvDB_Request", docXRef, "TvDBID");
                int    tvDBID = 0;
                int.TryParse(tvid, out tvDBID);

                string tvseason   = Utils.TryGetProperty("AddCrossRef_AniDB_TvDB_Request", docXRef, "TvDBSeason");
                int    tvDBSeason = 0;
                if (!int.TryParse(tvseason, out tvDBSeason))
                {
                    Response.Write(Constants.ERROR_XML);
                    return;
                }


                if (string.IsNullOrEmpty(uname) || animeid <= 0 || tvDBID <= 0)
                {
                    Response.Write(Constants.ERROR_XML);
                    return;
                }

                CrossRef_AniDB_TvDB        xref = null;
                List <CrossRef_AniDB_TvDB> recs = repCrossRef.GetByAnimeIDUser(animeid, uname);
                if (recs.Count == 1)
                {
                    xref = recs[0];
                }

                if (recs.Count == 0)
                {
                    xref = new CrossRef_AniDB_TvDB();
                }
                else
                {
                    xref = recs[0];
                }

                xref.AnimeID          = animeid;
                xref.AdminApproved    = 0;
                xref.CrossRefSource   = 1;
                xref.TvDBID           = tvDBID;
                xref.TvDBSeasonNumber = tvDBSeason;
                xref.Username         = uname;
                xref.SeriesName       = sname;
                repCrossRef.Save(xref);

                // now send to mirror
                string uri = string.Format("http://{0}/AddCrossRef_AniDB_TvDB.aspx", Constants.MirrorWAIX);
                XMLService.SendData(uri, xmlData);
            }
            catch (Exception ex)
            {
                Response.Write(Constants.ERROR_XML);
            }
        }