/// <summary>
        /// Формирует список получателей ответного сообщения
        /// </summary>
        /// <param name="message">оригинальное сообщение</param>
        /// <param name="sender">отправитель ответного сообщения</param>
        /// <returns></returns>
        public static MessageRecipient[] GetRecipientListForSender(this Message message, MessageRecipient sender)
        {
            var recipients = new List<MessageRecipient>();

            // добавляем отправителя оригинального сообщения
            var senderAsRecipient =
                new MessageRecipient
                    {
                        OrganizationBoxId = message.From,
                        DepartmentId = message.FromDepartment
                    };
            if (!sender.Equals(senderAsRecipient))
                recipients.Add(senderAsRecipient);

            // добавляем всех получателей, не включая указанного
            if (sender != null)
            {
                recipients.AddRange(
                    message.Recipients
                        .Where(r => !r.Equals(sender))
                        .ToList());
            }

            return recipients.ToArray();
        }
Exemple #2
0
        /// <summary>
        /// The ActionArrow is much like the IdentityArrow, but calls
        /// an Action &lt;S&gt; on every accepted message/object before
        /// forwarding it.
        /// </summary>
        /// <param name="Action">An Action &lt;S&gt; to invoke on every accepted message/object before forwarding it.</param>
        /// <param name="Recipient">A recipient of the processed messages.</param>
        /// <param name="Recipients">The recipients of the processed messages.</param>
        public ActionArrow(Action_Object Action, MessageRecipient Recipient, params MessageRecipient[] Recipients)
            : base(Recipient, Recipients)
        {

            if (Action == null)
                throw new ArgumentNullException("The given Action<TIn> must not be null!");

            this.Action = Action;

        }
Exemple #3
0
        private bool IsUnread(Message message, out MessageRecipient recipientObject)
        {
            MessageRecipient rec = (from r in message.Recipients where r.User.UserID == this.user.UserID && !r.IsRead select r as MessageRecipient).FirstOrDefault();
            if (rec != null)
            {
                recipientObject = rec;
                return true;
            }

            recipientObject = null;
            return false;
        }
 public void SaveMessageRecipient(MessageRecipient messageRecipient)
 {
     using (SPKTDataContext dc = conn.GetContext())
     {
         if (messageRecipient.MessageRecipientID > 0)
         {
             dc.MessageRecipients.Attach(messageRecipient, true);
         }
         else
         {
             dc.MessageRecipients.InsertOnSubmit(messageRecipient);
         }
         dc.SubmitChanges();
     }
 }
        public JSMessageSender(MessageRecipient recipient)
        {
            Recipient = recipient;

            var mappingToolControllerObject = HtmlPage.Window.Eval("Glyma.MappingTool.MappingToolController") as ScriptObject;
            if (mappingToolControllerObject != null)
            {
                MappingToolController = mappingToolControllerObject.Invoke("getInstance") as ScriptObject;
            }

            var videoControllerObject = HtmlPage.Window.Eval("Glyma.RelatedContentPanels.VideoController") as ScriptObject;
            if (videoControllerObject != null)
            {
                VideoControllerObject = videoControllerObject;
            }
        }
        public void DeleteMessageRecipient(MessageRecipient messageRecipient)
        {
            using (SPKTDataContext dc = conn.GetContext())
            {
                dc.MessageRecipients.Attach(messageRecipient, true);
                dc.MessageRecipients.DeleteOnSubmit(messageRecipient);
                dc.SubmitChanges();

                int RemainingRecipientCount =
                    dc.MessageRecipients.Where(mr => mr.MessageID == messageRecipient.MessageID).Count();
                if (RemainingRecipientCount == 0)
                {
                    dc.Messages.DeleteOnSubmit(
                        dc.Messages.Where(m => m.MessageID == messageRecipient.MessageID).FirstOrDefault());
                    dc.SubmitChanges();
                }
            }
        }
Exemple #7
0
        public void SendMessage(string Body, string Subject, string[] To)
        {
            Message m = new Message();
            m.Body = Body;
            m.Subject = Subject;
            m.CreateDate = DateTime.Now;
            m.MessageTypeID = (int)MessageType.MessageTypes.Message;
            m.SendByAccountID = _userSession.CurrentUser.AccountID;
            Int32 messageID = _messageRepository.SaveMessage(m);

            //create a copy in the sent items folder for this user
            MessageRecipient sendermr = new MessageRecipient();
            sendermr.AccountID = _userSession.CurrentUser.AccountID;
            sendermr.MessageFolderID = (int)MessageFolders.Sent;
            sendermr.MessageStatusTypeID = (int)MessageStatusType.MessageStatusTypes.Unread;
            sendermr.MessageRecipientTypeID = (int)MessageRecipientTypes.TO;
            sendermr.MessageID = messageID;
            _messageRecipientRepository.SaveMessageRecipient(sendermr);

            //send to people in the To field
            foreach (string s in To)
            {
                Account toAccount = null;
                if (s.Contains("@"))
                    toAccount = _accountRepository.GetAccountByEmail(s);
                else
                    toAccount = _accountRepository.GetAccountByUsername(s);

                if (toAccount != null)
                {
                    MessageRecipient mr = new MessageRecipient();
                    mr.AccountID = toAccount.AccountID;
                    mr.MessageFolderID = (int)MessageFolders.Inbox;
                    mr.MessageID = messageID;
                    mr.MessageRecipientTypeID = (int)MessageRecipientTypes.TO;
                    mr.MessageStatusTypeID = (int)MessageStatusType.MessageStatusTypes.Unread;
                    _messageRecipientRepository.SaveMessageRecipient(mr);
                   _email.SendNewMessageNotification(_userSession.CurrentUser, toAccount.Email);
                }
            }
        }
