Esempio n. 1
0
    /// <summary>
    /// Creates a message. Called when the "Create message" button is pressed.
    /// </summary>
    private bool CreateMessage()
    {
        // Create new message object
        MessageInfo newMessage = new MessageInfo();

        // Set the properties
        newMessage.MessageSubject = "API example message";
        newMessage.MessageBody    = "Hello! This is a sample message created by Kentico API.";

        // Get sender and recipient of the message
        UserInfo sender    = MembershipContext.AuthenticatedUser;
        UserInfo recipient = UserInfoProvider.GetUserInfo("administrator");

        // Check if both sender and recipient exist
        if ((sender != null) && (recipient != null))
        {
            newMessage.MessageSenderUserID      = sender.UserID;
            newMessage.MessageSenderNickName    = sender.UserNickName;
            newMessage.MessageRecipientUserID   = recipient.UserID;
            newMessage.MessageRecipientNickName = recipient.UserNickName;
            newMessage.MessageSent = DateTime.Now;

            // Save the message
            MessageInfoProvider.SetMessageInfo(newMessage);

            return(true);
        }

        return(false);
    }
Esempio n. 2
0
    /// <summary>
    /// Gets and bulk updates messages created by multiple executions of the first method. Called when the "Get and bulk update messages" button is pressed.
    /// Expects the CreateMessage method to be run first and multiple times to demonstrate the full functionality.
    /// </summary>
    private bool GetAndBulkUpdateMessages()
    {
        // Prepare the parameters
        string where = "[MessageSubject] = 'API example message'";

        // Get the data
        DataSet messages = MessageInfoProvider.GetMessages(where, null);

        if (!DataHelper.DataSourceIsEmpty(messages))
        {
            // Loop through the individual items
            foreach (DataRow messageDr in messages.Tables[0].Rows)
            {
                // Create object from DataRow
                MessageInfo modifyMessage = new MessageInfo(messageDr);

                // Update the properties
                modifyMessage.MessageBody = modifyMessage.MessageBody.ToLowerCSafe();

                // Save the changes
                MessageInfoProvider.SetMessageInfo(modifyMessage);
            }

            return(true);
        }

        return(false);
    }
Esempio n. 3
0
    /// <summary>
    /// Perform selected action (Mark as read, Mark as unread, Delete).
    /// </summary>
    private void PerformAction()
    {
        string resultMessage = string.Empty;

        Action action = (Action)ValidationHelper.GetInteger(drpAction.SelectedItem.Value, 0);
        What   what   = (What)ValidationHelper.GetInteger(drpWhat.SelectedItem.Value, 0);

        string where = null;

        // All messages
        if (what == What.AllMessages)
        {
            resultMessage = GetString("Messaging." + What.AllMessages);
        }
        // Selected messages
        else if (what == What.SelectedMessages)
        {
            where         = SqlHelperClass.GetWhereCondition <int>("MessageID", (string[])inboxGrid.SelectedItems.ToArray(typeof(string)), false);
            resultMessage = GetString("Messaging." + What.SelectedMessages);
        }
        else
        {
            return;
        }

        // Action 'Delete'
        if ((action == Action.Delete))
        {
            MessageInfoProvider.DeleteReceivedMessages(CMSContext.CurrentUser.UserID, where);
            resultMessage += " " + GetString("Messaging.Action.Result.Deleted");
        }
        // Action 'Mark as read'
        else if ((action == Action.MarkAsRead))
        {
            MessageInfoProvider.MarkReadReceivedMessages(CMSContext.CurrentUser.UserID, where, DateTime.Now);
            resultMessage += " " + GetString("Messaging.Action.Result.MarkAsRead");
        }
        // Action 'Mark as unread'
        else if (action == Action.MarkAsUnread)
        {
            MessageInfoProvider.MarkUnreadReceivedMessages(CMSContext.CurrentUser.UserID, where);
            resultMessage += " " + GetString("Messaging.Action.Result.MarkAsUnread");
        }
        else
        {
            return;
        }

        lblInfo.Text    = resultMessage;
        lblInfo.Visible = true;

        if (!string.IsNullOrEmpty(resultMessage))
        {
            lblInfo.Text    = resultMessage;
            lblInfo.Visible = true;
        }

        inboxGrid.ClearSelectedItems();
        inboxGrid.ReloadData();
    }
