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

📄 forumrsshandler.cs

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

using System;
using CommunityServer.Components;

namespace CommunityServer.Discussions.Components
{
	/// <summary>
	/// Summary description for ForumRssHandler.
	/// </summary>
	public class ForumRssHandler : BaseSyndicationHandler
	{
		public ForumRssHandler()
		{
			//
			// TODO: Add constructor logic here
			//
		}

        protected  ThreadViewMode mode = ThreadViewMode.Default;

	    /// <summary>
	    /// The length of time the feed should be cached.
	    /// </summary>
	    protected override int CacheTime
	    {
	        get { return 90; }
	    }

	    /// <summary>
	    /// The key used to lookup the feed uniquely in the cache.
	    /// </summary>
	    /// <returns></returns>
	    protected override string CacheKey
	    {
            get { return string.Format("ForumRss:{0}:Mode{1}", CSContext.Current.ForumID.ToString(), mode); }
	    }

	    /// <summary>
	    /// The Fully Qualifed part of the Url for the current request
	    /// </summary>
	    protected override string BaseUrl
	    {
	        get { return Globals.HostPath(Context.Request.Url); }
	    }

        

        protected override void ProcessFeed()
        {
            if(!CSContext.Current.SiteSettings.EnableRSS)
            {
                 Context.Response.Write("Error - RSS Is Not Enabled.");
                return;
            }
            CSContext csContext = CSContext.Current;

            // Do we have a mode argument?
            if (csContext.Context.Request.QueryString["mode"] != null) 
            {
                mode = (ThreadViewMode) int.Parse(csContext.Context.Request.QueryString["mode"]);
            }

            if(csContext.ForumID <= 0)
            {
                Context.Response.StatusCode = 404;
                Context.Response.SuppressContent = true;
                Context.Response.End();
            }

            base.ProcessFeed ();
        }


	    /// <summary>
	    /// Builds the actual feed.
	    /// </summary>
	    /// <returns>The cached feed.</returns>
	    protected override CachedFeed BuildFeed()
	    {
             ThreadSet threads = null;
            switch (mode) 
            {
                case ThreadViewMode.Active:
                    threads = Threads.GetThreads(GetCurrentSection.SectionID, 0, 15, CSContext.Current.User, DateTime.MinValue, SortThreadsBy.LastPost, SortOrder.Descending, ThreadStatus.NotSet, ThreadUsersFilter.All, true, false, true, true);
                    break;

                case ThreadViewMode.Unanswered:
                    threads = Threads.GetThreads(GetCurrentSection.SectionID, 0, 15, CSContext.Current.User, DateTime.MinValue, SortThreadsBy.LastPost, SortOrder.Descending, ThreadStatus.NotSet, ThreadUsersFilter.All, false, false, true, true);
                    break;

                default:
                    threads = Threads.GetThreads(GetCurrentSection.SectionID, 0, 15, CSContext.Current.User, DateTime.MinValue, SortThreadsBy.LastPost, SortOrder.Descending, ThreadStatus.NotSet, ThreadUsersFilter.All, false, false, false, true);
                    break;
            }

            ForumRssWriter writer = new ForumRssWriter(threads.Threads,GetCurrentSection,this.BaseUrl);

            DateTime dt =  threads.Threads.Count > 0 ? ((Post)threads.Threads[threads.Threads.Count -1]).PostDate : DateTime.Now;
            
            return new CachedFeed(dt,null,writer.GetXml());
	    }

        private Forum _forum;
	    protected override Section GetCurrentSection
	    {
	        get
	        {
                if(_forum == null)
                {
                    _forum = Forums.GetForum(CSContext.Current.ForumID,true,false,0);
                    if(_forum == null)
                        throw new CSException(CSExceptionType.SectionNotFound,"The forum could not be found");

                    Permissions.AccessCheck(_forum,Permission.Read,CSContext.Current.User);
                }
                return _forum;
	        }
	    }
	}
}

⌨️ 快捷键说明

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