Exemple #8
0
 /// <summary>
 /// The MinMaxArrow produces two side effects which keep
 /// track of the Min and Max values of S.
 /// </summary>
 /// <param name="Min">The initial minimum.</param>
 /// <param name="Max">The initial maximum.</param>
 /// <param name="Recipient">A recipient of the processed messages.</param>
 /// <param name="Recipients">The recipients of the processed messages.</param>
 public MinMaxArrow(TMessage Min, TMessage Max, MessageRecipient <TMessage> Recipient, params MessageRecipient <TMessage>[] Recipients)
     : base(Recipient, Recipients)
 {
     this.SideEffect1 = Min;
     this.SideEffect2 = Max;
 }
Exemple #9
0
 public static void RemoveMessageRecipient(MessageRecipient recipient)
 {
     try
     {
         string query = "DELETE MessageRecipient WHERE MessageID = " + recipient.MessageID + " AND UserID = " + recipient.User.UserID;
         SqlConnection connection = new SqlConnection(ConnectionString);
         SqlCommand cmd = new SqlCommand(query, connection);
         connection.Open();
         cmd.ExecuteNonQuery();
         connection.Close();
     }
     catch (Exception ex)
     {
         LogWriter.Write(ex, LOGFILE_NAME);
         string errmsg = "Fehler beim Löschen des Nachrichtenempfängers (" + recipient.MessageID + ").\n\n";
         errmsg += "DatabaseHandler.RemoveMessageRecipient(recipient): " + ex.ToString();
         throw new Exception(errmsg);
     }
 }
Exemple #10
0
 public async Task <MessageRecipient> SaveMessageRecipientAsync(MessageRecipient messageRecipient, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(await _messageRecipientRepository.SaveOrUpdateAsync(messageRecipient, cancellationToken));
 }
        private static string GetEmailItemContent(PortalSettings portalSettings, MessageRecipient message, string itemTemplate)
        {
            var messageDetails = InternalMessagingController.Instance.GetMessage(message.MessageID);

            var authorId = message.CreatedByUserID > 0 ? message.CreatedByUserID : messageDetails.SenderUserID;

            var emailItemContent = itemTemplate;
            emailItemContent = emailItemContent.Replace("[TITLE]", messageDetails.Subject);
            emailItemContent = emailItemContent.Replace("[CONTENT]", messageDetails.Body);
            emailItemContent = emailItemContent.Replace("[PROFILEPICURL]", GetProfilePicUrl(portalSettings, authorId));
            emailItemContent = emailItemContent.Replace("[PROFILEURL]", GetProfileUrl(portalSettings, authorId));

            if (messageDetails.NotificationTypeID == 1)
            {

                var toUser = UserController.Instance.GetUser(messageDetails.PortalID, message.UserID);
                var defaultLanguage = toUser.Profile.PreferredLocale;

                var acceptUrl = GetRelationshipAcceptRequestUrl(portalSettings, authorId, "AcceptFriend");
                var profileUrl = GetProfileUrl(portalSettings, authorId);
                var linkContent = GetFriendRequestActionsTemplate(defaultLanguage);
                emailItemContent = emailItemContent.Replace("[FRIENDREQUESTACTIONS]", string.Format(linkContent, acceptUrl, profileUrl));                
            }
            if (messageDetails.NotificationTypeID == 3)
            {

                var toUser = UserController.Instance.GetUser(messageDetails.PortalID, message.UserID);
                var defaultLanguage = toUser.Profile.PreferredLocale;

                var acceptUrl = GetRelationshipAcceptRequestUrl(portalSettings, authorId, "FollowBack");
                var profileUrl = GetProfileUrl(portalSettings, authorId);
                var linkContent = GetFollowRequestActionsTemplate(defaultLanguage);
                emailItemContent = emailItemContent.Replace("[FOLLOWREQUESTACTIONS]", string.Format(linkContent, acceptUrl, profileUrl));            
            }

            //No social actions for the rest of notifications types
            emailItemContent = emailItemContent.Replace("[FOLLOWREQUESTACTIONS]", "");
            emailItemContent = emailItemContent.Replace("[FRIENDREQUESTACTIONS]", "");    
            
            return emailItemContent;
        }
