public async Task <PostConversationResponse> PostConversation(PostConversationRequest postConversationRequest, string conversationId)
        {
            using (_logger.BeginScope("{ConversationId}", conversationId))
            {
                PostMessageResponse message = new PostMessageResponse
                {
                    Id             = postConversationRequest.FirstMessage.Id,
                    Text           = postConversationRequest.FirstMessage.Text,
                    SenderUsername = postConversationRequest.FirstMessage.SenderUsername,
                    UnixTime       = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
                };

                PostConversationResponse conversation = new PostConversationResponse
                {
                    Id = conversationId,
                    CreatedUnixTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
                };
                var stopWatch = Stopwatch.StartNew();
                await _messageStore.AddMessage(message, conversationId);

                var fetchedConversation = await _conversationStore.AddConversation(conversation, postConversationRequest.Participants);

                _telemetryClient.TrackMetric("ConversationStore.AddConversation.Time", stopWatch.ElapsedMilliseconds);
                _telemetryClient.TrackEvent("ConversationAdded");
                return(fetchedConversation);
            }
        }
Beispiel #2
0
        public async Task <AddConversationResponse> AddConversation(AddConversationRequestBody addConversationRequestBody)
        {
            var id           = "m_" + addConversationRequestBody.Participants[0] + "_" + addConversationRequestBody.Participants[1];
            var conversation = new Conversation
            {
                Id                   = id,
                Participants         = addConversationRequestBody.Participants,
                LastModifiedUnixTime = DateTimeOffset.Now.ToUnixTimeMilliseconds()
            };
            var addConversationResponse = new AddConversationResponse
            {
                Id = addConversationRequestBody.Participants[0] + "_" + addConversationRequestBody.Participants[1],
                CreatedUnixTime = conversation.LastModifiedUnixTime
            };

            using (_logger.BeginScope("{ConversationId}", id))
            {
                var stopWatch = Stopwatch.StartNew();
                await _conversationStore.AddConversation(conversation);

                _telemetryClient.TrackMetric("ConversationStore.AddConversation.Time", stopWatch.ElapsedMilliseconds);
                _telemetryClient.TrackEvent("ConversationCreated");
                var message = new Message
                {
                    Id             = addConversationRequestBody.FirstMessage["Id"],
                    Text           = addConversationRequestBody.FirstMessage["Text"],
                    SenderUsername = addConversationRequestBody.FirstMessage["SenderUsername"],
                    UnixTime       = DateTimeOffset.Now.ToUnixTimeMilliseconds()
                };
                await _messageStore.AddMessage(id.Remove(0, 2), message);

                return(addConversationResponse);
            }
        }
Beispiel #3
0
        public async Task <IActionResult> AddConversation([FromBody] AddConversationDto conversationDto)
        {
            using (logger.BeginScope("This log is for {conversationId}",
                                     Conversation.GenerateId(conversationDto.Participants)))
            {
                var stopWatch = Stopwatch.StartNew();
                try
                {
                    var conversation = await store.AddConversation(new Conversation(conversationDto));

                    logger.LogInformation(Events.ConversationCreated,
                                          $"Conversation of Participants {conversationDto.Participants[0]} " +
                                          $"and {conversationDto.Participants[1]} was created", DateTime.UtcNow);
                    await CreateConversationPayloadAndSend(conversation);

                    var GetConversationDto = new GetConversationDto(conversation);
                    return(Ok(GetConversationDto));
                }
                catch (StorageUnavailableException e)
                {
                    logger.LogError(Events.StorageError, e,
                                    "Storage was not available to add conversation of Participants " +
                                    $"{conversationDto.Participants[0]} and {conversationDto.Participants[1]}", DateTime.UtcNow);
                    return(StatusCode(503, "Failed to reach Storage"));
                }
                catch (Exception e)
                {
                    logger.LogError(Events.InternalError, e,
                                    $"Failed to add conversation of Participants {conversationDto.Participants[0]} " +
                                    $"and {conversationDto.Participants[1]}", DateTime.UtcNow);
                    return(StatusCode(500,
                                      $"Failed to add conversation of Participants {conversationDto.Participants[0]} " +
                                      $"and {conversationDto.Participants[1]}"));
                }
                finally
                {
                    PostConversationMetric.TrackValue(stopWatch.ElapsedMilliseconds);
                }
            }
        }
 public async Task <Conversation> AddConversation(Conversation conversation)
 {
     return(await resiliencyPolicy.ExecuteAsync(() => conversationStore.AddConversation(conversation)));
 }
Beispiel #5
0
 public Task <Conversation> AddConversation(Conversation conversation)
 {
     return(AddConversationMetric.TrackTime(() => store.AddConversation(conversation)));
 }