Example #1
0
        /// <summary>
        /// Claims the thread specified for the user specified. As the thread can be in one queue at a time, it simply has to update the SupportQueueThread entity.
        /// </summary>
        /// <param name="userID">The user ID.</param>
        /// <param name="threadID">The thread ID.</param>
        public static void ClaimThread(int userID, int threadID)
        {
            SupportQueueThreadEntity supportQueueThread = new SupportQueueThreadEntity();
            supportQueueThread.FetchUsingUCThreadID(threadID);
            if(supportQueueThread.IsNew)
            {
                // not found, return
                return;
            }

            // simply overwrite an existing claim if any.
            supportQueueThread.ClaimedByUserID = userID;
            supportQueueThread.ClaimedOn = DateTime.Now;

            // done, save it
            supportQueueThread.Save();
        }
Example #2
0
        /// <summary>
        /// Adds the thread with the ID specified to the support queue with the ID specified
        /// </summary>
        /// <param name="threadID">The thread ID.</param>
        /// <param name="queueID">The queue ID.</param>
        /// <param name="userID">The user ID of the user causing this thread to be placed in the queue specified.</param>
        /// <param name="transactionToUse">The transaction to use. Is not null if there's a transaction in progress.</param>
        /// <remarks>first removes the thread from a queue if it's in a queue</remarks>
        public static void AddThreadToQueue(int threadID, int queueID, int userID, Transaction transactionToUse)
        {
            // first remove the thread from any queue it's in.
            RemoveThreadFromQueue(threadID, transactionToUse);

            // then add it to the queue specified.
            SupportQueueThreadEntity supportQueueThread = new SupportQueueThreadEntity();
            supportQueueThread.ThreadID = threadID;
            supportQueueThread.QueueID = queueID;
            supportQueueThread.PlacedInQueueByUserID = userID;
            supportQueueThread.PlacedInQueueOn = DateTime.Now;

            if(transactionToUse != null)
            {
                // transaction in progress, add the entity to the transaction
                transactionToUse.Add(supportQueueThread);
            }
            supportQueueThread.Save();
        }