Exemple #12
0
        internal static MailMessage GenerateMessageEmail(MessageRecipient msgRecip)
        {
            Console.WriteLine(String.Format("Sending an e-mail to {0} at {1}{2}", msgRecip.Profile.FirstName, msgRecip.Profile.Email, Environment.NewLine));

            try
            {
                MailMessage mail = new MailMessage();

                string firstName = msgRecip.Message.AppUser.Profile.FirstName;
                string lastName  = msgRecip.Message.AppUser.Profile.LastName;
                if (!String.IsNullOrEmpty(firstName) && !String.IsNullOrEmpty(lastName))
                {
                    mail.From = new MailAddress("*****@*****.**", string.Format("{0} {1}", firstName, lastName));
                }

                if (!string.IsNullOrEmpty(msgRecip.Profile.Email))
                {
                    mail.To.Add(msgRecip.Profile.Email);
                }
                if (!string.IsNullOrEmpty(msgRecip.Profile.EmailAlternate))
                {
                    mail.To.Add(msgRecip.Profile.EmailAlternate);
                }
                mail.Subject    = "You Have a Viternus Message Waiting for You";
                mail.IsBodyHtml = false;

                StringBuilder body = new StringBuilder();
                body.Append("Dear ");
                body.Append(String.IsNullOrEmpty(msgRecip.Profile.FirstName) ? "Recipient" : msgRecip.Profile.FirstName);
                body.Append(",");
                body.Append(Environment.NewLine);
                body.Append(Environment.NewLine);
                body.Append("A message awaits you on the Viternus website, at the link below:");
                body.Append(Environment.NewLine);
                body.Append(Environment.NewLine);
                body.Append("(Click the link to view the message)");
                body.Append(Environment.NewLine);
                body.Append(@"http://www.Viternus.com/Message/ViewMessageFromUrl/" + msgRecip.Id);
                body.Append(Environment.NewLine);
                body.Append(Environment.NewLine);

                body.Append("This message has been sent by ");
                if (String.IsNullOrEmpty(firstName) && String.IsNullOrEmpty(lastName))
                {
                    body.Append(msgRecip.Message.AppUser.UserName);
                }
                else
                {
                    body.Append(firstName);
                    body.Append(" ");
                    body.Append(lastName);
                }
                body.Append(".  The message is not urgent, but he/she requests you view it at your earliest convenience.  If you are not ");
                if (String.IsNullOrEmpty(msgRecip.Profile.FirstName) && String.IsNullOrEmpty(msgRecip.Profile.LastName))
                {
                    body.Append("the owner of this email address");
                }
                else
                {
                    body.Append(msgRecip.Profile.FirstName);
                    body.Append(" ");
                    body.Append(msgRecip.Profile.LastName);
                }
                body.Append(", then please disregard this message.");
                body.Append(Environment.NewLine);
                body.Append(Environment.NewLine);
                body.Append("Thank you,");
                body.Append(Environment.NewLine);
                body.Append("Viternus Webmaster");

                mail.Body = body.ToString();
                return(mail);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error" + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
                ErrorLogRepository errorRepos = new ErrorLogRepository();
                errorRepos.SaveErrorToDB(ex, "GenerateMessageMail failed", String.Empty);
                return(null);
            }
        }
 /// <summary>
 /// The StdDevSideEffectArrow produces a side effect that
 /// is the sliding standard deviation and the average of
 /// messages/objects that have passed through it.
 /// </summary>
 /// <param name="ArrowSender">The sender of the messages/objects.</param>
 /// <param name="Recipient">A recipient of the processed messages.</param>
 /// <param name="Recipients">Further recipients of the processed messages.</param>
 public static StdDevSideEffectArrow StdDevSideEffectArrow(this IArrowSender<Double> ArrowSender, MessageRecipient<Double> Recipient, params MessageRecipient<Double>[] Recipients)
 {
     var _CountArrow = new StdDevSideEffectArrow(Recipient, Recipients);
     ArrowSender.OnMessageAvailable += _CountArrow.ReceiveMessage;
     return _CountArrow;
 }
 public async Task AddAsync(MessageRecipient messageRecipient)
 {
     _context.MessageRecipients.Add(messageRecipient);
     await _context.SaveChangesAsync();
 }
