public void PollForPriorityInQueueNotification() { try { var eventCustomerResultIds = _customerEventPriorityInQueueDataRepository.GetEventCustomerResultIdsForPriorityInQueueNotification(_settings.DaysToCheckPriorityInQueue); if (eventCustomerResultIds == null || !eventCustomerResultIds.Any()) { _logger.Info("No records found for priority in queue"); } foreach (var eventCustomerResultId in eventCustomerResultIds) { try { var eventCustomerResult = _eventCustomerResultRepository.GetById(eventCustomerResultId); _logger.Info(string.Format("Checking Priority In Queue mail for EventId {0}, CustomerId {1}", eventCustomerResult.EventId, eventCustomerResult.CustomerId)); var messageAlreadySent = _eventCustomerNotificationRepository.GetByEventCustomerId(eventCustomerResultId, NotificationTypeAlias.PriorityInQueueCustomer); if (messageAlreadySent != null) { _logger.Info(string.Format("Priority In Queue mail has been already sent for EventId {0}, CustomerId {1}", eventCustomerResult.EventId, eventCustomerResult.CustomerId)); continue; } var priorityInQueueNotificationModel = _emailNotificationModelsFactory.GetPriorityInQueueNotificationModel(eventCustomerResult.EventId, eventCustomerResult.CustomerId, "", eventCustomerResultId); var notifications = _notifier.NotifySubscribersViaEmail(NotificationTypeAlias.PriorityInQueueCustomer, EmailTemplateAlias.PriorityInQueueCustomer, priorityInQueueNotificationModel, 0, 1, "Priority in queue Customer"); if (notifications != null && notifications.Any()) { _logger.Info(string.Format("Priority In Queue mail has been queued for EventId {0}, CustomerId {1}", eventCustomerResult.EventId, eventCustomerResult.CustomerId)); var notification = notifications.First(); var eventCustomerNotification = new EventCustomerNotification { EventCustomerId = eventCustomerResultId, NotificationId = notification.Id, NotificationTypeId = notification.NotificationType.Id }; _eventCustomerNotificationRepository.Save(eventCustomerNotification); } } catch (Exception ex) { _logger.Error(string.Format("Error for priority in queue for EventCustomerResultId {0}. \n Message : {1}, \n Stack Trace : {2}", eventCustomerResultId, ex.Message, ex.StackTrace)); } } } catch (Exception ex) { _logger.Error(string.Format("Error while polling data for priority in queue. \n Message : {0}, \n Stack Trace : {1}", ex.Message, ex.StackTrace)); } }
public void PollforFaxResultNotification() { try { var value = _configurationSettingRepository.GetConfigurationValue(ConfigurationSettingName.EnablePhysicianPartnerCustomerResultFaxNotification); if (value.ToLower() != bool.TrueString.ToLower()) { return; } var account = _corporateAccountRepository.GetById(_settings.PhysicianPartnerAccountId); DateTime?stopSendingPdftoHealthPlanDate = null; if (account != null && account.IsHealthPlan) { stopSendingPdftoHealthPlanDate = _settings.StopSendingPdftoHealthPlanDate; } var eventCustomerResults = _eventCustomerResultRepository.GetEventCustomerResultsToFax( (int)TestResultStateNumber.ResultDelivered, (int)NewTestResultStateNumber.ResultDelivered, false, DateTime.Now, DateTime.Now.AddHours(-_faxInterval), _settings.PhysicianPartnerAccountId, "", stopSendingPdftoHealthPlanDate: stopSendingPdftoHealthPlanDate); var customerResults = eventCustomerResults as EventCustomerResult[] ?? eventCustomerResults.ToArray(); if (eventCustomerResults == null || !customerResults.Any()) { _logger.Info("No event customer result list found for Fax queue."); return; } _logger.Info("Get the event customer result list for Fax queue."); var fileName = _mediaRepository.GetPdfFileNameForPcpResultReport(); var customerIds = customerResults.Select(x => x.CustomerId).ToArray(); var pcpList = _pcpRepository.GetByCustomerIds(customerIds).Where(x => x.Fax != null && !string.IsNullOrEmpty(x.Fax.ToString())); foreach (var ecr in customerResults) { var messageAlreadySent = _eventCustomerNotificationRepository.GetByEventCustomerId(ecr.Id, NotificationTypeAlias.PhysicianPartnerCustomerResultFaxNotification); if (messageAlreadySent != null) { _logger.Info(string.Format("Fax already queued for EventId {0}, CustomerId {1}", ecr.EventId, ecr.CustomerId)); continue; } var path = _mediaRepository.GetPremiumVersionResultPdfLocation(ecr.EventId, ecr.CustomerId).PhysicalPath; var pdfUrl = path + fileName; if (path.IndexOfAny(Path.GetInvalidPathChars()) != -1) { throw new InvalidDirectoryPathException(); } if (File.Exists(pdfUrl)) { var pcp = pcpList.FirstOrDefault(x => x.CustomerId == ecr.CustomerId); if (pcp == null) { _logger.Error(string.Format("PCP not found/or pcp Fax not found where customerId {0}", ecr.CustomerId)); } else { try { PhoneNotificationModel model = null; var notification = _notifier.NotifyViaFax(NotificationTypeAlias.PhysicianPartnerCustomerResultFaxNotification, model, pcp.Fax, DirectoryOperationsHelper.ReadAllBytes(pdfUrl), 1, "Faxing Notification"); if (notification != null) { var eventCustomerNotification = new EventCustomerNotification { EventCustomerId = ecr.Id, NotificationId = notification.Id, NotificationTypeId = notification.NotificationType.Id }; _eventCustomerNotificationRepository.Save(eventCustomerNotification); } _logger.Info(string.Format("Fax queued for EventId {0}, CustomerId {1}", ecr.EventId, ecr.CustomerId)); } catch (Exception ex) { _logger.Error(string.Format("Fax not queued for EventId {0}, CustomerId {1}", ecr.EventId, ecr.CustomerId)); _logger.Error("\n"); _logger.Error(ex.Message + "Stack Trace:" + ex.StackTrace); } } } else { _logger.Error(string.Format("Fax queue: File Not found for EventId {0}, CustomerId {1}", ecr.EventId, ecr.CustomerId)); } } } catch (Exception ex) { _logger.Error(ex.Message + "Fax queue: Stack Trace:" + ex.StackTrace); } }