Example #3
0
        /// <summary>
        /// Deletes the user with the ID passed in. Will reset all posts made by the user to the userid 0. 
        /// </summary>
        /// <param name="userID">The user ID.</param>
        /// <remarks>Can't delete user 0</remarks>
        /// <returns>true if succeeded, false otherwise</returns>
        public static bool DeleteUser(int userID)
        {
            if(userID == 0)
            {
                // can't delete the Anonymous coward user.
                return false;
            }

            UserEntity toDelete = UserGuiHelper.GetUser(userID);
            if(toDelete==null)
            {
                // user doesn't exist
                return false;
            }

            // all actions have to take place in a transaction.
            Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "DeleteUser");

            try
            {
                // we'll first update all PostedByUserId fields of all messages which are posted by the user to delete.
                MessageEntity messageUpdater = new MessageEntity();
                messageUpdater.PostedByUserID = 0;	// reset to AC.
                MessageCollection messages = new MessageCollection();
                trans.Add(messages);	// add to the transaction
                // update all entities directly in the DB, which match the following filter and update them with the new values set in messageUpdater.
                messages.UpdateMulti(messageUpdater, (MessageFields.PostedByUserID == userID));

                // set the startuser of threads started by this user to 0
                ThreadEntity threadUpdater = new ThreadEntity();
                threadUpdater.StartedByUserID = 0;
                ThreadCollection threads = new ThreadCollection();
                trans.Add(threads);
                threads.UpdateMulti(threadUpdater, (ThreadFields.StartedByUserID == userID));

                // remove the user from the UserRoles set, as the user shouldn't be in any roles.
                RoleUserCollection roleUsersDeleter = new RoleUserCollection();
                trans.Add(roleUsersDeleter);
                // delete all entities directly from the DB which match the following filter.
                roleUsersDeleter.DeleteMulti(RoleUserFields.UserID == userID);

                // delete all bookmarks of user
                BookmarkCollection bookmarkDeleter = new BookmarkCollection();
                trans.Add(bookmarkDeleter);
                // delete all bookmarks for this user directly from the DB using the following filter.
                bookmarkDeleter.DeleteMulti(BookmarkFields.UserID == userID);

                // delete all audit data
                AuditDataCoreCollection auditDataDeleter = new AuditDataCoreCollection();
                // first fetch it, then delete all entities from the collection, as the audit data is in an inheritance hierarchy of TargetPerEntity which can't
                // be deleted directly from the db.
                trans.Add(auditDataDeleter);
                auditDataDeleter.GetMulti(AuditDataCoreFields.UserID == userID);
                auditDataDeleter.DeleteMulti();

                // set IP bans set by this user to userid 0
                IPBanEntity ipbanUpdater = new IPBanEntity();
                ipbanUpdater.IPBanSetByUserID = 0;
                IPBanCollection ipBans = new IPBanCollection();
                trans.Add(ipBans);
                ipBans.UpdateMulti(ipbanUpdater, (IPBanFields.IPBanSetByUserID == userID));

                // delete threadsubscriptions
                ThreadSubscriptionCollection threadSubscriptionsDeleter = new ThreadSubscriptionCollection();
                trans.Add(threadSubscriptionsDeleter);
                threadSubscriptionsDeleter.DeleteMulti(ThreadSubscriptionFields.UserID == userID);

                // remove supportqueuethread claims
                SupportQueueThreadCollection supportQueueThreads = new SupportQueueThreadCollection();
                trans.Add(supportQueueThreads);
                supportQueueThreads.DeleteMulti(SupportQueueThreadFields.ClaimedByUserID == userID);

                // set all placed in queue references to userid 0, so the threads stay in the queues.
                SupportQueueThreadEntity supportQueueThreadUpdater = new SupportQueueThreadEntity();
                supportQueueThreadUpdater.PlacedInQueueByUserID=0;
                supportQueueThreads.UpdateMulti(supportQueueThreadUpdater, (SupportQueueThreadFields.PlacedInQueueByUserID == userID));

                // now delete the actual user entity
                trans.Add(toDelete);
                toDelete.Delete();

                // all done
                trans.Commit();
                return true;
            }
            catch
            {
                trans.Rollback();
                throw;
            }
            finally
            {
                trans.Dispose();
            }
        }
Example #4
0
        /// <summary>
        /// Releases the claim on the thread specified. As the thread can be in one queue at a time, it simply has to update the SupportQueueThread entity.
        /// </summary>
        /// <param name="threadID">The thread ID.</param>
        public static void ReleaseClaimOnThread(int threadID)
        {
            SupportQueueThreadEntity supportQueueThread = new SupportQueueThreadEntity();
            supportQueueThread.FetchUsingUCThreadID(threadID);
            if(supportQueueThread.IsNew)
            {
                // not found, return
                return;
            }

            // simply reset an existing claim
            supportQueueThread.ClaimedByUserID = null;		// nullable type, so set to null.
            supportQueueThread.ClaimedOn = null;			// nullable type, so set to null.

            // done, save it
            supportQueueThread.Save();
        }
Example #5
0
        /// <summary>
        /// Gets the support queue thread info entity and if specified, prefetches the user entity which claimed the related thread. 
        /// </summary>
        /// <param name="threadID">The thread ID.</param>
        /// <param name="prefetchClaimUser">if set to true it will </param>
        /// <returns>fetched entity if found, otherwise null</returns>
        public static SupportQueueThreadEntity GetSupportQueueThreadInfo(int threadID, bool prefetchClaimUser)
        {
            SupportQueueThreadEntity toReturn = new SupportQueueThreadEntity();
            PrefetchPath path = null;
            if(prefetchClaimUser)
            {
                // prefetch the user who claimed this thread (if any)
                path = new PrefetchPath((int)EntityType.SupportQueueThreadEntity);
                path.Add(SupportQueueThreadEntity.PrefetchPathClaimedByUser);
            }

            // now fetch the entity using the unique constraint on Thread by specifying the threadID passed in. Also specify the prefetch path (if any)
            toReturn.FetchUsingUCThreadID(threadID, path);
            if(toReturn.IsNew)
            {
                // not found
                return null;
            }
            return toReturn;
        }
