private async Task ProcessMessageAsync(EmailMessageEvent message) { var context = new { message.CustomerId, message.MessageTemplateId, message.Source, message.SubjectTemplateId }; _log.Info("Email message subscriber received message", context); try { await _messageService.ProcessEmailAsync(_mapper.Map <EmailMessage>(message), CallType.RabbitMq); } catch (Exception e) { _log.Error(e, "Failed to process email message", context); return; } _log.Info("Email message subscriber processed message", context); }
private async Task CreateSalesforceAccountAsync(Guid customerId, string note, IEnumerable <Image> images) { var registrationResponse = await _tokenPropertyIntegrationClient.Api .RegisterConnectorAsync(new ConnectorRegisterRequestModel { CustomerId = customerId.ToString(), Note = note, Images = images.Select(o => new AgentImage { ImageName = o.Name, ImageBase64 = o.Content, DocumentType = Enum.Parse <ImageDocumentType>(o.DocumentType.ToString()) }).ToList() }); switch (registrationResponse.Status) { case ConnectorRegisterStatus.Ok: await _agentRepository.UpdateStatusAsync(customerId, registrationResponse.ConnectorSalesforceId, AgentStatus.ApprovedAgent); var approvedEvent = new PushNotificationEvent { CustomerId = customerId.ToString(), MessageTemplateId = _agentApprovedPushTemplateId, Source = _componentSourceName, }; await _pushNotificationPublisher.PublishAsync(approvedEvent); break; case ConnectorRegisterStatus.AlreadyExists: await _agentRepository.UpdateStatusAsync(customerId, AgentStatus.Rejected); var rejectedEvent = new PushNotificationEvent { CustomerId = customerId.ToString(), MessageTemplateId = _agentRejectedPushTemplateId, Source = _componentSourceName, }; await _pushNotificationPublisher.PublishAsync(rejectedEvent); var evt = new EmailMessageEvent { CustomerId = customerId.ToString(), SubjectTemplateId = _agentRejectedEmailSubjectTemplateId, MessageTemplateId = _agentRejectedEmailTemplateId, Source = _componentSourceName, }; await _emailNotificationPublisher.PublishAsync(evt); throw new SalesforceAccountAlreadyExistsException(); case ConnectorRegisterStatus.ImageUploadError: throw new SalesforceImageUploadFailException(); case ConnectorRegisterStatus.ConnectorRegistrationError: throw new SalesforceAccountRegistrationFailException(); default: throw new InvalidOperationException("Received unknown status while creating salesforce account."); } }