public async Task InsertMessageInMessageQueueRequestException(MessageQueueRequestException messageQueueRequestException, string connectionString) { try { SqlParameter[] parameters = { new SqlParameter("@Source", SqlDbType.NVarChar), new SqlParameter("@SNSTopic", SqlDbType.NVarChar), new SqlParameter("@MessageAttribute", SqlDbType.NVarChar), new SqlParameter("@MessageBody", SqlDbType.NVarChar), new SqlParameter("@Status", SqlDbType.Int), new SqlParameter("@PublishedOn", SqlDbType.DateTime), new SqlParameter("@CreatedOn", SqlDbType.DateTime), new SqlParameter("@NumberOfRetries", SqlDbType.Int), new SqlParameter("@LastTriedOn", SqlDbType.DateTime), new SqlParameter("@Remark", SqlDbType.NVarChar), new SqlParameter("@Exception", SqlDbType.NVarChar) }; parameters[0].Value = messageQueueRequestException.Source; parameters[1].Value = messageQueueRequestException.SNSTopic; parameters[2].Value = messageQueueRequestException.MessageAttribute; parameters[3].Value = messageQueueRequestException.MessageBody; parameters[4].Value = messageQueueRequestException.Status; parameters[5].Value = messageQueueRequestException.PublishedOn; parameters[6].Value = messageQueueRequestException.CreatedOn; parameters[7].Value = messageQueueRequestException.NumberOfRetries; parameters[8].Value = messageQueueRequestException.LastTriedOn; parameters[9].Value = messageQueueRequestException.Remark; parameters[10].Value = messageQueueRequestException.Exception; _DataHelper = new DataAccessHelper(DbObjectNames.z_UpdateStatusInMessageQueueRequestsException, parameters, connectionString); await _DataHelper.RunAsync(); } catch (Exception ex) { Log.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); throw; } finally { _DataHelper.Dispose(); } }
public async Task <int> ProcessOrderQueueMessage(int orderID) { try { BuddyDataAccess _buddyAccess = new BuddyDataAccess(); QMDataAccess _qMDataAccess = new QMDataAccess(); DatabaseResponse orderMqResponse = new DatabaseResponse(); orderMqResponse = await _qMDataAccess.GetOrderMessageQueueBody(orderID, _connectionString); OrderQM orderDetails = new OrderQM(); string topicName = ConfigHelper.GetValueByKey(ConfigKey.SNS_Topic_ChangeRequest.GetDescription(), _connectionString).Results.ToString().Trim(); string pushResult = string.Empty; if (orderMqResponse != null && orderMqResponse.Results != null) { orderDetails = (OrderQM)orderMqResponse.Results; DatabaseResponse OrderCountResponse = await _qMDataAccess.GetCustomerOrderCount(orderDetails.customerID, _connectionString); MessageQueueRequest queueRequest = new MessageQueueRequest { Source = CheckOutType.Orders.ToString(), NumberOfRetries = 1, SNSTopic = topicName, CreatedOn = DateTime.Now, LastTriedOn = DateTime.Now, PublishedOn = DateTime.Now, MessageAttribute = ((int)OrderCountResponse.Results) == 1 ? Core.Enums.RequestType.NewCustomer.GetDescription() : Core.Enums.RequestType.NewService.GetDescription(), MessageBody = JsonConvert.SerializeObject(orderDetails), Status = 0 }; try { Dictionary <string, string> attribute = new Dictionary <string, string>(); DatabaseResponse configValueResponse = ConfigHelper.GetValueByKey(ConfigKey.SNS_Topic_ChangeRequest.GetDescription(), _connectionString); topicName = (string)configValueResponse.Results; attribute.Add(EventTypeString.EventType, ((int)OrderCountResponse.Results) == 1 ? Core.Enums.RequestType.NewCustomer.GetDescription() : Core.Enums.RequestType.NewService.GetDescription()); var publisher = new InfrastructureService.MessageQueue.Publisher(_connectionString, topicName); pushResult = await publisher.PublishAsync(orderDetails, attribute); if (pushResult.Trim().ToUpper() == "OK") { queueRequest.Status = 1; queueRequest.PublishedOn = DateTime.Now; LogInfo.Information(EnumExtensions.GetDescription(CommonErrors.PendingBuddyOrderProcessed)); await _buddyAccess.InsertMessageInMessageQueueRequest(queueRequest, _connectionString); return(1); } else { // publising failed queueRequest.Status = 0; await _buddyAccess.InsertMessageInMessageQueueRequest(queueRequest, _connectionString); return(0); } } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); MessageQueueRequestException queueExceptionRequest = new MessageQueueRequestException { Source = CheckOutType.Orders.ToString(), NumberOfRetries = 1, SNSTopic = string.IsNullOrWhiteSpace(topicName) ? null : topicName, CreatedOn = DateTime.Now, LastTriedOn = DateTime.Now, PublishedOn = DateTime.Now, MessageAttribute = Core.Enums.RequestType.RescheduleDelivery.GetDescription().ToString(), MessageBody = orderDetails != null?JsonConvert.SerializeObject(orderDetails) : null, Status = 0, Remark = "Critical Exception while sending MQ from buddy console", Exception = new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical) }; await _buddyAccess.InsertMessageInMessageQueueRequestException(queueExceptionRequest, _connectionString); return(0); } } else { LogInfo.Information(EnumExtensions.GetDescription(CommonErrors.PendingBuddyMQBodyFailed)); return(0); } } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); return(0); } }
public async Task <int> SendMQ(DatabaseResponse orderMqResponse) { string topicName = string.Empty; string pushResult = string.Empty; if (orderMqResponse != null && orderMqResponse.Results != null) { object orderDetails = orderMqResponse.Results; try { Dictionary <string, string> attribute = new Dictionary <string, string>(); topicName = ConfigHelper.GetValueByKey(ConfigKey.SNS_Topic_ChangeRequest.GetDescription(), _iconfiguration).Results.ToString().Trim(); attribute.Add(EventTypeString.EventType, RequestType.RescheduleDelivery.GetDescription()); pushResult = await _messageQueueDataAccess.PublishMessageToMessageQueue(topicName, orderDetails, attribute); if (pushResult.Trim().ToUpper() == "OK") { MessageQueueRequest queueRequest = new MessageQueueRequest { Source = CheckOutType.Orders.ToString(), NumberOfRetries = 1, SNSTopic = topicName, CreatedOn = DateTime.Now, LastTriedOn = DateTime.Now, PublishedOn = DateTime.Now, MessageAttribute = RequestType.RescheduleDelivery.GetDescription(), MessageBody = JsonConvert.SerializeObject(orderDetails), Status = 1 }; await _messageQueueDataAccess.InsertMessageInMessageQueueRequest(queueRequest); } else { MessageQueueRequest queueRequest = new MessageQueueRequest { Source = CheckOutType.Orders.ToString(), NumberOfRetries = 1, SNSTopic = topicName, CreatedOn = DateTime.Now, LastTriedOn = DateTime.Now, PublishedOn = DateTime.Now, MessageAttribute = RequestType.RescheduleDelivery.GetDescription(), MessageBody = JsonConvert.SerializeObject(orderDetails), Status = 0 }; await _messageQueueDataAccess.InsertMessageInMessageQueueRequest(queueRequest); } } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); MessageQueueRequestException queueRequest = new MessageQueueRequestException { Source = CheckOutType.Orders.ToString(), NumberOfRetries = 1, SNSTopic = string.IsNullOrWhiteSpace(topicName) ? null : topicName, CreatedOn = DateTime.Now, LastTriedOn = DateTime.Now, PublishedOn = DateTime.Now, MessageAttribute = Core.Enums.RequestType.RescheduleDelivery.GetDescription().ToString(), MessageBody = orderDetails != null?JsonConvert.SerializeObject(orderDetails) : null, Status = 0, Remark = "Error Occured in Reschedule Delivery", Exception = new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical) }; await _messageQueueDataAccess.InsertMessageInMessageQueueRequestException(queueRequest); return(0); } } return(1); }
public async Task <int> ProcessSuccessTransaction(CheckOutResponseUpdate updateRequest) { try { OrderDataAccess _orderAccess = new OrderDataAccess(_iconfiguration); DatabaseResponse sourceTyeResponse = new DatabaseResponse(); sourceTyeResponse = await _orderAccess.GetSourceTypeByMPGSSOrderId(updateRequest.MPGSOrderID); if (sourceTyeResponse.ResponseCode == (int)DbReturnValue.RecordExists) { if (((OrderSource)sourceTyeResponse.Results).SourceType == CheckOutType.ChangeRequest.ToString()) { var details = await _messageQueueDataAccess.GetMessageDetails(updateRequest.MPGSOrderID); if (details != null) { MessageBodyForCR msgBody = new MessageBodyForCR(); string topicName = string.Empty, pushResult = string.Empty; try { Dictionary <string, string> attribute = new Dictionary <string, string>(); msgBody = await _messageQueueDataAccess.GetMessageBodyByChangeRequest(details.ChangeRequestID); DatabaseResponse changeRequestTypeResponse = await _orderAccess.GetChangeRequestTypeFromID(details.ChangeRequestID); if (((string)changeRequestTypeResponse.Results) == NotificationEvent.ReplaceSIM.ToString()) { if (msgBody.SlotDate != null) { CustomerDetails customer = new CustomerDetails { Name = msgBody.Name, DeliveryEmail = msgBody.Email, ShippingContactNumber = msgBody.ShippingContactNumber, OrderNumber = msgBody.OrderNumber, SlotDate = msgBody.SlotDate ?? DateTime.Now, SlotFromTime = msgBody.SlotFromTime ?? DateTime.Now.TimeOfDay, SlotToTime = msgBody.SlotToTime ?? DateTime.Now.TimeOfDay }; string status = await SendOrderSuccessSMSNotification(customer, NotificationEvent.ReplaceSIM.ToString()); } } if (details.RequestTypeID == (int)Core.Enums.RequestType.ReplaceSIM) { topicName = ConfigHelper.GetValueByKey(ConfigKey.SNS_Topic_ChangeRequest.GetDescription(), _iconfiguration).Results.ToString().Trim(); attribute.Add(EventTypeString.EventType, Core.Enums.RequestType.ReplaceSIM.GetDescription()); pushResult = await _messageQueueDataAccess.PublishMessageToMessageQueue(topicName, msgBody, attribute); } if (pushResult.Trim().ToUpper() == "OK") { MessageQueueRequest queueRequest = new MessageQueueRequest { Source = Source.ChangeRequest, NumberOfRetries = 1, SNSTopic = topicName, CreatedOn = DateTime.Now, LastTriedOn = DateTime.Now, PublishedOn = DateTime.Now, MessageAttribute = Core.Enums.RequestType.ReplaceSIM.GetDescription(), MessageBody = JsonConvert.SerializeObject(msgBody), Status = 1 }; await _messageQueueDataAccess.InsertMessageInMessageQueueRequest(queueRequest); } else { MessageQueueRequest queueRequest = new MessageQueueRequest { Source = Source.ChangeRequest, NumberOfRetries = 1, SNSTopic = topicName, CreatedOn = DateTime.Now, LastTriedOn = DateTime.Now, PublishedOn = DateTime.Now, MessageAttribute = Core.Enums.RequestType.ReplaceSIM.GetDescription(), MessageBody = JsonConvert.SerializeObject(msgBody), Status = 0 }; await _messageQueueDataAccess.InsertMessageInMessageQueueRequest(queueRequest); } } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); MessageQueueRequestException queueRequest = new MessageQueueRequestException { Source = Source.ChangeRequest, NumberOfRetries = 1, SNSTopic = string.IsNullOrWhiteSpace(topicName) ? null : topicName, CreatedOn = DateTime.Now, LastTriedOn = DateTime.Now, PublishedOn = DateTime.Now, MessageAttribute = Core.Enums.RequestType.ReplaceSIM.GetDescription().ToString(), MessageBody = msgBody != null?JsonConvert.SerializeObject(msgBody) : null, Status = 0, Remark = "Error Occured in ProcessSuccessTransaction", Exception = new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical) }; await _messageQueueDataAccess.InsertMessageInMessageQueueRequestException(queueRequest); } } return(3); } else if (((OrderSource)sourceTyeResponse.Results).SourceType == CheckOutType.Orders.ToString()) { try { LogInfo.Information("Calling SendEmailNotification"); string emailStatus = await SendEmailNotification(updateRequest.MPGSOrderID, ((OrderSource)sourceTyeResponse.Results).SourceID); LogInfo.Information("Email Send status for : " + emailStatus); } catch (Exception ex) { LogInfo.Information("Email Send failed"); LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); } ProcessOrderQueueMessage(((OrderSource)sourceTyeResponse.Results).SourceID); BuddyHelper buddyHelper = new BuddyHelper(_iconfiguration, _messageQueueDataAccess); // Proess VAS bundles added to Order DatabaseResponse getVASToProcessResponse = await _orderAccess.GetOrderedVASesToProcess(((OrderSource)sourceTyeResponse.Results).SourceID); LogInfo.Information("Processing VASes for Order:" + ((OrderSource)sourceTyeResponse.Results).SourceID); if (getVASToProcessResponse.ResponseCode == (int)DbReturnValue.RecordExists && getVASToProcessResponse.Results != null) { List <VasToProcess> vasListToProcess = (List <VasToProcess>)getVASToProcessResponse.Results; LogInfo.Information(" VAS list to Process for Order:" + +((OrderSource)sourceTyeResponse.Results).SourceID + " - " + JsonConvert.SerializeObject(vasListToProcess)); DatabaseResponse customerResponse = await _orderAccess.GetCustomerIdFromOrderId(((OrderSource)sourceTyeResponse.Results).SourceID); if (customerResponse != null && customerResponse.ResponseCode == (int)DbReturnValue.RecordExists) { int customerID = ((OrderCustomer)customerResponse.Results).CustomerId; foreach (VasToProcess vas in vasListToProcess) { BuyVASStatus vasProcessStatus = await buddyHelper.ProcessVas(customerID, vas.MobileNumber, vas.BundleID, 1); } } } return(3); // not buddy plan; MQ send } else if (((OrderSource)sourceTyeResponse.Results).SourceType == CheckOutType.AccountInvoices.ToString()) { //send invoice queue message ProcessAccountInvoiceQueueMessage(((OrderSource)sourceTyeResponse.Results).SourceID); return(3); } else { return(5); // incorrect CheckOutType, no chance to reach here, but just to do //returnn from all code path, because in all of the above I need to keep CheckOutType check } } else { // unable to get sourcetype form db return(4); } } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); return(0); } }
public async void ProcessOrderQueueMessage(int orderID) { try { OrderDataAccess _orderAccess = new OrderDataAccess(_iconfiguration); DatabaseResponse orderMqResponse = new DatabaseResponse(); orderMqResponse = await _messageQueueDataAccess.GetOrderMessageQueueBody(orderID); OrderQM orderDetails = new OrderQM(); string topicName = string.Empty; string pushResult = string.Empty; if (orderMqResponse != null && orderMqResponse.Results != null) { orderDetails = (OrderQM)orderMqResponse.Results; DatabaseResponse OrderCountResponse = await _orderAccess.GetCustomerOrderCount(orderDetails.customerID); try { Dictionary <string, string> attribute = new Dictionary <string, string>(); topicName = ConfigHelper.GetValueByKey(ConfigKey.SNS_Topic_ChangeRequest.GetDescription(), _iconfiguration).Results.ToString().Trim(); if (string.IsNullOrWhiteSpace(topicName)) { throw new NullReferenceException("topicName is null for Order (" + orderID + ") for RemoveVAS Request Service API"); } attribute.Add(EventTypeString.EventType, ((OrderCount)OrderCountResponse.Results).SuccessfulOrders == 1 ? Core.Enums.RequestType.NewCustomer.GetDescription() : Core.Enums.RequestType.NewService.GetDescription()); pushResult = await _messageQueueDataAccess.PublishMessageToMessageQueue(topicName, orderDetails, attribute); if (pushResult.Trim().ToUpper() == "OK") { MessageQueueRequest queueRequest = new MessageQueueRequest { Source = CheckOutType.Orders.ToString(), NumberOfRetries = 1, SNSTopic = topicName, CreatedOn = DateTime.Now, LastTriedOn = DateTime.Now, PublishedOn = DateTime.Now, MessageAttribute = ((OrderCount)OrderCountResponse.Results).SuccessfulOrders == 1 ? Core.Enums.RequestType.NewCustomer.GetDescription() : Core.Enums.RequestType.NewService.GetDescription(), MessageBody = JsonConvert.SerializeObject(orderDetails), Status = 1 }; await _messageQueueDataAccess.InsertMessageInMessageQueueRequest(queueRequest); } else { MessageQueueRequest queueRequest = new MessageQueueRequest { Source = CheckOutType.Orders.ToString(), NumberOfRetries = 1, SNSTopic = topicName, CreatedOn = DateTime.Now, LastTriedOn = DateTime.Now, PublishedOn = DateTime.Now, MessageAttribute = ((OrderCount)OrderCountResponse.Results).SuccessfulOrders == 1 ? Core.Enums.RequestType.NewCustomer.GetDescription() : Core.Enums.RequestType.NewService.GetDescription(), MessageBody = orderDetails != null?JsonConvert.SerializeObject(orderDetails) : null, Status = 0 }; await _messageQueueDataAccess.InsertMessageInMessageQueueRequest(queueRequest); } } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); MessageQueueRequestException queueRequest = new MessageQueueRequestException { Source = CheckOutType.Orders.ToString(), NumberOfRetries = 1, SNSTopic = topicName, CreatedOn = DateTime.Now, LastTriedOn = DateTime.Now, PublishedOn = DateTime.Now, MessageAttribute = ((OrderCount)OrderCountResponse.Results).SuccessfulOrders == 1 ? Core.Enums.RequestType.NewCustomer.GetDescription() : Core.Enums.RequestType.NewService.GetDescription(), MessageBody = JsonConvert.SerializeObject(orderDetails), Status = 0 }; await _messageQueueDataAccess.InsertMessageInMessageQueueRequestException(queueRequest); } } } catch (Exception ex) { throw ex; } }
public async Task <BuyVASStatus> ProcessVas(int customerID, string mobileNumber, int bundleID, int quantity) { BuyVASStatus processVasStatus = new BuyVASStatus(); try { OrderDataAccess _orderDataAccess = new OrderDataAccess(_iconfiguration); var statusResponse = await _orderDataAccess.BuyVasService(customerID, mobileNumber, bundleID, quantity); processVasStatus.BuyVASResponse = (BuyVASResponse)statusResponse.Results; processVasStatus.ResponseCode = statusResponse.ResponseCode; if (statusResponse.ResponseCode == (int)DbReturnValue.CreateSuccess) { //Ninad K : Message Publish code MessageBodyForCR msgBody = new MessageBodyForCR(); Dictionary <string, string> attribute = new Dictionary <string, string>(); string topicName = string.Empty, subject = string.Empty; try { topicName = ConfigHelper.GetValueByKey(ConfigKey.SNS_Topic_ChangeRequest.GetDescription(), _iconfiguration) .Results.ToString().Trim(); if (string.IsNullOrWhiteSpace(topicName)) { throw new NullReferenceException("topicName is null for ChangeRequest (" + processVasStatus.BuyVASResponse.ChangeRequestID + ") for BuyVAS Request Service API"); } msgBody = await _messageQueueDataAccess.GetMessageBodyByChangeRequest(processVasStatus.BuyVASResponse.ChangeRequestID); if (msgBody == null || msgBody.ChangeRequestID == 0) { throw new NullReferenceException("message body is null for ChangeRequest (" + processVasStatus.BuyVASResponse.ChangeRequestID + ") for BuyVAS Service API"); } attribute.Add(EventTypeString.EventType, Core.Enums.RequestType.AddVAS.GetDescription()); var pushResult = await _messageQueueDataAccess.PublishMessageToMessageQueue(topicName, msgBody, attribute); if (pushResult.Trim().ToUpper() == "OK") { MessageQueueRequest queueRequest = new MessageQueueRequest { Source = Source.ChangeRequest, NumberOfRetries = 1, SNSTopic = topicName, CreatedOn = DateTime.Now, LastTriedOn = DateTime.Now, PublishedOn = DateTime.Now, MessageAttribute = Core.Enums.RequestType.AddVAS.GetDescription().ToString(), MessageBody = JsonConvert.SerializeObject(msgBody), Status = 1 }; await _messageQueueDataAccess.InsertMessageInMessageQueueRequest(queueRequest); } else { MessageQueueRequest queueRequest = new MessageQueueRequest { Source = Source.ChangeRequest, NumberOfRetries = 1, SNSTopic = topicName, CreatedOn = DateTime.Now, LastTriedOn = DateTime.Now, PublishedOn = DateTime.Now, MessageAttribute = Core.Enums.RequestType.AddVAS.GetDescription().ToString(), MessageBody = JsonConvert.SerializeObject(msgBody), Status = 0 }; await _messageQueueDataAccess.InsertMessageInMessageQueueRequest(queueRequest); } } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); MessageQueueRequestException queueRequest = new MessageQueueRequestException { Source = Source.ChangeRequest, NumberOfRetries = 1, SNSTopic = string.IsNullOrWhiteSpace(topicName) ? null : topicName, CreatedOn = DateTime.Now, LastTriedOn = DateTime.Now, PublishedOn = DateTime.Now, MessageAttribute = Core.Enums.RequestType.AddVAS.GetDescription().ToString(), MessageBody = msgBody != null?JsonConvert.SerializeObject(msgBody) : null, Status = 0, Remark = "Error Occured in BuyVASService", Exception = new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical) }; await _messageQueueDataAccess.InsertMessageInMessageQueueRequestException(queueRequest); } processVasStatus.Result = 1; return(processVasStatus); } else { LogInfo.Warning(DbReturnValue.NoRecords.GetDescription()); processVasStatus.Result = 0; return(processVasStatus); } } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); processVasStatus.Result = 0; return(processVasStatus); } }