예제 #1
0
        public async Task <bool> AuthorizeCustomerAsync(CustomerDto customerDto, string audioUrl)
        {
            var profile = await Store.GetProfile(customerDto.Id);

            var verificationProfileId = profile.Id;
            var bytes = await Converter.ConvertOggToWav(audioUrl);

            var response = await Client.PostAsync($"verify?verificationProfileId={verificationProfileId}",
                                                  new ByteArrayContent(bytes));

            if (!response.IsSuccessStatusCode)
            {
                return(false);
            }

            var jsonContent = await response.Content.ReadAsStringAsync();

            var returnedDto = JsonConvert.DeserializeObject <VerificationResultDto>(jsonContent);

            if (returnedDto.Result == "Reject" || (returnedDto.Result == "Accept" & returnedDto.Confidence == "Low"))
            {
                return(false);
            }

            await TryAddCustomerEnrollmentAsync(customerDto, bytes);

            return(true);
        }
예제 #2
0
        public async Task AddGetProfile()
        {
            await _profileStore.AddProfile(_profile);

            var storedProfile = await _profileStore.GetProfile(_profile.Username);

            Assert.Equal(_profile, storedProfile);
        }
예제 #3
0
        public async Task <IActionResult> Get(string username)
        {
            using (_logger.BeginScope("{Username}", username))
            {
                try
                {
                    var     stopWatch = Stopwatch.StartNew();
                    Profile profile   = await _profileStore.GetProfile(username);

                    _telemetryClient.TrackMetric("ProfileStore.GetProfile.Time", stopWatch.ElapsedMilliseconds);
                    return(Ok(profile));
                }
                catch (ProfileNotFoundException e)
                {
                    _logger.LogError(e, $"Profile {username} was not found in storage");
                    return(NotFound($"The profile with username {username} was not found"));
                }
                catch (StorageErrorException e)
                {
                    _logger.LogError(e, $"Failed to retrieve profile {username} from storage");
                    return(StatusCode(503, "The service is unavailable, please retry in few minutes"));
                }
                catch (Exception e)
                {
                    _logger.LogError(e, $"Unknown exception occured while retrieving profile {username} from storage");
                    return(StatusCode(500, "An internal server error occured, please reachout to support if this error persists"));
                }
            }
        }
예제 #4
0
        public async Task <IActionResult> GetProfile(string username)
        {
            var stopWatch = Stopwatch.StartNew();

            try
            {
                UserProfile profile = await profileStore.GetProfile(username);

                return(Ok(profile));
            }
            catch (ProfileNotFoundException)
            {
                logger.LogInformation(Events.ProfileNotFound,
                                      "A profile was request for user {username} but was not found", username);
                return(NotFound());
            }
            catch (StorageErrorException e)
            {
                logger.LogError(Events.StorageError, e, "Failed to retrieve profile of user {username}", username);
                return(StatusCode(503, "Failed to reach storage"));
            }
            catch (Exception e)
            {
                logger.LogError(e, "Error occured while retrieving a user profile");
                return(StatusCode(500, "Failed to retrieve profile of user {username}"));
            }
            finally
            {
                GetProfileMetric.TrackValue(stopWatch.ElapsedMilliseconds);
            }
        }
예제 #5
0
        public async Task <IActionResult> GetProfile(string username)
        {
            try
            {
                UserProfile profile = await profileStore.GetProfile(username);

                return(Ok(profile));
            }
            catch (ProfileNotFoundException)
            {
                logger.LogInformation(Events.ProfileNotFound,
                                      "A profile was request for user {username} but was not found", username);
                return(NotFound());
            }
            catch (StorageErrorException e)
            {
                logger.LogError(Events.StorageError, e, "Failed to retrieve profile of user {username}", username);
                return(StatusCode(503, "Failed to reach storage"));
            }
            catch (Exception e)
            {
                logger.LogError(e, "Error occured while retrieving a user profile");
                return(StatusCode(500, "Failed to retrieve profile of user {username}"));
            }
        }
예제 #6
0
        public async Task <IActionResult> ListConversations(string username)
        {
            try
            {
                var conversations = await conversationsStore.ListConversations(username);

                var conversationList = new List <ListConversationsItemDto>();
                foreach (var conversation in conversations)
                {
                    string      recipientUserName = conversation.Participants.Except(new[] { username }).First();
                    UserProfile profile           = await profileStore.GetProfile(recipientUserName);

                    var recipientInfo = new UserInfoDto(profile.Username, profile.FirstName, profile.LastName);
                    conversationList.Add(new ListConversationsItemDto(conversation.Id, recipientInfo, conversation.LastModifiedDateUtc));
                }
                return(Ok(new ListConversationsDto(conversationList)));
            }
            catch (StorageErrorException e)
            {
                logger.LogError(Events.StorageError, e, "Could not reach storage to list user conversations, username {username}", username);
                return(StatusCode(503));
            }
            catch (Exception e)
            {
                logger.LogError(Events.InternalError, e, "Failed to retrieve conversations for user {username}", username);
                return(StatusCode(500));
            }
        }
        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);
            }
        }