Exemple #15
0
        public string SendInvitations(Account sender, string ToEmailArray, string Message)
        {
            string resultMessage = Message;
            foreach (string s in ToEmailArray.Split(new char[] { ',', ';' }))
            {
                FriendInvitation friendInvitation = new FriendInvitation();
                friendInvitation.AccountID = sender.AccountID;
                friendInvitation.Email = s;
                friendInvitation.GUID = Guid.NewGuid();
                friendInvitation.BecameAccountID = 0;
                FriendInvitation.SaveFriendInvitation(friendInvitation);

                //add alert to existing users alerts
                Account account = Account.GetAccountByEmail(s);
                if (account != null)
                {
                    _alertService.AddFriendRequestAlert(_userSession.CurrentUser, account, friendInvitation.GUID,
                                                        Message);
                }

                //CHAPTER 6
                //TODO: MESSAGING - if this email is already in our system add a message through messaging system
                //if(email in system)
                //{
                //      add message to messaging system
                //}
                //else
                //{
                //      send email
                SendFriendInvitation(s, sender.FirstName, sender.LastName, friendInvitation.GUID.ToString(), Message);
                //send into mailbox
                Message = sender.FirstName + " " + sender.LastName +
          "Muốn kết bạn với bạn!<HR><a href=\"" + _configuration.RootURL +
          "Friends/ConfirmFriendInSite.aspx?InvitationKey=" + friendInvitation.GUID.ToString() + "\">" + _configuration.RootURL +
          "Friends/ConfirmFriendInSite.aspx?InvitationKey=" + friendInvitation.GUID.ToString() + "</a><HR>" + Message;
                Messages m = new Messages();
                m.Body = Message;
                m.Subject = "Thư mời kết bạn";
                m.CreateDate = DateTime.Now;
                m.MessageTypeID = (int)MessageTypes.FriendRequest;
                m.SentByAccountID = _userSession.CurrentUser.AccountID;
                m.MessageID = 0;
                m.Save();

                Int64 messageID = m.MessageID;

                MessageRecipient sendermr = new MessageRecipient();
                sendermr.AccountID = _userSession.CurrentUser.AccountID;
                sendermr.MessageFolderID = (int)MessageFolders.Sent;
                sendermr.MessageRecipientTypeID = (int)MessageRecipientTypes.TO;
                sendermr.MessageID = messageID;
                sendermr.MessageStatusTypeID = (int)MessageStatusTypes.Unread;
                sendermr.MessageRecipientID = 0;
                sendermr.Save();

                Account toAccount = Account.GetAccountByEmail(s);
                if (toAccount != null)
                {
                    MessageRecipient mr = new MessageRecipient();
                    mr.AccountID = toAccount.AccountID;
                    mr.MessageFolderID = (int)MessageFolders.Inbox;
                    mr.MessageID = messageID;
                    mr.MessageRecipientTypeID = (int)MessageRecipientTypes.TO;
                    mr.MessageRecipientID = 0;
                    mr.MessageStatusTypeID = 1;
                    mr.Save();
                    //_email.SendNewMessageNotification(toAccount, toAccount.Email);
                }
                //}
                resultMessage += "• " + s + "<BR>";
            }
            return resultMessage;
        }
Exemple #16
0
 public int SaveMessageRecipient(MessageRecipient messageRecipient, int createUpdateUserId)
 {
     return(_provider.ExecuteScalar <int>("CoreMessaging_SaveMessageRecipient", messageRecipient.RecipientID, messageRecipient.MessageID, messageRecipient.UserID, messageRecipient.Read, messageRecipient.Archived, createUpdateUserId));
 }
        /// <summary>
        /// The AggregatorArrow produces a side effect that is the provided collection
        /// filled with the contents of all the objects that have passed through it.
        /// The collection enumerator is used as the emitting enumerator. Thus, what
        /// goes into AggregatorArrow may not be the same as what comes out of
        /// AggregatorPipe.
        /// For example, duplicates removed, different order to the stream, etc.
        /// Finally, note that different Collections have different behaviors and
        /// write/read times.
        /// </summary>
        /// <param name="ArrowSender">The sender of the messages/objects.</param>
        /// <param name="ICollection">An optional ICollection to store the passed messages/objects.</param>
        /// <param name="Recipient">A recipient of the processed messages.</param>
        /// <param name="Recipients">Further recipients of the processed messages.</param>
        public static AggregatorArrow <TMessage> Aggregator <TMessage>(this IArrowSender <TMessage> ArrowSender, ICollection <TMessage> ICollection, MessageRecipient <TMessage> Recipient, params MessageRecipient <TMessage>[] Recipients)
        {
            var _AggregatorArrow = new AggregatorArrow <TMessage>(ICollection, Recipient, Recipients);

            ArrowSender.OnMessageAvailable += _AggregatorArrow.ReceiveMessage;
            return(_AggregatorArrow);
        }
Exemple #18
0
 /// <summary>
 /// The SkipArrow simply sends the incoming message to the recipients
 /// without any processing, but skips the first n messages.
 /// </summary>
 /// <param name="NumberOfMessagesToSkip">The number of messages to skip.</param>
 /// <param name="Recipient">A recipient of the processed messages.</param>
 /// <param name="Recipients">The recipients of the processed messages.</param>
 public SkipArrow(UInt32 NumberOfMessagesToSkip, MessageRecipient Recipient, params MessageRecipient[] Recipients)
     : base(Recipient, Recipients)
 {
     this.NumberOfMessagesToSkip = NumberOfMessagesToSkip;
 }
Exemple #19
0
 /// <summary>
 /// The SameValueFilterArrow will not allow to send two
 /// consecutive identical messages twice.
 /// </summary>
 /// <param name="Recipient">A recipient of the processed messages.</param>
 /// <param name="Recipients">The recipients of the processed messages.</param>
 public SameValueFilterArrow(MessageRecipient <TMessage> Recipient, params MessageRecipient <TMessage>[] Recipients)
     : base(Recipient, Recipients)
 {
 }
