using HZY.Framework.DependencyInjection; using Microsoft.Identity.Client; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CloudGaming.Code.DataBaseModel; /// /// /// public class AppConfig : IScopedSelfDependency { public AppConfig() { } /// /// 用户数据库连接字符串 /// public string? UserConnectionString { get; set; } /// /// 游戏 /// public string? GameConnectionString { get; set; } /// /// 扩展 /// public string? ExtConnectionString { get; set; } /// /// 手机app配置 /// public string? PhoneConnectionString { get; set; } /// /// redis连接字符串 /// public string? RedisConnectionString { get; set; } /// /// 域名 /// public string? DomainName { get; set; } /// /// 标识 /// public string Identifier { get; set; } /// /// 名称 /// public string Name { get; set; } /// /// 租户 /// public Guid TenantId { get; set; } /// /// 项目支付数据 /// public AppPayment? Payment { get; set; } /// /// app版本 /// public string AppVersion { get; set; } /// /// 缓存版本 /// public int CacheVersion { get; set; } /// /// oss阿里云配置 /// public AliyunOssConfig AliyunConfig { get; set; } /// /// 获取数据库连接字符串 /// /// user,game,ext,phone /// /// public string GetConnectionString(AppDataBaseType appDataBaseType) { switch (appDataBaseType) { case AppDataBaseType.User: return UserConnectionString; case AppDataBaseType.Game: return GameConnectionString; case AppDataBaseType.Ext: return ExtConnectionString; case AppDataBaseType.App: return PhoneConnectionString; default: throw new NotImplementedException("数据库连接字符串不存在"); } } } /// /// /// public static class AppConfigExtend { /// /// /// public static string[] AppDataBaseTypes = { AppDataBaseType.Game.ToString(), AppDataBaseType.App.ToString(), AppDataBaseType.User.ToString(), AppDataBaseType.Ext.ToString() }; /// /// /// /// /// public static bool IsAppDataBase(string type) { return AppDataBaseTypes.Contains(type); } /// /// /// /// /// public static void CopyTo(this AppConfig _appConfig, AppConfig appConfig) { if (appConfig == null) { appConfig = new AppConfig(); } appConfig.AppVersion = _appConfig.AppVersion; appConfig.Identifier = _appConfig.Identifier; appConfig.UserConnectionString = _appConfig.UserConnectionString; appConfig.GameConnectionString = _appConfig.GameConnectionString; appConfig.ExtConnectionString = _appConfig.ExtConnectionString; appConfig.PhoneConnectionString = _appConfig.PhoneConnectionString; appConfig.RedisConnectionString = _appConfig.RedisConnectionString; appConfig.DomainName = _appConfig.DomainName; appConfig.Name = _appConfig.Name; appConfig.TenantId = _appConfig.TenantId; appConfig.Payment = _appConfig.Payment; appConfig.CacheVersion = _appConfig.CacheVersion; appConfig.AliyunConfig = _appConfig.AliyunConfig; } /// /// /// /// /// /// public static void GetTenantIdAppConfig(this List appConfigs, Guid tenantId, AppConfig appConfig = null) { if (appConfigs == null && appConfigs.Count == 0) { return; } var _appConfig = appConfigs.FirstOrDefault(it => it.TenantId == tenantId); if (_appConfig == null) { return; } if (appConfig == null) { appConfig = new AppConfig(); } _appConfig.CopyTo(appConfig); } /// /// /// /// /// /// public static void GetHostOrDefaultAppConfig(this List appConfigs, string host, AppConfig appConfig = null) { if (appConfigs == null && appConfigs.Count == 0) { return; } var _appConfig = appConfigs.FirstOrDefault(it => it.DomainName == host); if (_appConfig == null) { _appConfig = appConfigs.FirstOrDefault(it => it.Identifier == "default" || it.Name == "default"); } if (_appConfig == null) { _appConfig = appConfigs[0]; } if (appConfig == null) { appConfig = new AppConfig(); } _appConfig.CopyTo(appConfig); } } /// /// 数据库选项 /// public enum AppDataBaseType { /// /// 用户数据库 /// User, /// /// 游戏数据库 /// Game, /// /// 扩展数据库 /// Ext, /// /// app数据库 /// App, /// /// /// Admin }