<%@ WebHandler Language="C#" Class="AdminService" %>

using System;
using System.Data;
using System.Web;
using System.Text;
using System.Web.Security;
using System.Xml;

public class AdminService : IHttpHandler {
    private int m_UserID=0;
    public void ProcessRequest (HttpContext context) 
    {
        context.Response.ContentType = "text/xml";
        string action = context.Request.Params["Action"]; 
        CheckAdminLogin _chk = new CheckAdminLogin();
        if (_chk.CheckLogin())
        {
            
            switch (action)
            {                
                case "GetRssContent":
                    GetRssContent(context);
                    break;
                default:
                    break;

            }

            context.Response.Flush();
            context.Response.Close();
        }
        else
        {
            context.Response.Write("当前用户未登录，请先登录");
            context.Response.Close();
        }
       
    }

    

    private void GetMyRssList(HttpContext context,int UserID)
    {
        if (UserID > 0)
        {
            MySpace _rss = new MySpace();
            DataTable dt = _rss.GetMyRss(UserID);
            if (dt.Rows.Count > 0)
            {
                StringBuilder _result = new StringBuilder("<rss>",300);                
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    _result.Append("<item><url>" + dt.Rows[i]["RssUrl"].ToString() + "</url><name>"+dt.Rows[i]["ClassName"].ToString()+"</name></item>");

                }
                _result.Append("</rss>");
                context.Response.Write(_result.ToString());

            }
        }

    }

    private void CheckReg(HttpContext context)
    {
        string result="";
        string RegName = context.Request.Params["UserName"];
        UserBLL _user = new UserBLL();
        DataTable dt = _user.GetUserByUserName(RegName);
        if (dt.Rows.Count > 0)
            result = "该用户名已经被注册";
        else
            result = "该用户名可以注册";
        context.Response.ContentType = "text/plain";
        context.Response.Write(result);

    }

    private void GetRssContent(HttpContext context)
    {
        XmlDocument doc = new XmlDocument();
        string m_RssUrl=context.Request.Params["rssurl"];
        doc.Load(m_RssUrl);
        context.Response.ContentType = "text/xml";
        if (doc.InnerXml.Contains("encoding=\"gbk\""))
            doc.InnerXml = doc.InnerXml.Replace("encoding=\"gbk\"", "");      
        context.Response.Write(doc.InnerXml);

    }

  
    public bool IsReusable {
        get {
            return false;
        }
    }

}