示例#1
0
        private void ServiceEmailNotification()
        {
            var notificationMediums = _notificationMediumRepository.GetAll().ToList();

            if (!notificationMediums.Any())
            {
                return;
            }

            var smsNotificationMedium   = notificationMediums.FirstOrDefault(x => x.Medium == NotificationMediumType.SmsNotification);
            var emailNotificationMedium = notificationMediums.FirstOrDefault(x => x.Medium == NotificationMediumType.EmailNotification);
            var mediumIds = notificationMediums.Where(x => x.Medium == NotificationMediumType.SmsNotification || x.Medium == NotificationMediumType.EmailNotification).Select(x => x.Id).ToArray();

            var notifications = _notificationRepository.GetNotificationsToService(mediumIds);

            foreach (var notification in notifications)
            {
                if (!notification.NotificationType.IsServiceEnabled)
                {
                    _logger.Info("Notifications of type " + notification.NotificationType.NotificationTypeName + " is tunred off!");
                    continue;
                }

                notification.AttemptCount++;

                try
                {
                    dynamic dispatch = notification;

                    if (emailNotificationMedium != null && emailNotificationMedium.Id == notification.NotificationMedium.Id)
                    {
                        ServiceNotification(dispatch);
                    }
                    else if (smsNotificationMedium != null && smsNotificationMedium.Id == notification.NotificationMedium.Id)
                    {
                        ServiceNotification(dispatch);
                    }

                    notification.ServicedDate  = _calendar.Now;
                    notification.ServiceStatus = NotificationServiceStatus.Serviced;
                }
                catch (Exception exception)
                {
                    // TODO: log why we could not save it.
                    if (notification.AttemptCount >= notification.NotificationType.NumberOfAttempts)
                    {
                        notification.ServiceStatus = NotificationServiceStatus.Failed;
                    }
                    _logger.Error("Failed to dispatch notification " + notification.Id, exception);
                }
                try
                {
                    _notificationRepository.Save(notification);
                }
                catch (Exception exception)
                {
                    _logger.Error("Could not update notification " + notification.Id, exception);
                }
            }
        }
示例#2
0
        public override NotificationType Map(NotificationTypeEntity objectToMap)
        {
            var notificationMedia = _notificationMediumRepository.GetAll().ToList();
            NotificationMedium notificationMedium = notificationMedia.FirstOrDefault(nm => nm.Id == objectToMap.NotificationMediumId);

            return(new NotificationType(objectToMap.NotificationTypeId)
            {
                DataRecorderMetaData =
                    new DataRecorderMetaData(0, objectToMap.DateCreated, objectToMap.DateModified)
                {
                    DataRecorderModifier =
                        objectToMap.ModifiedByOrgRoleUserId != null
                                               ? new OrganizationRoleUser(objectToMap.ModifiedByOrgRoleUserId.Value)
                                               : null
                },
                Description = objectToMap.Description,
                IsServiceEnabled = objectToMap.IsServiceEnabled,
                IsQueuingEnabled = objectToMap.IsQueuingEnabled,
                NotificationTypeAlias = objectToMap.NotificationTypeNameAlias,
                NotificationTypeName = objectToMap.NotificationTypeName,
                NumberOfAttempts = objectToMap.NoOfAttempts,
                IsActive = objectToMap.IsActive,
                NotificationMedium = notificationMedium,
                AllowTemplateCreation = objectToMap.AllowTemplateCreation
            });
        }
        private void ServiceFaxNotification()
        {
            var notificationMediums = _notificationMediumRepository.GetAll().ToList();

            if (!notificationMediums.Any())
            {
                return;
            }

            var notificationType = _notificationTypeRepository.GetByAlias(NotificationTypeAlias.AwvCustomerResultFaxNotification);

            if (notificationType == null)
            {
                return;
            }

            var faxNotificationMedium = notificationMediums.First(x => x.Medium == NotificationMediumType.FaxNotification);

            var notifications = _notificationRepository.GetFaxNotificationByNotificationTypeId(faxNotificationMedium.Id, notificationType.Id);

            if (notifications == null || !notifications.Any())
            {
                return;
            }
        }
示例#4
0
        public override Notification Map(NotificationEntity objectToMap)
        {
            var notificationMedia = _notificationMediumRepository.GetAll().ToList();
            NotificationMedium notificationMedium = notificationMedia.FirstOrDefault(nm => nm.Id == objectToMap.NotificationMediumId);

            if (notificationMedium != null)
            {
                switch (notificationMedium.Medium)
                {
                case NotificationMediumType.EmailNotification:
                    return(MapNotificationEmail(objectToMap));

                case NotificationMediumType.PhoneNotification:
                case NotificationMediumType.SmsNotification:
                case NotificationMediumType.FaxNotification:
                    return(MapNotificationPhone(objectToMap));
                }
            }
            else
            {
                throw new NotSupportedException();
                // Log that the notification medium was not found...
            }
            var notification = new Notification(objectToMap.NotificationId);

            _notificationPopulator.Populate(objectToMap, notification);
            return(notification);
        }
