📄 forumdataprovider.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.Data;
using CommunityServer;
using CommunityServer.Components;
using CommunityServer.Configuration;
namespace CommunityServer.Discussions.Components
{
/// <summary>
/// Summary description for ForumsDataProvider.
/// </summary>
public abstract class ForumDataProvider
{
public ForumDataProvider()
{
}
public static readonly string ForumDataProviderName = "ForumDataProvider";
public abstract SearchResultSet GetSearchResults(SearchQuery query, SearchTerms terms);
public abstract PostSet SearchReindexPosts (int setsize, int settingsID);
#region Instance
private static ForumDataProvider _defaultInstance = null;
static ForumDataProvider()
{
CreateDefaultCommonProvider();
}
/// <summary>
/// Returns an instance of the user-specified data provider class.
/// </summary>
/// <returns>An instance of the user-specified data provider class. This class must inherit the
/// CommonDataProvider interface.</returns>
public static ForumDataProvider Instance()
{
return _defaultInstance;
}
public static ForumDataProvider Instance (Provider dataProvider)
{
ForumDataProvider fdp = CSCache.Get(dataProvider.Name) as ForumDataProvider;
if(fdp == null)
{
fdp = DataProviders.Invoke(dataProvider) as ForumDataProvider;
CSCache.Max(dataProvider.Name,fdp);
}
return fdp;
}
/// <summary>
/// Creates the Default CommonDataProvider
/// </summary>
private static void CreateDefaultCommonProvider()
{
// Get the names of the providers
//
CSConfiguration config = CSConfiguration.GetConfig();
// Read the configuration specific information
// for this provider
//
Provider sqlForumsProvider = (Provider) config.Providers[ForumDataProviderName];
// Read the connection string for this provider
//
_defaultInstance = DataProviders.CreateInstance(sqlForumsProvider) as ForumDataProvider;
}
#endregion
#region Base Methods
#region Posts
public abstract PostSet GetPosts(int postID, int pageIndex, int pageSize, int sortBy, int sortOrder, int userID, bool returnRecordCount);
public abstract ForumPost GetPost(int postID, int userID, bool trackViews);
public abstract ForumPost AddPost(ForumPost postToAdd, int userID, bool autoApprove);
public abstract void UpdatePost(ForumPost post, int editedBy);
public abstract PostSet GetTopNNewPosts(string username, int postCount);
public abstract PostSet GetTopNPopularPosts(string username, int postCount, int days);
public abstract int GetTotalPostCount();
public abstract void MarkPostAsRead(int postID, string username);
#endregion
#region Threads
public abstract Thread GetThread(int threadID, int userID);
public abstract 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 unanswered, bool returnRecordCount);
public abstract int GetNextThreadID(int postID);
public abstract int GetPrevThreadID(int postID);
public abstract void UpdateThreadStatus (int threadID, ThreadStatus status);
#endregion
#region Forums
public abstract Hashtable GetForums();
public abstract int GetForumIDByPostID(int postID);
public abstract void MarkAllForumsRead(int userID, int forumGroupID, int forumID, bool markThreadsRead);
#endregion
#region Private Messages
public abstract void CreatePrivateMessage(ArrayList users, int threadID);
public abstract void DeletePrivateMessage(int userID, ArrayList deleteList);
public abstract HybridDictionary GetPrivateMessageRecipients(int threadID);
public static PrivateMessage PopulatePrivateMessageFromIDataReader (IDataReader reader)
{
PrivateMessage thread = new PrivateMessage();
return (PrivateMessage) PopulateThreadFromIDataReader(thread, reader);
}
#endregion
#region Permissions
public abstract ArrayList GetForumPermissions(int sectionID);
#endregion
#region RSS
public abstract void RssPingback(Hashtable pingbackList);
#endregion
#region Moderation (宝玉修改 2005-6-14)
public abstract PostSet GetPostsToModerate(int forumID, int pageIndex, int pageSize, int sortBy, int sortOrder, int userID, bool returnRecordCount); //
public abstract ArrayList GetForumsToModerate (int userID, ApplicationType applicationType); //
public abstract bool ApprovePost(int postID, int userIDApprovedBy);
public abstract bool CheckIfUserIsModerator(int userID, int groupID, int forumID);
public abstract void ThreadSplit (int postID, int moveToForumID, int splitByUserID);
public abstract void ThreadJoin (int parentThreadID, int childThreadID, int joinedByUserID);
public abstract void ModeratorDeletePost(int postID, int deletedBy, string reason, bool deleteChildPosts);
// bool DeleteModeratedPost(int postID, string approvedBy);
public abstract bool CanEditPost(String Username, int PostID);
public abstract MovedPostStatus MovePost(int postID, int moveToForumID, int movedBy);
public abstract bool UserHasPostsAwaitingModeration(String Username);
public abstract ArrayList GetForumsModeratedByUser(String Username);
// public abstract ArrayList GetForumsNotModeratedByUser(String Username);
public abstract void AddModeratedForumForUser(string username, int groupID, int forumID);
public abstract void RemoveModeratedForumForUser(int userID, int groupID, int forumID, out bool isModerator);
// public abstract ArrayList GetModeratorsInterestedInPost(int PostID);
public abstract ArrayList GetForumModerators(int groupID, int forumID);
public abstract ArrayList GetForumModeratorRoles (int forumID);
public abstract void TogglePostSettings(ModeratePostSetting setting, ForumPost post, int moderatorID);
public abstract void ToggleUserSettings(ModerateUserSetting setting, User user, int moderatorID);
public abstract ModerationQueueStatus GetQueueStatus(int sectionID, string username);
#endregion
#region Threads Read
public abstract HybridDictionary GetThreadsRead (int sectionID, int userID);
#endregion
#endregion
#region Populate
// *********************************************************************
//
// PopulateThreadFromIDataReader
//
/// <summary>
/// This private method accepts a datareader and attempts to create and
/// populate a thread class instance which is returned to the caller. For
/// all practical purposes, a thread is simply a lightweigh version of a
/// post - no details, such as the body, are provided though and a thread is
/// always considered the first post in a thread.
/// </summary>
//
// ********************************************************************/
public static Thread PopulateThreadFromIDataReader(IDataReader reader)
{
Thread thread = new Thread();
return PopulateThreadFromIDataReader(thread, reader);
}
public static Thread PopulateThreadFromIDataReader(Thread thread, IDataReader reader)
{
thread.SectionID = (int) reader["SectionID"];
thread.PostID = (int) reader["PostID"];
thread.Replies = (int) reader["TotalReplies"];
thread.AuthorID = (int) reader["UserID"];
thread.Views = (int) reader["TotalViews"];
thread.MostRecentPostID = (int) reader["MostRecentPostID"];
thread.ThreadID = (int) reader["ThreadID"];
thread.Subject = (string) reader["Subject"];
thread.Body = (string) reader["Body"];
thread.Username = (string) reader["Username"];
thread.MostRecentPostAuthor = (string) reader["MostRecentPostAuthor"];
thread.MostRecentPostAuthorID = (int) reader["MostRecentPostAuthorID"];
thread.PostDate = (DateTime) reader["PostDate"];
thread.ThreadDate = (DateTime) reader["ThreadDate"];
thread.StickyDate = (DateTime) reader["StickyDate"];
thread.IsLocked = (bool) reader["IsLocked"];
thread.IsSticky = (bool) reader["IsSticky"];
thread.HasRead = Convert.ToBoolean(reader["HasRead"]);
thread.TotalRatings = (int) reader["TotalRatings"];
thread.RatingSum = (int) reader["RatingSum"];
thread.EmoticonID = (int) reader["ThreadEmoticonID"];
thread.Status = (ThreadStatus) ((int) reader["ThreadStatus"]);
thread.FormattedBody = reader["FormattedBody"] as string;
thread.PostConfiguration = (int) reader["PostConfiguration"];
return thread;
}
public static ForumPost PopulatePostSetFromIDataReader(IDataReader dr)
{
ForumPost post = PopulatePostFromIDataReader(dr);
post.Section = PopulateForumFromIDataReader(dr);
post.User = CommonDataProvider.PopulateUserFromIDataReader(dr,CommonDataProvider.PopulateMembershipUserFromIDataReader(dr,null),false);
return post;
}
/// <summary>
/// Builds and returns an instance of the Post class based on the current row of an
/// aptly populated IDataReader object.
/// </summary>
/// <param name="dr">The IDataReader object that contains, at minimum, the following
/// columns: PostID, ParentID, Body, ForumID, PostDate, PostLevel, SortOrder, Subject,
/// ThreadDate, ThreadID, Replies, Username, and Approved.</param>
/// <returns>An instance of the Post class that represents the current row of the passed
/// in SqlDataReader, dr.</returns>
public static ForumPost PopulatePostFromIDataReader(IDataReader dr)
{
ForumPost post = new ForumPost();
CommonDataProvider.PopulatePostFromIDataReader(dr,post);
return post;
}
#region Forums
public static Forum PopulateForumFromIDataReader(IDataReader dr)
{
Forum s = new Forum();
CommonDataProvider.PopulateSectionFromIDataReader(dr, s);
return s;
}
public static ModeratedForum PopulateModeratedForumFromIDataReader(IDataReader dr)
{
ModeratedForum forum = new ModeratedForum();
forum.SectionID = Convert.ToInt32(dr["SectionID"]);
forum.GroupID = Convert.ToInt32(dr["GroupID"]);
forum.DateCreated = Convert.ToDateTime(dr["DateCreated"]);
forum.Description = Convert.ToString(dr["Description"]);
forum.Name = Convert.ToString(dr["Name"]);
forum.IsModerated = Convert.ToBoolean(dr["Moderated"]);
forum.DefaultThreadDateFilter = (ThreadDateFilterMode) Convert.ToInt32(dr["DaysToView"]);
forum.IsActive = Convert.ToBoolean(dr["Active"]);
forum.SortOrder = Convert.ToInt32(dr["SortOrder"]);
forum.IsPrivate = Convert.ToBoolean(dr["IsPrivate"]);
return forum;
}
#endregion
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -