// ---------------------------- // CONSTRUCTORS // ---------------------------- #region Constructors /// <summary> /// Initializes a new instance of AppModuleInstance class. /// </summary> /// <param name="module">Module to consider.</param> /// <param name="uri">URI to consider.</param> public AppModuleInstance( IAppModule module, string uri) { Module = module; Uri = uri; }
public AppModuleUsingArguments(AppSetup appSetup, IAppModule usingAppModule, IAppModule targetAppModule, IEnumerable <AttributeAndTypeInfo> scannedAttributeAndTypeInfos) { AppSetup = appSetup; this.UsingAppModule = usingAppModule; TargetAppModule = targetAppModule; ScannedAttributeAndTypeInfos = scannedAttributeAndTypeInfos; }
/// <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); } }
public void AddConfig(IAppModule appModule, MethodInfo methodInfo) { Type returnType = methodInfo.ReturnType; ConfigCreatorAttribute attr = methodInfo.GetCustomAttribute <ConfigCreatorAttribute>(); this.configTypeToRegistionMap[returnType] = new CreatorConfigRegistion(appModule, attr, methodInfo); }
/// <summary> /// 启动应用程序,并返回 <see cref="App"/> 的一个实例。<br /> /// 执行该方法的流程:<br /> /// 10. <see cref="AppSetup"/> 将 <see cref="CoreAppModule"/> 和 参数提供的 <see cref="IAppModule"/> 作为根模块扫描所有参与启动的 <see cref="IAppModule"/> 类型 <br /> /// 11. 根据收集到的类型所在的程序集,注册所有标记了 <see cref="ToolAttribute"/> 的类型到 <see cref="Tools"/> 属性中 <br /> /// 15. 调用所有 <see cref="IAppModule"/> 上的 <see cref="AppModulePrepairAttribute.Prepair(AppModulePrepareArguments)"/> 方法。<br /> /// 20. 触发 <see cref="IAppSetupPlugin.OnAllAppModuleTypeCollected(AppSetup, OnAllAppModuleTypeCollectedArguments)"/> 事件 <br /> /// 30. 调用 <see cref="Use(IAppModule, IAppModule)"/>,参数是 null 和 <see cref="CoreAppModule"/> 用于加载 AppStarter 库中的各种组件 <br /> /// 40. 调用 <see cref="Use(IAppModule, IAppModule)"/>,参数是 null 和 appModule 用于加载指定的 <see cref="IAppModule"/> 中的各种组件 <br /> /// 50. 触发 <see cref="AllModulesLoaded"/> 事件 <br /> /// 60. 遍历所有 <see cref="IAppContainerBuilder"/> 分别调用 <see cref="IAppContainerBuilder.Prepare(AppSetup)"/> 和 <see cref="IAppContainerBuilder.Build(AppSetup)"/> 方法 <br /> /// 70. 生成 <see cref="App"/> 实例 <br /> /// 80. 调用所有 <see cref="IAppContainer.OnAppStarted(App)"/> 方法 /// </summary> /// <param name="appModule"></param> /// <returns></returns> public App Start(IAppModule appModule) { IEnumerable <IAppModule> rootModules = new IAppModule[] { new CoreAppModule(), appModule }; this.CollectAllAppModuleType(rootModules); this.Tools.InjectFields(this); rootModules.ForEach(module => { this.Use(null, module); }); this.AllModulesLoaded?.Invoke(this, EventArgs.Empty); IEnumerable <IAppContainer> appContainers = this.appContainerBuilders .ForEach(x => x.Prepare(this)) .Select(x => x.Build(this)) .ToList(); App app = new App(appContainers, this.AppContext); appContainers.ForEach(x => x.OnAppStarted(app)); using (var work = app.BeginWork("OnAppStart")) { work.PublishEvent(new AppStartingEvent(this, app)); work.PublishEvent(new AppStartedEvent(this, app)); } return(app); }
public void Execute(IAppModule aModule) { if (_onExecute != null) { _onExecute(aModule); } }
// ------------------------------------------ // CONSTRUCTORS // ------------------------------------------ #region Constructors /// <summary> /// Initializes a new instance of the AppModuleSection class. /// </summary> /// <param name="name">The name to consider.</param> /// <param name="module">The application module of the instance.</param> /// <param name="parent">The parent section of the instance.</param> public AppSection( string name, IAppModule module = null, IAppSection parent = null) : base(name, "section_") { Module = module; Parent = parent; }
internal AppModuleDescriptor(IAppModule instance) { ModuleType = instance.GetType(); Assembly = ModuleType.Assembly; Instance = instance; _dependencies = new List <AppModuleDescriptor>(); }
private void Check(IAppModule module, string relativeUri) { var url = new Uri(new Application().Url(), relativeUri); var expectedResponse = new HttpLessWebSite(module).Response(url).Body; var responseFromIIS = new WebClient().DownloadString(url); Assert.That(responseFromIIS, Is.EqualTo(expectedResponse)); }
public AppShell() { appModules = new ObservableCollection <IAppModule> { new ProductModule(), new SceneModule(), }; selectedAppModule = appModules[1]; }
/// <summary> /// 注册扫描的结果 /// </summary> /// <param name="setup"></param> /// <param name="targetModule">目标模块,A 使用 B,那 A 就是 targetModule</param> /// <param name="autofacContainerBuilder">autofac 容器构建器</param> private static void RegisterScanResult(AppSetup setup, IAppModule targetModule, AutofacContainerBuilder autofacContainerBuilder, IEnumerable <AttributeAndTypeInfo> infos) { infos.Where(x => x.Attribute is ComponentAttribute) .Where(x => x.Type.IsClass && !x.Type.IsAbstract) .ForEach(x => { autofacContainerBuilder.Register(x.Type, ((ComponentAttribute)x.Attribute).RegistionMode); }); }
public void AddMenuEntry(string cmd, string description, IAppModule module) { var item = new MenuItem { Command = cmd, Description = description, Module = module }; items.Add(item); }
/// <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); }
private void FillTypeSet(ref HashSet <Type> set, IAppModule appModule) { set.Add(appModule.GetType()); if (appModule.DependentModules == null) { return; } foreach (var module in appModule.DependentModules) { FillTypeSet(ref set, module); } }
public static void FillComboBranches(ComboBox combo, IAppModule appModule) { var selectedItem = combo.SelectedItem; combo.Items.Clear(); combo.Items.Add("master"); foreach (var branchView in appModule.GetBranchViews().OrderBy(b => b.Branch)) { if (!string.IsNullOrEmpty(branchView.Branch)) combo.Items.Add(branchView.Branch); } combo.SelectedItem = selectedItem; }
public void Handle(AppSetup appSetup, IAppModule appModule, MethodInfo method, Attribute attribute) { if (method.ReturnType == typeof(void)) { return; } ConfigAppContainerBuilder builder = appSetup.GetAppContainerBuilder <ConfigAppContainerBuilder>(); ConfigCreatorAttribute config = (ConfigCreatorAttribute)attribute; builder.AddConfig(appModule, method); }
public void TryRegister(IAppModule appModule) { var scannedMethods = appModule.GetType().GetMethods() .Where(x => x.ReturnType != typeof(void)) .Select(x => new { Method = x, Attribute = x.GetCustomAttribute <ReplaceCreatorAttribute>() }) .Where(x => x.Attribute != null) .Select(x => x.Method); foreach (var method in scannedMethods) { this.TryRegister(appModule, method); } }
/// <summary> /// 从 <see cref="IAppModule"/> 实例的方法中创建组件, /// 这些方法必须被标记 <see cref="ComponentAttribute"/> 特征。 /// </summary> /// <param name="targetModule"></param> /// <param name="autofacContainerBuilder"></param> private static void ReplaceComponentFromMethods(IAppModule targetModule, AutofacContainerBuilder autofacContainerBuilder) { var methods = targetModule.GetType().GetMethods() .Where(x => x.ReturnType != typeof(void)) .Select(x => new { Method = x, Attribute = x.GetCustomAttribute <ReplaceCreatorAttribute>() }) .Where(x => x.Attribute != null) .Select(x => x.Method); foreach (var method in methods) { RemoveService(targetModule, autofacContainerBuilder, method); } //RegisterMethods(targetModule, autofacContainerBuilder, methods); }
public void TryRegister(IAppModule appModule, MethodInfo method) { if (method.ReturnType == typeof(void)) { return; } IAppModule appModuleHasBeenReplaced; if (replacedServiceToAppModuleMap.TryGetValue(method.ReturnType.FullName, out appModuleHasBeenReplaced)) { throw new ServiceHasBeenReplacedException(method.ReturnType, appModuleHasBeenReplaced.GetType()); } replacedServiceToAppModuleMap[method.ReturnType.FullName] = appModule; methods.Add(new TargetAndMethodInfo(appModule, method)); }
public void Execute(IAppModule aModule) { try { if (_onExecute != null) { _onExecute(aModule); } } catch (Exception e) { if (!UnhandledExceptionManager.HandleException(this, e)) { throw; } } }
/// <summary> /// Updates this instance. /// </summary> /// <param name="item">The item to consider.</param> /// <param name="specificationAreas">The specification areas to consider.</param> /// <param name="updateModes">The update modes to consider.</param> /// <returns>Log of the operation.</returns> /// <remarks>Put reference collections as null if you do not want to repair this instance.</remarks> public override IBdoLog Update <T>( T item = default, string[] specificationAreas = null, UpdateModes[] updateModes = null) { var log = new BdoLog(); if (item is IAppModule) { IAppModule module = item as AppModule; log.AddEvents(Sections.Update( module.Sections, null, new[] { UpdateModes.Incremental_AddItemsMissingInTarget })); } return(log); }
public IEnumerable <AttributeAndTypeInfo> Scan(IAppModule appModule) { if (appModule == null) { return new AttributeAndTypeInfo[] { } } ; var assembly = appModule.GetType().Assembly; var assemblyName = assembly.FullName; IEnumerable <AttributeAndTypeInfo> result; if (sacennedAssemlyNameToInfoCache.TryGetValue(assemblyName, out result)) { return(result); } Type[] types = assembly.GetExportedTypes(); IList <AttributeAndTypeInfo> scannableAttributeAndTypeInfos = new List <AttributeAndTypeInfo>(); foreach (Type type in types) { object[] objects = type.GetCustomAttributes(typeof(ScannableAttribute), true); if (objects.Length == 0) { continue; } foreach (var obj in objects) { AttributeAndTypeInfo attributeAndTypeInfo = new AttributeAndTypeInfo(obj as ScannableAttribute, type); scannableAttributeAndTypeInfos.Add( attributeAndTypeInfo ); } } sacennedAssemlyNameToInfoCache[assemblyName] = scannableAttributeAndTypeInfos; return(scannableAttributeAndTypeInfos); } }
public void Handle(AppSetup appSetup, IAppModule appModule, MethodInfo method, Attribute attribute) { AutofacContainerBuilder autofacContainerBuilder = appSetup.GetAppContainerBuilder <AutofacContainerBuilder>(); autofacContainerBuilder.RegisterByCreator(cm => { ParameterInfo[] ps = method.GetParameters(); if (ps.Length == 0) { return(method.Invoke(appModule, null)); } object[] values = new object[ps.Length]; for (int i = 0; i < ps.Length; i++) { Type pType = ps[i].ParameterType; object value = cm.CreateComponent(pType); values[i] = value; } return(method.Invoke(appModule, values)); }, method.ReturnType); }
public OnAppModuleUsedArguments(IAppModule appModule) { AppModule = appModule; }
public CompareBranchesForm(IAppModule appModule) { InitializeComponent(); _appModule = appModule; gridCompareBranches.AutoGenerateColumns = false; }
public AppModuleScanResult(IAppModule appModule, IEnumerable <AttributeAndTypeInfo> scannableAttributeAndTypeInfos) { AppModule = appModule; ScannableAttributeAndTypeInfos = scannableAttributeAndTypeInfos; }
/// <summary> /// 添加新的 <see cref="AppModule"/> 实例 /// </summary> /// <param name="appModule"></param> /// <returns></returns> protected AppModule AddModule(IAppModule appModule) { this.dependentModules.Add(appModule); return(this); }
public ModuleViewModel(IAppModule module) { this.Module = module; }
public OnAppModuleScannedArguments(IAppModule appModule, IEnumerable <AttributeAndTypeInfo> attributeAndTypeInfos) { AppModule = appModule; AttributeAndTypeInfos = new ReadOnlyCollection <AttributeAndTypeInfo>(attributeAndTypeInfos.ToList()); }
/// <summary> /// 移除服务 /// </summary> /// <param name="targetModule"></param> /// <param name="autofacContainerBuilder"></param> /// <param name="method"></param> private static void RemoveService(IAppModule targetModule, AutofacContainerBuilder autofacContainerBuilder, MethodInfo method) { autofacContainerBuilder.RemoveComponentByServiceType(method.ReturnType); }
public CreatorConfigRegistion(IAppModule appModule, ConfigCreatorAttribute attribute, MethodInfo method) { this.appModule = appModule; this.attribute = attribute; this.method = method; }
public void Handle(AppSetup appSetup, IAppModule appModule, MethodInfo method, Attribute attribute) { var replaceBuilder = appSetup.GetAppContainerBuilder <ReplaceServiceContainerBuilder>(); replaceBuilder.TryRegister(appModule, method); }
public HttpLessWebSite(IAppModule module) { _handler = module; }