Esempio n. 4
0
    /// <summary>
    /// Sets message to read message.
    /// </summary>
    private void ReadMessage()
    {
        if (Message != null)
        {
            bool updateMessage = false;

            // Check message read date
            if (Message.MessageRead == DateTimeHelper.ZERO_TIME)
            {
                Message.MessageRead = DateTime.Now;
                updateMessage       = true;
            }

            // Check message read flag
            if (!Message.MessageIsRead)
            {
                Message.MessageIsRead = true;
                updateMessage         = true;
            }

            // Update message
            if (updateMessage)
            {
                MessageInfoProvider.SetMessageInfo(Message);
            }
        }
    }
Esempio n. 5
0
        /// <summary>
        /// Показать сообшение системы CAS с заменой в тексте сообшения
        /// </summary>
        /// <param name="messageType"></param>
        /// <param name="objectsToReplace"></param>
        public static DialogResult Show(MessageType messageType, object[] objectsToReplace)
        {
            MessageInfoProvider messageInfoProvider = new MessageInfoProvider();

            return(MessageBox.Show(
                       string.Format(messageInfoProvider[messageType.ToString()].ToString(), objectsToReplace) + GetMessageEnd(messageType)
                       , messageType.ToString()));
        }
Esempio n. 6
0
    /// <summary>
    /// Perform selected action (Mark as read, Mark as unread, Delete).
    /// </summary>
    private void PerformAction()
    {
        string resultMessage;

        Action action = (Action)ValidationHelper.GetInteger(drpAction.SelectedItem.Value, 0);
        What   what   = (What)ValidationHelper.GetInteger(drpWhat.SelectedItem.Value, 0);

        string where = null;

        // All messages
        if (what == What.AllMessages)
        {
            resultMessage = GetString("Messaging." + What.AllMessages);
        }
        // Selected messages
        else if (what == What.SelectedMessages)
        {
            where         = SqlHelper.GetWhereCondition <int>("MessageID", inboxGrid.SelectedItems, false);
            resultMessage = GetString("Messaging." + What.SelectedMessages);
        }
        else
        {
            return;
        }

        // Action 'Delete'
        if ((action == Action.Delete))
        {
            MessageInfoProvider.DeleteReceivedMessages(MembershipContext.AuthenticatedUser.UserID, where);
            resultMessage += " " + GetString("Messaging.Action.Result.Deleted");
        }
        // Action 'Mark as read'
        else if ((action == Action.MarkAsRead))
        {
            MessageInfoProvider.MarkReadReceivedMessages(MembershipContext.AuthenticatedUser.UserID, where, DateTime.Now);
            resultMessage += " " + GetString("Messaging.Action.Result.MarkAsRead");
        }
        // Action 'Mark as unread'
        else if (action == Action.MarkAsUnread)
        {
            MessageInfoProvider.MarkUnreadReceivedMessages(MembershipContext.AuthenticatedUser.UserID, where);
            resultMessage += " " + GetString("Messaging.Action.Result.MarkAsUnread");
        }
        else
        {
            return;
        }

        if (!string.IsNullOrEmpty(resultMessage))
        {
            ShowConfirmation(resultMessage);
        }

        inboxGrid.ResetSelection(doPostback: false);
        inboxGrid.ReloadData();
    }
Esempio n. 7
0
    /// <summary>
    /// Mark message as unread.
    /// </summary>
    private void MarkAsUnread()
    {
        if (Message != null)
        {
            // Mark as unread
            if (Message.MessageIsRead)
            {
                Message.MessageIsRead = false;
                MessageInfoProvider.SetMessageInfo(Message);
            }
        }

        inboxGrid.DelayedReload = false;
    }
Esempio n. 8
0
 /// <summary>
 /// Delete message.
 /// </summary>
 private void DeleteMessage()
 {
     try
     {
         inboxGrid.DelayedReload = false;
         MessageInfoProvider.DeleteReceivedMessage(CurrentMessageId);
         ShowConfirmation(GetString("Messsaging.MessageDeleted"));
         pnlList.Visible       = true;
         pnlNew.Visible        = false;
         pnlView.Visible       = false;
         pnlBackToList.Visible = false;
     }
     catch (Exception ex)
     {
         ShowError(ex.Message);
     }
 }
