Exemple #1
0
 /// <summary>
 /// Inserts a new message in thread given. All exceptions are passed upwards, caller has full control over transaction.
 /// </summary>
 /// <param name="threadID">Thread wherein the new message will be placed</param>
 /// <param name="userID">User who posted this message</param>
 /// <param name="messageText">Message text</param>
 /// <param name="messageAsHTML">Message text as HTML</param>
 /// <param name="userIDIPAddress">IP address of user calling this method</param>
 /// <param name="messageAsXML">Message text as XML, which is the result of the parse action on MessageText.</param>
 /// <param name="transactionToUse">the open transaction to use for saving this message.</param>
 /// <param name="postingDate">The posting date.</param>
 /// <returns>new messageid</returns>
 private static int InsertNewMessage(int threadID, int userID, string messageText, string messageAsHTML, string userIDIPAddress, 
     string messageAsXML, Transaction transactionToUse, DateTime postingDate)
 {
     MessageEntity message = new MessageEntity();
     message.MessageText = messageText;
     message.MessageTextAsHTML = messageAsHTML;
     message.PostedByUserID = userID;
     message.PostingDate = postingDate;
     message.ThreadID = threadID;
     message.PostedFromIP = userIDIPAddress;
     message.MessageTextAsXml = messageAsXML;
     transactionToUse.Add(message);
     bool result = message.Save();
     if(result)
     {
         return message.MessageID;
     }
     else
     {
         return 0;
     }
 }
Exemple #2
0
        /// <summary>
        /// Updates the given message with the message passed, and logs the user passed as the changer of this
        /// message.
        /// </summary>
        /// <param name="editorUserID">ID of user who changed the message</param>
        /// <param name="editedMessageID">ID of message which was changed</param>
        /// <param name="messageText">Changed message text</param>
        /// <param name="messageAsHTML">Changed message text in HTML</param>
        /// <param name="editorUserIDIPAddress">IP address used to make the modification. This IP address is logged with the
        /// change to keep evidence who made which change from which IP address</param>
        /// <param name="messageAsXML">Message text as XML, which is the result of the parse action on MessageText.</param>
        /// <returns>True if succeeded, false otherwise</returns>
        /// <remarks>This routine is migrated to LLBLGen Pro</remarks>
        public static bool UpdateEditedMessage(int editorUserID, int editedMessageID, string messageText, string messageAsHTML, 
            string editorUserIDIPAddress, string messageAsXML)
        {
            // now save the message. First pull it from the db
            MessageEntity message = new MessageEntity(editedMessageID);

            //update the fields with the new passed values
            message.MessageText = messageText;
            message.MessageTextAsHTML = messageAsHTML;
            message.MessageTextAsXml = messageAsXML;
            return message.Save();
        }
Exemple #3
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();
            }
        }
Exemple #4
0
        /// <summary>
        /// Re-parses all messages from start date till now or when amountToIndex is reached. This routine will read messagetext for a message,
        /// parse it, and update the MessageTextAsXML field with the parse result. 
        /// </summary>
        /// <param name="amountToParse">Amount to parse.</param>
        /// <param name="startDate">Start date.</param>
        /// <param name="reGenerateHTML">If true, the HTML is also re-generated and saved.</param>
        /// <returns>the amount of messages re-parsed</returns>
        public static int ReParseMessages(int amountToParse, DateTime startDate, bool reGenerateHTML, ParserData parserData)
        {
            // index is blocks of 100 messages.
            var qf = new QueryFactory();
            var q = qf.Create()
                        .Select(MessageFields.MessageID, MessageFields.MessageText)
                        .Where(MessageFields.PostingDate >= new DateTime(startDate.Year, startDate.Month, startDate.Day, 0, 0, 0, 0));

            if(amountToParse <= 0)
            {
                // If we don't have a specific amount of messages to parse, then parse all messages posted till Now.
                q.AndWhere(MessageFields.PostingDate <= DateTime.Now);
            }

            TypedListDAO dao = new TypedListDAO();

            bool parsingFinished = false;
            int amountProcessed = 0;
            int pageSize = 100;
            int pageNo = 1;

            while(!parsingFinished)
            {
                q.Page(pageNo, pageSize);
                DataTable messagesToParse = dao.FetchAsDataTable(q);
                parsingFinished = (messagesToParse.Rows.Count <= 0);

                if(!parsingFinished)
                {
                    foreach(DataRow row in messagesToParse.Rows)
                    {
                        MessageEntity directUpdater = new MessageEntity();
                        directUpdater.IsNew = false;

                        string messageXML = string.Empty;
                        string messageHTML = string.Empty;
                        TextParser.ReParseMessage((string)row["MessageText"], reGenerateHTML, parserData, out messageXML, out messageHTML);

                        // use the directupdater entity to create an update query without fetching the entity first.
                        directUpdater.Fields[(int)MessageFieldIndex.MessageID].ForcedCurrentValueWrite((int)row["MessageID"]);
                        directUpdater.MessageTextAsXml = messageXML;

                        if(reGenerateHTML)
                        {
                            directUpdater.MessageTextAsHTML=messageHTML;
                        }
                        directUpdater.Fields.IsDirty=true;

                        // no transactional update.
                        directUpdater.Save();
                    }

                    amountProcessed += messagesToParse.Rows.Count;
                    pageNo++;

                    if(amountToParse > 0)
                    {
                        parsingFinished = (amountToParse <= amountProcessed);
                    }
                }
            }
            return amountProcessed;
        }