public void ProcessNotification(Core.Models.Messaging.Queue.BaseNotification notification) { if (notification.NotificationType != Core.Enumerations.Messaging.NotificationType.InvoiceAttention) { throw new ApplicationException("notification/handler type mismatch"); } }
public void ProcessNotification(Core.Models.Messaging.Queue.BaseNotification notification) { try { if (notification.NotificationType != NotificationType.Eta) { throw new ApplicationException("notification/handler type mismatch"); } EtaNotification eta = (EtaNotification)notification; // load up recipients, customer and message eventLogRepository.WriteInformationLog("Received ETA Message with " + eta.Orders.Count + " orders"); List <string> invoiceNumbers = eta.Orders.Select(x => x.OrderId).ToList(); string etaBranch = eta.Orders[0].BranchId; var orders = orderHistoryRepository.Read(x => x.BranchId == etaBranch && invoiceNumbers.Contains(x.InvoiceNumber)).ToList(); // get all orders for order ETAs foreach (OrderHistoryHeader order in orders) { try { var etaInfo = eta.Orders.Where(o => o.OrderId.Equals(order.InvoiceNumber) && o.BranchId.Equals(order.BranchId)).FirstOrDefault(); if (etaInfo != null) { //The information has a timezone offset that has already been accounted for, so we just need to ignore it order.ScheduledDeliveryTime = String.IsNullOrEmpty(etaInfo.ScheduledTime) ? null : IgnoreOffsetTimeString(etaInfo.ScheduledTime); order.EstimatedDeliveryTime = String.IsNullOrEmpty(etaInfo.EstimatedTime) ? null : IgnoreOffsetTimeString(etaInfo.EstimatedTime); order.ActualDeliveryTime = String.IsNullOrEmpty(etaInfo.ActualTime) ? null : IgnoreOffsetTimeString(etaInfo.ActualTime); order.RouteNumber = String.IsNullOrEmpty(etaInfo.RouteId) ? String.Empty : etaInfo.RouteId; order.StopNumber = String.IsNullOrEmpty(etaInfo.StopNumber) ? String.Empty : etaInfo.StopNumber; order.DeliveryOutOfSequence = etaInfo.OutOfSequence == null ? false : etaInfo.OutOfSequence; } } catch (Exception ex) { eventLogRepository.WriteErrorLog("Error processing ETA notification for : " + order.InvoiceNumber + ". " + ex.Message + ". " + ex.StackTrace); } } foreach (var order in orders) { try { orderHistoryRepository.Update(order); System.Threading.Thread.Sleep(200); } catch (Exception ex) { eventLogRepository.WriteErrorLog("Error saving ETA notification for : " + order.InvoiceNumber + ". " + ex.Message + ". " + ex.StackTrace); } } unitOfWork.SaveChanges(); } catch (Exception ex) { throw new Core.Exceptions.Queue.QueueDataError <BaseNotification>(notification, "EtaNotification:ProcessNotification", "Send ETA Notification", "There was an error processing an ETA notification", ex); } }
public void ProcessNotification(Core.Models.Messaging.Queue.BaseNotification notification) { try { if (notification.NotificationType != Core.Enumerations.Messaging.NotificationType.HasNews) { throw new ApplicationException("notification/handler type mismatch"); } var hasNewsNotification = (HasNewsNotification)notification; Svc.Core.Models.Profile.Customer customer = customerRepository.GetCustomerByCustomerNumber(notification.CustomerNumber, hasNewsNotification.BranchId); if (customer == null) { System.Text.StringBuilder warningMessage = new StringBuilder(); warningMessage.AppendFormat("Could not find customer({0}-{1}) to send Has News notification.", notification.BranchId, hasNewsNotification.CustomerNumber); warningMessage.AppendLine(); warningMessage.AppendLine(); warningMessage.AppendLine("Notification:"); warningMessage.AppendLine(notification.ToJson()); eventLogRepository.WriteWarningLog(warningMessage.ToString()); } else { List <Recipient> recipients = base.LoadRecipients(notification.NotificationType, customer, notification.DSRDSMOnly); if (recipients != null && recipients.Count > 0) { // send messages to providers... Message msg = new Message() { CustomerName = customer.CustomerName, CustomerNumber = customer.CustomerNumber, BranchId = customer.CustomerBranch, MessageSubject = hasNewsNotification.Subject, MessageBody = hasNewsNotification.Notification, NotificationType = NotificationType.HasNews }; msg.BodyIsHtml = true; base.SendMessage(recipients, msg); } } } catch (Exception ex) { throw new Core.Exceptions.Queue.QueueDataError <BaseNotification>(notification, "HasNews:ProcessNotification", "Sending HasNews notification", "There was an error sending a HasNews notification", ex); } }