public DatabaseSample(IServiceProvider serviceProvider, ColorService colorService, Lazy <XncfModuleService> xncfModuleService) : base(xncfModuleService) { _colorService = colorService; _serviceProvider = serviceProvider; var databaseConfigurationFactory = DatabaseConfigurationFactory.Instance; var currentDatabaseConfiguration = databaseConfigurationFactory.Current; MultipleDatabaseType = currentDatabaseConfiguration.MultipleDatabaseType; }
/// <summary> /// MultipleMigrationDbContext 构造函数。指定多数据库配置。 /// </summary> /// <param name="multipleDatabaseType">MultipleDatabaseType 数据库类型</param> /// <param name="xncfDatabaseRegisterType">XncfDatabase 注册类类型</param> /// <param name="runtimeDbContextType">当运行时使用的统一数据库上下文类型</param> public MultipleMigrationDbContextAttribute(MultipleDatabaseType multipleDatabaseType, Type xncfDatabaseRegisterType /*, Type runtimeDbContextType*/) { if (xncfDatabaseRegisterType == null || !xncfDatabaseRegisterType.GetInterfaces().Contains(typeof(IXncfDatabase))) { throw new NcfDatabaseException($"xncfDatabaseRegisterType 不能为空,且对应类型必须实现 IXncfDatabase 接口!", null); } MultipleDatabaseType = multipleDatabaseType; XncfDatabaseRegisterType = xncfDatabaseRegisterType; //RuntimeDbContextType = runtimeDbContextType; }
public async Task <IActionResult> OnGetAsync() { try { MultipleDatabaseType = DatabaseConfigurationFactory.Instance.Current.MultipleDatabaseType; var adminUserInfo = await _accountInfoService.GetObjectAsync(z => true);//检查是否已初始化 if (adminUserInfo == null) { throw new Exception("需要初始化"); } } catch (Exception) { { //开始安装系统模块(Service) Senparc.Service.Register serviceRegister = new Service.Register(); await serviceRegister.InstallOrUpdateAsync(_serviceProvider, Ncf.Core.Enums.InstallOrUpdate.Install); //启用系统模块(Service) var serviceModule = await _xncfModuleService.GetObjectAsync(z => z.Uid == serviceRegister.Uid); serviceModule.UpdateState(Ncf.Core.Enums.XncfModules_State.开放); } { //开始安装系统模块(Admin) Senparc.Areas.Admin.Register adminRegister = new Areas.Admin.Register(); await adminRegister.InstallOrUpdateAsync(_serviceProvider, Ncf.Core.Enums.InstallOrUpdate.Install); //启用系统模块(Admin) var adminModule = await _xncfModuleService.GetObjectAsync(z => z.Uid == adminRegister.Uid); adminModule.UpdateState(Ncf.Core.Enums.XncfModules_State.开放); //一次性保存修改 await _xncfModuleService.SaveObjectAsync(adminModule).ConfigureAwait(false); } //((SenparcEntities)_accountInfoService.BaseData.BaseDB.BaseDataContext).ResetMigrate();//重置合并状态 //((SenparcEntities)_accountInfoService.BaseData.BaseDB.BaseDataContext).Migrate();//进行合并 return(Page()); } //base.Response.StatusCode = 404; return(new StatusCodeResult(404));//已经安装完毕,且存在管理员则不进行安装 }
/// <summary> /// 获取指定 IXncfDatabase 关联的当前数据库上下文(DbContext) /// </summary> /// <param name="xncfDatabaseRegisterType">实现了 IXncfDatabase 的具体类型</param> /// <returns></returns> public Type GetXncfDbContextType(Type xncfDatabaseRegisterType) { //数据库配置工厂 var databaseConfigurationFactory = DatabaseConfigurationFactory.Instance; //当前数据库配置 var currentDatabaseConfiguration = databaseConfigurationFactory.Current; //当前数据库类型 MultipleDatabaseType multipleDatabaseType = currentDatabaseConfiguration.MultipleDatabaseType; if (!this.ContainsKey(multipleDatabaseType)) { throw new NcfDatabaseException($"未发现任何支持此数据库类型的 XNCF 模块:{multipleDatabaseType}", currentDatabaseConfiguration.GetType()); } var xncdDatabaseRegisterCollection = this[multipleDatabaseType]; if (!xncdDatabaseRegisterCollection.ContainsKey(xncfDatabaseRegisterType)) { throw new NcfDatabaseException($"{xncfDatabaseRegisterType.FullName} 模块未支持数据库:{multipleDatabaseType}", currentDatabaseConfiguration.GetType()); } return(xncdDatabaseRegisterCollection[xncfDatabaseRegisterType]); }