예제 #1
0
        public async Task <Account> GetAccount(User user, CancellationToken cancellationToken)
        {
            Ensure.Any.IsNotNull(user, nameof(user));

            var cachedAccount = _accountCache.GetAccount(user.Username);

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

            var parsedAccount = new Account(user.Username);

            var account = await _accountStore.GetAccount(parsedAccount.Provider, parsedAccount.Subject, cancellationToken).ConfigureAwait(false);

            if (account.IsNewAccount)
            {
                // This account has just been created
                var profile = await CreateProfile(account.Id, user, cancellationToken).ConfigureAwait(false);

                _profileCache.StoreProfile(profile);
            }

            _accountCache.StoreAccount(account);

            return(account);
        }
        private async Task UpdateProfile(Profile profile, CancellationToken cancellationToken)
        {
            var storeTask   = _profileStore.StoreProfile(profile, cancellationToken);
            var triggerTask = _eventTrigger.ProfileUpdated(profile, cancellationToken);

            await Task.WhenAll(storeTask, triggerTask).ConfigureAwait(false);

            _profileCache.StoreProfile(profile);
        }
예제 #3
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);
        }