Example #6
0
        /// <summary>
        /// Creates a new thread in the given forum and places the passed in message as the first message in the thread.
        /// Caller should validate input parameters.
        /// </summary>
        /// <param name="forumID">Forum wherein the new thread will be placed</param>
        /// <param name="userID">User who started this thread</param>
        /// <param name="subject">Subject of the thread</param>
        /// <param name="messageText">First message of the thread</param>
        /// <param name="messageAsHTML">Message text as HTML</param>
        /// <param name="isSticky">Flag if the thread is sticky / pinned (true) or not (false)</param>
        /// <param name="userIDIPAddress">IP address of user calling this method</param>
        /// <param name="defaultSupportQueueID">The ID of the default support queue for this forum. If not null, the thread created will be
        /// added to the support queue with the ID specified.</param>
        /// <param name="messageID">The message ID of the new message, which is the start message in the thread.</param>
        /// <returns>ThreadID if succeeded, 0 if not.</returns>
        public static int CreateNewThreadInForum(int forumID, int userID, string subject, string messageText, string messageAsHTML, bool isSticky, 
            string userIDIPAddress, int? defaultSupportQueueID, bool subscribeToThread, out int messageID)
        {
            Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "NewThread");
            try
            {
                DateTime postDate = DateTime.Now;

                ThreadEntity newThread = new ThreadEntity();
                newThread.ForumID = forumID;
                newThread.IsClosed = false;
                newThread.IsSticky = isSticky;
                newThread.StartedByUserID = userID;
                newThread.Subject = subject;
                newThread.ThreadLastPostingDate = postDate;

                if(defaultSupportQueueID.HasValue)
                {
                    // a support queue has been specified as the default support queue for this forum. Add the new thread to this support queue.
                    SupportQueueThreadEntity supportQueueThread = new SupportQueueThreadEntity();
                    supportQueueThread.QueueID = defaultSupportQueueID.Value;
                    supportQueueThread.PlacedInQueueByUserID = userID;
                    supportQueueThread.PlacedInQueueOn = DateTime.Now;
                    // assign the Thread property to the newly created thread entity, so this supportqueuethreadentity will be part of the graph
                    // of objects which will be saved.
                    supportQueueThread.Thread = newThread;
                }

                DateTime postingDate = DateTime.Now;
                MessageEntity newMessage = new MessageEntity();
                newMessage.MessageText = messageText;
                newMessage.MessageTextAsHTML = messageAsHTML;
                newMessage.PostedByUserID = userID;
                newMessage.PostingDate = postingDate;
                newMessage.PostedFromIP = userIDIPAddress;
                newMessage.Thread = newThread;

                // add the newMessage entity to the transaction object. All entities saved recursively will be added automatically
                trans.Add(newMessage);

                // save the complete graph
                newMessage.Save(true);

                messageID = newMessage.MessageID;
                int threadID = newMessage.ThreadID;

                // update thread statistics, this is the task for the message manager, and we pass the transaction object so the actions will run in
                // the same transaction.
                MessageManager.UpdateStatisticsAfterMessageInsert(threadID, userID, trans, postingDate, false, subscribeToThread);

                trans.Commit();
                return newThread.ThreadID;
            }
            catch(Exception)
            {
                trans.Rollback();
                throw;
            }
            finally
            {
                trans.Dispose();
            }
        }
Example #7
0
        /// <summary>Creates a new, empty SupportQueueThreadEntity object.</summary>
        /// <returns>A new, empty SupportQueueThreadEntity object.</returns>
        public override IEntity Create()
        {
            IEntity toReturn = new SupportQueueThreadEntity();

            // __LLBLGENPRO_USER_CODE_REGION_START CreateNewSupportQueueThread
            // __LLBLGENPRO_USER_CODE_REGION_END
            return toReturn;
        }
