/// <summary> /// Gets the support queue of the thread with the threadID specified. /// </summary> /// <param name="threadID">The thread ID.</param> /// <param name="trans">The transaction currently in progress. Can be null if no transaction is in progress.</param> /// <returns> /// The requested supportqueue entity, or null if the thread isn't in a support queue. /// </returns> public static SupportQueueEntity GetQueueOfThread(int threadID, Transaction trans) { // the relation supportqueue - thread is stored in a SupportQueueThread entity. Use that entity as a filter for the support queue. If // that entity doesn't exist, the thread isn't in a supportqueue. var qf = new QueryFactory(); var q = qf.SupportQueueThread .From(QueryTarget.InnerJoin(qf.SupportQueue).On(SupportQueueThreadFields.QueueID == SupportQueueFields.QueueID)) .Where(SupportQueueThreadFields.ThreadID == threadID); // use a supportqueue collection to fetch the support queue, which will contain 0 or 1 entities after the fetch SupportQueueCollection supportQueues = new SupportQueueCollection(); // if a transaction has been specified, we've to add the collection to the transaction so the fetch takes place inside the same transaction so no // deadlocks occur on sqlserver if (trans != null) { trans.Add(supportQueues); } supportQueues.GetMulti(q); if (supportQueues.Count > 0) { // in a queue, return the instance return(supportQueues[0]); } else { // not in a queue, return null return(null); } }
private void Page_Load(object sender, System.EventArgs e) { // If the user doesn't have any access rights to management stuff, the user should // be redirected to the default of the global system. if (!SessionAdapter.HasSystemActionRights()) { // doesn't have system rights. redirect. Response.Redirect("../Default.aspx", true); } // Check if the user has the right systemright if (!SessionAdapter.HasSystemActionRight(ActionRights.SystemManagement)) { // no, redirect to admin default page, since the user HAS access to the admin menu. Response.Redirect("Default.aspx", true); } if (!Page.IsPostBack) { // Read all the current existing forums and their section names. ForumsWithSectionNameTypedList forumsWithSectionNames = ForumGuiHelper.GetAllForumsWithSectionNames(); rpForums.DataSource = forumsWithSectionNames; rpForums.DataBind(); SectionCollection sections = SectionGuiHelper.GetAllSections(); cbxSections.DataSource = sections; cbxSections.DataBind(); SupportQueueCollection supportQueues = CacheManager.GetAllSupportQueues(); cbxSupportQueues.DataSource = supportQueues; cbxSupportQueues.DataBind(); } }
/// <summary> /// Gets all support queues known in the system, sorted by orderno, ascending. /// </summary> /// <returns>filled collection with entities requested.</returns> public static SupportQueueCollection GetAllSupportQueues() { SupportQueueCollection toReturn = new SupportQueueCollection(); // fetch all supportqueue entities and sort on the orderno fields toReturn.GetMulti(null, 0, new SortExpression(SupportQueueFields.OrderNo.Ascending())); return toReturn; }
/// <summary> /// Gets all support queues known in the system, sorted by orderno, ascending. /// </summary> /// <returns>filled collection with entities requested.</returns> public static SupportQueueCollection GetAllSupportQueues() { SupportQueueCollection toReturn = new SupportQueueCollection(); // fetch all supportqueue entities and sort on the orderno fields toReturn.GetMulti(null, 0, new SortExpression(SupportQueueFields.OrderNo.Ascending())); return(toReturn); }
/// <summary> /// Gets all support queues from the cache. If it's not available, the collection with all the support queue entities is loaded from the DB and /// added to the cache. /// </summary> /// <returns>A SupportQueueCollection with all supportqueue Entity instances of the support queues of the forum system. This collection has to be threated as /// a readonly collection with readonly objects</returns> /// </summary> public static SupportQueueCollection GetAllSupportQueues() { Cache activeCache = HttpRuntime.Cache; SupportQueueCollection toReturn = (SupportQueueCollection)activeCache[CacheKeys.AllSupportQueues]; if (toReturn == null) { // not there, store it. toReturn = SupportQueueGuiHelper.GetAllSupportQueues(); // just store it in the cache without any dependency, as it's hardly changing. activeCache.Insert(CacheKeys.AllSupportQueues, toReturn); } return(toReturn); }
/// <summary> /// Deletes the support queue with the ID specified. /// </summary> /// <param name="queueID">The queue ID of the queue to delete.</param> /// <returns>true if succeeded, false otherwise</returns> /// <remarks>All threads in the queue are automatically de-queued and not in a queue anymore. The Default support queue /// for forums which have this queue as the default support queue is reset to null.</remarks> public static bool DeleteSupportQueue(int queueID) { // we'll do several actions in one atomic transaction, so start a transaction first. Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "DeleteSupportQ"); try { // first reset all the FKs in Forum to NULL if they point to this queue. ForumEntity forumUpdater = new ForumEntity(); // set the field to NULL. This is a nullable field, so we can just set the field to 'null', thanks to nullable types. forumUpdater.DefaultSupportQueueID = null; // update the entities directly in the db, use a forum collection for that ForumCollection forums = new ForumCollection(); trans.Add(forums); // specify a filter that only the forums which have this queue as the default queue are updated and have their FK field set to NULL. forums.UpdateMulti(forumUpdater, (ForumFields.DefaultSupportQueueID == queueID)); // delete all SupportQueueThread entities which refer to this queue. This will make all threads which are in this queue become queue-less. SupportQueueThreadCollection supportQueueThreads = new SupportQueueThreadCollection(); trans.Add(supportQueueThreads); // delete them directly from the db. supportQueueThreads.DeleteMulti((SupportQueueThreadFields.QueueID == queueID)); // it's now time to delete the actual supportqueue entity. SupportQueueCollection supportQueues = new SupportQueueCollection(); trans.Add(supportQueues); // delete it directly from the db. int numberOfQueuesDeleted = supportQueues.DeleteMulti((SupportQueueFields.QueueID == queueID)); // done so commit the transaction. trans.Commit(); return(numberOfQueuesDeleted > 0); } catch { // first roll back the transaction trans.Rollback(); // then bubble up the exception throw; } finally { trans.Dispose(); } }
protected void Page_Load(object sender, EventArgs e) { // check if the user has the right to be here bool userMayManageQueues = SessionAdapter.HasSystemActionRight(ActionRights.QueueContentManagement); if (!userMayManageQueues) { // doesn't have the right to manage queue contents. redirect Response.Redirect("default.aspx", true); } if (!Page.IsPostBack) { SupportQueueCollection supportQueues = CacheManager.GetAllSupportQueues(); rpQueues.DataSource = supportQueues; rpQueues.DataBind(); } }
/// <summary> /// Deletes the support queue with the ID specified. /// </summary> /// <param name="queueID">The queue ID of the queue to delete.</param> /// <returns>true if succeeded, false otherwise</returns> /// <remarks>All threads in the queue are automatically de-queued and not in a queue anymore. The Default support queue /// for forums which have this queue as the default support queue is reset to null.</remarks> public static bool DeleteSupportQueue(int queueID) { // we'll do several actions in one atomic transaction, so start a transaction first. Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "DeleteSupportQ"); try { // first reset all the FKs in Forum to NULL if they point to this queue. ForumEntity forumUpdater = new ForumEntity(); // set the field to NULL. This is a nullable field, so we can just set the field to 'null', thanks to nullable types. forumUpdater.DefaultSupportQueueID = null; // update the entities directly in the db, use a forum collection for that ForumCollection forums = new ForumCollection(); trans.Add(forums); // specify a filter that only the forums which have this queue as the default queue are updated and have their FK field set to NULL. forums.UpdateMulti(forumUpdater, (ForumFields.DefaultSupportQueueID == queueID)); // delete all SupportQueueThread entities which refer to this queue. This will make all threads which are in this queue become queue-less. SupportQueueThreadCollection supportQueueThreads = new SupportQueueThreadCollection(); trans.Add(supportQueueThreads); // delete them directly from the db. supportQueueThreads.DeleteMulti((SupportQueueThreadFields.QueueID == queueID)); // it's now time to delete the actual supportqueue entity. SupportQueueCollection supportQueues = new SupportQueueCollection(); trans.Add(supportQueues); // delete it directly from the db. int numberOfQueuesDeleted = supportQueues.DeleteMulti((SupportQueueFields.QueueID == queueID)); // done so commit the transaction. trans.Commit(); return (numberOfQueuesDeleted > 0); } catch { // first roll back the transaction trans.Rollback(); // then bubble up the exception throw; } finally { trans.Dispose(); } }
private void Page_Load(object sender, System.EventArgs e) { // If the user doesn't have any access rights to management stuff, the user should // be redirected to the default of the global system. if (!SessionAdapter.HasSystemActionRights()) { // doesn't have system rights. redirect. Response.Redirect("../Default.aspx", true); } // Check if the user has the right systemright if (!SessionAdapter.HasSystemActionRight(ActionRights.SystemManagement)) { // no, redirect to admin default page, since the user HAS access to the admin menu. Response.Redirect("Default.aspx", true); } _forumID = HnDGeneralUtils.TryConvertToInt(Request.QueryString["ForumID"]); if (!Page.IsPostBack) { // read sections for the drop down list. SectionCollection sections = SectionGuiHelper.GetAllSections(); cbxSections.DataSource = sections; cbxSections.DataBind(); SupportQueueCollection supportQueues = CacheManager.GetAllSupportQueues(); cbxSupportQueues.DataSource = supportQueues; cbxSupportQueues.DataBind(); // Load the forum. ForumEntity forum = ForumGuiHelper.GetForum(_forumID); if (forum != null) { // forum found tbxForumDescription.Text = forum.ForumDescription; tbxForumName.Value = forum.ForumName; tbxOrderNo.Text = forum.OrderNo.ToString(); cbxSections.SelectedValue = forum.SectionID.ToString(); if (forum.DefaultSupportQueueID.HasValue) { cbxSupportQueues.SelectedValue = forum.DefaultSupportQueueID.Value.ToString(); } chkHasRSSFeed.Checked = forum.HasRSSFeed; cbxThreadListInterval.SelectedValue = forum.DefaultThreadListInterval.ToString(); tbxMaxAttachmentSize.Text = forum.MaxAttachmentSize.ToString(); tbxMaxNoOfAttachmentsPerMessage.Text = forum.MaxNoOfAttachmentsPerMessage.ToString(); if (forum.NewThreadWelcomeText != null) { tbxNewThreadWelcomeText.Text = forum.NewThreadWelcomeText; } } else { // not found Response.Redirect("Default.aspx", true); } } }
/// <summary> /// Gets the support queue of the thread with the threadID specified. /// </summary> /// <param name="threadID">The thread ID.</param> /// <param name="trans">The transaction currently in progress. Can be null if no transaction is in progress.</param> /// <returns> /// The requested supportqueue entity, or null if the thread isn't in a support queue. /// </returns> public static SupportQueueEntity GetQueueOfThread(int threadID, Transaction trans) { // the relation supportqueue - thread is stored in a SupportQueueThread entity. Use that entity as a filter for the support queue. If // that entity doesn't exist, the thread isn't in a supportqueue. var qf = new QueryFactory(); var q = qf.SupportQueueThread .From(QueryTarget.InnerJoin(qf.SupportQueue).On(SupportQueueThreadFields.QueueID == SupportQueueFields.QueueID)) .Where(SupportQueueThreadFields.ThreadID == threadID); // use a supportqueue collection to fetch the support queue, which will contain 0 or 1 entities after the fetch SupportQueueCollection supportQueues = new SupportQueueCollection(); // if a transaction has been specified, we've to add the collection to the transaction so the fetch takes place inside the same transaction so no // deadlocks occur on sqlserver if(trans != null) { trans.Add(supportQueues); } supportQueues.GetMulti(q); if(supportQueues.Count > 0) { // in a queue, return the instance return supportQueues[0]; } else { // not in a queue, return null return null; } }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void Page_Load(object sender, System.EventArgs e) { int threadID = HnDGeneralUtils.TryConvertToInt(Request.QueryString["ThreadID"]); _thread = ThreadGuiHelper.GetThread(threadID); if (_thread == null) { // not found, return to start page Response.Redirect("default.aspx"); } // Check credentials bool userHasAccess = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AccessForum); if (!userHasAccess) { // doesn't have access to this forum. redirect Response.Redirect("default.aspx"); } _startMessageNo = HnDGeneralUtils.TryConvertToInt(Request.QueryString["StartAtMessage"]); bool highLightSearchResults = (HnDGeneralUtils.TryConvertToInt(Request.QueryString["HighLight"]) == 1); if (!_thread.IsClosed) { if (_thread.IsSticky) { _userMayAddNewMessages = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AddAndEditMessageInSticky); } else { _userMayAddNewMessages = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AddAndEditMessage); } // set show*link class members. These have to be set despite the postback status, as they're used in the repeater. Only set // them to true if the thread isn't closed. They've been initialized to false already. _showEditMessageLink = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.EditDeleteOtherUsersMessages); _showDeleteMessageLink = _showEditMessageLink; _showQuoteMessageLink = _userMayAddNewMessages; } // show user IP addresses if the user has system admin rights, security admin rights or user admin rights. _showIPAddresses = (SessionAdapter.HasSystemActionRight(ActionRights.SystemManagement) || SessionAdapter.HasSystemActionRight(ActionRights.SecurityManagement) || SessionAdapter.HasSystemActionRight(ActionRights.UserManagement)); // Get the forum entity related to the thread. Use BL class. We could have used Lazy loading, though for the sake of separation, we'll // call into the BL class. ForumEntity forum = CacheManager.GetForum(_thread.ForumID); if (forum == null) { // not found, orphaned thread, return to default page. Response.Redirect("default.aspx"); } _forumAllowsAttachments = (forum.MaxNoOfAttachmentsPerMessage > 0); // check if the user can view this thread. If not, don't continue. if ((_thread.StartedByUserID != SessionAdapter.GetUserID()) && !SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.ViewNormalThreadsStartedByOthers) && !_thread.IsSticky) { // can't view this thread, it isn't visible to the user Response.Redirect("default.aspx", true); } _threadStartedByCurrentUser = (_thread.StartedByUserID == SessionAdapter.GetUserID()); _userMayAddAttachments = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AddAttachment); _userCanCreateThreads = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AddNormalThread) || SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AddStickyThread); _userMayDoForumSpecificThreadManagement = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.ForumSpecificThreadManagement); _userMayDoSystemWideThreadManagement = SessionAdapter.HasSystemActionRight(ActionRights.SystemWideThreadManagement); _userMayEditMemo = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.EditThreadMemo); _userMayMarkThreadAsDone = (SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.FlagThreadAsDone) || _threadStartedByCurrentUser); _userMayManageSupportQueueContents = SessionAdapter.HasSystemActionRight(ActionRights.QueueContentManagement); _userMayDoBasicThreadOperations = (SessionAdapter.GetUserID() > 0); if (!Page.IsPostBack) { plPageListBottom.HighLight = highLightSearchResults; plPageListTop.HighLight = highLightSearchResults; litHighLightLogic.Visible = highLightSearchResults; if (highLightSearchResults) { // make highlighting of search results possible string searchTerms = SessionAdapter.GetSearchTerms(); if (searchTerms == null) { searchTerms = string.Empty; } this.ClientScript.RegisterHiddenField("searchTerms", searchTerms.Replace("AND", "").Replace("OR", "").Replace("and", "").Replace("or", "").Replace("\"", "")); } else { // replace hightlighting scriptblock. this.ClientScript.RegisterClientScriptBlock(this.GetType(), "onLoad", "<script language=\"javascript\" type=\"text/javascript\">function SearchHighlight() {}</script>"); } if (_userMayManageSupportQueueContents) { // fill support queue management area with data. SupportQueueCollection supportQueues = CacheManager.GetAllSupportQueues(); cbxSupportQueues.DataSource = supportQueues; cbxSupportQueues.DataBind(); SupportQueueEntity containingQueue = SupportQueueGuiHelper.GetQueueOfThread(_thread.ThreadID); if (containingQueue != null) { cbxSupportQueues.SelectedValue = containingQueue.QueueID.ToString(); // get claim info SupportQueueThreadEntity supportQueueThreadInfo = SupportQueueGuiHelper.GetSupportQueueThreadInfo(_thread.ThreadID, true); if ((supportQueueThreadInfo != null) && supportQueueThreadInfo.ClaimedByUserID.HasValue) { // claimed by someone lblClaimDate.Text = supportQueueThreadInfo.ClaimedOn.Value.ToString("dd-MMM-yyyy HH:mm.ss", DateTimeFormatInfo.InvariantInfo); lnkClaimerThread.Visible = true; lblNotClaimed.Visible = false; lnkClaimerThread.Text = supportQueueThreadInfo.ClaimedByUser.NickName; lnkClaimerThread.NavigateUrl += supportQueueThreadInfo.ClaimedByUserID.ToString(); btnClaim.Visible = false; btnRelease.Visible = true; } else { // not claimed lblClaimDate.Text = string.Empty; btnClaim.Visible = true; btnRelease.Visible = false; } } } phSupportQueueManagement.Visible = _userMayManageSupportQueueContents; if ((_thread.Memo.Length > 0) && _userMayEditMemo) { // convert memo contents to HTML so it's displayed above the thread. string parserLog, messageTextXml; bool errorsOccured = false; string memoAsHTML = TextParser.TransformUBBMessageStringToHTML(_thread.Memo, ApplicationAdapter.GetParserData(), out parserLog, out errorsOccured, out messageTextXml); lblMemo.Text = memoAsHTML; } phMemo.Visible = _userMayEditMemo; bool isBookmarked = UserGuiHelper.CheckIfThreadIsAlreadyBookmarked(SessionAdapter.GetUserID(), threadID); bool isSubscribed = UserGuiHelper.CheckIfThreadIsAlreadySubscribed(SessionAdapter.GetUserID(), threadID); btnBookmarkThread.Visible = !isBookmarked && _userMayDoBasicThreadOperations; btnUnbookmarkThread.Visible = isBookmarked && _userMayDoBasicThreadOperations; bool sendReplyNotifications = CacheManager.GetSystemData().SendReplyNotifications; btnSubscribeToThread.Visible = !isSubscribed && _userMayDoBasicThreadOperations && sendReplyNotifications; btnUnsubscribeFromThread.Visible = isSubscribed && _userMayDoBasicThreadOperations && sendReplyNotifications; // fill the page's content lnkThreads.Text = HttpUtility.HtmlEncode(forum.ForumName); lnkThreads.NavigateUrl += "?ForumID=" + _thread.ForumID; lblForumName_Header.Text = forum.ForumName; lblSectionName.Text = CacheManager.GetSectionName(forum.SectionID); // Check if the current user is allowed to add new messages to the thread. // these controls are not visible by default, show them if necessary if (_userMayDoForumSpecificThreadManagement || _userMayDoSystemWideThreadManagement) { if (!_thread.IsClosed && _userMayAddNewMessages) { lnkCloseThread.Visible = true; lnkCloseThread.NavigateUrl += "?ThreadID=" + threadID + "&StartAtMessage=" + _startMessageNo; } lnkEditThreadProperties.Visible = true; lnkEditThreadProperties.NavigateUrl += "?ThreadID=" + threadID; } if (_userMayDoSystemWideThreadManagement) { lnkMoveThread.Visible = true; lnkMoveThread.NavigateUrl += "?ThreadID=" + threadID; lnkDeleteThread.Visible = true; lnkDeleteThread.NavigateUrl += "?ThreadID=" + threadID; } btnThreadDone.Visible = _thread.MarkedAsDone; btnThreadNotDone.Visible = !_thread.MarkedAsDone; btnThreadDone.Enabled = _userMayMarkThreadAsDone; btnThreadNotDone.Enabled = _userMayMarkThreadAsDone; if (_userMayEditMemo) { lnkEditMemo.Visible = true; lnkEditMemo.NavigateUrl += "?ThreadID=" + threadID + "&StartAtMessage=" + _startMessageNo; } // These controls are visible by default. Hide them when the user can't create threads on this forum if (_userCanCreateThreads) { lnkNewThreadBottom.NavigateUrl += "?ForumID=" + _thread.ForumID + "&StartAtMessage=" + _startMessageNo; lnkNewThreadTop.NavigateUrl += "?ForumID=" + _thread.ForumID + "&StartAtMessage=" + _startMessageNo; } else { lnkNewThreadBottom.Visible = false; lnkNewThreadTop.Visible = false; } if (_userMayAddNewMessages) { lnkNewMessageBottom.NavigateUrl += "?ThreadID=" + threadID + "&StartAtMessage=" + _startMessageNo; lnkNewMessageTop.NavigateUrl += "?ThreadID=" + threadID + "&StartAtMessage=" + _startMessageNo; } else { lnkNewMessageBottom.Visible = false; lnkNewMessageTop.Visible = false; } lblSeparatorTop.Visible = (_userMayAddNewMessages && _userCanCreateThreads); lblSeparatorBottom.Visible = (_userMayAddNewMessages && _userCanCreateThreads); // The amount of postings in this thread are in the dataview row, which should contain just 1 row. int maxAmountMessagesPerPage = SessionAdapter.GetUserDefaultNumberOfMessagesPerPage(); int amountOfMessages = ThreadGuiHelper.GetTotalNumberOfMessagesInThread(threadID); int amountOfPages = ((amountOfMessages - 1) / maxAmountMessagesPerPage) + 1; int currentPageNo = (_startMessageNo / maxAmountMessagesPerPage) + 1; lblCurrentPage.Text = currentPageNo.ToString(); lblTotalPages.Text = amountOfPages.ToString(); lnkPrintThread.NavigateUrl += "?ThreadID=" + threadID; plPageListBottom.AmountMessages = amountOfMessages; plPageListBottom.StartMessageNo = _startMessageNo; plPageListBottom.ThreadID = threadID; plPageListTop.AmountMessages = amountOfMessages; plPageListTop.StartMessageNo = _startMessageNo; plPageListTop.ThreadID = threadID; // Get messages and bind it to the repeater control. Use the startmessage to get only the message visible on the current page. MessagesInThreadTypedList messages = ThreadGuiHelper.GetAllMessagesInThreadAsTypedList(threadID, currentPageNo, maxAmountMessagesPerPage); rptMessages.DataSource = messages; rptMessages.DataBind(); } }