Exemple #1
0
        private void SendNotification(NotificationMessage message) {
            // send the notification email
            var senderMailAddress = new MailAddress(Sender);

            var notificationEmail = new MailMessage() {
                Sender = senderMailAddress,
                From = senderMailAddress,
                Subject = $"{ message.NotificationDetails.EmailSubjectPrefix } { message.SubjectSuffix }".Trim(),
                Body = message.Content,
                IsBodyHtml = message.NotificationDetails.BodyIsHtml,
            };

            notificationEmail.ReplyToList.Add(senderMailAddress);

            foreach (var recipient in message.NotificationDetails.Recipients) {
                notificationEmail.To.Add(new MailAddress(recipient));
            }

            notificationHistory.Add(message);
            EmailSmtpClient.Send(notificationEmail);
        }
Exemple #2
0
        public void SendNotification(string notificationName, string content, string subjectSuffix) {
            var notification = notifications.Where(n => n.Name == notificationName).FirstOrDefault();
            if (notification != null) {
                var message = new NotificationMessage() {
                    NotificationDetails = notification,
                    Content = content,
                    SubjectSuffix = subjectSuffix,
                    NotificationUsed = true
                };

                if (NotificationMessageIsNew(message)) {
                    SendNotification(message);
                }
            }
        }
Exemple #3
0
        private bool NotificationMessageIsNew(NotificationMessage message) {
            if (DaysToWait <= 0) {
                return true;
            }

            if (notificationHistory.Count() == 0) {
                return true;
            }

            var previousMessage = (from n in notificationHistory
                                   where n.NotificationDetails.Name == message.NotificationDetails.Name &&
                                         n.SubjectSuffix == message.SubjectSuffix &&
                                         n.Content == message.Content
                                   orderby n.DateSent
                                   select n).FirstOrDefault();

            if (previousMessage == null) {
                return true;
            }

            var timeBetweenMessages = message.DateSent - previousMessage.DateSent;
            if (timeBetweenMessages.TotalDays >= DaysToWait) {
                return true;
            }
            else {
                previousMessage.NotificationUsed = true;
                return false;
            }
        }