public async Task AddMessageAsync(CommunicationMessageIdentifier message) { var storageAccount = CloudStorageAccount.Parse(_storageConnectionString); var client = storageAccount.CreateCloudQueueClient(); var queue = client.GetQueueReference(QueueName); await queue.CreateIfNotExistsAsync(); var cloudMessage = new CloudQueueMessage(JsonConvert.SerializeObject(message, Formatting.Indented)); await queue.AddMessageAsync(cloudMessage); }
public async Task Run(CommunicationMessageIdentifier commMsgId) { _logger.LogInformation($"Retrieving {nameof(CommunicationMessage)}:{commMsgId.Id.ToString()} from CommunicationMessages Store"); var commMsg = await _repository.GetAsync(commMsgId.Id); if (commMsg == null) { throw new ArgumentException($"Could not find communication message: {commMsgId.Id} in CommunicationMessages Store."); } try { _logger.LogInformation($"Retrieving {nameof(CommunicationMessage)}:{commMsgId.Id.ToString()} from CommunicationMessages Store"); switch (commMsg.Channel) { case DeliveryChannel.Sms: throw new NotSupportedException("Currently not supporting sending SMS via DAS Notifications."); case DeliveryChannel.Email: case DeliveryChannel.Default: await SendEmail(commMsg); break; } commMsg.Status = CommunicationMessageStatus.Sent; commMsg.DispatchOutcome = DispatchOutcome.Succeeded; commMsg.DispatchDateTime = _timeProvider.Now; await _repository.UpdateAsync(commMsg); } catch (HttpRequestException ex) { _logger.LogError(ex, $"Failed to submit communication message {commMsg.Id} to DAS Notifications API."); commMsg.Status = CommunicationMessageStatus.NotSent; commMsg.DispatchDateTime = _timeProvider.Now; commMsg.DispatchOutcome = DispatchOutcome.Failed; await _repository.UpdateAsync(commMsg); } }