Esempio n. 9
0
    /// <summary>
    /// Mark message as read.
    /// </summary>
    private void MarkAsRead()
    {
        if (Message != null)
        {
            // Mark as read
            if ((Message.MessageRead == DateTimeHelper.ZERO_TIME) || !Message.MessageIsRead)
            {
                Message.MessageIsRead = true;
                if (Message.MessageRead == DateTimeHelper.ZERO_TIME)
                {
                    Message.MessageRead = DateTime.Now;
                }
                MessageInfoProvider.SetMessageInfo(Message);
            }
        }

        inboxGrid.DelayedReload = false;
    }
Esempio n. 10
0
 /// <summary>
 /// Delete message.
 /// </summary>
 private void DeleteMessage()
 {
     try
     {
         inboxGrid.DelayedReload = false;
         MessageInfoProvider.DeleteReceivedMessage(CurrentMessageId);
         lblInfo.Visible       = true;
         lblInfo.Text          = GetString("Messsaging.MessageDeleted");
         pnlList.Visible       = true;
         pnlNew.Visible        = false;
         pnlView.Visible       = false;
         pnlBackToList.Visible = false;
     }
     catch (Exception ex)
     {
         lblError.Visible = true;
         lblError.Text    = ex.Message;
     }
 }
Esempio n. 11
0
    /// <summary>
    /// Perform selected action (Delete).
    /// </summary>
    private void PerformAction()
    {
        string resultMessage = string.Empty;

        Action action = (Action)ValidationHelper.GetInteger(drpAction.SelectedItem.Value, 0);
        What   what   = (What)ValidationHelper.GetInteger(drpWhat.SelectedItem.Value, 0);

        string where = null;

        // All messages
        if (what == What.AllMessages)
        {
            resultMessage = GetString("Messaging." + What.AllMessages);
        }
        // Selected messages
        else if (what == What.SelectedMessages)
        {
            where         = SqlHelperClass.GetWhereCondition <int>("MessageID", (string[])outboxGrid.SelectedItems.ToArray(typeof(string)), false);
            resultMessage = GetString("Messaging." + What.SelectedMessages);
        }
        else
        {
            return;
        }

        // Action 'Delete'
        if ((action == Action.Delete))
        {
            // Delete selected messages
            MessageInfoProvider.DeleteSentMessages(CMSContext.CurrentUser.UserID, where);

            resultMessage += " " + GetString("Messaging.Action.Result.Deleted");

            lblInfo.Text    = resultMessage;
            lblInfo.Visible = true;

            outboxGrid.ClearSelectedItems();
            outboxGrid.ReloadData();
        }
    }
Esempio n. 12
0
    /// <summary>
    /// Perform selected action (Delete).
    /// </summary>
    private void PerformAction()
    {
        string resultMessage;

        Action action = (Action)ValidationHelper.GetInteger(drpAction.SelectedItem.Value, 0);
        What   what   = (What)ValidationHelper.GetInteger(drpWhat.SelectedItem.Value, 0);

        string where = null;

        // All messages
        if (what == What.AllMessages)
        {
            resultMessage = GetString("Messaging." + What.AllMessages);
        }
        // Selected messages
        else if (what == What.SelectedMessages)
        {
            where         = SqlHelper.GetWhereCondition <int>("MessageID", outboxGrid.SelectedItems, false);
            resultMessage = GetString("Messaging." + What.SelectedMessages);
        }
        else
        {
            return;
        }

        // Action 'Delete'
        if ((action == Action.Delete))
        {
            // Delete selected messages
            MessageInfoProvider.DeleteSentMessages(MembershipContext.AuthenticatedUser.UserID, where);

            resultMessage += " " + GetString("Messaging.Action.Result.Deleted");

            ShowConfirmation(resultMessage);

            outboxGrid.ResetSelection();
            outboxGrid.ReloadData();
        }
    }
Esempio n. 13
0
    /// <summary>
    /// Gets and updates the message created by the previous method. Called when the "Get and update message" button is pressed.
    /// Expects the CreateMessage method to be run first.
    /// </summary>
    private bool GetAndUpdateMessage()
    {
        // Prepare the parameters
        string where = "[MessageSubject] = 'API example message'";

        // Get the data
        DataSet messages = MessageInfoProvider.GetMessages(where, null, 1, null);

        if (!DataHelper.DataSourceIsEmpty(messages))
        {
            // Get the message from the DataSet
            MessageInfo modifyMessage = new MessageInfo(messages.Tables[0].Rows[0]);

            // Update the properties
            modifyMessage.MessageBody = modifyMessage.MessageBody.ToUpper();

            // Save the changes
            MessageInfoProvider.SetMessageInfo(modifyMessage);

            return(true);
        }

        return(false);
    }