Example #8
0
 /// <summary> setups the sync logic for member _supportQueueThread</summary>
 /// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
 private void SetupSyncSupportQueueThread(IEntityCore relatedEntity)
 {
     if(_supportQueueThread!=relatedEntity)
     {
         DesetupSyncSupportQueueThread(true, true);
         _supportQueueThread = (SupportQueueThreadEntity)relatedEntity;
         this.PerformSetupSyncRelatedEntity( _supportQueueThread, new PropertyChangedEventHandler( OnSupportQueueThreadPropertyChanged ), "SupportQueueThread", SD.HnD.DAL.RelationClasses.StaticThreadRelations.SupportQueueThreadEntityUsingThreadIDStatic, false, ref _alreadyFetchedSupportQueueThread, new string[] {  } );
     }
 }
Example #9
0
 /// <summary> Removes the sync logic for member _supportQueueThread</summary>
 /// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
 /// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param>
 private void DesetupSyncSupportQueueThread(bool signalRelatedEntity, bool resetFKFields)
 {
     this.PerformDesetupSyncRelatedEntity( _supportQueueThread, new PropertyChangedEventHandler( OnSupportQueueThreadPropertyChanged ), "SupportQueueThread", SD.HnD.DAL.RelationClasses.StaticThreadRelations.SupportQueueThreadEntityUsingThreadIDStatic, false, signalRelatedEntity, "Thread", false, new int[] { (int)ThreadFieldIndex.ThreadID } );
     _supportQueueThread = null;
 }
Example #10
0
 /// <summary> Retrieves the related entity of type 'SupportQueueThreadEntity', using a relation of type '1:1'</summary>
 /// <param name="forceFetch">if true, it will discard any changes currently in the currently loaded related entity and will refetch the entity from the persistent storage</param>
 /// <returns>A fetched entity of type 'SupportQueueThreadEntity' which is related to this entity.</returns>
 public virtual SupportQueueThreadEntity GetSingleSupportQueueThread(bool forceFetch)
 {
     if( ( !_alreadyFetchedSupportQueueThread || forceFetch || _alwaysFetchSupportQueueThread) && !this.IsSerializing && !this.IsDeserializing && !this.InDesignMode )
     {
         bool performLazyLoading = this.CheckIfLazyLoadingShouldOccur(Relations.SupportQueueThreadEntityUsingThreadID);
         SupportQueueThreadEntity newEntity = new SupportQueueThreadEntity();
         bool fetchResult = false;
         if(performLazyLoading)
         {
             AddToTransactionIfNecessary(newEntity);
             fetchResult = newEntity.FetchUsingUCThreadID(this.ThreadID);
         }
         if(fetchResult)
         {
             newEntity = (SupportQueueThreadEntity)GetFromActiveContext(newEntity);
         }
         else
         {
             if(!_supportQueueThreadReturnsNewIfNotFound)
             {
                 RemoveFromTransactionIfNecessary(newEntity);
                 newEntity = null;
             }
         }
         this.SupportQueueThread = newEntity;
         _alreadyFetchedSupportQueueThread = fetchResult;
     }
     return _supportQueueThread;
 }
