예제 #1
0
        public async Task <RecommendationsList> GetRecommendationsAsync(int statusId, CancellationToken cancellationToken = default)
        {
            try
            {
                _connectivityService.CheckConnection();
                cancellationToken.ThrowIfCancellationRequested();

                var recommendationsList = await _platformClient.Endpoints.GetRecommendationsAsync(statusId, cancellationToken).ConfigureAwait(false);

                cancellationToken.ThrowIfCancellationRequested();
                await _recommendationsContainer.SetAsync(recommendationsList).ConfigureAwait(false);

                return(recommendationsList);
            }
            catch (Exception ex)
            {
                if (_serviceErrorHandler.TryHandle(ex, out var generatedException, cancellationToken))
                {
                    if (!(ex is OperationCanceledException))
                    {
                        _logger.LogError(ex, "Failed to load user recommendations.");
                    }
                    generatedException.Rethrow();
                }

                throw;
            }
        }
예제 #2
0
        private async Task ExecuteCreateProfileAsync(UserSignUpInfo signUpInfo, bool retryOnTokenException)
        {
            try
            {
                _connectivityService.CheckConnection();

                await _secretsProvider.InitializeAsync().ConfigureAwait(false);

                var identifier = await _secretsProvider.GetDeviceIdentifierAsync().ConfigureAwait(false);

                var request  = new RegisterRequest(signUpInfo.Username, signUpInfo.Password, identifier);
                var response = await _platformClient.Endpoints.RegisterUserAsync(request).ConfigureAwait(false);

                await _authenticationInfoService.InitUserInfoAsync(response.Metadata, response.UserProfile, response.Token).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Failed to create user profile.");
                if (!_serviceErrorHandler.TryHandle(ex, out var generatedException))
                {
                    throw;
                }

                if (generatedException is CreateProfileTokenValidationException)
                {
                    await ExecuteCreateProfileAsync(signUpInfo, false);

                    return;
                }

                generatedException.Rethrow();
            }
        }
예제 #3
0
        public async Task <MedicalCode> InitStatusChangeAsync(int statusId, DateTime statusChangedOn)
        {
            try
            {
                _connectivityService.CheckConnection();

                var request = new ChangeRequest
                {
                    StatusId        = statusId,
                    StatusChangedOn = statusChangedOn.ToUniversalTime()
                };

                return(await _platformClient.Endpoints.InitStatusChangeAsync(request).ConfigureAwait(false));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Failed to init status change.");
                if (_serviceErrorHandler.TryHandle(ex, out var generatedException))
                {
                    generatedException.Rethrow();
                }

                throw;
            }
        }
예제 #4
0
        public async Task <bool> MedicalAuthenticateAsync(string healthSecurityId)
        {
            var isMedicalAuthenticated = false;

            try
            {
                _connectivityService.CheckConnection();

                var profileResponse = await _client.Endpoints
                                      .RegisterMedicalAsync(new RegisterDoctorRequest(healthSecurityId)).ConfigureAwait(false);

                if (profileResponse != null)
                {
                    var newAccount = new Account.Models.AccountInformation(profileResponse.UserProfile.Roles);
                    await _accountContainer.SetAsync(newAccount);

                    isMedicalAuthenticated = true;
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Failed to authenticate as medical user.");
                if (_serviceErrorHandler.TryHandle(ex, out var generatedException))
                {
                    generatedException.Rethrow();
                }

                throw;
            }

            return(isMedicalAuthenticated);
        }
예제 #5
0
        private async Task <Metadata> LoadDataInternalAsync(CancellationToken cancellationToken = default)
        {
            _connectivityService.CheckConnection();

            var profileResponse = await _platformClient.Endpoints.GetUserProfileAsync(cancellationToken).ConfigureAwait(false);

            var metadata = profileResponse.Metadata;

            cancellationToken.ThrowIfCancellationRequested();
            await _metadataContainer.SetAsync(metadata).ConfigureAwait(false);

            await _userProfileContainer.SetAsync(profileResponse.UserProfile).ConfigureAwait(false);

            return(metadata);
        }
예제 #6
0
        private async Task <Client.Services.Platform.Models.UserState> GetUserStateInternalAsync(CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();

            _connectivityService.CheckConnection();
            var profileResponse = await _platformClient.Endpoints.GetUserProfileAsync(cancellationToken).ConfigureAwait(false);

            var profile = profileResponse.UserProfile;

            cancellationToken.ThrowIfCancellationRequested();
            // metadata should be set first
            await _metadataContainer.SetAsync(profileResponse.Metadata).ConfigureAwait(false);

            await _userProfileContainer.SetAsync(profile).ConfigureAwait(false);

            await _accountContainer.SetAsync(new AccountInformation(profile.Roles)).ConfigureAwait(false);

            return(profile);
        }
        public async Task<UserProfileResponse> ApplyStatusChangeCode(string code)
        {
            try
            {
                code = code.ToUpperInvariant();

                _connectivityService.CheckConnection();

                var meetings = ShouldShareDeviceContacts(code)
                    ? await _meetingsService.GetMeetingsAsync().ConfigureAwait(false)
                    : new List<Meeting>(0);

                var request = new AcceptRequest(code, meetings.ToList());
                var response = await _platformClient.Endpoints.AcceptStatusChangeAsync(request).ConfigureAwait(false);
                if (response.Metadata != null)
                {
                    await _metadataContainer.SetAsync(response.Metadata).ConfigureAwait(false);
                }

                if (response.UserProfile != null)
                {
                    await _userProfileContainer.SetAsync(response.UserProfile).ConfigureAwait(false);
                }

                return response;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Failed to apply the code.");
                if (_serviceErrorHandler.TryHandle(ex, out var generatedException))
                {
                    generatedException.Rethrow();
                }

                throw;
            }
        }
예제 #8
0
        public async Task SignInAsync(UserCredentials userCredentials)
        {
            try
            {
                _connectivityService.CheckConnection();

                var request  = new LoginRequest(userCredentials.Username, userCredentials.Password);
                var response = await _platformClient.Endpoints.LoginAsync(request).ConfigureAwait(false);

                await _secretsProvider.InitializeAsync(response.UserToken).ConfigureAwait(false);

                await _authenticationInfoService.InitUserInfoAsync(response.Metadata, response.UserProfile, response.Token).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Failed to sign in.");
                if (_serviceErrorHandler.TryHandle(ex, out var generatedException))
                {
                    generatedException.Rethrow();
                }

                throw;
            }
        }