예제 #1
0
 public void HandleRequest(HttpListenerContext context)
 {
     NameValueCollection query;
     using (StreamReader rdr = new StreamReader(context.Request.InputStream))
     {
         query = HttpUtility.ParseQueryString(rdr.ReadToEnd());
     }
     int offset = int.Parse(query["offset"]);
     using (Database dbx = new Database())
     {
         var cmd = dbx.CreateQuery();
         cmd.CommandText = "SELECT * FROM info ORDER BY date DESC LIMIT 1 OFFSET @off;";
         cmd.Parameters.AddWithValue("@off", offset);
         using (var rdr = cmd.ExecuteReader())
         {
             rdr.Read();
             var page = new PageItem()
             {
             };
             page.Name = rdr.GetString("name");
             List<string> contents = new List<string>();
             if (rdr.GetInt32("newsType") == 0)
             {
                 foreach (var i in rdr.GetString("contents").Split('&'))
                 {
                     contents.Add(i);
                 }
                 page.ContentType = 0;
                 page.ContentLines = contents.ToArray();
             }
             else
             {
                 foreach (var i in rdr.GetString("contents").Split('&'))
                     contents.Add(i);
                 page.ContentType = rdr.GetInt32("newsType");
                 page.ContentLines = contents.ToArray();
             }
             DateTime time = rdr.GetDateTime("date");
             page.Date = time.ToString("g");
             if (!rdr.IsDBNull(rdr.GetOrdinal("link")) && rdr.GetString("link") != "")
             {
                 page.Link = rdr.GetString("link");
             }
             byte[] fff = Encoding.ASCII.GetBytes(page.ToString());
             context.Response.OutputStream.Write(fff, 0, fff.Length);
             context.Response.Close();
         }
         dbx.Dispose();
     }
 }