/// <summary> /// Updates the user/forum/thread statistics after a message insert. Also makes sure if the thread isn't in a queue and the forum has a default support /// queue that the thread is added to that queue /// </summary> /// <param name="threadID">The thread ID.</param> /// <param name="userID">The user ID.</param> /// <param name="transactionToUse">The transaction to use.</param> /// <param name="postingDate">The posting date.</param> /// <param name="addToQueueIfRequired">if set to true, the thread will be added to the default queue of the forum the thread is in, if the forum /// has a default support queue and the thread isn't already in a queue.</param> /// <remarks>Leaves the passed in transaction open, so it doesn't commit/rollback, it just performs a set of actions inside the /// passed in transaction.</remarks> internal static void UpdateStatisticsAfterMessageInsert(int threadID, int userID, Transaction transactionToUse, DateTime postingDate, bool addToQueueIfRequired, bool subscribeToThread) { // user statistics UserEntity userUpdater = new UserEntity(); // set the amountofpostings field to an expression so it will be increased with 1. userUpdater.Fields[(int)UserFieldIndex.AmountOfPostings].ExpressionToApply = (UserFields.AmountOfPostings + 1); UserCollection users = new UserCollection(); transactionToUse.Add(users); users.UpdateMulti(userUpdater, (UserFields.UserID == userID)); // update directly on the DB. // thread statistics ThreadEntity threadUpdater = new ThreadEntity(); threadUpdater.ThreadLastPostingDate = postingDate; threadUpdater.MarkedAsDone = false; ThreadCollection threads = new ThreadCollection(); transactionToUse.Add(threads); threads.UpdateMulti(threadUpdater, (ThreadFields.ThreadID == threadID)); // forum statistics. Load the forum from the DB, as we need it later on. Use a fieldcompareset predicate to fetch the forum as we don't know the // forumID as we haven't fetched the thread ForumCollection forums = new ForumCollection(); transactionToUse.Add(forums); // use a fieldcompare set predicate to select the forumid based on the thread. This filter is equal to // WHERE ForumID == (SELECT ForumID FROM Thread WHERE ThreadID=@ThreadID) var forumFilter = new FieldCompareSetPredicate( ForumFields.ForumID, ThreadFields.ForumID, SetOperator.Equal, (ThreadFields.ThreadID == threadID)); forums.GetMulti(forumFilter); ForumEntity containingForum = null; if(forums.Count>0) { // forum found. There's just one. containingForum = forums[0]; containingForum.ForumLastPostingDate = postingDate; // save the forum. Just save the collection forums.SaveMulti(); } if(addToQueueIfRequired) { // If the thread involved isn't in a queue, place it in the default queue of the forum (if applicable) SupportQueueEntity containingQueue = SupportQueueGuiHelper.GetQueueOfThread(threadID, transactionToUse); if((containingQueue == null) && (containingForum != null) && (containingForum.DefaultSupportQueueID.HasValue)) { // not in a queue, and the forum has a default queue. Add the thread to the queue of the forum SupportQueueManager.AddThreadToQueue(threadID, containingForum.DefaultSupportQueueID.Value, userID, transactionToUse); } } //subscribe to thread if indicated if(subscribeToThread) { UserManager.AddThreadToSubscriptions(threadID, userID, transactionToUse); } }
/// <summary> /// Inserts in each predicate expression element the persistence info object for the field used. If there is already a fieldpersistenceinfo /// element for a given field, it is skipped. /// </summary> /// <param name="expression">IPredicateExpression object which has predicate elements whose persistence info objects have to be /// set to a value.</param> protected override void InsertPersistenceInfoObjects(IPredicateExpression expression) { if (expression == null) { return; } for (int i = 0; i < expression.Count; i++) { if (expression[i].Type != PredicateExpressionElementType.Predicate) { continue; } IPredicate currentPredicate = (IPredicate)expression[i].Contents; switch ((PredicateType)currentPredicate.InstanceType) { case PredicateType.Undefined: continue; case PredicateType.PredicateExpression: // recurse InsertPersistenceInfoObjects((IPredicateExpression)expression[i].Contents); break; case PredicateType.FieldBetweenPredicate: FieldBetweenPredicate betweenPredicate = (FieldBetweenPredicate)currentPredicate; if (betweenPredicate.PersistenceInfo == null) { betweenPredicate.PersistenceInfo = GetFieldPersistenceInfo((IEntityField2)betweenPredicate.FieldCore); } if (betweenPredicate.BeginIsField && (betweenPredicate.PersistenceInfoBegin == null)) { betweenPredicate.PersistenceInfoBegin = GetFieldPersistenceInfo((IEntityField2)betweenPredicate.FieldBeginCore); } if (betweenPredicate.EndIsField && (betweenPredicate.PersistenceInfoEnd == null)) { betweenPredicate.PersistenceInfoEnd = GetFieldPersistenceInfo((IEntityField2)betweenPredicate.FieldEndCore); } break; case PredicateType.FieldCompareNullPredicate: FieldCompareNullPredicate compareNullPredicate = (FieldCompareNullPredicate)currentPredicate; if (compareNullPredicate.PersistenceInfo == null) { compareNullPredicate.PersistenceInfo = GetFieldPersistenceInfo((IEntityField2)compareNullPredicate.FieldCore); } break; case PredicateType.FieldCompareValuePredicate: FieldCompareValuePredicate compareValuePredicate = (FieldCompareValuePredicate)currentPredicate; if (compareValuePredicate.PersistenceInfo == null) { compareValuePredicate.PersistenceInfo = GetFieldPersistenceInfo((IEntityField2)compareValuePredicate.FieldCore); } break; case PredicateType.FieldLikePredicate: FieldLikePredicate likePredicate = (FieldLikePredicate)currentPredicate; if (likePredicate.PersistenceInfo == null) { likePredicate.PersistenceInfo = GetFieldPersistenceInfo((IEntityField2)likePredicate.FieldCore); } break; case PredicateType.FieldCompareRangePredicate: FieldCompareRangePredicate compareRangePredicate = (FieldCompareRangePredicate)currentPredicate; if (compareRangePredicate.PersistenceInfo == null) { compareRangePredicate.PersistenceInfo = GetFieldPersistenceInfo((IEntityField2)compareRangePredicate.FieldCore); } break; case PredicateType.FieldCompareExpressionPredicate: FieldCompareExpressionPredicate expressionPredicate = (FieldCompareExpressionPredicate)currentPredicate; if (expressionPredicate.PersistenceInfo == null) { expressionPredicate.PersistenceInfo = GetFieldPersistenceInfo((IEntityField2)expressionPredicate.FieldCore); } if (expressionPredicate.ExpressionToCompareWith != null) { InsertPersistenceInfoObjects(expressionPredicate.ExpressionToCompareWith); } break; case PredicateType.FieldFullTextSearchPredicate: FieldFullTextSearchPredicate fullTextSearchPredicate = (FieldFullTextSearchPredicate)currentPredicate; if (fullTextSearchPredicate.TargetIsFieldList) { if (fullTextSearchPredicate.PersistenceInfosFieldsList == null) { ArrayList persistenceInfos = new ArrayList(); foreach (IEntityField2 field in fullTextSearchPredicate.FieldsList) { persistenceInfos.Add(GetFieldPersistenceInfo(field)); } fullTextSearchPredicate.PersistenceInfosFieldsList = persistenceInfos; } } else { if (fullTextSearchPredicate.PersistenceInfo == null) { fullTextSearchPredicate.PersistenceInfo = GetFieldPersistenceInfo((IEntityField2)fullTextSearchPredicate.FieldCore); } } break; case PredicateType.FieldCompareSetPredicate: FieldCompareSetPredicate compareSetPredicate = (FieldCompareSetPredicate)currentPredicate; if ((compareSetPredicate.PersistenceInfoField == null) && (compareSetPredicate.FieldCore != null)) { compareSetPredicate.PersistenceInfoField = GetFieldPersistenceInfo((IEntityField2)compareSetPredicate.FieldCore); } if (compareSetPredicate.PersistenceInfoSetField == null) { compareSetPredicate.PersistenceInfoSetField = GetFieldPersistenceInfo((IEntityField2)compareSetPredicate.SetFieldCore); } InsertPersistenceInfoObjects(compareSetPredicate.SetFilterAsPredicateExpression); InsertPersistenceInfoObjects(compareSetPredicate.SetRelations); InsertPersistenceInfoObjects(compareSetPredicate.SetSorter); InsertPersistenceInfoObjects(compareSetPredicate.GroupByClause); break; default: // __LLBLGENPRO_USER_CODE_REGION_START InsertPersistenceInfoObjectsPredicate // __LLBLGENPRO_USER_CODE_REGION_END OnInsertPersistenceObjects(currentPredicate); break; } } }
/// <summary> /// Updates the user/forum/thread statistics after a message insert. Also makes sure if the thread isn't in a queue and the forum has a default support /// queue that the thread is added to that queue /// </summary> /// <param name="threadID">The thread ID.</param> /// <param name="userID">The user ID.</param> /// <param name="transactionToUse">The transaction to use.</param> /// <param name="postingDate">The posting date.</param> /// <param name="addToQueueIfRequired">if set to true, the thread will be added to the default queue of the forum the thread is in, if the forum /// has a default support queue and the thread isn't already in a queue.</param> /// <remarks>Leaves the passed in transaction open, so it doesn't commit/rollback, it just performs a set of actions inside the /// passed in transaction.</remarks> internal static void UpdateStatisticsAfterMessageInsert(int threadID, int userID, Transaction transactionToUse, DateTime postingDate, bool addToQueueIfRequired, bool subscribeToThread) { // user statistics UserEntity userUpdater = new UserEntity(); // set the amountofpostings field to an expression so it will be increased with 1. userUpdater.Fields[(int)UserFieldIndex.AmountOfPostings].ExpressionToApply = (UserFields.AmountOfPostings + 1); UserCollection users = new UserCollection(); transactionToUse.Add(users); users.UpdateMulti(userUpdater, (UserFields.UserID == userID)); // update directly on the DB. // thread statistics ThreadEntity threadUpdater = new ThreadEntity(); threadUpdater.ThreadLastPostingDate = postingDate; threadUpdater.MarkedAsDone = false; ThreadCollection threads = new ThreadCollection(); transactionToUse.Add(threads); threads.UpdateMulti(threadUpdater, (ThreadFields.ThreadID == threadID)); // forum statistics. Load the forum from the DB, as we need it later on. Use a fieldcompareset predicate to fetch the forum as we don't know the // forumID as we haven't fetched the thread ForumCollection forums = new ForumCollection(); transactionToUse.Add(forums); // use a fieldcompare set predicate to select the forumid based on the thread. This filter is equal to // WHERE ForumID == (SELECT ForumID FROM Thread WHERE ThreadID=@ThreadID) var forumFilter = new FieldCompareSetPredicate( ForumFields.ForumID, ThreadFields.ForumID, SetOperator.Equal, (ThreadFields.ThreadID == threadID)); forums.GetMulti(forumFilter); ForumEntity containingForum = null; if(forums.Count>0) { // forum found. There's just one. containingForum = forums[0]; containingForum.ForumLastPostingDate = postingDate; // save the forum. Just save the collection forums.SaveMulti(); } if(addToQueueIfRequired) { // If the thread involved isn't in a queue, place it in the default queue of the forum (if applicable) SupportQueueEntity containingQueue = SupportQueueGuiHelper.GetQueueOfThread(threadID, transactionToUse); if((containingQueue == null) && (containingForum != null) && (containingForum.DefaultSupportQueueID.HasValue)) { // not in a queue, and the forum has a default queue. Add the thread to the queue of the forum SupportQueueManager.AddThreadToQueue(threadID, containingForum.DefaultSupportQueueID.Value, userID, transactionToUse); } } //subscribe to thread if indicated if(subscribeToThread) { UserManager.AddThreadToSubscriptions(threadID, userID, transactionToUse); } }