コード例 #1
0
        public void ProcessNotification(BaseNotification notification)
        {
            try {
                if (notification.NotificationType != NotificationType.OrderConfirmation)
                {
                    throw new ApplicationException("notification/handler type mismatch");
                }

                OrderConfirmationNotification orderConfirmation = (OrderConfirmationNotification)notification;

                // load up recipients, customer and message
                eventLogRepository.WriteInformationLog("order confirmation base, custNum: " + notification.CustomerNumber + ", branch: " + notification.BranchId);
                Customer customer = customerRepository.GetCustomerByCustomerNumber(notification.CustomerNumber, notification.BranchId);

                NewRelic.Api.Agent.NewRelic.AddCustomParameter("OrderNumber", orderConfirmation.OrderNumber);
                NewRelic.Api.Agent.NewRelic.AddCustomParameter("InvoiceNumber", orderConfirmation.InvoiceNumber);
                NewRelic.Api.Agent.NewRelic.AddCustomParameter("CustomerNumber", orderConfirmation.CustomerNumber);
                NewRelic.Api.Agent.NewRelic.AddCustomParameter("BranchId", orderConfirmation.BranchId);
                NewRelic.Api.Agent.NewRelic.AddCustomParameter("OrderChange.Items.Count", orderConfirmation.OrderChange.Items.Count);

                if (customer == null)
                {
                    StringBuilder warningMessage = new StringBuilder();
                    warningMessage.AppendFormat("Could not find customer({0}-{1}) to send Order Confirmation notification.", notification.BranchId, notification.CustomerNumber);
                    warningMessage.AppendLine();
                    warningMessage.AppendLine();
                    warningMessage.AppendLine("Notification:");
                    warningMessage.AppendLine(notification.ToJson());

                    eventLogRepository.WriteWarningLog(warningMessage.ToString());
                }
                else
                {
                    List <Recipient> recipients = LoadRecipients(orderConfirmation.NotificationType, customer);
                    Message          message    = GetEmailMessageForNotification(orderConfirmation, customer);

                    // send messages to providers...
                    if (recipients != null && recipients.Count > 0)
                    {
                        SendMessage(recipients, message);
                    }
                }
            } catch (Exception ex) {
                throw new Core.Exceptions.Queue.QueueDataError <BaseNotification>(notification, "OrderConfirmation:ProcessNotification", "Sending order confirmation", "There was an exception sending an order confirmation", ex);
            }
        }
コード例 #2
0
        private void GenericSubscriptionQueue_MessageReceived
            (RabbitMQ.Client.IBasicConsumer sender, RabbitMQ.Client.Events.BasicDeliverEventArgs args)
        {
            RabbitMQ.Client.Events.EventingBasicConsumer consumer = (RabbitMQ.Client.Events.EventingBasicConsumer)sender;

            try {
                // don't reprocess items that have been processed
                if (genericSubscriptionQueue.GetLastProcessedUndelivered() != args.DeliveryTag)
                {
                    BaseNotification notification = NotificationExtension.Deserialize(Encoding.ASCII.GetString(args.Body));

                    eventLogRepository.WriteInformationLog("Processing notification type: {NotificationType}. Data: {QueueMessage}".Inject(new { QueueMessage = notification.ToJson(), NotificationType = notification.NotificationType.ToString() }));

                    var handler = notificationHandlerFactory(notification.NotificationType); // autofac will get the right handler
                    handler.ProcessNotification(notification);

                    // Always clear the context at the end of a transaction
                    _uow.ClearContext();
                }

                genericSubscriptionQueue.Ack(consumer, args.DeliveryTag);
            } catch (QueueDataError <string> serializationEx)  {
                eventLogRepository.WriteErrorLog("Serializing problem with notification.", serializationEx);
            } catch (QueueDataError <BaseNotification> notificationEx) {
                eventLogRepository.WriteErrorLog("Error processing notification.", notificationEx);

                PublishToQueue(notificationEx.ProcessingObject, Configuration.RabbitMQNotificationErrorQueue);
            } catch (Exception ex) {
                eventLogRepository.WriteErrorLog("Unhandled error processing notification.", ex);
            }
        }
コード例 #3
0
        public void ProcessNotification(BaseNotification notification)
        {
            try {
                if (notification.NotificationType != NotificationType.PaymentConfirmation)
                {
                    throw new ApplicationException("notification/handler type mismatch");
                }

                // had to setup a translation for this type in Svc.Core.Extensions to deserialize the message with the concrete type
                PaymentConfirmationNotification confirmation = (PaymentConfirmationNotification)notification;

                // UserContextEqualityComparer discriminates usercontext's to allow distinct to weed out duplicates
                List <UserSelectedContext> customerCtxs = confirmation.Payments
                                                          .Select(p => new UserSelectedContext()
                {
                    CustomerId = p.CustomerNumber, BranchId = p.BranchId
                })
                                                          .Distinct(new UserContextEqualityComparer())
                                                          .ToList();

                bool             complexPayment = customerCtxs.Count > 1;
                string           payerEmail     = confirmation.SubmittedBy;
                List <Recipient> payerRecipient = null;

                foreach (UserSelectedContext customerCtx in customerCtxs)
                {
                    // load up recipients, customer and message
                    Svc.Core.Models.Profile.Customer customer = _customerRepo.GetCustomerByCustomerNumber(customerCtx.CustomerId, customerCtx.BranchId);

                    if (customer == null)
                    {
                        StringBuilder warningMessage = new StringBuilder();
                        warningMessage.AppendFormat("Could not find customer({0}-{1}) to send Payment Confirmation notification.", customerCtx.BranchId, customerCtx.CustomerId);
                        warningMessage.AppendLine();
                        warningMessage.AppendLine();
                        warningMessage.AppendLine("Notification:");
                        warningMessage.AppendLine(notification.ToJson());

                        _log.WriteWarningLog(warningMessage.ToString());
                    }
                    else
                    {
                        List <Recipient> recipients = LoadRecipients(confirmation.NotificationType, customer);
                        Message          message    = GetEmailMessageForNotification(confirmation.Payments
                                                                                     .Where(p => p.CustomerNumber == customerCtx.CustomerId && p.BranchId == customerCtx.BranchId)
                                                                                     .ToList(),
                                                                                     customer);

                        // send messages to providers...
                        if (recipients != null && recipients.Count > 0)
                        {
                            if (complexPayment) // mask out payeremail recipient from the regular recipients
                            {
                                payerRecipient = recipients.Where(r => r.UserEmail.ToLower() == payerEmail.ToLower()).ToList();
                                recipients     = recipients.Where(r => r.UserEmail.ToLower() != payerEmail.ToLower()).ToList();
                            }

                            if (recipients.Count > 0)
                            {
                                SendMessage(recipients, message);
                            }
                        }
                    }
                }

                if (complexPayment && payerRecipient != null)
                {
                    SendMessage(payerRecipient,
                                GetEmailMessageForMultipleAccountSummaryNotification(confirmation.Payments, customerCtxs));
                }
            }
            catch (Exception ex) {
                throw new Core.Exceptions.Queue.QueueDataError <BaseNotification>(notification, "PaymentConfirmation:ProcessNotification", "Sending PaymentConfirmation notification", "An error occured processing a payment confirmation", ex);
            }
        }