Example #11
0
        /// <summary>Private CTor for deserialization</summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        protected ThreadEntityBase(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            _auditDataThreadRelated = (SD.HnD.DAL.CollectionClasses.AuditDataThreadRelatedCollection)info.GetValue("_auditDataThreadRelated", typeof(SD.HnD.DAL.CollectionClasses.AuditDataThreadRelatedCollection));
            _alwaysFetchAuditDataThreadRelated = info.GetBoolean("_alwaysFetchAuditDataThreadRelated");
            _alreadyFetchedAuditDataThreadRelated = info.GetBoolean("_alreadyFetchedAuditDataThreadRelated");

            _presentInBookmarks = (SD.HnD.DAL.CollectionClasses.BookmarkCollection)info.GetValue("_presentInBookmarks", typeof(SD.HnD.DAL.CollectionClasses.BookmarkCollection));
            _alwaysFetchPresentInBookmarks = info.GetBoolean("_alwaysFetchPresentInBookmarks");
            _alreadyFetchedPresentInBookmarks = info.GetBoolean("_alreadyFetchedPresentInBookmarks");

            _messages = (SD.HnD.DAL.CollectionClasses.MessageCollection)info.GetValue("_messages", typeof(SD.HnD.DAL.CollectionClasses.MessageCollection));
            _alwaysFetchMessages = info.GetBoolean("_alwaysFetchMessages");
            _alreadyFetchedMessages = info.GetBoolean("_alreadyFetchedMessages");

            _threadSubscription = (SD.HnD.DAL.CollectionClasses.ThreadSubscriptionCollection)info.GetValue("_threadSubscription", typeof(SD.HnD.DAL.CollectionClasses.ThreadSubscriptionCollection));
            _alwaysFetchThreadSubscription = info.GetBoolean("_alwaysFetchThreadSubscription");
            _alreadyFetchedThreadSubscription = info.GetBoolean("_alreadyFetchedThreadSubscription");
            _usersWhoBookmarkedThread = (SD.HnD.DAL.CollectionClasses.UserCollection)info.GetValue("_usersWhoBookmarkedThread", typeof(SD.HnD.DAL.CollectionClasses.UserCollection));
            _alwaysFetchUsersWhoBookmarkedThread = info.GetBoolean("_alwaysFetchUsersWhoBookmarkedThread");
            _alreadyFetchedUsersWhoBookmarkedThread = info.GetBoolean("_alreadyFetchedUsersWhoBookmarkedThread");

            _usersWhoPostedInThread = (SD.HnD.DAL.CollectionClasses.UserCollection)info.GetValue("_usersWhoPostedInThread", typeof(SD.HnD.DAL.CollectionClasses.UserCollection));
            _alwaysFetchUsersWhoPostedInThread = info.GetBoolean("_alwaysFetchUsersWhoPostedInThread");
            _alreadyFetchedUsersWhoPostedInThread = info.GetBoolean("_alreadyFetchedUsersWhoPostedInThread");

            _usersWhoSubscribedThread = (SD.HnD.DAL.CollectionClasses.UserCollection)info.GetValue("_usersWhoSubscribedThread", typeof(SD.HnD.DAL.CollectionClasses.UserCollection));
            _alwaysFetchUsersWhoSubscribedThread = info.GetBoolean("_alwaysFetchUsersWhoSubscribedThread");
            _alreadyFetchedUsersWhoSubscribedThread = info.GetBoolean("_alreadyFetchedUsersWhoSubscribedThread");
            _forum = (ForumEntity)info.GetValue("_forum", typeof(ForumEntity));
            if(_forum!=null)
            {
                _forum.AfterSave+=new EventHandler(OnEntityAfterSave);
            }
            _forumReturnsNewIfNotFound = info.GetBoolean("_forumReturnsNewIfNotFound");
            _alwaysFetchForum = info.GetBoolean("_alwaysFetchForum");
            _alreadyFetchedForum = info.GetBoolean("_alreadyFetchedForum");

            _userWhoStartedThread = (UserEntity)info.GetValue("_userWhoStartedThread", typeof(UserEntity));
            if(_userWhoStartedThread!=null)
            {
                _userWhoStartedThread.AfterSave+=new EventHandler(OnEntityAfterSave);
            }
            _userWhoStartedThreadReturnsNewIfNotFound = info.GetBoolean("_userWhoStartedThreadReturnsNewIfNotFound");
            _alwaysFetchUserWhoStartedThread = info.GetBoolean("_alwaysFetchUserWhoStartedThread");
            _alreadyFetchedUserWhoStartedThread = info.GetBoolean("_alreadyFetchedUserWhoStartedThread");
            _supportQueueThread = (SupportQueueThreadEntity)info.GetValue("_supportQueueThread", typeof(SupportQueueThreadEntity));
            if(_supportQueueThread!=null)
            {
                _supportQueueThread.AfterSave+=new EventHandler(OnEntityAfterSave);
            }
            _supportQueueThreadReturnsNewIfNotFound = info.GetBoolean("_supportQueueThreadReturnsNewIfNotFound");
            _alwaysFetchSupportQueueThread = info.GetBoolean("_alwaysFetchSupportQueueThread");
            _alreadyFetchedSupportQueueThread = info.GetBoolean("_alreadyFetchedSupportQueueThread");
            this.FixupDeserialization(FieldInfoProviderSingleton.GetInstance(), PersistenceInfoProviderSingleton.GetInstance());
            // __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor
            // __LLBLGENPRO_USER_CODE_REGION_END
        }