public override async Task InstallOrUpdateAsync(IServiceProvider serviceProvider, InstallOrUpdate installOrUpdate) { XscfModuleServiceExtension xscfModuleServiceExtension = serviceProvider.GetService <XscfModuleServiceExtension>(); SenparcEntities senparcEntities = (SenparcEntities)xscfModuleServiceExtension.BaseData.BaseDB.BaseDataContext; //更新数据库 var pendingMigs = await senparcEntities.Database.GetPendingMigrationsAsync(); if (pendingMigs.Count() > 0) { senparcEntities.ResetMigrate(); //重置合并状态 senparcEntities.Migrate(); //进行合并 } var systemModule = xscfModuleServiceExtension.GetObject(z => z.Uid == this.Uid); if (systemModule == null) { //只在未安装的情况下进行安装,InstallModuleAsync会访问到此方法,不做判断可能会引发死循环。 //常规模块中请勿在此方法中自动安装模块! await xscfModuleServiceExtension.InstallModuleAsync(this.Uid).ConfigureAwait(false); } await base.InstallOrUpdateAsync(serviceProvider, installOrUpdate); }
public override async Task InstallOrUpdateAsync(IServiceProvider serviceProvider, InstallOrUpdate installOrUpdate) { //TODO:DI注入注册时候,根据指定数据库进行绑定 XncfModuleServiceExtension xncfModuleServiceExtension = serviceProvider.GetService <XncfModuleServiceExtension>(); //SenparcEntities senparcEntities = (SenparcEntities)xncfModuleServiceExtension.BaseData.BaseDB.BaseDataContext; SenparcEntities senparcEntities = (SenparcEntities)xncfModuleServiceExtension.BaseData.BaseDB.BaseDataContext; //更新数据库 var pendingMigs = await senparcEntities.Database.GetPendingMigrationsAsync(); if (pendingMigs.Count() > 0) { senparcEntities.ResetMigrate();//重置合并状态 try { var script = senparcEntities.Database.GenerateCreateScript(); SenparcTrace.SendCustomLog("senparcEntities.Database.GenerateCreateScript", script); senparcEntities.Migrate();//进行合并 } catch (Exception ex) { var currentDatabaseConfiguration = DatabaseConfigurationFactory.Instance.Current; SenparcTrace.BaseExceptionLog(new NcfDatabaseException(ex.Message, currentDatabaseConfiguration.GetType(), senparcEntities.GetType(), ex)); } } //更新数据库(目前不使用 SystemServiceEntities 存放数据库模型) //await base.MigrateDatabaseAsync<SystemServiceEntities>(serviceProvider); var systemModule = xncfModuleServiceExtension.GetObject(z => z.Uid == this.Uid); if (systemModule == null) { //只在未安装的情况下进行安装,InstallModuleAsync会访问到此方法,不做判断可能会引发死循环。 //常规模块中请勿在此方法中自动安装模块! await xncfModuleServiceExtension.InstallModuleAsync(this.Uid).ConfigureAwait(false); } await base.InstallOrUpdateAsync(serviceProvider, installOrUpdate); }
public async Task <(bool success, string msg)> InitDatabase(IServiceProvider serviceProvider, TenantInfoService tenantInfoService, HttpContext httpContext) { var success = true; string msg = null; //SenparcEntities senparcEntities = (SenparcEntities)xncfModuleServiceExtension.BaseData.BaseDB.BaseDataContext; using (var scope = serviceProvider.CreateScope()) { //暂时关闭多租户状态 SiteConfig.SenparcCoreSetting.EnableMultiTenant = false; SenparcEntities senparcEntities = scope.ServiceProvider.GetRequiredService <SenparcEntities>(); //更新数据库 var pendingMigs = await senparcEntities.Database.GetPendingMigrationsAsync(); if (pendingMigs.Count() > 0) { senparcEntities.ResetMigrate();//重置合并状态 try { var script = senparcEntities.Database.GenerateCreateScript(); SenparcTrace.SendCustomLog("senparcEntities.Database.GenerateCreateScript", script); senparcEntities.Migrate();//进行合并 } catch (Exception ex) { success = false; msg = ex.Message; var currentDatabaseConfiguration = DatabaseConfigurationFactory.Instance.Current; SenparcTrace.BaseExceptionLog(new NcfDatabaseException(ex.Message, currentDatabaseConfiguration.GetType(), senparcEntities.GetType(), ex)); } } SiteConfig.SenparcCoreSetting.EnableMultiTenant = true; } return(success : success, msg : msg); }