private TModule GetModule(IModuleStore <TModule, TModuleInputDto, TModuleKey> moduleStore, string position) { if (_positionDictionary.ContainsKey(position)) { return(_positionDictionary[position]); } string[] codes = position.Split('.'); if (codes.Length == 0) { return(null); } string code = codes[0]; TModule module = moduleStore.Modules.FirstOrDefault(m => m.Code == code); if (module == null) { return(null); } for (int i = 1; i < codes.Length; i++) { code = codes[i]; module = moduleStore.Modules.FirstOrDefault(m => m.Code == code && m.ParentId.Equals(module.Id)); if (module == null) { return(null); } } _positionDictionary.Add(position, module); return(module); }
public static TFeature Populate <TFeature>(this IModuleStore store) where TFeature : new() { var feature = new TFeature(); store.Populate(feature); return(feature); }
public ModuleService(IModuleStore moduleStore, IFileStore fileStore, IPortalSettingsStore portalSettingsStore, IUserDataStore userDataStore, ISyrinxCamundaClientService camundaClient) { this.moduleStore = moduleStore; this.fileStore = fileStore; this.portalSettingsStore = portalSettingsStore; this.userDataStore = userDataStore; this.camundaClient = camundaClient; }
public AspNetModuleManager( IModuleStore <TModule, TProject> store, IModuleAccessor <TModule, TProject> accessor, IEnumerable <IValidator <TModule, TProject> > validators, ILogger <ModuleManager <TModule, TProject> > logger, ILookupNormalizer <TModule> nameNormalizer, IHttpContextAccessor contextAccessor) : base(store, accessor, validators, logger, nameNormalizer) => _cancel = contextAccessor?.HttpContext?.RequestAborted ?? CancellationToken.None;
public HealthChecksService(ISyrinxCamundaClientService camundaService, IMemoryCacheService memoryCacheService, IPortalSettingsStore portalSettingsStore, IPortalSettingsService portalSettingsService, IModuleStore moduleStore) { this.camundaService = camundaService; this.memoryCacheService = memoryCacheService; this.portalSettingsStore = portalSettingsStore; this.portalSettingsService = portalSettingsService; this.moduleStore = moduleStore; }
public ModuleManager( IModuleStore <TModule, TProject> store, IModuleAccessor <TModule, TProject> accessor, IEnumerable <IValidator <TModule, TProject> > validators, ILogger <ModuleManager <TModule, TProject> > logger, ILookupNormalizer <TModule> nameNormalizer) : base(store, accessor, validators, logger) { NameNormalizer = nameNormalizer ?? throw new ArgumentNullException(nameof(nameNormalizer)); }
/// <summary> /// 重写以实现将提取到的模块信息同步到数据库中 /// </summary> /// <param name="provider">局部服务提供者</param> /// <param name="moduleInfos">从程序集中提取到的模块信息</param> protected virtual void SyncToDatabase(IServiceProvider provider, ModuleInfo[] moduleInfos) { Check.NotNull(moduleInfos, nameof(moduleInfos)); if (moduleInfos.Length == 0) { return; } IModuleStore <TModule, TModuleInputDto, TModuleKey> moduleStore = provider.GetService <IModuleStore <TModule, TModuleInputDto, TModuleKey> >(); IModuleFunctionStore <TModuleFunction, TModuleKey> moduleFunctionStore = provider.GetService <IModuleFunctionStore <TModuleFunction, TModuleKey> >(); foreach (ModuleInfo info in moduleInfos) { TModule parent = GetModule(moduleStore, info.Position); if (parent == null) { throw new OsharpException($"路径为“{info.Position}”的模块信息无法找到"); } OperationResult result; TModule module = moduleStore.Modules.FirstOrDefault(m => m.ParentId.Equals(parent.Id) && m.Code == info.Code); if (module == null) { TModuleInputDto dto = GetDto(info, parent.Id, null); result = moduleStore.CreateModule(dto).Result; if (result.Errored) { throw new OsharpException(result.Message); } module = moduleStore.Modules.First(m => m.ParentId.Equals(parent.Id) && m.Code == info.Code); } else { TModuleInputDto dto = GetDto(info, parent.Id, module); result = moduleStore.UpdateModule(dto).Result; if (result.Errored) { throw new OsharpException(result.Message); } } if (info.DependOnFunctions.Length > 0) { Guid[] functionIds = info.DependOnFunctions.Select(m => m.Id).ToArray(); result = moduleFunctionStore.SetModuleFunctions(module.Id, functionIds).Result; if (result.Errored) { throw new OsharpException(result.Message); } } } IUnitOfWork unitOfWork = provider.GetService <IUnitOfWork>(); unitOfWork.Commit(); }
public ModularManager(IOptions <ModularOptions> options, IModuleStore store) { _options = options.Value; _store = store; _moduleLoadContext = new AssemblyLoadContext("Modules", true); // 发现所有模块信息 _infos = _store.Find(); var loggerFactory = LoggerFactory.Create(builder => { builder .AddConsole() .AddEventLog(); }); _logger = loggerFactory.CreateLogger <ModularManager>(); }
/// <summary> /// 重写以实现将提取到的模块信息同步到数据库中 /// </summary> /// <param name="provider">局部服务提供者</param> /// <param name="moduleInfos">从程序集中提取到的模块信息</param> protected virtual void SyncToDatabase(IServiceProvider provider, ModuleInfo[] moduleInfos) { Check.NotNull(moduleInfos, nameof(moduleInfos)); if (moduleInfos.Length == 0) { return; } IModuleStore <TModule, TModuleInputDto, TModuleKey> moduleStore = provider.GetService <IModuleStore <TModule, TModuleInputDto, TModuleKey> >(); if (moduleStore == null) { Logger.LogWarning("初始化模块数据时,IRepository<,>的服务未找到,请初始化 EntityFrameworkCoreModule 模块"); return; } IModuleFunctionStore <TModuleFunction, TModuleKey> moduleFunctionStore = provider.GetService <IModuleFunctionStore <TModuleFunction, TModuleKey> >(); if (moduleFunctionStore == null) { Logger.LogWarning("初始化模块功能数据时,IRepository<,>的服务未找到,请初始化 EntityFrameworkCoreModule 模块"); return; } IUnitOfWork unitOfWork = provider.GetUnitOfWork(true); if (!moduleInfos.CheckSyncByHash(provider, Logger)) { Logger.LogInformation("同步模块数据时,数据签名与上次相同,取消同步"); return; } //删除数据库中多余的模块 TModule[] modules = moduleStore.Modules.ToArray(); var positionModules = modules.Select(m => new { m.Id, Position = GetModulePosition(modules, m) }) .OrderByDescending(m => m.Position.Length).ToArray(); string[] deletePositions = positionModules.Select(m => m.Position) .Except(moduleInfos.Select(n => $"{n.Position}.{n.Code}")) .Except(new[] { "Root" }) .ToArray(); TModuleKey[] deleteModuleIds = positionModules.Where(m => deletePositions.Contains(m.Position)).Select(m => m.Id).ToArray(); foreach (TModuleKey id in deleteModuleIds) { OperationResult result = moduleStore.DeleteModule(id).GetAwaiter().GetResult(); if (result.Error) { throw new OsharpException(result.Message); } Logger.LogDebug($"删除模块:{result.Message}"); } //新增或更新传入的模块 foreach (ModuleInfo info in moduleInfos) { TModule parent = GetModule(moduleStore, info.Position); //插入父级分类 if (parent == null) { int lastIndex = info.Position.LastIndexOf('.'); string parent1Position = info.Position.Substring(0, lastIndex); TModule parent1 = GetModule(moduleStore, parent1Position); if (parent1 == null) { throw new OsharpException($"路径为“{parent1Position}”的模块信息无法找到"); } string parentCode = info.Position.Substring(lastIndex + 1, info.Position.Length - lastIndex - 1); ModuleInfo parentInfo = new ModuleInfo() { Code = parentCode, Name = info.PositionName ?? parentCode, Position = parent1Position }; TModuleInputDto dto = GetDto(parentInfo, parent1, null); OperationResult result = moduleStore.CreateModule(dto).GetAwaiter().GetResult(); if (result.Error) { throw new OsharpException(result.Message); } parent = moduleStore.Modules.First(m => m.ParentId.Equals(parent1.Id) && m.Code == parentCode); } TModule module = moduleStore.Modules.FirstOrDefault(m => m.ParentId.Equals(parent.Id) && m.Code == info.Code); //新建模块 if (module == null) { TModuleInputDto dto = GetDto(info, parent, null); OperationResult result = moduleStore.CreateModule(dto).GetAwaiter().GetResult(); if (result.Error) { throw new OsharpException(result.Message); } module = moduleStore.Modules.First(m => m.ParentId.Equals(parent.Id) && m.Code == info.Code); } else //更新模块 { TModuleInputDto dto = GetDto(info, parent, module); OperationResult result = moduleStore.UpdateModule(dto).GetAwaiter().GetResult(); if (result.Error) { throw new OsharpException(result.Message); } } if (info.DependOnFunctions.Length > 0) { Guid[] functionIds = info.DependOnFunctions.Select(m => m.Id).ToArray(); OperationResult result = moduleFunctionStore.SetModuleFunctions(module.Id, functionIds).GetAwaiter().GetResult(); if (result.Error) { throw new OsharpException(result.Message); } } } unitOfWork.Commit(); }
public static TypeFeature Populate(this IModuleStore store) => store.Populate <TypeFeature>();
public StopWorker(IFileStore fileStore, IModuleStore moduleStore, IPortalSettingsStore portalSettingsStore) : base(fileStore, moduleStore, portalSettingsStore) { }
protected ModuleProcessingWorker(IFileStore fileStore, IModuleStore moduleStore, IPortalSettingsStore portalSettingsStore) { this.fileStore = fileStore; this.moduleStore = moduleStore; this.portalSettingsStore = portalSettingsStore; }
public HomeController(IFunctionStore <Function, FunctionInputDto> functionStore, IModuleStore <Module, ModuleInputDto, int> moduleStore) { _functionStore = functionStore; _moduleStore = moduleStore; }
public StopWorker(IModuleStore moduleStore, ISyrinxCamundaClientService camundaClient) { this.moduleStore = moduleStore; this.camundaClient = camundaClient; }
/// <summary> /// 重写以实现将提取到的模块信息同步到数据库中 /// </summary> /// <param name="provider">局部服务提供者</param> /// <param name="moduleInfos">从程序集中提取到的模块信息</param> protected virtual void SyncToDatabase(IServiceProvider provider, ModuleInfo[] moduleInfos) { Check.NotNull(moduleInfos, nameof(moduleInfos)); if (moduleInfos.Length == 0) { return; } IModuleStore <TModule, TModuleInputDto, TModuleKey> moduleStore = provider.GetService <IModuleStore <TModule, TModuleInputDto, TModuleKey> >(); IModuleFunctionStore <TModuleFunction, TModuleKey> moduleFunctionStore = provider.GetService <IModuleFunctionStore <TModuleFunction, TModuleKey> >(); //删除数据库中多余的模块 TModule[] modules = moduleStore.Modules.ToArray(); var positionModules = modules.Select(m => new { m.Id, Position = GetModulePosition(modules, m) }) .OrderByDescending(m => m.Position.Length).ToArray(); string[] deletePositions = positionModules.Select(m => m.Position) .Except(moduleInfos.Select(n => $"{n.Position}.{n.Code}")) .Except("Root,Root.Site,Root.Admin,Root.Admin.Identity,Root.Admin.Security,Root.Admin.System".Split(',')) .ToArray(); TModuleKey[] deleteModuleIds = positionModules.Where(m => deletePositions.Contains(m.Position)).Select(m => m.Id).ToArray(); OperationResult result; foreach (TModuleKey id in deleteModuleIds) { result = moduleStore.DeleteModule(id).Result; if (result.Errored) { throw new OsharpException(result.Message); } } //新增或更新传入的模块 foreach (ModuleInfo info in moduleInfos) { TModule parent = GetModule(moduleStore, info.Position); if (parent == null) { throw new OsharpException($"路径为“{info.Position}”的模块信息无法找到"); } TModule module = moduleStore.Modules.FirstOrDefault(m => m.ParentId.Equals(parent.Id) && m.Code == info.Code); if (module == null) { TModuleInputDto dto = GetDto(info, parent, null); result = moduleStore.CreateModule(dto).Result; if (result.Errored) { throw new OsharpException(result.Message); } module = moduleStore.Modules.First(m => m.ParentId.Equals(parent.Id) && m.Code == info.Code); } else { TModuleInputDto dto = GetDto(info, parent, module); result = moduleStore.UpdateModule(dto).Result; if (result.Errored) { throw new OsharpException(result.Message); } } if (info.DependOnFunctions.Length > 0) { Guid[] functionIds = info.DependOnFunctions.Select(m => m.Id).ToArray(); result = moduleFunctionStore.SetModuleFunctions(module.Id, functionIds).Result; if (result.Errored) { throw new OsharpException(result.Message); } } } IUnitOfWork unitOfWork = provider.GetService <IUnitOfWork>(); unitOfWork.Commit(); }
public StatusWorker(IModuleStore moduleStore) { this.moduleStore = moduleStore; }
public ErrorWorker(IModuleStore moduleStore) { this.moduleStore = moduleStore; }
public RemoveWorker(IModuleStore moduleStore) { this.moduleStore = moduleStore; }