using System;
using System.Data;
using System.Configuration;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using NBear.Common;
using Aspxcn.function;

public partial class _rss : System.Web.UI.Page
{
    protected static Aspxcn.ServiceImpls.MessageService cmd = new Aspxcn.ServiceImpls.MessageService();
    protected void Page_Load(object sender, EventArgs e)
    {
        Int32 pageSize;
        Int32 catalog=0;
        if (!Page.IsPostBack)
        {
            UbbCode ubb = new UbbCode();
            
            StringBuilder sb = new StringBuilder();

            sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
            sb.Append("<?xml-stylesheet href=\"css/feed.xsl\" type=\"text/xsl\" media=\"screen\"?>\n");
            sb.Append("<?xml-stylesheet type=\"text/css\" href=\"css/rss.css\" media=\"screen\"?>\n");
            sb.Append("<rss version=\"2.0\">\n");
            sb.Append("<channel>\n");
            sb.Append("<title>AspxCn中华网(RSS2.0聚合内容)</title>\n");

            if (!Request.QueryString.HasKeys())
            {
                pageSize = 15;
            }
            else
            {
                if (Int32.Parse(Request.QueryString["pageSize"]) > 15)
                {
                    pageSize = 15;
                }
                else
                {
                    pageSize = Int32.Parse(Request.QueryString["pageSize"]);
                }

                if (Request.QueryString["catalog"]!=null)
                {
                    catalog=Int32.Parse(Request.QueryString["catalog"]);
                }
            }
            
            sb.Append("<link>http://www.aspxcn.com.cn/</link>\n");
            sb.Append("<description>.NET技术交流平台</description>\n");
            sb.Append("<language>zh-cn</language>\n");
            sb.Append("<copyright><![CDATA[Copyright 2007 ASPXCN中华网]]></copyright>\n");
            sb.Append("<webMaster><![CDATA[webmaster@aspxcn.com.cn(小宝.NET)]]></webMaster>\n");
            sb.Append("<generator>ASPXCN中华网</generator>\n");
            
            Aspxcn.Entities.Lists[] rsslist = cmd.GetRssContent(pageSize,catalog);
            for (int i = 0; i <= rsslist.Length - 1; i++)
            {
                sb.Append("<item>\n");
                sb.Append("<title><![CDATA[" + rsslist[i]._Title + "]]></title>\n");
                sb.Append("<pubDate>" + Convert.ToDateTime(rsslist[i]._Date).ToString("r") + "</pubDate>\n");
                sb.Append("<link>default.aspx?uid="+rsslist[i].ListId.ToString()+"</link>\n");
                sb.Append("<author><![CDATA[" + rsslist[i].UserName + "]]></author>\n");
                sb.Append("<category><![CDATA[" + rsslist[i].Catalog1.Name + "]]></category>");
                sb.Append("<description><![CDATA[" + ubb.UBBRSS(Server.HtmlDecode(rsslist[i]._Content)) + "]]></description>\n");
                sb.Append("</item>\n");
            }
            sb.Append("</channel>\n");
            sb.Append("</rss>");
            Response.Write(sb.ToString());
        }
    }
}