Exemple #20
0
            public async Task <ChatMessageResource> Handle(SendMessageCommand request, CancellationToken cancellationToken = default)
            {
                int currentUserId = _userProvider.GetCurrentUserId();

                MessageRecipient ownMessageRecipient;

                Func <Task> notificationFactory;

                // Message to be stored
                Message message = new Message
                {
                    AuthorId    = currentUserId,
                    ParentId    = request.ParentId,
                    HtmlContent = request.HtmlContent,
                    Created     = _dateProvider.UtcNow(),
                    IsEdited    = false,
                };

                await _unitOfWork.Messages.Add(message, cancellationToken);

                // Recipient to send the message to
                Recipient recipient = await _unitOfWork.Recipients
                                      .GetById(request.RecipientId)
                                      .AsTracking()
                                      .Include(r => r.GroupMembership)
                                      .ThenInclude(gm => gm.Group)
                                      .ThenInclude(g => g.Memberships)
                                      .ThenInclude(gm => gm.Recipient)
                                      .SingleOrDefaultAsync(cancellationToken);

                // Send group chat message to all members of the group
                if (recipient.UserId == null)
                {
                    IEnumerable <GroupMembership> members = recipient.GroupMembership.Group.Memberships;

                    IEnumerable <MessageRecipient> messageRecipients = members.Select(member => new MessageRecipient
                    {
                        Message     = message,
                        MessageId   = message.MessageId,
                        RecipientId = member.Recipient.RecipientId,
                        Recipient   = member.Recipient,
                        ReadDate    = null,
                        IsForwarded = false,
                        IsRead      = member.UserId == currentUserId,
                    });

                    // Get instance of relevant MessageRecipient for the current user
                    ownMessageRecipient = messageRecipients
                                          .Single(mr => mr.Recipient.GroupMembership.UserId == currentUserId);

                    await _unitOfWork.MessageRecipients.AddRange(messageRecipients, cancellationToken);

                    // Pass task to perform when notifying users
                    notificationFactory = async() => await NotifyGroupChatRecipients(members, messageRecipients);
                }

                // Send private chat message
                else
                {
                    MessageRecipient messageRecipient = new MessageRecipient
                    {
                        Message     = message,
                        MessageId   = message.MessageId,
                        RecipientId = recipient.RecipientId,
                        Recipient   = recipient,
                        ReadDate    = null,
                        IsForwarded = false,
                        IsRead      = false
                    };

                    ownMessageRecipient = messageRecipient;

                    await _unitOfWork.MessageRecipients.Add(messageRecipient, cancellationToken);

                    // Pass task to perform when notifying the recipient user
                    notificationFactory = async() => await NotifyPrivateChatRecipient(messageRecipient);
                }

                // Commit changes to the database
                await _unitOfWork.CommitAsync(cancellationToken);

                // Notify recipient(s) of message
                await notificationFactory();

                return(new ChatMessageResource
                {
                    MessageRecipientId = ownMessageRecipient.MessageRecipientId,
                    MessageId = ownMessageRecipient.MessageId,
                    HtmlContent = ownMessageRecipient.Message.HtmlContent,
                    AuthorName = ownMessageRecipient.Message.HtmlContent,
                    Created = ownMessageRecipient.Message.Created,
                    IsOwnMessage = true,
                    IsRead = true,
                });
            }
 /// <summary>
 /// The SkipArrow simply sends the incoming message to the recipients
 /// without any processing, but skips the first n messages.
 /// </summary>
 /// <param name="ArrowSender">The sender of the messages/objects.</param>
 /// <param name="NumberOfMessagesToSkip">The number of messages to skip.</param>
 /// <param name="Recipient">A recipient of the processed messages.</param>
 /// <param name="Recipients">Further recipients of the processed messages.</param>
 public static SkipArrow SkipArrow(this IArrowSender ArrowSender, UInt32 NumberOfMessagesToSkip, MessageRecipient Recipient, params MessageRecipient[] Recipients)
 {
     var _SkipArrow = new SkipArrow(NumberOfMessagesToSkip, Recipient, Recipients);
     ArrowSender.OnMessageAvailable += _SkipArrow.ReceiveMessage;
     return _SkipArrow;
 }
        private void SendMessage(MessageRecipient objMessage)
        {
            //todo: check if host user can send to multiple portals...
            var messageDetails = InternalMessagingController.Instance.GetMessage(objMessage.MessageID);

            var fromAddress = _pController.GetPortal(messageDetails.PortalID).Email;
            var toAddress = _uController.GetUser(messageDetails.PortalID, objMessage.UserID).Email;

            var sender = _uController.GetUser(messageDetails.PortalID, messageDetails.SenderUserID).DisplayName;
            if (string.IsNullOrEmpty(sender))
                sender = _pController.GetPortal(messageDetails.PortalID).PortalName;
            var senderAddress = sender + "< " + fromAddress + ">";
            var subject = string.Format(Localization.Localization.GetString("EMAIL_SUBJECT_FORMAT",
                                                                  Localization.Localization.GlobalResourceFile), sender);

            var body = string.Format(Localization.Localization.GetString("EMAIL_BODY_FORMAT",
                                                                  Localization.Localization.GlobalResourceFile), messageDetails.Subject, messageDetails.Body);

            Mail.Mail.SendEmail(fromAddress, senderAddress, toAddress, subject, body);

            InternalMessagingController.Instance.MarkMessageAsDispatched(objMessage.MessageID, objMessage.RecipientID);
        }
        public static Message ConvertFromMessageDB(MessageDB item)
        {
            Message toReturn = new Message ();

            toReturn.Errors = item.Errors;
            toReturn.FromAccountID = item.FromAccountID;
            toReturn.MessageID = item.MessageID;
            toReturn.MessageSent = item.MessageSent;
            toReturn.MessageConfirmed = item.MessageConfirmed;

            if (null != item.MessageStepDBList &&
                item.MessageStepDBList.Count > 0) {
                MessageStep[] messageSteps = new MessageStep[item.MessageStepDBList.Count];
                for (int i = 0; i < item.MessageStepDBList.Count; i++) {
                    messageSteps [i] = MessageStepDB.ConvertFromMessageStepDB (item.MessageStepDBList [i]);
                }//end for

                toReturn.MessageSteps = messageSteps.ToList ();
            }//end if

            if (null != item.MessageRecipientDBList &&
                item.MessageRecipientDBList.Count > 0) {
                Message.MessageRecipient[] recipients = new MessageRecipient[item.MessageRecipientDBList.Count];
                for (int i = 0; i < item.MessageRecipientDBList.Count; i++) {
                    recipients [i] = MessageRecipientDB.ConvertFromMessageRecipientDB (item.MessageRecipientDBList [i]);
                }//end for

                toReturn.MessageRecipients = recipients.ToList ();
            }//end if

            return toReturn;
        }
 /// <summary>
 /// The ActionArrow is much like the IdentityArrow, but calls
 /// an Action &lt;S&gt; on every accepted message/object before
 /// forwarding it.
 /// </summary>
 /// <param name="ArrowSender">The sender of the messages/objects.</param>
 /// <param name="Action">An Action &lt;S&gt; to invoke on every accepted message/object before forwarding it.</param>
 /// <param name="Recipient">A recipient of the processed messages.</param>
 /// <param name="Recipients">Further recipients of the processed messages.</param>
 public static ActionArrow ActionArrow(this IArrowSender ArrowSender, Action_Object Action, MessageRecipient Recipient, params MessageRecipient[] Recipients)
 {
     var _ActionArrow = new ActionArrow(Action, Recipient, Recipients);
     ArrowSender.OnMessageAvailable += _ActionArrow.ReceiveMessage;
     return _ActionArrow;
 }
 public abstract void Insert(MessageRecipient messageRecipient);