예제 #8
0
        public async Task <UserProfile> GetProfile(string username)
        {
            using (_logger.BeginScope("{Username}", username))
            {
                var stopWatch = Stopwatch.StartNew();
                var profile   = await _profileStore.GetProfile(username);

                _telemetryClient.TrackMetric("ProfileStore.GetProfile.Time", stopWatch.ElapsedMilliseconds);
                return(profile);
            }
        }
예제 #9
0
        public async Task DeleteProfile(Guid profileId, CancellationToken cancellationToken)
        {
            Ensure.Guid.IsNotEmpty(profileId, nameof(profileId));

            var profile = await _store.GetProfile(profileId, cancellationToken).ConfigureAwait(false);

            if (profile == null)
            {
                return;
            }

            // We will mark the profile (in memory) as hidden here so that the hide profile logic
            // will ensure that the profile is not added back into the profile results cache
            profile.Status = ProfileStatus.Hidden;

            // Remove all the category links, profile cache and profile results cache entries related
            // to this profile
            await HideProfile(profile, cancellationToken).ConfigureAwait(false);

            await _store.DeleteProfile(profileId, cancellationToken).ConfigureAwait(false);
        }
예제 #10
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 <IActionResult> ListConversations(string username, [FromQuery] string startCt, [FromQuery] string endCt, [FromQuery] int limit)
        {
            try
            {
                return(await listConversationsControllerTimeMetric.TrackTime(async() =>
                {
                    var conversationsWindow =
                        await conversationsStore.ListConversations(username, startCt, endCt, limit);

                    var conversationList = new List <ListConversationsItemDto>();
                    foreach (var conversation in conversationsWindow.Conversations)
                    {
                        string recipientUserName = conversation.Participants.Except(new[] { username }).First();
                        UserProfile profile = await profileStore.GetProfile(recipientUserName);
                        var recipientInfo = new UserInfoDto(profile.Username, profile.FirstName, profile.LastName);
                        conversationList.Add(new ListConversationsItemDto(conversation.Id, recipientInfo,
                                                                          conversation.LastModifiedDateUtc));
                    }

                    string newStartCt = conversationsWindow.StartCt;
                    string newEndCt = conversationsWindow.EndCt;

                    string nextUri = (string.IsNullOrEmpty(newStartCt)) ? "" : $"api/conversations/{username}?startCt={newStartCt}&limit={limit}";
                    string previousUri = (string.IsNullOrEmpty(newEndCt)) ? "" : $"api/conversations/{username}?endCt={newEndCt}&limit={limit}";

                    return Ok(new ListConversationsDto(conversationList, nextUri, previousUri));
                }));
            }
            catch (ProfileNotFoundException)
            {
                return(NotFound($"Profile for user {username} was not found"));
            }
            catch (StorageErrorException e)
            {
                logger.LogError(Events.StorageError, e, "Could not reach storage to list user conversations, username {username}", username);
                return(StatusCode(503, $"Could not reach storage to list user conversations, username {username}"));
            }
            catch (Exception e)
            {
                logger.LogError(Events.InternalError, e, "Failed to retrieve conversations for user {username}", username);
                return(StatusCode(500, $"Failed to retrieve conversations for user {username}"));
            }
        }
예제 #12
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);
            }
        }
예제 #13
0
        private async Task <Profile> FindProfile(Guid id, CancellationToken cancellationToken)
        {
            var profile = _cache.GetProfile(id);

            if (profile != null)
            {
                return(profile);
            }

            profile = await _store.GetProfile(id, cancellationToken).ConfigureAwait(false);

            if (profile == null)
            {
                return(null);
            }

            _cache.StoreProfile(profile);

            return(profile);
        }
 public async Task <UserProfile> GetProfile(string username)
 {
     return(await resiliencyPolicy.ExecuteAsync(() => profileStore.GetProfile(username)));
 }
 public Task <UserProfile> GetProfile(string username)
 {
     return(faultTolerancePolicy.Execute(
                async() => await store.GetProfile(username)
                ));
 }
예제 #16
0
 public Task <UserProfile> GetProfile(string username)
 {
     return(getProfileMetric.TrackTime(() => store.GetProfile(username)));
 }
예제 #17
0
        public async Task <FullProfile> GetFullProfile(string username)
        {
            var profile = await _profileStore.GetProfile(username);

            return(await GetFullProfile(profile));
        }