示例#5
0
        public void SetUp()
        {
            DependencyRegistrar.RegisterDependencies();

            _notificationRepository       = IoC.Resolve <INotificationRepository>();
            _notificationTypeRepository   = IoC.Resolve <INotificationTypeRepository>();
            _notificationMediumRepository = IoC.Resolve <INotificationMediumRepository>();

            _notificationTypes = _notificationTypeRepository.GetAll().ToList();
            _notificationMedia = _notificationMediumRepository.GetAll().ToList();
        }
示例#6
0
        public NotificationEmail CreateNotificationEmail(NotificationType notificationType, NotificationSubscriber notificationSubscriber, Email fromEmail, string fromName, EmailMessage formatMessage, string source, string notes, int priority, long requestedBy, long userId)
        {
            var notificationMediumList  = _notificationMediumRepository.GetAll();
            var emailNotificationMedium = notificationMediumList.Single(s => s.Medium == NotificationMediumType.EmailNotification);

            return(new NotificationEmail
            {
                Body = formatMessage.Body,
                Subject = formatMessage.Subject,
                ToEmail = notificationSubscriber.Email,
                FromEmail = fromEmail,
                FromName = fromName,
                Source = source,
                Notes = notes,
                DateCreated = _calendar.Now,
                Priority = priority,
                ServiceStatus = NotificationServiceStatus.Unserviced,
                NotificationType = notificationType,
                NotificationMedium = emailNotificationMedium,
                RequestedBy = requestedBy,
                NotificationDate = _calendar.Now,
                UserId = userId
            });
        }
示例#7
0
        private void ServiceFaxNotification()
        {
            var notificationMediums = _notificationMediumRepository.GetAll().ToList();

            if (!notificationMediums.Any())
            {
                return;
            }
            _sendFaxToEmergencyFaxNumber = false;

            var notificationType = _notificationTypeRepository.GetByAlias(NotificationTypeAlias.PhysicianPartnerCustomerResultFaxNotification);

            if (notificationType == null)
            {
                return;
            }

            var faxNotificationMedium = notificationMediums.First(x => x.Medium == NotificationMediumType.FaxNotification);

            var notifications = _notificationRepository.GetFaxNotificationByNotificationTypeId(faxNotificationMedium.Id, notificationType.Id);

            if (notifications == null || !notifications.Any())
            {
                return;
            }

            _listOfServicedNotifications = new List <long>();
            _listOfBadRecivers           = new List <string>();

            _logger.Info("attempteing to send on real fax number \n");

            AttemptToSendOnFax(notifications);

            _logger.Info("attempteing to send on real fax number-- completed\n");

            var isAnyBadReciver = _listOfBadRecivers.Any();

            _logger.Info(string.Format("defualter recivers for fax {0} \n", string.Join(",", _listOfBadRecivers)));

            if (isAnyBadReciver)
            {
                _sendFaxToEmergencyFaxNumber = true;

                var listOfPendingNotification = notifications.Where(x => !_listOfServicedNotifications.Contains(x.Id)).ToList();

                _logger.Info("attempteing to send on Emergency fax number \n");

                AttemptToSendFaxOnBackupNumber(listOfPendingNotification);

                _logger.Info("attempteing to send on Emergency fax number-completed \n");
            }

            isAnyBadReciver = _listOfBadRecivers.Contains(_emergencyFaxNumber);

            if (isAnyBadReciver)
            {
                var listOfPendingNotification = notifications.Where(x => !_listOfServicedNotifications.Contains(x.Id)).ToList();

                foreach (var notification in listOfPendingNotification)
                {
                    var lastMessage = notification.Notes ?? string.Empty;

                    notification.AttemptCount++;
                    notification.ServicedDate  = _calendar.Now;
                    notification.ServiceStatus = NotificationServiceStatus.Failed;

                    _logger.Error(string.Format("All level of esclation has been met Notication Id {0} \n", notification.Id));
                    notification.Notes = string.Format("{0} marking as failed after attempt on emergency Number \n", lastMessage);

                    try
                    {
                        _notificationRepository.Save(notification);
                    }
                    catch (Exception exception)
                    {
                        _logger.Error("Could not update notification \n" + notification.Id, exception);
                    }
                }
            }
        }