コード例 #1
0
        public void PollforKynNotification()
        {
            var notificationTypes = _notificationTypeRepository.GetAll();

            var notificationIsActive = notificationTypes.Any(nt => (nt.NotificationTypeAlias == NotificationTypeAlias.KynSecondNotification) && nt.IsActive);

            if (!notificationIsActive)
            {
                return;
            }

            const int pageSize   = 50;
            int       pageNumber = 1;

            while (true)
            {
                long totalRecords;

                var eventCustomers = _eventCustomerRepository.GetEventCustomersForKynSecondNotification(_hoursBeforeKynSecondNotification, _intervalKynSecondNotification, pageNumber, pageSize, out totalRecords);

                if (eventCustomers == null || !eventCustomers.Any())
                {
                    _logger.Info("No Customers Found!");
                    break;
                }

                foreach (var eventCustomer in eventCustomers)
                {
                    try
                    {
                        var corporateAccount = _corporateAccountRepository.GetbyEventId(eventCustomer.EventId);
                        if (corporateAccount != null && !corporateAccount.AllowCustomerPortalLogin)
                        {
                            continue;
                        }

                        var notificationModel = _kynNotificationService.IsApplicableForNotification(eventCustomer);
                        if (notificationModel != null)
                        {
                            _logger.Info(string.Format("Sending Second Kyn Notification for Customer [Id:{0}] and Event[Id:{1}]  ", eventCustomer.CustomerId, eventCustomer.EventId));
                            _notifier.NotifySubscribersViaEmail(NotificationTypeAlias.KynSecondNotification, EmailTemplateAlias.KynSecondNotification, notificationModel, notificationModel.UserId, eventCustomer.CustomerId, "Kyn Second Notification");
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.Error(string.Format("Message:{0} \nStackTrace: {1}", ex.Message, ex.StackTrace));
                    }
                }
                if ((pageNumber * pageSize) >= totalRecords)
                {
                    break;
                }

                pageNumber++;
            }
        }