Ejemplo n.º 1
0
        /// <summary>
        /// Add a message to the list of pending messages that should be shown to the end user
        /// </summary>
        /// <param name="message">The message to add</param>
        /// <param name="type">The message type</param>
        static private void AddGenericMessageForAll(string message, SystemMessage.SystemMessageType type)
        {
            try
            {
                List <SystemMessage> allUsersMessages = new List <SystemMessage>();
                if (SystemMessageList.AllUsersMessageList != null)
                {
                    for (int i = 0; i < SystemMessageList.AllUsersMessageList.Length; i++)
                    {
                        allUsersMessages.Add(SystemMessageList.AllUsersMessageList[i]);
                    }
                }

                // Create a new list with our message at the top
                List <SystemMessage> newList = new List <SystemMessage>();
                // added to the session for the user control to display the message only once
                HttpContext.Current.Session["SHOW_MESSAGE"] = true;
                SystemMessage theNewMessageForAllUsers = new SystemMessage(message, type);
                theNewMessageForAllUsers.ForAllUsers = true;
                newList.Add(theNewMessageForAllUsers);

                // Add all the elements from the previous list to the end of the new list
                while (allUsersMessages.Count > 0)
                {
                    SystemMessage theElement = allUsersMessages[0];
                    allUsersMessages.RemoveAt(0);
                    newList.Add(theElement);
                }

                // Save the list back to the user's profile
                SystemMessageList.AllUsersSetList(newList);
            }
            catch (Exception q)
            {
                log.Error("Failed to add message of type " + type.ToString(), q);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Clear the messages that are older than the number of minutes defined in the
        /// system configuration file.  Save the rest.
        /// </summary>
        static public void ExpireOlderSystemMessages()
        {
            // Get a list of existing messages...
            SystemMessageList theUsersList = GetMessageListForUser(false);

            List <SystemMessage> myList = theUsersList.GetList();

            if (myList == null)
            {
                myList = new List <SystemMessage>();
            }

            // Get from the configuration the number of minutes that the messages should be
            // kept
            int secondsToKeep = App.Configuration.Configuration.GetTimeToExpireSystemMessages();

            // Create a list with the new messages that are not too old.
            List <SystemMessage> newList = new List <SystemMessage>();

            // Copy all the messages that are not too old to the new list
            while (myList.Count > 0)
            {
                SystemMessage theElement = myList[0];
                myList.RemoveAt(0);
                if (theElement.Time.AddSeconds(secondsToKeep).CompareTo(DateTime.Now) >= 0)
                {
                    // Keep the element. The alloted time has not passed.
                    newList.Add(theElement);
                }
            }

            // Save the list back to the user's profile
            theUsersList.SetList(newList);
            SaveMessageListForUser(theUsersList);

            // ================ DO THE SAME FOR MESSAGES FOR ALL USERS ==============
            List <SystemMessage> allUsersMessages = new List <SystemMessage>();

            if (SystemMessageList.AllUsersMessageList != null)
            {
                for (int i = 0; i < SystemMessageList.AllUsersMessageList.Length; i++)
                {
                    allUsersMessages.Add(SystemMessageList.AllUsersMessageList[i]);
                }
            }

            // Create a list with the new messages that are not too old.
            newList = new List <SystemMessage>();
            if (allUsersMessages.Count > 0)
            {
                // Copy all the messages that are not too old to the new list
                while (allUsersMessages.Count > 0)
                {
                    SystemMessage theElement = allUsersMessages[0];
                    allUsersMessages.RemoveAt(0);
                    if (theElement.Time.AddSeconds(secondsToKeep).CompareTo(DateTime.Now) >= 0)
                    {
                        // Keep the element. The alloted time has not passed.
                        newList.Add(theElement);
                    }
                }
            }

            // Save the list back to the list for all users
            SystemMessageList.AllUsersSetList(newList);
        }