コード例 #1
0
        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 aidList = Utils.TryGetProperty("AniDB_Updated", docXRef, "AnimeIDList").Trim().ToUpper();
                string uname   = Utils.TryGetProperty("AniDB_Updated", docXRef, "Username");

                string utime      = Utils.TryGetProperty("AniDB_Updated", docXRef, "UpdatedTime");
                long   updateTime = 0;
                long.TryParse(utime, out updateTime);

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

                AniDB_UpdatedRepository repUpdates = new AniDB_UpdatedRepository();
                AniDB_Updated           aniUpdated = new AniDB_Updated();
                aniUpdated.AnimeIDList     = aidList;
                aniUpdated.Username        = uname;
                aniUpdated.UpdateTime      = updateTime;
                aniUpdated.DateTimeCreated = DateTime.Now;
                repUpdates.Save(aniUpdated);

                // now send to mirror
                string uri = string.Format("http://{0}/AddUpdatedList.aspx", Constants.MirrorWAIX);
                XMLService.SendData(uri, xmlData);
            }
            catch (Exception ex)
            {
                Response.Write(Constants.ERROR_XML);
            }
        }
コード例 #2
0
ファイル: GetUpdates.aspx.cs プロジェクト: ewelike23/jmm
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.ContentType = "text/xml";

            try
            {
                AniDB_UpdatedRepository repUpdates = new AniDB_UpdatedRepository();

                string updatetime  = Utils.GetParam("updatetime");
                long   fupdatetime = 0;
                long.TryParse(updatetime, out fupdatetime);

                if (fupdatetime <= 0)
                {
                    Response.Write(Constants.ERROR_XML);
                    return;
                }

                // get all the records
                // we need to find all the records greater than the update time, and one record
                // which is just before the update time
                // this will ensure we get all records
                List <AniDB_Updated> allUpdateRecords = repUpdates.GetAll();
                if (allUpdateRecords.Count == 0)
                {
                    Response.Write(Constants.ERROR_XML);
                    return;
                }

                List <string> allUpdates = new List <string>();

                int idxSmallest = -1;
                // find the first record greater
                for (int i = 0; i < allUpdateRecords.Count; i++)
                {
                    if (allUpdateRecords[i].UpdateTime > fupdatetime)
                    {
                        if (idxSmallest < 0)
                        {
                            idxSmallest = i;
                            if (i > 0)
                            {
                                string[] ids = allUpdateRecords[i - 1].AnimeIDList.Split(',');
                                foreach (string id in ids)
                                {
                                    if (!allUpdates.Contains(id.Trim()))
                                    {
                                        allUpdates.Add(id.Trim());
                                    }
                                }
                            }
                        }

                        // get a list of anime id's
                        string[] ids2 = allUpdateRecords[i].AnimeIDList.Split(',');
                        foreach (string id in ids2)
                        {
                            if (!allUpdates.Contains(id.Trim()))
                            {
                                allUpdates.Add(id.Trim());
                            }
                        }
                    }
                }

                UpdatesCollection colUpdates = new UpdatesCollection();
                foreach (string id in allUpdates)
                {
                    colUpdates.AddToCollection(int.Parse(id));
                }

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