/// <summary> /// 获取当前系统支持的所有游戏供应商 /// </summary> /// <returns></returns> public static Dictionary <string, string> GetGameProvider() { return(MemoryUtils.Get("GAMEPROVIDER", TimeSpan.FromDays(1), () => { return typeof(GameFactory).Assembly.GetTypes().Where(t => t.IsPublic && !t.IsAbstract && t.BaseType == typeof(IGameProvider)).ToDictionary( t => t.Name, t => t.GetDescription()); })); }
private Result CheckCode(string key, string value) { string code = MemoryUtils.Get <string>(key); Result result = new Result(!string.IsNullOrEmpty(code) && code == value); if (result) { MemoryUtils.Remove(key); } return(result); }
/// <summary> /// 获取远程接口的数据(本地缓存) /// </summary> /// <returns></returns> public static Dictionary <long, Dictionary <Language, string> > GetData() { if (string.IsNullOrEmpty(APIURL)) { return(null); } return(MemoryUtils.Get(KEY, TimeSpan.FromDays(7), () => { return GetAPIData(); })); }
/// <summary> /// 创建游戏工厂实现 /// </summary> /// <param name="type">游戏厂商的名字(对应类名)</param> /// <param name="setting">参数设定 QueryString 格式</param> /// <returns></returns> public static IGameProvider GetFactory(string type, string setting) { string key = $"{type}{setting.GetLongHashCode()}"; return(MemoryUtils.Get(key, TimeSpan.FromHours(1), () => { Type assembly = typeof(GameFactory).Assembly.GetType($"{typeof(GameFactory).Namespace}.Clients.{type}"); if (assembly == null) { return null; } return (IGameProvider)Activator.CreateInstance(assembly, setting); })); }
/// <summary> /// 获取语言包(内存中缓存) /// </summary> /// <returns></returns> public Dictionary <string, Dictionary <Language, string> > GetTranslate(string channelName, bool fromDatabase = false) { int channelId = this.GetChannelID(channelName); if (channelId == 0) { return(new Dictionary <string, Dictionary <Language, string> >()); } Func <Dictionary <string, Dictionary <Language, string> > > action = () => { Dictionary <string, Dictionary <Language, string> > data = new Dictionary <string, Dictionary <Language, string> >(); using (DbExecutor db = NewExecutor()) { IDataReader reader = db.ReadData(CommandType.Text, "SELECT * FROM tran_Content WHERE EXISTS(SELECT 0 FROM tran_Token WHERE ChannelID = @ChannelID AND tran_Token.KeyID = tran_Content.KeyID)", new { ChannelID = channelId }); while (reader.Read()) { string keyId = (string)reader["KeyID"]; Language language = (Language)reader["Language"]; string content = (string)reader["Content"]; if (!data.ContainsKey(keyId)) { data.Add(keyId, new Dictionary <Language, string>()); } if (!data[keyId].ContainsKey(language)) { data[keyId].Add(language, content); } } } return(data); }; if (fromDatabase) { return(action.Invoke()); } return(MemoryUtils.Get(channelName, TimeSpan.FromHours(1), action)); }
/// <summary> /// 获取当前登录的管理员信息(本地缓存10分钟) /// </summary> /// <param name="token"></param> /// <returns></returns> public SystemAdmin GetAdminInfo(string input) { if (!Guid.TryParse(input, out Guid token)) { return(null); } int adminId = AdminCaching.Instance().GetAdminID(token); if (adminId == 0) { return(null); } string key = $"SYSTEMADMIN:{adminId}"; return(MemoryUtils.Get(key, TimeSpan.FromMinutes(10), () => { return this.GetAdminInfo(adminId); })); }
/// <summary> /// 创建DNS供应商工厂 /// </summary> /// <param name="type"></param> /// <param name="setting"></param> /// <returns></returns> public static IDNSProvider GetFactory(DNSProviderType type, string setting) { /// 手动配置 if (type == DNSProviderType.Manual) { return(null); } string key = $"{type}{setting.GetHash(8)}"; return(MemoryUtils.Get(key, TimeSpan.FromHours(1), () => { Type assembly = typeof(DNSFactory).Assembly.GetType($"SP.StudioCore.API.DNS.{type}"); if (assembly == null) { return null; } return (IDNSProvider)Activator.CreateInstance(assembly, setting); })); }
/// <summary> /// 创建DNS供应商工厂 /// </summary> /// <param name="type"></param> /// <param name="setting"></param> /// <returns></returns> public static ICDNProvider GetFactory(CDNProviderType type, string setting) { /// 手动配置 if (type == CDNProviderType.Manual) { return(null); } string key = $"{type}{setting.GetHash(8)}"; return(MemoryUtils.Get(key, TimeSpan.FromHours(1), () => { Type assembly = typeof(CDNFactory).Assembly.GetType($"{typeof(CDNFactory).Namespace}.{type}"); if (assembly == null) { return null; } return (ICDNProvider)Activator.CreateInstance(assembly, setting); })); }