Beispiel #1
0
        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);
        }
        /// <summary>
        /// 安装模块之后,安装菜单
        /// </summary>
        /// <param name="register"></param>
        /// <returns></returns>
        public async Task InstallMenuAsync(IXncfRegister register, InstallOrUpdate installOrUpdate)
        {
            var topMenu = await _sysMenuService.Value.GetObjectAsync(z => z.MenuName == "扩展模块").ConfigureAwait(false);

            var currentMenu = await _sysMenuService.Value.GetObjectAsync(z => z.ParentId == topMenu.Id && z.MenuName == register.MenuName).ConfigureAwait(false);

            SysMenuDto menuDto;

            if (installOrUpdate == InstallOrUpdate.Update && currentMenu != null)
            {
                //更新菜单
                menuDto          = _sysMenuService.Value.Mapper.Map <SysMenuDto>(currentMenu);
                menuDto.MenuName = register.MenuName; //更新菜单名称
                menuDto.Icon     = register.Icon;     //更新菜单图标
            }
            else
            {
                //新建菜单
                var icon  = register.Icon.IsNullOrEmpty() ? "fa fa-bars" : register.Icon;
                var order = 20;
                switch (register.Uid)
                {
                case SiteConfig.SYSTEM_XNCF_MODULE_SERVICE_UID:
                    order = 160;
                    break;

                case SiteConfig.SYSTEM_XNCF_MODULE_AREAS_ADMIN_UID:
                    order = 150;
                    break;

                default:
                    break;
                }
                menuDto = new SysMenuDto(true, null, register.MenuName, topMenu.Id, $"/Admin/XncfModule/Start/?uid={register.Uid}", icon, order, true, null);
            }

            var sysMemu = await _sysMenuService.Value.CreateOrUpdateAsync(menuDto).ConfigureAwait(false);

            if (installOrUpdate == InstallOrUpdate.Install)
            {
                //更新菜单信息
                SysPermissionDto sysPermissionDto = new SysPermissionDto()
                {
                    IsMenu       = true,
                    ResourceCode = sysMemu.ResourceCode,
                    RoleId       = "1",
                    RoleCode     = "administrator",
                    PermissionId = sysMemu.Id
                };
                SenparcEntities db = _serviceProvider.GetService <SenparcEntities>();
                db.SysPermission.Add(new SysPermission(sysPermissionDto));
                await db.SaveChangesAsync();

                var updateMenuDto = new UpdateMenuId_XncfModuleDto(register.Uid, sysMemu.Id);
                await base.UpdateMenuIdAsync(updateMenuDto).ConfigureAwait(false);
            }
        }
Beispiel #3
0
        /// <summary>
        /// handler=SelectItems
        /// </summary>
        /// <param name="senparcEntities"></param>
        /// <returns></returns>
        public async Task <IActionResult> OnGetSelectItemsAsync([FromServices] SenparcEntities senparcEntities)
        {
            var list = await senparcEntities.SysRoles.Where(_ => _.Enabled)
                       .Select(_ => new SelectListItem()
            {
                Value = _.Id, Text = _.RoleName
            })
                       .ToListAsync();

            return(Ok(list));
        }
Beispiel #4
0
        public CompetitionProgramController(
            CompetitionProgramService competitionProgramService
            , SenparcEntities senparcEntities
            , ActivityService activityService
            , ProjectMemberService projectMemberService
            , ScheduleService scheduleService
            , AdminUserInfoService adminUserInfoService

            )
        {
            _competitionProgramService = competitionProgramService;
            _senparcEntities           = senparcEntities;
            _scheduleService           = scheduleService;
            _activityService           = activityService;
            _projectMemberService      = projectMemberService;
            _adminUserInfoService      = adminUserInfoService;
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
 public AccountController(AccountService accountService, SenparcEntities senparcEntities)
 {
     _accountService  = accountService;
     _senparcEntities = senparcEntities;
 }
Beispiel #8
0
 public SysButtonRespository(ISqlBaseFinanceData db) : base(db)
 {
     _senparcEntities = db.BaseDataContext as SenparcEntities;
 }