public virtual UserWithFriendsCacheItem GetCacheItem(UserIdentifier userIdentifier) { return(_cacheManager .GetCache(FriendCacheItem.CacheName) .AsTyped <string, UserWithFriendsCacheItem>() .Get(userIdentifier.ToUserIdentifierString(), f => GetUserFriendsCacheItemInternal(userIdentifier))); }
public virtual UserWithFriendsCacheItem GetCacheItemOrNull(UserIdentifier userIdentifier) { return(_cacheManager .GetCache(FriendCacheItem.CacheName) .AsTyped <string, UserWithFriendsCacheItem>() .GetOrDefault(userIdentifier.ToUserIdentifierString())); }
/// <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); }
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); }
/// <inheritdoc/> public virtual void ChangeSettingForUser(UserIdentifier user, string name, string value) { _unitOfWorkManager.WithUnitOfWork(() => { InsertOrUpdateOrDeleteSettingValue(name, value, user.TenantId, user.UserId); _userSettingCache.Remove(user.ToUserIdentifierString()); }); }
/// <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()); }); }
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); })); }
private Dictionary <string, SettingInfo> GetUserSettingsFromCache(UserIdentifier user) { return(_userSettingCache.Get( user.ToUserIdentifierString(), () => { var settingValues = SettingStore.GetAllList(user.TenantId, user.UserId); return ConvertSettingInfosToDictionary(settingValues); })); }
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; })); }
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))); }
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; })); }
public void ChangeSettingForUser(UserIdentifier user, string name, string value) { InsertOrUpdateOrDeleteSettingValue(name, value, user.TenantId, user.UserId); _userSettingCache.Remove(user.ToUserIdentifierString()); }
public async Task ChangeSettingForUserAsync(UserIdentifier user, string name, string value) { await InsertOrUpdateOrDeleteSettingValueAsync(name, value, user.TenantId, user.UserId); await _userSettingCache.RemoveAsync(user.ToUserIdentifierString()); }
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; }); }
private bool IsUserOnline(UserIdentifier user) { var _database = GetDatabase(); return(_database.HashExists(_userStoreKey, user.ToUserIdentifierString())); }
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())); }
private void UpdateUserOnCache(UserIdentifier userIdentifier, UserWithFriendsCacheItem user) { _cacheManager.GetCache(FriendCacheItem.CacheName).Set(userIdentifier.ToUserIdentifierString(), user); }