public NotificationEnvelope Mail(NotificationBase notification)
        {
            
            if(notification is NotificationOrderSale)
            {
                var envelope = new NotificationEnvelope();
                envelope.MailMessage= FormatOrderSale(notification as NotificationOrderSale);
                envelope.SmsMessage = FormatOrderSaleSms(notification as NotificationOrderSale);
                return envelope;
            }
            if (notification is NotificationInvoice)
            {
                var envelope = new NotificationEnvelope();
                envelope.MailMessage = FormatInvoice(notification as NotificationInvoice);
                envelope.SmsMessage = FormatInvoiceSms(notification as NotificationInvoice);

                return envelope;
            }
            if (notification is NotificationReceipt)
            {
                var envelope = new NotificationEnvelope();
                envelope.MailMessage = FormatReceipt(notification as NotificationReceipt);
                envelope.SmsMessage = FormatReceiptSms(notification as NotificationReceipt);
                return envelope;
            }
            if (notification is NotificationPurchase)
            {
                var envelope = new NotificationEnvelope();
                envelope.MailMessage = FormatPurchase(notification as NotificationPurchase);
                envelope.SmsMessage = FormatPurchaseSms(notification as NotificationPurchase);
                return envelope;
            }
            if (notification is NotificationDispatch)
            {
                var envelope = new NotificationEnvelope();
                envelope.MailMessage = FormatDispatch(notification as NotificationDispatch);
                envelope.SmsMessage = FormatDispatchSms(notification as NotificationDispatch);
                return envelope;
            }
            if (notification is NotificationDelivery)
            {
                var envelope = new NotificationEnvelope();
                envelope.MailMessage = FormatDelivery(notification as NotificationDelivery);
                envelope.SmsMessage = FormatDeliverySms(notification as NotificationDelivery);
                return envelope;
            }
            return null;
        }
 public void Add(NotificationBase notification)
 {
     
     if(notification ==null) return;
     var item = new OutGoingNotificationQueueItemLocal();
     item.NotificationId = Guid.NewGuid();
     item.DateInserted = DateTime.Now;
     item.DateSent = DateTime.Now;
     item.IsSent = false;
     if(notification is NotificationOrderSale)
     {
         var n = notification as NotificationOrderSale;
         item.Type = NotificationType.OrderSale;
         item.JsonDTO = JsonConvert.SerializeObject(n);
         AddItem(item);
     }
     if (notification is NotificationInvoice)
     {
         var n = notification as NotificationInvoice;
         item.Type = NotificationType.Invoice;
         item.JsonDTO = JsonConvert.SerializeObject(n);
         AddItem(item);
     }
     if (notification is NotificationReceipt)
     {
         var n = notification as NotificationReceipt;
         item.Type = NotificationType.Receipt;
         item.JsonDTO = JsonConvert.SerializeObject(n);
         AddItem(item);
     }
     if (notification is NotificationPurchase)
     {
         var n = notification as NotificationPurchase;
         item.Type = NotificationType.CommodityPurchase;
         item.JsonDTO = JsonConvert.SerializeObject(n);
         AddItem(item);
     }
     if (notification is NotificationDispatch)
     {
         var n = notification as NotificationDispatch;
         item.Type = NotificationType.OrderDispatch;
         item.JsonDTO = JsonConvert.SerializeObject(n);
         AddItem(item);
     }
    
 }
Example #3
0
        public async Task<bool> SendNotificationsAsync(NotificationBase notification)
        {
            bool success = false;
            string urlSuffix = "api/notification/notify";
            HttpClient client = setupClient();
            _log.InfoFormat("Attempting to post notification with id {0} to {1}", notification.Id, client.BaseAddress + urlSuffix);
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            try
            {

                var response = await client.PostAsJsonAsync(urlSuffix, notification);
                response.EnsureSuccessStatusCode();
                ResponseBasic _response = await response.Content.ReadAsAsync<ResponseBasic>();
                if (_response == null)
                {
                    _log.InfoFormat("Sent notification id {0} Failed", notification.Id);
                    return success;
                }
                if (_response.Result.Equals("Notification Processed") && response.IsSuccessStatusCode)
                {
                    _log.InfoFormat("Sent notification id {0} success", notification.Id);
                    success = true;
                }
                else
                {
                    _log.InfoFormat("Sent notification id {0} Failed, ResultInfo= {1}, ErrorInfo= {2} ", notification.Id, _response.ResultInfo, _response.ErrorInfo);

                }
            }
            catch (Exception ex)
            {

                _log.ErrorFormat("Failed to send notification {0}", notification.Id);
                _log.Error("Failed to send notification", ex);
                throw ex;
            }
            return success;
        }