public static void GetModulesValid(IModuleBase moduleBase) { moduleBase.IpAddress = Module_IP; moduleBase.Name = Module_Name; moduleBase.Port = Module_Port; moduleBase.Chanels = GetChanelsValid(); }
private IResult ExecuteConcurrent(CommandContext context, ICommand command, IModuleBase module, object[] args) { var tsc = new TaskCompletionSource <IResult>(); _ = Task.Run(() => { return(ExecuteSequentialAsync(context, command, module, args)); }).ContinueWith(async task => { IResult result = null; try { result = await task; } catch (Exception ex) { result = ExceptionResult.FromException(ex); } finally { tsc.SetResult(result); } }); return(AsyncResult.FromTsc(tsc)); }
/// <summary> /// 释放时移除 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="tInstance"></param> public void OnServiceModuleRelease(IModuleBase module) { _serviceModuleDic.Remove(module.ModuleName); if (module.Priority > 0) { _onUpdateLinkedList.Remove(module); _onUpdateLinkedListCount -= 1; } }
public MainWindow() { this.InitializeComponent(); var initializeModules = new InitializeModules(); this.modules = initializeModules.Modules; this.adam6015 = this.modules.FirstOrDefault(foo => foo.ModuleSerie == "Adam6015"); this.adam6066 = this.modules.FirstOrDefault(foo => foo.ModuleSerie == "Adam6066"); this.Ip6015.Text = this.adam6015.IpAddress; this.Ip6066.Text = this.adam6066.IpAddress; }
private ModuleInfo BuildImpl(CommandService service, IServiceProvider services, ModuleInfo parent = null) { //Default name to first alias if (Name == null) { Name = _aliases[0]; } if (TypeInfo != null && !TypeInfo.IsAbstract) { IModuleBase moduleInstance = ReflectionUtils.CreateObject <IModuleBase>(TypeInfo, service, services); moduleInstance.OnModuleBuilding(service, this); } return(new ModuleInfo(this, service, services, parent)); }
/// <summary> /// 加载模块主方法 /// </summary> /// <param name="moduleinfo">模块信息</param> /// <returns></returns> public virtual bool LoadModule(ModuleInfo moduleinfo) { _ModuleFileName = moduleinfo.ModuleFile; _ModuleAssembly = moduleinfo.ModuleAssembly; string entry = GetModuleEntryNameSpace(_ModuleAssembly); if (string.Empty == entry) { return(false); } Form form = (Form)_ModuleAssembly.CreateInstance(entry); _ModuleMainForm = null; if (form is IModuleBase) { _ModuleMainForm = (IModuleBase)form; } return(_ModuleMainForm != null); }
/// <summary> /// 程序集对象引用置空,优化GC回收内存 /// </summary> public void ClearAssemble() { _ModuleAssembly = null; _ModuleMainForm = null; }
public IModuleBase InitializeModule(string moduleSerie, string moduleType) { var modules = new Modules(); this.ModuleBase = new ModuleTest().Initialize(moduleSerie, moduleType, modules); return this.ModuleBase; }
private void SetModulesWithValidModule() { this.moduleBase = this.fackInitializeModules.ModuleBase.Initialize(ModulesValidForTest.Module_Serie, ModulesValidForTest.Module_Type, this.fackInitializeModules.Modules); ModulesValidForTest.GetModulesValid(this.moduleBase); this.modules.Setup(foo => foo.ModuleList).Returns(new List<IModuleBase> {this.moduleBase}); }
private async Task <IResult> ExecuteSequentialAsync(CommandContext context, ICommand command, IModuleBase module, object[] args) { await module.OnCommandExecutingAsync(); var result = await command.Executor.ExecuteAsync(module, args); await module.OnCommandExecutedAsync(); var filterProvider = context.CommandServices.GetRequiredService <IFilterProvider>(); await filterProvider.InvokeFiltersAsync <CommandResultContext, ICommandResultFilter>(new CommandResultContext(context, result)); return(result); }
private static void BuildCommand(CommandBuilder builder, TypeInfo typeInfo, MethodInfo method, CommandService service, IServiceProvider serviceprovider) { IEnumerable <Attribute> attributes = method.GetCustomAttributes(); foreach (Attribute attribute in attributes) { switch (attribute) { case CommandAttribute command: builder.AddAliases(command.Text); builder.RunMode = command.RunMode; builder.Name = builder.Name ?? command.Text; builder.IgnoreExtraArgs = command.IgnoreExtraArgs ?? service._ignoreExtraArgs; break; case NameAttribute name: builder.Name = name.Text; break; case PriorityAttribute priority: builder.Priority = priority.Priority; break; case SummaryAttribute summary: builder.Summary = summary.Text; break; case RemarksAttribute remarks: builder.Remarks = remarks.Text; break; case AliasAttribute alias: builder.AddAliases(alias.Aliases); break; case PreconditionAttribute precondition: builder.AddPrecondition(precondition); break; default: builder.AddAttributes(attribute); break; } } if (builder.Name == null) { builder.Name = method.Name; } System.Reflection.ParameterInfo[] parameters = method.GetParameters(); int pos = 0, count = parameters.Length; foreach (System.Reflection.ParameterInfo paramInfo in parameters) { builder.AddParameter((parameter) => { BuildParameter(parameter, paramInfo, pos++, count, service, serviceprovider); }); } Func <IServiceProvider, IModuleBase> createInstance = ReflectionUtils.CreateBuilder <IModuleBase>(typeInfo, service); async Task <IResult> ExecuteCallback(ICommandContext context, object[] args, IServiceProvider services, CommandInfo cmd) { IModuleBase instance = createInstance(services); instance.SetContext(context); try { instance.BeforeExecute(cmd); Task task = method.Invoke(instance, args) as Task ?? Task.Delay(0); if (task is Task <RuntimeResult> resultTask) { return(await resultTask.ConfigureAwait(false)); } else { await task.ConfigureAwait(false); return(ExecuteResult.FromSuccess()); } } finally { instance.AfterExecute(cmd); (instance as IDisposable)?.Dispose(); } } builder.Callback = ExecuteCallback; }
public static IMvcBuilder AddMvcModules(this IMvcBuilder builder, IServiceCollection services, IConfigurationRoot configuration) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } string path = configuration.GetValue <string>(CONFIG_MODULES_PATH); List <IModuleBase> modulesList = new List <IModuleBase>(); if (string.IsNullOrEmpty(path)) { path = Path.Combine(new FileInfo(Assembly.GetEntryAssembly().Location).DirectoryName, BASE_DIR_NAME_FOR_MODULES); } if (!Directory.Exists(path)) { return(builder); } DirectoryInfo di = new DirectoryInfo(path); foreach (var file in di.GetFileSystemInfos("*.dll", SearchOption.TopDirectoryOnly)) { Assembly moduleAssembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(file.FullName); Type moduleType = moduleAssembly.GetTypes().FirstOrDefault(x => typeof(IModuleBase).IsAssignableFrom(x)); if (moduleType == null) { throw new MissingMemberException(); } if (moduleType.GetConstructors().FirstOrDefault(x => (x.Attributes & MethodAttributes.Public) != 0 && x.GetParameters().Length == 1 && x.GetParameters()[0].ParameterType == typeof(Assembly)) == null) { throw new MissingMethodException($"{moduleType.FullName} does not have a constructor with parameter of type '{nameof(Assembly)}'"); } List <ControllerInfo> list = new List <ControllerInfo>(); AreaAttribute area; foreach (Type controller in moduleAssembly.GetTypes().Where(x => typeof(Controller).IsAssignableFrom(x))) { area = controller.GetTypeInfo().GetCustomAttribute <AreaAttribute>(); if (area == null) { throw new MissingAttributeException($"Missing '{nameof(AreaAttribute)}' for controller {controller.FullName}"); } list.Add(new ControllerInfo(area.RouteValue, controller.Name.Replace("Controller", ""))); } IModuleBase module = (IModuleBase)Activator.CreateInstance(moduleType, moduleAssembly); module.Controllers = list.ToArray().AsEnumerable(); module.InitServices(services, configuration); builder.AddApplicationPart(module.Assembly).AddRazorOptions(o => { o.AdditionalCompilationReferences.Add(MetadataReference.CreateFromFile(module.Assembly.Location)); o.FileProviders.Add(new EmbeddedFileProvider(module.Assembly, module.Assembly.GetName().Name.Replace("." + module.AreaName, ""))); }); modulesList.Add(module); } ModulesList = modulesList.ToArray().AsEnumerable(); modulesList.Clear(); // Add custom locations for searching Views in modules services.Configure <RazorViewEngineOptions>(options => { options.AreaViewLocationFormats.Add("{2}/Views/{1}/{0}.cshtml"); options.AreaViewLocationFormats.Add("{2}/Views/Shared/{0}.cshtml"); }); return(builder); }
/// <summary>Validats the data.</summary> /// <returns>True if ok.</returns> public virtual bool ValidatData(IModuleBase module) { return (string.IsNullOrWhiteSpace(module.IpAddress) || string.IsNullOrWhiteSpace(module.Name) || module.Port > 81 || !module.Chanels.Any() || this.ValidChanel(module.Chanels)); }
/// <summary> /// 加载模块主方法 /// </summary> /// <param name="moduleinfo">模块信息</param> /// <returns></returns> public virtual bool LoadModule(ModuleInfo moduleinfo) { _ModuleFileName = moduleinfo.ModuleFile; _ModuleAssembly = moduleinfo.ModuleAssembly; string entry = GetModuleEntryNameSpace(_ModuleAssembly); if (string.Empty == entry) return false; Form form = (Form)_ModuleAssembly.CreateInstance(entry); _ModuleMainForm = null; if (form is IModuleBase) _ModuleMainForm = (IModuleBase)form; return _ModuleMainForm != null; }
/// <summary> /// 程序集对象引用置空,优化GC回收内存 /// </summary> public void ClearAssemble() { _ModuleAssembly = null; _ModuleMainForm = null; }