コード例 #1
0
 public virtual UserWithFriendsCacheItem GetCacheItem(UserIdentifier userIdentifier)
 {
     return(_cacheManager
            .GetCache(FriendCacheItem.CacheName)
            .AsTyped <string, UserWithFriendsCacheItem>()
            .Get(userIdentifier.ToUserIdentifierString(), f => GetUserFriendsCacheItemInternal(userIdentifier)));
 }
コード例 #2
0
 public virtual UserWithFriendsCacheItem GetCacheItemOrNull(UserIdentifier userIdentifier)
 {
     return(_cacheManager
            .GetCache(FriendCacheItem.CacheName)
            .AsTyped <string, UserWithFriendsCacheItem>()
            .GetOrDefault(userIdentifier.ToUserIdentifierString()));
 }
コード例 #3
0
        /// <summary>
        /// 获取指定user的所有clients
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public IReadOnlyList <IOnlineClient> GetAllByUserId(IUserIdentifier user)
        {
            var clients = new List <OnlineClient>();

            var userIdentifier = new UserIdentifier(user.TenantId, user.UserId);

            if (!IsUserOnline(userIdentifier))
            {
                return(clients);
            }

            lock (_syncObj)
            {
                var _database = GetDatabase();

                var userClients      = new List <string>();
                var userClientsValue = _database.HashGet(_userStoreKey, userIdentifier.ToUserIdentifierString());
                if (userClientsValue.HasValue)
                {
                    userClients = JsonConvert.DeserializeObject <List <string> >(userClientsValue);
                    foreach (var connectionId in userClients)
                    {
                        var clientValue = _database.HashGet(_clientStoreKey, connectionId);
                        if (clientValue.IsNullOrEmpty)
                        {
                            continue;
                        }

                        clients.Add(JsonConvert.DeserializeObject <OnlineClient>(clientValue));
                    }
                }
            }

            return(clients);
        }
コード例 #4
0
        private async Task <IEnumerable <Claim> > CreateJwtClaims(ClaimsIdentity identity, User user, TimeSpan?expiration = null)
        {
            var tokenValidityKey = Guid.NewGuid().ToString();
            var claims           = identity.Claims.ToList();
            var nameIdClaim      = claims.First(c => c.Type == _identityOptions.ClaimsIdentity.UserIdClaimType);

            if (_identityOptions.ClaimsIdentity.UserIdClaimType != JwtRegisteredClaimNames.Sub)
            {
                claims.Add(new Claim(JwtRegisteredClaimNames.Sub, nameIdClaim.Value));
            }

            var userIdentifier = new UserIdentifier(AbpSession.TenantId, Convert.ToInt64(nameIdClaim.Value));

            claims.AddRange(new[]
            {
                new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
                new Claim(JwtRegisteredClaimNames.Iat, DateTimeOffset.Now.ToUnixTimeSeconds().ToString(), ClaimValueTypes.Integer64),
                new Claim(AppConsts.TokenValidityKey, tokenValidityKey),
                new Claim(AppConsts.UserIdentifier, userIdentifier.ToUserIdentifierString())
            });

            _cacheManager
            .GetCache(AppConsts.TokenValidityKey)
            .Set(tokenValidityKey, "");

            await _userManager.AddTokenValidityKeyAsync(user, tokenValidityKey,
                                                        DateTime.UtcNow.Add(expiration ?? _configuration.Expiration));

            return(claims);
        }
コード例 #5
0
 /// <inheritdoc/>
 public virtual void ChangeSettingForUser(UserIdentifier user, string name, string value)
 {
     _unitOfWorkManager.WithUnitOfWork(() =>
     {
         InsertOrUpdateOrDeleteSettingValue(name, value, user.TenantId, user.UserId);
         _userSettingCache.Remove(user.ToUserIdentifierString());
     });
 }
コード例 #6
0
 /// <inheritdoc/>
 public virtual async Task ChangeSettingForUserAsync(UserIdentifier user, string name, string value)
 {
     await _unitOfWorkManager.WithUnitOfWorkAsync(async() =>
     {
         await InsertOrUpdateOrDeleteSettingValueAsync(name, value, user.TenantId, user.UserId);
         await _userSettingCache.RemoveAsync(user.ToUserIdentifierString());
     });
 }
コード例 #7
0
 private async Task <Dictionary <string, SettingInfo> > GetUserSettingsFromCacheAsync(UserIdentifier user)
 {
     return(await _userSettingCache.GetAsync(
                user.ToUserIdentifierString(),
                async() =>
     {
         var settingValues = await SettingStore.GetAllListAsync(user.TenantId, user.UserId);
         return ConvertSettingInfosToDictionary(settingValues);
     }));
 }
