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

📄 threads.cs

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

using System;
using System.Collections;
using System.Collections.Specialized;
using System.Web;
using System.IO;
using System.Web.Caching;
using CommunityServer.Components;


namespace CommunityServer.Discussions.Components {

    // *********************************************************************
    //  Threads
    //
    /// <summary>
    /// This class contains methods for working with an individual post.  There are methods to
    /// Add a New Post, Update an Existing Post, retrieve a single post, etc.
    /// </summary>
    // ***********************************************************************/
    public class Threads {

        // *********************************************************************
        //  GetThreads
        //
        /// <summary>
        /// Returns a collection of threads based on the properties specified
        /// </summary>
        /// <param name="forumID">Id of the forum to retrieve posts from</param>
        /// <param name="pageSize">Number of results to return</param>
        /// <param name="pageIndex">Location in results set to return</param>
        /// <param name="endDate">Results before this date</param>
        /// <param name="username">Username asking for the threads</param>
        /// <param name="unreadThreadsOnly">Return unread threads</param>
        /// <returns>A collection of threads</returns>
        // ***********************************************************************/
		public static ThreadSet GetThreads(int forumID, int pageIndex, int pageSize, User user, DateTime threadsNewerThan, SortThreadsBy sortBy, SortOrder sortOrder, ThreadStatus threadStatus, ThreadUsersFilter userFilter, bool activeTopics, bool unreadOnly, bool unansweredOnly, bool returnRecordCount) {
			string key;
			string cacheKey;
			
			key = "Forum-Threads::S:{0}-PS:{1}-PI:{2}-Day:{3}-Year{4}-SB:{5}-SO{6}-AT:{7}-U:{8}-R:{9}";
			cacheKey = string.Format(key,forumID,pageIndex,pageSize, threadsNewerThan.DayOfYear, threadsNewerThan.Year, sortBy,sortOrder,activeTopics,unansweredOnly,user.RoleKey);
	
			ThreadSet threadSet;

            // If the user is anonymous take some load off the db
            //
			if (user.IsAnonymous) {
				threadSet = CSCache.Get(cacheKey) as ThreadSet;
				if (threadSet != null)
					return threadSet;

			}

			// if the user is not anonymous we still may be able to take
			// some load off the db
			//
			if (	(threadStatus == ThreadStatus.NotSet) &&
					(userFilter == ThreadUsersFilter.All) &&
					(!unreadOnly) &&
					(forumID != 0) ) {

				threadSet = CSCache.Get(cacheKey) as ThreadSet;

				// We still need to show unread/read
				if (threadSet != null) {
					ArrayList threads;
					HybridDictionary readThreads = GetReadThreads(forumID, user.UserID, false);

					int markReadAfter = (int) readThreads["ReadAfter"];

					// Set the status on announcements
					threads = threadSet.Announcements;
					for (int i = 0; i < threads.Count; i++) {
						Thread t = threads[i] as Thread;

						if ((t.ThreadID < markReadAfter) || (readThreads[t.ThreadID] != null))
							t.HasRead = true;
						else
							t.HasRead = false;
					}

					// Set the status on threads
					threads = threadSet.Threads;
					for (int i = 0; i < threads.Count; i++) {
						Thread t = threads[i] as Thread;

						if ((t.ThreadID < markReadAfter) || (readThreads[t.ThreadID] != null))
							t.HasRead = true;
						else
							t.HasRead = false;
					}

					return threadSet;
				}

			}

            // Create Instance of the IDataProvider
            //
            ForumDataProvider dp = ForumDataProvider.Instance();

            // Get the threads
            //
            threadSet = dp.GetThreads(forumID, pageIndex, pageSize, user, threadsNewerThan, sortBy, sortOrder, threadStatus, userFilter, activeTopics, unreadOnly, unansweredOnly, returnRecordCount);

			// Insert into the Cache
			if	(	(user.IsAnonymous) || 
					(threadStatus == ThreadStatus.NotSet) &&
					(userFilter == ThreadUsersFilter.All) &&
					(!unreadOnly) &&
					(forumID != 0) ) {

				CSCache.Insert(cacheKey,threadSet, CSCache.MinuteFactor,CacheItemPriority.Low);
			}

			// We need to do read/unread again since we didn't execute that code path above
			if (threadSet != null) 
			{
				ArrayList threads;
				HybridDictionary readThreads = GetReadThreads(forumID, user.UserID, false);

				int markReadAfter = (int) readThreads["ReadAfter"];

				// Set the status on announcements
				threads = threadSet.Announcements;
				for (int i = 0; i < threads.Count; i++) 
				{
					Thread t = threads[i] as Thread;

					if ((t.ThreadID < markReadAfter) || (readThreads[t.ThreadID] != null))
						t.HasRead = true;
					else
						t.HasRead = false;
				}

				// Set the status on threads
				threads = threadSet.Threads;
				for (int i = 0; i < threads.Count; i++) 
				{
					Thread t = threads[i] as Thread;

					if ((t.ThreadID < markReadAfter) || (readThreads[t.ThreadID] != null))
						t.HasRead = true;
					else
						t.HasRead = false;
				}
			}

			return threadSet;
        }

        // *********************************************************************
        //  GetNextThreadID
        //
        /// <summary>
        /// Returns the id of the next thread.
        /// </summary>
        /// <param name="postID">Current threadid is determined from postsid</param>
        // ***********************************************************************/
        public static int GetNextThreadID(int postID) {
            // Create Instance of the IDataProvider
            ForumDataProvider dp = ForumDataProvider.Instance();

            return dp.GetNextThreadID(postID);			
        }

        // *********************************************************************
        //  GetPrevThreadID
        //
        /// <summary>
        /// Returns the id of the previous thread.
        /// </summary>
        /// <param name="postID">Current threadid is determined from postsid</param>
        // ***********************************************************************/
        public static int GetPrevThreadID(int postID) {
            // Create Instance of the IDataProvider
            ForumDataProvider dp = ForumDataProvider.Instance();

            return dp.GetPrevThreadID(postID);			
        }

		// *********************************************************************
		//  GetReadThreads
		//
		/// <summary>
		/// Returns an array list of threads the user has read
		/// </summary>
		// ***********************************************************************/
		public static HybridDictionary GetReadThreads(int sectionID, int userID, bool flush) {

			string cacheKey = "threads-read-" + sectionID.ToString() + userID.ToString();

			HybridDictionary d = CSCache.Get(cacheKey) as HybridDictionary;

			if (d == null || flush) {

				// Create Instance of the IDataProvider
				ForumDataProvider dp = ForumDataProvider.Instance();

				d = dp.GetThreadsRead(sectionID, userID);		
			}

			CSCache.MicroInsert(cacheKey, d, 1);

			return d;
		}

		public static Thread GetThread(int threadID)
		{
			string cacheKey = "Thread-ThreadID:" + threadID + "-UserID:" + CSContext.Current.User.UserID;
			Thread thread = HttpContext.Current.Items[cacheKey] as Thread;

			if(thread == null)
			{
				thread = ForumDataProvider.Instance().GetThread(threadID, CSContext.Current.User.UserID);
				HttpContext.Current.Items.Add(cacheKey, thread);
			}

			return thread;
		}

        public static void UpdateThreadStatus (int threadID, ThreadStatus status) {
            // For tests :)
            //HttpContext.Current.Response.Write( string.Format( "<br />Thread ID={0} and its status should be: {1}.<br />", threadID, status ) );

            ForumDataProvider.Instance().UpdateThreadStatus( threadID, status );
        }

    }
}

⌨️ 快捷键说明

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