/// <summary>
        /// 构建插件执行的参数
        /// </summary>
        /// <param name="argument"></param>
        /// <returns></returns>
        public static PluginsBuilder <T> SetArgument(T argument)
        {
            PluginInvoker <T> invoker = new PluginInvoker <T>();

            invoker.argument = argument;
            return(new PluginsBuilder <T>(invoker));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 应用一个模块,当 A 使用 B 时, A 就是 target ,B 就是 appModule
        /// </summary>
        /// <param name="target"></param>
        /// <param name="appModule"></param>
        private void Use(IAppModule target, IAppModule appModule)
        {
            IEnumerable <AttributeAndTypeInfo> targetInfos = this.scanner.Scan(target);

            var arguments = PluginInvoker <AppModuleUsingArguments>
                            .SetArgument(new AppModuleUsingArguments(this, appModule, target, targetInfos))
                            .SetPlugins(this.Plugins)
                            .Invoke((p, args) => p.OnAppModuleBeforeUsing(this, args));

            appModule.OnUsing(arguments);

            PluginInvoker <OnAppModuleUsedArguments>
            .SetArgument(new OnAppModuleUsedArguments(appModule))
            .SetPlugins(this.Plugins)
            .Invoke((p, args) => p.OnAppModuleUsed(this, args));

            IEnumerable <IAppModule> dependentModules = appModule.DependentModules;

            if (dependentModules == null || !dependentModules.Any())
            {
                return;
            }

            foreach (IAppModule subAppModule in dependentModules)
            {
                this.Use(appModule, subAppModule);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 扫描指定的模块,返回扫描得到的结果集
        /// </summary>
        /// <param name="appModule"></param>
        /// <returns></returns>
        private IEnumerable <AttributeAndTypeInfo> ScanAppModule(IAppModule appModule)
        {
            IEnumerable <AttributeAndTypeInfo> result = this.scanner.Scan(appModule);

            PluginInvoker <OnAppModuleScannedArguments>
            .SetArgument(new OnAppModuleScannedArguments(appModule, result))
            .SetPlugins(this.Plugins)
            .Invoke((p, args) => p.OnAppModuleScanned(this, args));

            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 收集所有模块的类型并触发所有的插件
        /// </summary>
        /// <param name="rootModules"></param>
        private void CollectAllAppModuleType(IEnumerable <IAppModule> rootModules)
        {
            IEnumerable <Type> allAppModuleTypes = this.allAppModuleTypeCollector.Collect(rootModules);

            CreateTools(allAppModuleTypes);

            AppModulePrepareArguments appModulePrepareArguments = new AppModulePrepareArguments(this);

            allAppModuleTypes.ForEach(type => InvokePrepairWhenTypeHasAppModulePrepairAttribute(type, appModulePrepareArguments));

            PluginInvoker <OnAllAppModuleTypeCollectedArguments>
            .SetArgument(new OnAllAppModuleTypeCollectedArguments(allAppModuleTypes))
            .SetPlugins(this.Plugins)
            .Invoke((p, args) => p.OnAllAppModuleTypeCollected(this, args));
        }
Exemplo n.º 5
0
        /// <summary>
        /// 获取指定类型的应用程序构建器
        /// </summary>
        /// <typeparam name="T">必须实现 <see cref="IAppContainerBuilder"/> 接口</typeparam>
        /// <returns></returns>
        public T GetAppContainerBuilder <T>()
            where T : IAppContainerBuilder, new()
        {
            Type type = typeof(T);
            IAppContainerBuilder builder
                =
                    this.appContainerBuilders.Where(x => type.IsAssignableFrom(x.GetType()))
                    .FirstOrDefault();

            if (builder == null)
            {
                builder = new T();

                PluginInvoker <OnAppContainerBuilderCreatedArguments>
                .SetArgument(new OnAppContainerBuilderCreatedArguments(builder))
                .SetPlugins(this.Plugins)
                .Invoke((t, args) => t.OnAppContainerBuilderCreated(this, args));

                this.appContainerBuilders.Add(builder);
            }
            return((T)builder);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 初始化工具管理器
        /// </summary>
        /// <param name="allAppModuleTypes"></param>
        private void CreateTools(IEnumerable <Type> allAppModuleTypes)
        {
            ContainerBuilder builder = new ContainerBuilder();

            foreach (var module in allAppModuleTypes)
            {
                foreach (var type in module.Assembly.GetExportedTypes())
                {
                    if (!type.IsTool())
                    {
                        continue;
                    }
                    builder.RegisterType(type)
                    .AsImplementedInterfaces()
                    .SingleInstance();
                }
            }
            this.Tools = new ContainerComponentManager(builder.Build());

            PluginInvoker <OnToolsCreatedArguments>
            .SetArgument(new OnToolsCreatedArguments())
            .SetPlugins(this.Plugins)
            .Invoke((p, e) => p.OnToolsCreated(this, e));
        }
 public PluginsBuilder(PluginInvoker <T> invoker)
 {
     this.invoker = invoker;
 }