コード例 #8
0
 private Dictionary <string, SettingInfo> GetUserSettingsFromCache(UserIdentifier user)
 {
     return(_userSettingCache.Get(
                user.ToUserIdentifierString(),
                () =>
     {
         var settingValues = SettingStore.GetAllList(user.TenantId, user.UserId);
         return ConvertSettingInfosToDictionary(settingValues);
     }));
 }
コード例 #9
0
        private Dictionary <string, SettingInfo> GetUserSettingsFromCache(UserIdentifier user)
        {
            return(_userSettingCache.Get(
                       user.ToUserIdentifierString(),
                       () =>
            {
                var dictionary = new Dictionary <string, SettingInfo>();

                var settingValues = SettingStore.GetAllList(user.TenantId, user.UserId);
                foreach (var settingValue in settingValues)
                {
                    dictionary[settingValue.Name] = settingValue;
                }

                return dictionary;
            }));
        }
コード例 #10
0
        private Task <Dictionary <string, SettingInfo> > GetUserSettingsFromCache(UserIdentifier user)
        {
            return(_cache.GetOrAddAsync(
                       string.Format(TenantSettingsCacheKeyTemplate, user.ToUserIdentifierString()),
                       async() =>
            {
                var dictionary = new Dictionary <string, SettingInfo>();

                var settingValues = await _store.ReadListAsync(user.TenantId, user.UserId);
                foreach (var settingValue in settingValues)
                {
                    dictionary[settingValue.Name] = settingValue;
                }

                return dictionary;
            }, DateTimeOffset.UtcNow.Add(_cacheDuration)));
        }
コード例 #11
0
        private async Task <Dictionary <string, SettingInfo> > GetUserSettingsFromCache(UserIdentifier user)
        {
            return(await _userSettingCache.GetAsync(
                       user.ToUserIdentifierString(),
                       async() =>
            {
                var dictionary = new Dictionary <string, SettingInfo>();

                var settingValues = await SettingStore.GetAllListAsync(user.UserId);
                foreach (var settingValue in settingValues)
                {
                    dictionary[settingValue.Name] = settingValue;
                }

                return dictionary;
            }));
        }
コード例 #12
0
 public void ChangeSettingForUser(UserIdentifier user, string name, string value)
 {
     InsertOrUpdateOrDeleteSettingValue(name, value, user.TenantId, user.UserId);
     _userSettingCache.Remove(user.ToUserIdentifierString());
 }
コード例 #13
0
        public async Task ChangeSettingForUserAsync(UserIdentifier user, string name, string value)
        {
            await InsertOrUpdateOrDeleteSettingValueAsync(name, value, user.TenantId, user.UserId);

            await _userSettingCache.RemoveAsync(user.ToUserIdentifierString());
        }
コード例 #14
0
        private async Task<Dictionary<string, SettingInfo>> GetUserSettingsFromCache(UserIdentifier user)
        {
            return await _userSettingCache.GetAsync(
                user.ToUserIdentifierString(),
                async () =>
                {
                    var dictionary = new Dictionary<string, SettingInfo>();

                    var settingValues = await SettingStore.GetAllListAsync(user.TenantId, user.UserId);
                    foreach (var settingValue in settingValues)
                    {
                        dictionary[settingValue.Name] = settingValue;
                    }

                    return dictionary;
                });
        }
コード例 #15
0
        private bool IsUserOnline(UserIdentifier user)
        {
            var _database = GetDatabase();

            return(_database.HashExists(_userStoreKey, user.ToUserIdentifierString()));
        }
コード例 #16
0
        public async Task ChangeSettingForUserAsync(UserIdentifier user, string name, string value)
        {
            await SaveValueAsync(name, value, user.TenantId, user.UserId);

            _cache.Remove(string.Format(UserSettingsCacheKeyTemplate, user.ToUserIdentifierString()));
        }
コード例 #17
0
 private void UpdateUserOnCache(UserIdentifier userIdentifier, UserWithFriendsCacheItem user)
 {
     _cacheManager.GetCache(FriendCacheItem.CacheName).Set(userIdentifier.ToUserIdentifierString(), user);
 }
コード例 #18
0
 public async Task ChangeSettingForUserAsync(UserIdentifier user, string name, string value)
 {
     await InsertOrUpdateOrDeleteSettingValueAsync(name, value, user.TenantId, user.UserId);
     await _userSettingCache.RemoveAsync(user.ToUserIdentifierString());
 }