Exemple #26
0
 /// <summary>
 /// Creates a new AbstractSideEffectArrow and adds the given
 /// recipients to the list of message recipients.
 /// </summary>
 /// <param name="Recipient">A recipient of the processed messages.</param>
 /// <param name="Recipients">The recipients of the processed messages.</param>
 public AbstractSideEffectArrow(MessageRecipient <TOut> Recipient, params MessageRecipient <TOut>[] Recipients)
     : base(Recipient, Recipients)
 {
 }
Exemple #27
0
 /// <summary>
 /// The SkipArrow simply sends the incoming message to the recipients
 /// without any processing, but skips the first n messages.
 /// </summary>
 /// <param name="NumberOfMessagesToSkip">The number of messages to skip.</param>
 /// <param name="Recipient">A recipient of the processed messages.</param>
 /// <param name="Recipients">The recipients of the processed messages.</param>
 public SkipArrow(UInt32 NumberOfMessagesToSkip, MessageRecipient Recipient, params MessageRecipient[] Recipients)
     : base(Recipient, Recipients)
 {
     this.NumberOfMessagesToSkip = NumberOfMessagesToSkip;
 }
        private static Message ConvertCoreMessageToServicesMessage(int PortalID, int UserID, MessageRecipient coreMessageRecipeint, Social.Messaging.Message coreMessage)
        {
            var message = new Message {
                AllowReply = true, Body = coreMessage.Body, FromUserID = coreMessage.SenderUserID, MessageDate = coreMessage.CreatedOnDate, PortalID = PortalID
            };

            switch (coreMessageRecipeint.Read)
            {
            case true:
                message.Status = MessageStatusType.Read;
                break;

            case false:
                message.Status = MessageStatusType.Unread;
                break;
            }

            message.ToUserID = UserID;
            return(message);
        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="BuiltToWithDisplayStep" /> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="recipient">The recipient.</param>
 public BuiltToWithDisplayStep(MailerMessage context, MessageRecipient recipient)
     : base(context, recipient)
 {
 }
        /// <summary>
        /// The SameValueFilterArrow will not allow to send two
        /// consecutive identical messages twice.
        /// </summary>
        /// <param name="ArrowSender">The sender of the messages/objects.</param>
        /// <param name="Recipient">A recipient of the processed messages.</param>
        /// <param name="Recipients">Further recipients of the processed messages.</param>
        public static SameValueFilterArrow <TMessage> SameValueFilter <TMessage>(this IArrowSender <TMessage> ArrowSender, MessageRecipient <TMessage> Recipient, params MessageRecipient <TMessage>[] Recipients)
            where TMessage : IEquatable <TMessage>
        {
            var _SameValueFilterArrow = new SameValueFilterArrow <TMessage>(Recipient, Recipients);

            ArrowSender.OnMessageAvailable += _SameValueFilterArrow.ReceiveMessage;
            return(_SameValueFilterArrow);
        }
        /// <summary>
        /// Creates a new AbstractArrow and adds the given recipients
        /// to the list of message recipients.
        /// </summary>
        /// <param name="Recipient">A recipient of the processed messages.</param>
        /// <param name="Recipients">The recipients of the processed messages.</param>
        public AbstractArrowSender(MessageRecipient Recipient, params MessageRecipient[] Recipients)
        {

            lock (this)
            {
                
                if (Recipient != null)
                    this.OnMessageAvailable += Recipient;

                if (Recipients != null)
                    foreach (var _Recipient in Recipients)
                        this.OnMessageAvailable += _Recipient;

            }

        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="BuildRecipientWithDisplaySubstitutionStep" /> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="recipient">The recipient.</param>
 public BuildRecipientWithDisplaySubstitutionStep(MailerMessage context, MessageRecipient recipient)
     : base(context, recipient)
 {
 }
Exemple #33
0
 public MessageReceivedEventArgs(string content, int duration, bool forceLogoff, MessageRecipient initialObject)
 {
     Content = content;
     ForceLogoff = forceLogoff;
     Duration = duration;
     InitialObject = initialObject;
 }
Exemple #34
0
 /// <summary>
 /// The IdentityArrow is the most basic arrow.
 /// It simply sends the incoming message to the recipients without any processing.
 /// This arrow is useful in various test case situations.
 /// </summary>
 /// <param name="Recipient">A recipient of the processed messages.</param>
 /// <param name="Recipients">The recipients of the processed messages.</param>
 public IdentityArrow(MessageRecipient Recipient, params MessageRecipient[] Recipients)
     : base(Recipient, Recipients)
 { }
        private static string GetEmailItemContent(PortalSettings portalSettings, MessageRecipient message, string itemTemplate)
        {
            var messageDetails = InternalMessagingController.Instance.GetMessage(message.MessageID);

            var authorId = message.CreatedByUserID > 0 ? message.CreatedByUserID : messageDetails.SenderUserID;

            var emailItemContent = itemTemplate;
            emailItemContent = emailItemContent.Replace("[TITLE]", messageDetails.Subject);
            emailItemContent = emailItemContent.Replace("[CONTENT]", messageDetails.Body);
            emailItemContent = emailItemContent.Replace("[PROFILEPICURL]", GetProfilePicUrl(portalSettings, authorId));

            return emailItemContent;
        }
 /// <summary>
 /// The IdentityArrow is much like the IdentityArrow, but calls
 /// an Action &lt;S&gt; on every accepted message/object before
 /// forwarding it.
 /// </summary>
 /// <param name="ArrowSender">The sender of the messages/objects.</param>
 /// <param name="Recipient">A recipient of the processed messages.</param>
 /// <param name="Recipients">Further recipients of the processed messages.</param>
 public static IdentityArrow IdentityArrow(this IArrowSender ArrowSender, MessageRecipient Recipient, params MessageRecipient[] Recipients)
 {
     var _IdentityArrow = new IdentityArrow(Recipient, Recipients);
     ArrowSender.OnMessageAvailable += _IdentityArrow.ReceiveMessage;
     return _IdentityArrow;
 }
Exemple #37
0
        private static ReadOnlyCollection<MessageRecipient> GetMessageRecipients(int messageId)
        {
            List<MessageRecipient> targets = new List<MessageRecipient>();

            try
            {
                SqlConnection connection = new SqlConnection(ConnectionString);
                SqlCommand cmd = new SqlCommand("SELECT * FROM MessageRecipient WHERE MessageID = " + messageId, connection);
                connection.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    MessageRecipient t = new MessageRecipient();
                    t.MessageRecipientID = Convert.ToInt32(reader["MessageRecipientID"]);
                    t.MessageID = messageId;
                    if (reader["Site"] == DBNull.Value || reader["ReadDate"] == DBNull.Value)
                        t.IsRead = false;
                    else
                        t.IsRead = true;
                    t.User = GetUser(Convert.ToInt32(reader["UserID"]));
                    if (t.IsRead)
                    {
                        t.Site = reader["Site"].ToString();
                        t.ReadDate = Convert.ToDateTime(reader["ReadDate"]);
                    }
                    targets.Add(t);
                }
                connection.Close();

            }
            catch (Exception ex)
            {
                LogWriter.Write(ex, LOGFILE_NAME);
                string errmsg = "Fehler beim Abrufen der Nachrichtenempfänger (" + messageId + ").\n\n";
                errmsg += "DatabaseHandler.GetMessageRecipients(messageId): " + ex.ToString();
                throw new Exception(errmsg);
            }

            return new ReadOnlyCollection<MessageRecipient>(targets);
        }
Exemple #38
0
        public static void SaveMessageRecipient(MessageRecipient recipient)
        {
            try
            {
                string query = "UPDATE MessageRecipient SET [Site] = " + (recipient.IsRead ? "'" + Environment.MachineName + "', ReadDate = '" + recipient.ReadDate + "'" : "NULL, ReadDate = NULL ") +
                    " WHERE MessageID = " + recipient.MessageID + " AND [UserID] = '" + recipient.User.UserID + "'";

                SqlConnection connection = new SqlConnection(ConnectionString);
                SqlCommand cmd = new SqlCommand(query, connection);
                connection.Open();
                cmd.ExecuteNonQuery();
                connection.Close();
            }
            catch (Exception ex)
            {
                LogWriter.Write(ex, LOGFILE_NAME);
                string errmsg = "Fehler beim Speichern des Nachrichtenempfängers (" + recipient.MessageID + ").\n\n";
                errmsg += "DatabaseHandler.SaveMessageRecipient(recipient): " + ex.ToString();
                throw new Exception(errmsg);
            }
        }
        private void SendMessage(MessageRecipient messageRecipient)
        {
            //todo: check if host user can send to multiple portals...
            var messageDetails = InternalMessagingController.Instance.GetMessage(messageRecipient.MessageID);            

            var toUser = UserController.Instance.GetUser(messageDetails.PortalID, messageRecipient.UserID);
            if (!IsUserAbleToReceiveAnEmail(toUser))
            {
                InternalMessagingController.Instance.MarkMessageAsDispatched(messageRecipient.MessageID, messageRecipient.RecipientID);
                return;
            }

            if (!IsSendEmailEnable(messageDetails.PortalID))
            {
                InternalMessagingController.Instance.MarkMessageAsSent(messageRecipient.MessageID, messageRecipient.RecipientID);
                return;
            }

            var defaultLanguage = toUser.Profile.PreferredLocale;

            var emailSubjectTemplate = GetEmailSubjectTemplate(defaultLanguage);
            var emailBodyTemplate = GetEmailBodyTemplate(defaultLanguage);
            var emailBodyItemTemplate =  GetEmailBodyItemTemplate(defaultLanguage);

            var author = UserController.Instance.GetUser(messageDetails.PortalID, messageDetails.SenderUserID);
            var portalSettings = new PortalSettings(messageDetails.PortalID);
            var fromAddress = portalSettings.Email;
            var toAddress = toUser.Email;

            if (Mail.Mail.IsValidEmailAddress(toUser.Email, toUser.PortalID))
            {
                var senderName = GetSenderName(author.DisplayName, portalSettings.PortalName);
                var senderAddress = GetSenderAddress(senderName, fromAddress);
                var emailBodyItemContent = GetEmailItemContent(portalSettings, messageRecipient, emailBodyItemTemplate);
                var subject = string.Format(emailSubjectTemplate, portalSettings.PortalName);
                var body = GetEmailBody(emailBodyTemplate, emailBodyItemContent, portalSettings, toUser);
                
                Mail.Mail.SendEmail(fromAddress, senderAddress, toAddress, subject, body);            
            }

            InternalMessagingController.Instance.MarkMessageAsDispatched(messageRecipient.MessageID, messageRecipient.RecipientID);
        }
Exemple #40
0
        /// <summary>
        /// Формирует список получателей ответного сообщения.
        /// </summary>
        /// <param name="message">Оригинальное сообщение.</param>
        /// <param name="sender">Отправитель ответного сообщения.</param>
        /// <returns>Получатели сообщения.</returns>
        public static MessageRecipient[] GetRecipientListForSender(this Message message, MessageRecipient sender)
        {
            var isOriginalSenderEqualsCurrent = message.From.Equals(sender.OrganizationBoxId, StringComparison.InvariantCultureIgnoreCase);

            // Добавляем отправителя оригинального сообщения.
            var recipients = new List <MessageRecipient>();

            if (!isOriginalSenderEqualsCurrent)
            {
                recipients.Add(new MessageRecipient
                {
                    OrganizationBoxId = message.From,
                    DepartmentId      = message.FromDepartment
                });
            }

            // Добавляем всех получателей, не включая указанного.
            if (sender != null)
            {
                recipients.AddRange(isOriginalSenderEqualsCurrent
                    ? message.Recipients
                    : message.Recipients.Where(r => !r.Equals(sender)));
            }

            return(recipients.ToArray());
        }