2024-01-18 02:49:23 +00:00
|
|
|
|
using Microsoft.Extensions.Caching.Distributed;
|
|
|
|
|
using System;
|
2021-07-23 00:41:12 +00:00
|
|
|
|
using System.Collections.Generic;
|
2024-01-18 02:49:23 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2021-07-23 00:41:12 +00:00
|
|
|
|
|
|
|
|
|
namespace BinaryDad.Coding
|
|
|
|
|
{
|
|
|
|
|
public static class Users
|
|
|
|
|
{
|
|
|
|
|
public static readonly IDictionary<string, User> Sessions = new Dictionary<string, User>(StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
}
|
2024-01-18 02:49:23 +00:00
|
|
|
|
|
|
|
|
|
public class UserCache
|
|
|
|
|
{
|
|
|
|
|
private readonly IDistributedCache _cache;
|
|
|
|
|
|
|
|
|
|
public UserCache(IDistributedCache cache)
|
|
|
|
|
{
|
|
|
|
|
_cache = cache;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<User> GetUser(string connectionId)
|
|
|
|
|
{
|
|
|
|
|
var user = new User();
|
|
|
|
|
|
|
|
|
|
user.Id = connectionId;
|
|
|
|
|
user.Name = await _cache.GetStringAsync($"name-{connectionId}");
|
|
|
|
|
user.Color = await _cache.GetStringAsync($"color-{connectionId}");
|
|
|
|
|
|
|
|
|
|
return user;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2021-07-23 00:41:12 +00:00
|
|
|
|
}
|