Esempio n. 14
0
    /// <summary>
    /// Deletes message(s). Called when the "Delete message" button is pressed.
    /// Expects the CreateMessage method to be run first.
    /// </summary>
    private bool DeleteMessage()
    {
        // Prepare the parameters
        string where = "[MessageSubject] = 'API example message'";

        // Get the message
        DataSet messages = MessageInfoProvider.GetMessages(where, null);

        if (!DataHelper.DataSourceIsEmpty(messages))
        {
            foreach (DataRow messageDr in messages.Tables[0].Rows)
            {
                // Create message object from DataRow
                MessageInfo deleteMessage = new MessageInfo(messageDr);

                // Delete the message
                MessageInfoProvider.DeleteMessageInfo(deleteMessage);
            }

            return(true);
        }

        return(false);
    }
Esempio n. 15
0
    protected void btnSendMessage_Click(object sender, EventArgs e)
    {
        // This is because of ASP.NET default behaviour
        // The first empty line was trimmed after each postback
        if (BBEditor.Text.StartsWithCSafe("\n"))
        {
            BBEditor.Text = "\n" + BBEditor.Text;
        }
        // Flood protection
        if (!FloodProtectionHelper.CheckFlooding(CMSContext.CurrentSiteName, CMSContext.CurrentUser))
        {
            CurrentUserInfo currentUser = CMSContext.CurrentUser;

            // Check banned IP
            if (BannedIPInfoProvider.IsAllowed(CMSContext.CurrentSiteName, BanControlEnum.AllNonComplete))
            {
                int recipientId = ucMessageUserSelector.Visible
                                      ? ucMessageUserSelector.SelectedUserID
                                      : ValidationHelper.GetInteger(hdnUserId.Value, 0);
                string message  = string.Empty;
                string nickName = HTMLHelper.HTMLEncode(txtFrom.Text.Trim());
                if (!ValidateBody(DiscussionMacroHelper.RemoveTags(ucBBEditor.Text)))
                {
                    message = GetString("SendMessage.EmptyBody");
                }


                // Check sender nick name if anonymous
                if (isAnonymousUser && (nickName == string.Empty))
                {
                    message = GetString("SendMesage.NoNickName");
                }

                UserInfo recipient = null;

                // Check recipient
                if (recipientId == 0)
                {
                    if (string.IsNullOrEmpty(ucMessageUserSelector.UserNameTextBox.Text.Trim()))
                    {
                        message = GetString("SendMesage.NoRecipient");
                    }
                    else
                    {
                        message = GetString("SendMesage.UserDoesntExists");
                    }
                }
                else
                {
                    recipient = UserInfoProvider.GetUserInfo(recipientId);

                    // Normal users can't send message to user from other site except for global admin
                    if (!recipient.IsInSite(CMSContext.CurrentSiteName) && !currentUser.IsGlobalAdministrator)
                    {
                        message = GetString("SendMesage.UserDoesntExists");
                    }

                    int defRecipientId = ValidationHelper.GetInteger(DefaultRecipient, 0);

                    // If default recipient selected and is same as message recipient, skip check on hidden users
                    if (recipient.UserID != defRecipientId)
                    {
                        //                  Manually disabled users              Hidden users if not replying to them                                       Not approved users
                        bool userAllowed = (recipient.UserIsDisabledManually || (recipient.UserIsHidden && (SendMessageMode != MessageActionEnum.Reply)) || recipient.UserSettings.UserWaitingForApproval);

                        // If live site mode hide not allowed users for all users except for global admins and public user for all users
                        if ((IsLiveSite && userAllowed && !currentUser.IsGlobalAdministrator) || (recipient.UserName.ToLowerCSafe() == "public"))
                        {
                            message = GetString("SendMesage.UserDoesntExists");
                        }
                    }
                }

                if (message == string.Empty)
                {
                    // Send message
                    try
                    {
                        // Check if current user is in recipient's ignore list
                        bool isIgnored = IgnoreListInfoProvider.IsInIgnoreList(recipientId, currentUser.UserID);


                        Message             = new MessageInfo();
                        Message.MessageBody = ucBBEditor.Text;
                        string subject = (txtSubject.Text.Trim() == string.Empty) ? GetString("Messaging.NoSubject") : txtSubject.Text.Trim();
                        Message.MessageSubject           = TextHelper.LimitLength(subject, 200);
                        Message.MessageRecipientUserID   = recipientId;
                        Message.MessageRecipientNickName = TextHelper.LimitLength(Functions.GetFormattedUserName(recipient.UserName, recipient.FullName, recipient.UserNickName, IsLiveSite), 200);
                        Message.MessageSent = DateTime.Now;

                        // Anonymous user
                        if (isAnonymousUser)
                        {
                            Message.MessageSenderNickName = TextHelper.LimitLength(nickName, 200);
                            Message.MessageSenderDeleted  = true;
                        }
                        else
                        {
                            Message.MessageSenderUserID   = currentUser.UserID;
                            Message.MessageSenderNickName = TextHelper.LimitLength(Functions.GetFormattedUserName(currentUser.UserName, currentUser.FullName, currentUser.UserNickName, IsLiveSite), 200);

                            // If the user is ignored, delete message automatically
                            if (isIgnored)
                            {
                                Message.MessageRecipientDeleted = true;
                            }
                        }

                        string error = string.Empty;

                        // Check bad words
                        if (!BadWordInfoProvider.CanUseBadWords(currentUser, CMSContext.CurrentSiteName))
                        {
                            // Prepare columns to check
                            Dictionary <string, int> columns = new Dictionary <string, int>();
                            columns.Add("MessageSubject", 200);
                            columns.Add("MessageBody", 0);
                            columns.Add("MessageSenderNickName", 200);
                            columns.Add("MessageRecipientNickName", 200);

                            // Perform bad word check
                            error = BadWordsHelper.CheckBadWords(Message, columns, currentUser.UserID, () => { return(ValidateBody(Message.MessageBody)); });
                        }

                        if (error != string.Empty)
                        {
                            ShowError(error);
                        }
                        else
                        {
                            // Check message subject, if empty set no subject text
                            if (Message.MessageSubject.Trim() == string.Empty)
                            {
                                Message.MessageSubject = GetString("Messaging.NoSubject");
                            }

                            // Whole text has been removed
                            if (!ValidateBody(Message.MessageBody))
                            {
                                ShowError(GetString("SendMessage.EmptyBodyBadWords"));
                            }
                            else
                            {
                                // Save the message
                                MessageInfoProvider.SetMessageInfo(Message);

                                // Send notification email, if not ignored
                                if (!isIgnored)
                                {
                                    MessageInfoProvider.SendNotificationEmail(Message, recipient, currentUser, CMSContext.CurrentSiteName);
                                }

                                ShowConfirmation(GetString("SendMesage.MessageSent"));
                                MessageId = 0;
                                ucMessageUserSelector.SelectedUserID = 0;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ShowError(ex.Message);
                        ErrorMessage = ex.Message;
                    }
                }
                // Error in the form
                else
                {
                    ShowError(message);
                    ErrorMessage = message;
                }
            }
            else
            {
                ShowError(GetString("General.BannedIP"));
            }
        }
        else
        {
            ShowError(GetString("General.FloodProtection"));
        }

        // External event
        if (SendButtonClick != null)
        {
            SendButtonClick(sender, e);
        }
    }
Esempio n. 16
0
    /// <summary>
    /// Bind the data.
    /// </summary>
    protected void BindFooter()
    {
        int userId = CMSContext.CurrentUser.UserID;

        lblFooter.Text = string.Format(GetString("Messaging.UnreadOfAll"), MessageInfoProvider.GetUnreadMessagesCount(userId), MessageInfoProvider.GetMessagesCount(userId));
    }
Esempio n. 17
0
    /// <summary>
    /// Send notifications.
    /// </summary>
    private void SentNotification()
    {
        if (SendNotificationMessage || SendNotificationEmail)
        {
            // Get e-mail template
            EmailTemplateInfo template = null;
            // Get message subject
            string messageSubject = null;

            switch (action)
            {
            case FriendsActionEnum.Approve:
                template = EmailTemplateProvider.GetEmailTemplate("Friends.Approve",
                                                                  SiteContext.CurrentSiteName);
                messageSubject = ApprovedCaption;
                break;

            case FriendsActionEnum.Reject:
                template = EmailTemplateProvider.GetEmailTemplate("Friends.Reject",
                                                                  SiteContext.CurrentSiteName);
                messageSubject = RejectedCaption;
                break;
            }
            if (template == null)
            {
                return;
            }

            // Get user infos
            UserInfo recipient = UserInfoProvider.GetFullUserInfo(friendship.FriendUserID);
            UserInfo sender    = UserInfoProvider.GetFullUserInfo(friendship.FriendRequestedUserID);

            MacroResolver resolver = MacroContext.CurrentResolver;
            resolver.SetAnonymousSourceData(sender, recipient, friendship);
            resolver.SetNamedSourceData("Sender", sender);
            resolver.SetNamedSourceData("Recipient", recipient);
            resolver.SetNamedSourceData("Friendship", friendship);
            resolver.SetNamedSourceData("FORMATTEDSENDERNAME", Functions.GetFormattedUserName(sender.UserName), false);

            if (SendNotificationMessage)
            {
                // Set message info object
                MessageInfo mi = new MessageInfo();
                mi.MessageLastModified      = DateTime.Now;
                mi.MessageSent              = DateTime.Now;
                mi.MessageRecipientUserID   = recipient.UserID;
                mi.MessageRecipientNickName = TextHelper.LimitLength(Functions.GetFormattedUserName(recipient.UserName, recipient.FullName, recipient.UserNickName, true), 200);
                mi.MessageSenderUserID      = friendship.FriendRequestedUserID;
                mi.MessageSenderNickName    = TextHelper.LimitLength(Functions.GetFormattedUserName(sender.UserName, sender.FullName, sender.UserNickName, true), 200);
                mi.MessageSenderDeleted     = true;
                mi.MessageSubject           = TextHelper.LimitLength(resolver.ResolveMacros(template.TemplateSubject), 200);
                mi.MessageBody              = resolver.ResolveMacros(template.TemplatePlainText);
                MessageInfoProvider.SetMessageInfo(mi);
            }
            if (SendNotificationEmail && !String.IsNullOrEmpty(recipient.Email) &&
                !String.IsNullOrEmpty(sender.Email))
            {
                // Send e-mail
                EmailMessage message = new EmailMessage();
                message.EmailFormat = EmailFormatEnum.Default;
                message.Recipients  = Functions.GetFormattedUserName(recipient.UserName, true) + " <" + recipient.Email + ">";
                message.From        = Functions.GetFormattedUserName(sender.UserName, true) + " <" + sender.Email + ">";
                message.Subject     = messageSubject;

                EmailSender.SendEmailWithTemplateText(SiteContext.CurrentSiteName, message, template, resolver, false);
            }
        }
    }
 /// <summary>
 /// Gets messages count according to caching properties.
 /// </summary>
 /// <returns>Number of new messages in the inbox</returns>
 public int GetCount()
 {
     return(MessageInfoProvider.GetUnreadMessagesCount(currentUser.UserID));
 }
Esempio n. 19
0
 /// <summary>
 /// Bind the data.
 /// </summary>
 private void BindFooter()
 {
     ShowInformation(string.Format(GetString("Messaging.NumOfMessages"), MessageInfoProvider.GetSentMessagesCount(MembershipContext.AuthenticatedUser.UserID)));
 }
Esempio n. 20
0
 /// <summary>
 /// Bind the data.
 /// </summary>
 private void BindFooter()
 {
     lblFooter.Text = string.Format(GetString("Messaging.NumOfMessages"), MessageInfoProvider.GetSentMessagesCount(CMSContext.CurrentUser.UserID));
 }
Esempio n. 21
0
        /// <summary>
        /// Показать сообшение системы CAS
        /// </summary>
        /// <param name="messageType">тип сообщения</param>
        /// <param name="messageBoxButtons"></param>
        public static DialogResult Show(MessageType messageType, MessageBoxButtons messageBoxButtons)
        {
            MessageInfoProvider messageInfoProvider = new MessageInfoProvider();

            return(MessageBox.Show(messageInfoProvider[messageType.ToString()] + GetMessageEnd(messageType), messageType.ToString(), messageBoxButtons, MessageBoxIcon.Information));
        }
Esempio n. 22
0
    /// <summary>
    /// Bind the data.
    /// </summary>
    protected void BindFooter()
    {
        int userId = MembershipContext.AuthenticatedUser.UserID;

        ShowInformation(string.Format(GetString("Messaging.UnreadOfAll"), MessageInfoProvider.GetUnreadMessagesCount(userId), MessageInfoProvider.GetMessagesCount(userId)));
    }
Esempio n. 23
0
    /// <summary>
    /// Send notifications.
    /// </summary>
    private void SentNotification()
    {
        if (SendNotificationMessage || SendNotificationEmail)
        {
            // Get e-mail template
            EmailTemplateInfo template = null;
            // Get message subject
            string messageSubject = null;

            switch (action)
            {
            case FriendsActionEnum.Approve:
                template = EmailTemplateProvider.GetEmailTemplate("Friends.Approve",
                                                                  CMSContext.CurrentSiteName);
                messageSubject = ApprovedCaption;
                break;

            case FriendsActionEnum.Reject:
                template = EmailTemplateProvider.GetEmailTemplate("Friends.Reject",
                                                                  CMSContext.CurrentSiteName);
                messageSubject = RejectedCaption;
                break;
            }
            if (template == null)
            {
                return;
            }

            // Get user infos
            UserInfo recipient = UserInfoProvider.GetFullUserInfo(friendship.FriendUserID);
            UserInfo sender    = UserInfoProvider.GetFullUserInfo(friendship.FriendRequestedUserID);

            MacroResolver resolver = CMSContext.CurrentResolver;
            resolver.SourceData = new object[] { sender, recipient, friendship };
            resolver.SetNamedSourceData("Sender", sender);
            resolver.SetNamedSourceData("Recipient", recipient);
            resolver.SetNamedSourceData("Friendship", friendship);

            string[,] replacements = new string[1, 2];
            replacements[0, 0]     = "FORMATTEDSENDERNAME";
            replacements[0, 1]     = Functions.GetFormattedUserName(sender.UserName);

            resolver.SourceParameters = replacements;

            if (SendNotificationMessage)
            {
                // Set message info object
                MessageInfo mi = new MessageInfo();
                mi.MessageLastModified      = DateTime.Now;
                mi.MessageSent              = DateTime.Now;
                mi.MessageRecipientUserID   = recipient.UserID;
                mi.MessageRecipientNickName = TextHelper.LimitLength(Functions.GetFormattedUserName(recipient.UserName, recipient.FullName, recipient.UserNickName, true), 200);
                mi.MessageSenderUserID      = friendship.FriendRequestedUserID;
                mi.MessageSenderNickName    = TextHelper.LimitLength(Functions.GetFormattedUserName(sender.UserName, sender.FullName, sender.UserNickName, true), 200);
                mi.MessageSenderDeleted     = true;
                mi.MessageSubject           = TextHelper.LimitLength(resolver.ResolveMacros(template.TemplateSubject), 200);
                mi.MessageBody              = resolver.ResolveMacros(template.TemplatePlainText);
                MessageInfoProvider.SetMessageInfo(mi);
            }
            if (SendNotificationEmail && !String.IsNullOrEmpty(recipient.Email) &&
                !String.IsNullOrEmpty(sender.Email))
            {
                // Send e-mail
                EmailMessage message = new EmailMessage();
                message.Recipients    = Functions.GetFormattedUserName(recipient.UserName, true) + " <" + recipient.Email + ">";
                message.From          = EmailHelper.GetSender(template, Functions.GetFormattedUserName(sender.UserName, true) + " <" + sender.Email + ">");
                message.Subject       = EmailHelper.GetSubject(template, messageSubject);
                message.CcRecipients  = template.TemplateCc;
                message.BccRecipients = template.TemplateBcc;
                message.EmailFormat   = EmailFormatEnum.Default;

                // Replace replacements, resolve macros
                resolver.EncodeResolvedValues = true;
                resolver.EncodeSpecialMacros  = true;
                message.Body = resolver.ResolveMacros(template.TemplateText);

                // Do not encode plain text body and subject
                resolver.EncodeResolvedValues = false;
                resolver.EncodeSpecialMacros  = false;
                message.Subject       = resolver.ResolveMacros(message.Subject);
                message.PlainTextBody = resolver.ResolveMacros(template.TemplatePlainText);

                MetaFileInfoProvider.ResolveMetaFileImages(message, template.TemplateID, EmailObjectType.EMAILTEMPLATE, MetaFileInfoProvider.OBJECT_CATEGORY_TEMPLATE);
                EmailSender.SendEmail(CMSContext.CurrentSiteName, message);
            }
        }
    }