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

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

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

                string hash  = Utils.TryGetProperty("DeleteCrossRef_File_EpisodeRequest", docXRef, "Hash").Trim().ToUpper();
                string uname = Utils.TryGetProperty("DeleteCrossRef_File_EpisodeRequest", docXRef, "Uname");

                // anonymous uers will not get this benefit
                if (uname.ToLower() == Utils.AnonWebCacheUsername.ToLower())
                {
                    return;
                }

                string eid       = Utils.TryGetProperty("DeleteCrossRef_File_EpisodeRequest", docXRef, "EpisodeID");
                int    episodeID = 0;
                int.TryParse(eid, out episodeID);

                CrossRef_File_Episode_Rep    repCrossRef = new CrossRef_File_Episode_Rep();
                List <CrossRef_File_Episode> recs        = repCrossRef.GetByHashAndUsername(hash, uname);
                foreach (CrossRef_File_Episode xref in recs)
                {
                    if (xref.EpisodeID == episodeID)
                    {
                        repCrossRef.Delete(xref.CrossRef_File_EpisodeID);
                    }
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
                return;
            }
        }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.ContentType = "text/xml";

            try
            {
                Response.Write(Constants.ERROR_XML);
                return;

                CrossRef_File_Episode_Rep repCrossRef = new CrossRef_File_Episode_Rep();

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

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

                string hash  = Utils.TryGetProperty("CrossRef_File_EpisodeRequest", docXRef, "Hash").Trim().ToUpper();
                string uname = Utils.TryGetProperty("CrossRef_File_EpisodeRequest", docXRef, "Uname");

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

                string eid       = Utils.TryGetProperty("CrossRef_File_EpisodeRequest", docXRef, "EpisodeID");
                int    episodeID = 0;
                int.TryParse(eid, out episodeID);

                string pct        = Utils.TryGetProperty("CrossRef_File_EpisodeRequest", docXRef, "Percentage");
                int    percentage = 0;
                int.TryParse(pct, out percentage);

                string eo      = Utils.TryGetProperty("CrossRef_File_EpisodeRequest", docXRef, "EpisodeOrder");
                int    eporder = 0;
                int.TryParse(eo, out eporder);

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

                CrossRef_File_Episode        xref = null;
                List <CrossRef_File_Episode> recs = repCrossRef.GetByHashUsernameAndEpisodeID(hash, uname, episodeID);
                if (recs.Count == 1)
                {
                    xref = recs[0];
                }

                if (recs.Count == 0)
                {
                    xref = new CrossRef_File_Episode();
                }

                if (recs.Count > 1)
                {
                    foreach (CrossRef_File_Episode rec in recs)
                    {
                        repCrossRef.Delete(rec.CrossRef_File_EpisodeID);
                    }
                    xref = new CrossRef_File_Episode();
                }

                xref.DateTimeUpdated = DateTime.Now;
                xref.AnimeID         = animeid;
                xref.EpisodeID       = episodeID;
                xref.EpisodeOrder    = eporder;
                xref.Percentage      = percentage;
                xref.Hash            = hash;
                xref.Username        = uname;
                repCrossRef.Save(xref);
            }
            catch (Exception ex)
            {
                Response.Write(Constants.ERROR_XML);
            }
        }
Ejemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.ContentType = "text/xml";

            try
            {
                Response.Write(Constants.ERROR_XML);
                return;

                string hash = Utils.GetParam("hash");
                if (hash.Trim().Length == 0)
                {
                    Response.Write(Constants.ERROR_XML);
                    return;
                }

                string uname = Utils.GetParam("uname");
                if (uname.Trim().Length == 0)
                {
                    Response.Write(Constants.ERROR_XML);
                    return;
                }

                CrossRef_File_EpisodeResultCollection colResults  = new CrossRef_File_EpisodeResultCollection();
                CrossRef_File_Episode_Rep             repCrossRef = new CrossRef_File_Episode_Rep();

                // check for user specific
                List <CrossRef_File_Episode> recs = repCrossRef.GetByHashAndUsername(hash, uname);
                if (recs.Count == 0)
                {
                    // check for other users (anonymous)
                    recs = repCrossRef.GetByHash(hash);

                    int  lastAnimeID  = -1;
                    bool invalidAnime = false;
                    foreach (CrossRef_File_Episode xref in recs)
                    {
                        if (lastAnimeID < 0)
                        {
                            lastAnimeID = xref.AnimeID;
                        }
                        if (lastAnimeID != xref.AnimeID)
                        {
                            invalidAnime = true;
                        }
                    }

                    // if we have one file which has been assigned episodes across multiple anime, something has gone
                    // wrong somewhere. So let's delete all the records for this hash so we can start again
                    // This case is for anonymous users, so this scenario could be likely
                    if (invalidAnime)
                    {
                        foreach (CrossRef_File_Episode xref in recs)
                        {
                            repCrossRef.Delete(xref.CrossRef_File_EpisodeID);
                        }

                        Response.Write(Constants.ERROR_XML);
                        return;
                    }
                }
                else
                {
                    // make sure all the episodes belong to the same anime
                    int  lastAnimeID  = -1;
                    bool invalidAnime = false;
                    foreach (CrossRef_File_Episode xref in recs)
                    {
                        if (lastAnimeID < 0)
                        {
                            lastAnimeID = xref.AnimeID;
                        }
                        if (lastAnimeID != xref.AnimeID)
                        {
                            invalidAnime = true;
                        }
                    }

                    // if we have one file which has been assigned episodes across multiple anime, something has gone
                    // wrong somewhere. So let's delete all the records for this hash so we can start again
                    if (invalidAnime)
                    {
                        foreach (CrossRef_File_Episode xref in recs)
                        {
                            repCrossRef.Delete(xref.CrossRef_File_EpisodeID);
                        }

                        Response.Write(Constants.ERROR_XML);
                        return;
                    }
                }

                if (recs.Count == 0)
                {
                    Response.Write(Constants.ERROR_XML);
                    return;
                }

                foreach (CrossRef_File_Episode xref in recs)
                {
                    colResults.AnimeID = xref.AnimeID;
                    colResults.AddToCollection(xref.EpisodeID.ToString(), xref.EpisodeOrder.ToString(), xref.Percentage.ToString());
                }

                string ret = Utils.ConvertToXML(colResults, typeof(CrossRef_File_EpisodeResultCollection));
                Response.Write(ret);
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
                return;
            }
        }