コード例 #1
0
        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;
            }
        }
コード例 #2
0
        public IEnumerable <Notification> NotifySubscribersViaEmail <T>(string notificationTypeAlias, string emailTemplateAlias, T model, long userId, long requestedBy,
                                                                        string source, string notes = null, int priority = 0, DateTime?notificationDate = null, bool useAlternateEmail = false)
        {
            NotificationType notificationType = _notificationTypeRepository.GetByAlias(notificationTypeAlias);

            if (!notificationType.IsQueuingEnabled)
            {
                return(null);
            }

            EmailTemplate emailTemplate = _emailTemplateRepository.GetByAlias(emailTemplateAlias);

            List <NotificationSubscriber> notificationSubscribers = _notificationSubscriberRepository.GetForNotificationType(notificationType.Id).ToList();

            notificationSubscribers.Add(GetUserToNotify(userId));

            if (useAlternateEmail)
            {
                var subscriber = GetAlternateEamilToNotify(userId);
                if (subscriber != null)
                {
                    notificationSubscribers.Add(subscriber);
                }
            }


            Email  fromEmail = _settings.EmailNotificationIssuedFrom;
            string fromName  = _settings.NameNotificationissuedFrom;

            var notifications = new List <Notification>();

            foreach (var notificationSubscriber in notificationSubscribers)
            {
                EmailMessage      formatMessage = _emailTemplateFormatter.FormatMessage(emailTemplate, model, notificationSubscriber.Email.ToString(), fromEmail.ToString(), fromName, emailTemplate.Id);
                NotificationEmail notificationEmail;
                if (notificationDate != null)
                {
                    notificationEmail = _notificationEmailFactory.CreateNotificationEmail(notificationType, notificationSubscriber, fromEmail,
                                                                                          fromName, formatMessage, source, notes, priority, requestedBy, userId, notificationDate.Value);
                }
                else
                {
                    notificationEmail = _notificationEmailFactory.CreateNotificationEmail(notificationType, notificationSubscriber, fromEmail,
                                                                                          fromName, formatMessage, source, notes, priority, requestedBy, userId);
                }

                Notification notification = _notificationRepository.Save(notificationEmail);
                notifications.Add(notification);
            }

            return(notifications);
        }
コード例 #3
0
        public void PollforCustomNotification()
        {
            try
            {
                var customEventNotifications = _customEventNotificationRepository.GetNotificationByStatus((long)CustomNotificationServiceStatus.Unserviced);

                if (customEventNotifications.IsNullOrEmpty())
                {
                    _logger.Info("No Custom Notification found for Event");
                    return;
                }


                var notificationType = _notificationTypeRepository.GetByAlias(NotificationTypeAlias.CustomEventSmsNotification);
                if (!notificationType.IsQueuingEnabled)
                {
                    _logger.Info("Custom Notification Queuing is disabled. To Send this message, enable Queuing and reset status of message.");
                    return;
                }

                foreach (var customEventNotification in customEventNotifications)
                {
                    try
                    {
                        var eventId = customEventNotification.EventId;
                        _logger.Info("running for event Id: " + eventId);

                        var eventCustomers = _eventCustomerRepository.GetbyEventId(eventId);

                        if (!eventCustomers.IsNullOrEmpty())
                        {
                            CorporateAccount corporateAccount = null;
                            if (customEventNotification.AccountId.HasValue && customEventNotification.AccountId.Value > 0)
                            {
                                corporateAccount = ((IUniqueItemRepository <CorporateAccount>)_corporateAccountRepository).GetById(customEventNotification.AccountId.Value);
                            }
                            var customers = _customerRepository.GetCustomers(eventCustomers.Select(x => x.CustomerId).ToArray());

                            foreach (var eventCustomer in eventCustomers)
                            {
                                var customer = customers.First(s => s.CustomerId == eventCustomer.CustomerId);

                                var message = SendCustomNotification(customer, eventCustomer, corporateAccount, customEventNotification);

                                _eventCustomerCustomNotificationRepository.Save(new EventCustomerCustomNotification
                                {
                                    CustomEventNotificationId = customEventNotification.Id,
                                    EventCustomerId           = eventCustomer.Id,
                                    Message = message
                                });
                            }
                            customEventNotification.ServiceStatus = (long)CustomNotificationServiceStatus.Serviced;
                        }
                        else
                        {
                            customEventNotification.ServiceStatus = (long)CustomNotificationServiceStatus.Failed;
                        }
                    }
                    catch (Exception)
                    {
                        customEventNotification.ServiceStatus = (long)CustomNotificationServiceStatus.Failed;
                    }

                    customEventNotification.ServiceDate = DateTime.Now;

                    _customEventNotificationRepository.SaveNotification(customEventNotification);
                }
            }
            catch (Exception ex)
            {
                _logger.Info("ex message: " + ex.Message);
            }
        }
コード例 #4
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);
                    }
                }
            }
        }