public ModulesConfigurationSection GetModuleConfigurationSection() { ModulesConfigurationSection globalSection = new ModulesConfigurationSection(); PopulateSection(globalSection, _baseDirectory, true); return(globalSection); }
private ModulesConfigurationSection ParseSection(string filePath) { ModulesConfigurationSection section = new ModulesConfigurationSection(); XmlDocument config = new XmlDocument(); config.Load(filePath); XmlNodeList moduleList = config.SelectNodes(XpathCompositeWebModuleNode); if (moduleList == null || moduleList.Count == 0) { XmlNamespaceManager nsmgr = new XmlNamespaceManager(config.NameTable); nsmgr.AddNamespace(QualifierXpath, NetConfigurationNamespace); moduleList = config.SelectNodes(QualifiedXpathCompositeWebModuleNode, nsmgr); } foreach (XmlNode module in moduleList) { string name = module.Attributes[NameAttribute].Value; string assemblyName = module.Attributes[AssemblyNameAttribute].Value; string virtualPath = null; if (module.Attributes[VirtualPathAttribute] != null) { virtualPath = module.Attributes[VirtualPathAttribute].Value; } ModuleConfigurationElement data = new ModuleConfigurationElement(name, assemblyName, virtualPath); section.Modules.Add(data); } return(section); }
public void IfModuleIsLoadedDoesNotLoadItAgain() { WebConfigModuleInfoStore store = new WebConfigModuleInfoStore(@"Services\Support\WebConfigWithRepeatedModules"); ModulesConfigurationSection section = store.GetModuleConfigurationSection(); Assert.AreEqual(1, section.Modules.Count); }
public void ReadsTwoModulesFromTwoFiles() { WebConfigModuleInfoStore store = new WebConfigModuleInfoStore(@"Services\Support\TwoFiles"); ModulesConfigurationSection section = store.GetModuleConfigurationSection(); Assert.AreEqual(2, section.Modules.Count); Assert.AreEqual("Module1.Name", section.Modules[0].Name); Assert.AreEqual("Module1.AssemblyName", section.Modules[0].AssemblyName); Assert.AreEqual("Module1.VirtualPath", section.Modules[0].VirtualPath); Assert.AreEqual("Module2.Name", section.Modules[1].Name); Assert.AreEqual("Module2.AssemblyName", section.Modules[1].AssemblyName); Assert.AreEqual("Module2.VirtualPath", section.Modules[1].VirtualPath); }
/// <summary> /// Gets the list of modules needed by the application. /// </summary> /// <returns>An array of <see cref="IModuleInfo"/>.</returns> public IModuleInfo[] EnumerateModules() { if (_modules != null) { return(_modules); } List <DependantModuleInfo> moduleInfos = new List <DependantModuleInfo>(); ModulesConfigurationSection section = _store.GetModuleConfigurationSection(); ValidateDuplicates(section); foreach (ModuleConfigurationElement data in section.Modules) { DependantModuleInfo moduleInfo = new DependantModuleInfo(data.Name, data.AssemblyName, data.VirtualPath); if (data.Dependencies.Count > 0) { moduleInfo.Dependencies = new ModuleDependency[data.Dependencies.Count]; for (int i = 0; i < data.Dependencies.Count; i++) { moduleInfo.Dependencies[i] = new ModuleDependency(); moduleInfo.Dependencies[i].Name = data.Dependencies[i].Module; } } if (data.Services.Count > 0) { moduleInfo.Services = new ServiceInfo[data.Services.Count]; for (int i = 0; i < data.Services.Count; i++) { moduleInfo.Services[i] = new ServiceInfo(data.Services[i].RegisterAs, data.Services[i].Type, data.Services[i].Scope); } } moduleInfos.Add(moduleInfo); } if (moduleInfos.Count > 0) { _modules = SortModules(moduleInfos); } else { _modules = moduleInfos.ToArray(); } return(_modules); }
public void ReadsOneModuleWebConfig() { WebConfigModuleInfoStore store = new WebConfigModuleInfoStore(@"Services\Support\OneModule"); ModulesConfigurationSection section = store.GetModuleConfigurationSection(); Assert.AreEqual(1, section.Modules.Count); Assert.AreEqual("Module1.Name", section.Modules[0].Name); Assert.AreEqual("Module1.AssemblyName", section.Modules[0].AssemblyName); Assert.AreEqual("Module1.VirtualPath", section.Modules[0].VirtualPath); Assert.AreEqual(1, section.Modules[0].Services.Count); Assert.AreEqual(typeof(IFoo), section.Modules[0].Services[0].RegisterAs); Assert.AreEqual(typeof(Foo), section.Modules[0].Services[0].Type); Assert.AreEqual("Global", section.Modules[0].Services[0].Scope); }
public void ReadsOneModuleAppConfig() { ConfigurationStore store = new ConfigurationStore(@"Mocks\Configuration\OneModule"); ModulesConfigurationSection section = store.RetrieveModuleConfigurationSection(); Assert.IsNotNull(section.Modules); Assert.AreEqual(1, section.Modules.Count); Assert.IsNotNull(section.Modules[0].AssemblyFile); Assert.AreEqual("MockModuleA", section.Modules[0].ModuleName); Assert.IsNotNull(section.Modules[0].AssemblyFile); Assert.IsTrue(section.Modules[0].AssemblyFile.Contains(@"MocksModules\MockModuleA.dll")); Assert.IsNotNull(section.Modules[0].ModuleType); Assert.IsTrue(section.Modules[0].StartupLoaded); Assert.AreEqual("Microsoft.Practices.Composite.Tests.Mocks.Modules.MockModuleA", section.Modules[0].ModuleType); }
public void ReadsTwoModulesWithDependency() { ConfigurationStore store = new ConfigurationStore(@"Mocks\Configuration\TwoModulesWithDependency"); ModulesConfigurationSection section = store.RetrieveModuleConfigurationSection(); Assert.AreEqual(2, section.Modules.Count); Assert.AreEqual("MockModuleA", section.Modules[0].ModuleName); Assert.IsTrue(section.Modules[0].AssemblyFile.Contains(@"MocksModules\MockModuleA.dll")); Assert.AreEqual("Microsoft.Practices.Composite.Tests.Mocks.Modules.MockModuleA", section.Modules[0].ModuleType); Assert.IsTrue(section.Modules[0].StartupLoaded); Assert.AreEqual("MockModuleB", section.Modules[0].Dependencies[0].ModuleName); Assert.AreEqual("MockModuleB", section.Modules[1].ModuleName); Assert.IsTrue(section.Modules[1].AssemblyFile.Contains(@"MocksModules\MockModuleB.dll")); Assert.AreEqual("Microsoft.Practices.Composite.Tests.Mocks.Modules.MockModuleB", section.Modules[1].ModuleType); Assert.IsTrue((section.Modules[1].StartupLoaded)); }
protected override IModuleCatalog CreateModuleCatalog() { ModulesConfigurationSection configurationSection = new ModulesConfigurationSection(); ModuleConfigurationElements ds = new ModuleConfigurationElements(); if (File.Exists("ModuleConfigurationElementCollection.xml") && File.Exists("ModuleConfigurationElementCollection.xsd")) { ds.ReadXml("ModuleConfigurationElementCollection.xml"); ds.ReadXmlSchema("ModuleConfigurationElementCollection.xsd"); var elements = ds.Tables[0].Rows.Cast <DataRow>().Select(e => new ModuleConfigurationElement() { Name = e["Name"].ToString(), AssemblyFile = e["AssemblyFile"].ToString(), TypeName = e["TypeName"].ToString() }).ToArray(); var modules = new ModuleConfigurationElementCollection(elements); configurationSection.Modules = modules; } return(new ConfigurationModuleCatalog(configurationSection)); }
private void PopulateSection(ModulesConfigurationSection section, string rootDirectory) { foreach (string fileName in Directory.GetFiles(rootDirectory, "Web.Config", SearchOption.TopDirectoryOnly)) { System.Configuration.Configuration configuration = GetConfiguration(Path.Combine(rootDirectory, fileName)); ModulesConfigurationSection localSection = (ModulesConfigurationSection)configuration.GetSection("compositeWeb/modules"); if (localSection != null) { foreach (ModuleConfigurationElement module in localSection.Modules) { if (!section.Modules.Contains(module.Name)) { section.Modules.Add(module); } } } } foreach (string childDirectory in Directory.GetDirectories(rootDirectory)) { PopulateSection(section, childDirectory); } }
private void PopulateSection(ModulesConfigurationSection section, string rootDirectory, bool recursive) { foreach (string fileName in Directory.GetFiles(rootDirectory, "Web.Config", SearchOption.TopDirectoryOnly)) { ModulesConfigurationSection localSection = ParseSection(Path.Combine(rootDirectory, fileName)); if (localSection != null) { foreach (ModuleConfigurationElement module in localSection.Modules) { if (!section.Modules.Contains(module.Name)) { section.Modules.Add(module); } } } } if (recursive) { foreach (string childDirectory in Directory.GetDirectories(rootDirectory)) { PopulateSection(section, childDirectory, recursive); } } }
private static void ValidateDuplicates(ModulesConfigurationSection section) { foreach (ModuleConfigurationElement data in section.Modules) { ICollection <ModuleConfigurationElement> found = section.Modules.FindAll(delegate(ModuleConfigurationElement match) { return (!string.IsNullOrEmpty(match.VirtualPath) && (String.Equals(match.VirtualPath, data.VirtualPath, StringComparison. InvariantCultureIgnoreCase) || String.Equals(match.AssemblyName, data.AssemblyName, StringComparison. InvariantCultureIgnoreCase))); }); if (found.Count > 1) { ThrowConfigurationErrorsException(found); } } }