⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 opmlhandler.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 CS
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.IO;
using System.Web;
using System.Xml;
using CommunityServer.Components;

namespace CommunityServer.Blogs.Components
{
	/// <summary>
	/// Summary description for OpmlHandler.
	/// </summary>
	public class OpmlHandler : IHttpHandler
	{
		public OpmlHandler()
		{
			//
			// TODO: Add constructor logic here
			//
		}

        public void ProcessRequest(HttpContext context)
        {
            int groupID = Globals.SafeInt(context.Request.QueryString["GroupID"],-1);

            //StringWriter sw = new StringWriter();

            context.Response.ContentEncoding = System.Text.Encoding.UTF8;
            context.Response.ContentType = "text/xml";
            context.Response.Cache.SetCacheability(HttpCacheability.Public);
            context.Response.Cache.VaryByParams["GroupID"] = true;
            context.Response.Cache.SetExpires(DateTime.Now.AddMinutes(5));
            context.Response.Cache.SetValidUntilExpires(true);

					
            XmlTextWriter writer = new XmlTextWriter(context.Response.Output);
            writer.Formatting = Formatting.Indented;

            writer.WriteStartElement("opml");

            //Body
            writer.WriteStartElement("body");

            BlogUrls urls = BlogUrls.Instance();

            string baseUrl = Globals.HostPath(context.Request.Url);



            if(groupID > -1)
            {
                Group group = WeblogGroups.GetWeblogGroup(groupID,true,false);
                WriteGroup(writer,group, urls, baseUrl);
            }
            else
            {
                ArrayList groups = WeblogGroups.GetWeblogGroups(true,false,false);
                foreach(Group group in groups)
                {
                    WriteGroup(writer, group, urls, baseUrl);
                }
            }

            writer.WriteEndElement();
            writer.WriteEndElement();
            writer.Flush();
            writer.Close();
            //sw.Close();
            
            
        }

        protected void WriteGroup(XmlTextWriter writer, Group group, BlogUrls urls, string baseUrl)
        {
            writer.WriteStartElement("outline");
            writer.WriteAttributeString("text",group.Name);

            ArrayList weblogs = Weblogs.GetWeblogsByGroupID(group.GroupID,false,true,false);
            foreach(Weblog blog in weblogs)
            {
                writer.WriteStartElement("outline");
                writer.WriteAttributeString("title",blog.Name);
                writer.WriteAttributeString("htmlUrl",baseUrl + urls.HomePage(blog.ApplicationKey));
                writer.WriteAttributeString("xmlUrl",baseUrl + urls.Rss(blog.ApplicationKey));
                writer.WriteEndElement();	  
            }

            writer.WriteEndElement();
        }

	    public bool IsReusable
	    {
	        get { return false; }
	    }
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -