public async Task <IActionResult> CreateConversation([FromBody] CreateConversationDto conversationDto)
        {
            try
            {
                return(await createConversationControllerTimeMetric.TrackTime(async() =>
                {
                    string id = GenerateConversationId(conversationDto);
                    var currentTime = DateTime.UtcNow;
                    Conversation conversation = new Conversation(id, conversationDto.Participants, currentTime);
                    await conversationsStore.AddConversation(conversation);

                    logger.LogInformation(Events.ConversationCreated, "Conversation with id {conversationId} was created");

                    var newConversationPayload = new NotificationPayload(currentTime, "ConversationAdded", id, conversationDto.Participants);
                    await notificationService.SendNotificationAsync(newConversationPayload);

                    return Ok(conversation);
                }));
            }
            catch (StorageErrorException e)
            {
                logger.LogError(Events.StorageError, e, "Could not reach storage to add user conversation");
                return(StatusCode(503, "Could not reach storage to add user conversation"));
            }
            catch (Exception e)
            {
                logger.LogError(Events.InternalError, e, "Failed to add conversation");
                return(StatusCode(500, "Failed to add conversation"));
            }
        }
示例#2
0
        public async Task <IActionResult> CreateConversation([FromBody] CreateConversationDto conversationDto)
        {
            try
            {
                string       id           = GenerateConversationId(conversationDto);
                Conversation conversation = new Conversation(id, conversationDto.Participants, DateTime.UtcNow);
                await conversationsStore.AddConversation(conversation);

                logger.LogInformation(Events.ConversationCreated, "Conversation with id {conversationId} was created");
                return(Ok(conversation));
            }
            catch (StorageErrorException e)
            {
                logger.LogError(Events.StorageError, e, "Could not reach storage to add user conversation");
                return(StatusCode(503));
            }
            catch (Exception e)
            {
                logger.LogError(Events.InternalError, e, "Failed to add conversation");
                return(StatusCode(500));
            }
        }
示例#3
0
 public Task AddConversation(Conversation conversation)
 {
     return(addConversationMetric.TrackTime(() => store.AddConversation(conversation)));
 }
 public Task AddConversation(Conversation conversation)
 {
     return(faultTolerancePolicy.Execute(
                async() => await store.AddConversation(conversation)
                ));
 }