public async Task <GetConversationsResponse> GetConversations(string username, string continuationToken, int limit, long lastSeenConversationTime)
        {
            using (_logger.BeginScope("{Username}", username))
            {
                var stopWatch = Stopwatch.StartNew();
                ConversationList conversations = await _conversationStore.GetConversations(username, continuationToken, limit, lastSeenConversationTime);

                _telemetryClient.TrackMetric("ConversationStore.GetConversations.Time", stopWatch.ElapsedMilliseconds);
                string nextUri = "";
                if (!string.IsNullOrWhiteSpace(conversations.ContinuationToken))
                {
                    nextUri = $"api/conversations?username={username}&continuationToken={WebUtility.UrlEncode(conversations.ContinuationToken)}&limit={limit}&lastSeenConversationTime={lastSeenConversationTime}";
                }

                string  recipientUsername;
                Profile recipient;
                List <GetConversationsResponseEntry> conversationEntries = new List <GetConversationsResponseEntry>();
                for (int index = 0; index < conversations.Conversations.Length; index++)
                {
                    if (conversations.Conversations[index].Participants[0] != username)
                    {
                        recipientUsername = conversations.Conversations[index].Participants[0];
                    }
                    else
                    {
                        recipientUsername = conversations.Conversations[index].Participants[1];
                    }
                    try
                    {
                        recipient = await _profileStore.GetProfile(recipientUsername);

                        conversationEntries.Add(new GetConversationsResponseEntry
                        {
                            LastModifiedUnixTime = conversations.Conversations[index].LastModifiedUnixTime,
                            Id        = conversations.Conversations[index].Id,
                            Recipient = recipient
                        }
                                                );
                    }
                    catch (ProfileNotFoundException)
                    {
                        //Disregard this profile because it is now not existing.
                    }
                }


                GetConversationsResponse conversationsResponse = new GetConversationsResponse
                {
                    Conversations = conversationEntries.ToArray(),
                    NextUri       = nextUri
                };

                return(conversationsResponse);
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetConversations(string username, string startCt, string endCt, int limit = 50)
        {
            var stopWatch = Stopwatch.StartNew();

            try
            {
                var resultConversations = await store.GetConversations(username, startCt, endCt, limit);

                var converter = new Converter <Conversation, GetConversationsDto>(
                    conversation =>
                {
                    var recipientUsername = GetConversationsDto.GetRecipient(username, conversation);
                    var profile           = profileStore.GetProfile(recipientUsername).Result;
                    return(new GetConversationsDto(conversation.Id, profile, conversation.LastModifiedDateUtc));
                });

                logger.LogInformation(Events.ConversationsRequested,
                                      $"Conversations for {username} has been requested!", DateTime.UtcNow);
                var nextUri     = NextConversationsUri(username, resultConversations.StartCt, limit);
                var previousUri = PreviousConversationsUri(username, resultConversations.EndCt, limit);

                var conversationsDto =
                    new GetConversationsListDto(resultConversations.Conversations.ConvertAll(converter), nextUri,
                                                previousUri);
                return(Ok(conversationsDto));
            }
            catch (StorageUnavailableException e)
            {
                logger.LogError(Events.StorageError, e,
                                $"Storage was not available to obtain list of conversations for {username}", DateTime.UtcNow);
                return(StatusCode(503, "Failed to reach Storage"));
            }
            catch (Exception e)
            {
                logger.LogError(Events.InternalError, e, $"Failed to obtain list of conversations for {username}",
                                DateTime.UtcNow);
                return(StatusCode(500, $"Failed to obtain list of conversations for {username}"));
            }
            finally
            {
                GetConversationMetric.TrackValue(stopWatch.ElapsedMilliseconds);
            }
        }
Exemplo n.º 3
0
        public async Task <GetConversationsResult> GetConversations(string username, string continuationToken, int limit, long lastSeenConversationTime)
        {
            using (_logger.BeginScope("{Username}", username))
            {
                var stopWatch           = Stopwatch.StartNew();
                var conversationsResult = await _conversationStore.GetConversations(username, continuationToken, limit, lastSeenConversationTime);

                _telemetryClient.TrackMetric("ConversationStore.GetConversations.Time", stopWatch.ElapsedMilliseconds);

                foreach (var conversation in conversationsResult.Conversations)
                {
                    string[] usernames = conversation.Id.Split('_');
                    if (usernames[0] != username)
                    {
                        conversation.Recipient = await _profileStore.GetProfile(usernames[0]);
                    }
                    else
                    {
                        conversation.Recipient = await _profileStore.GetProfile(usernames[1]);
                    }
                }
                return(conversationsResult);
            }
        }
 public async Task <ResultConversations> GetConversations(string userName, string startCt, string endCt, int limit = 50)
 {
     return(await resiliencyPolicy.ExecuteAsync(() => conversationStore.GetConversations(userName, startCt, endCt, limit)));
 }
Exemplo n.º 5
0
 public Task <ResultConversations> GetConversations(string userName, string startCt, string endCt, int limit = 50)
 {
     return(GetConversationsMetric.TrackTime(() => store.GetConversations(userName, startCt, endCt, limit)));
 }