public void CanDeserializeSerializedConfiguration() { string sourceName1 = "source1"; string sourceName2 = "source2"; string sourceFile1 = "file 1"; ConfigurationSourceSection settings = new ConfigurationSourceSection(); FileConfigurationSource.ResetImplementation(sourceFile1, false); ConfigurationSourceElement data1 = new FileConfigurationSourceElement(sourceName1, sourceFile1); ConfigurationSourceElement data2 = new SystemConfigurationSourceElement(sourceName2); settings.Sources.Add(data1); settings.Sources.Add(data2); settings.SelectedSource = sourceName1; IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>(); sections[ConfigurationSourceSection.SectionName] = settings; IConfigurationSource configurationSource = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections); ConfigurationSourceSection roSettigs = (ConfigurationSourceSection)configurationSource.GetSection(ConfigurationSourceSection.SectionName); Assert.IsNotNull(roSettigs); Assert.AreEqual(2, roSettigs.Sources.Count); Assert.AreEqual(sourceName1, roSettigs.SelectedSource); Assert.IsNotNull(roSettigs.Sources.Get(sourceName1)); Assert.AreSame(typeof(FileConfigurationSourceElement), roSettigs.Sources.Get(sourceName1).GetType()); Assert.AreEqual(sourceFile1, ((FileConfigurationSourceElement)roSettigs.Sources.Get(sourceName1)).FilePath); Assert.IsNotNull(roSettigs.Sources.Get(sourceName2)); Assert.AreSame(typeof(SystemConfigurationSourceElement), roSettigs.Sources.Get(sourceName2).GetType()); }
public UserManagerImplementation() { // Get configuration source this._source = ConfigurationSourceFactory.Create(UserSettings.SectionName); // Load & Clone configuration (so not read-only) this.Load(); // Determine configuration file path if (this.Source is SystemConfigurationSource) { this._filePath = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; } else if (this.Source is FileConfigurationSource) { ConfigurationSourceSection configurationSourceSection = ConfigurationSourceSection.GetConfigurationSourceSection(); FileConfigurationSourceElement objectConfiguration = (FileConfigurationSourceElement)configurationSourceSection.Sources.Get(UserSettings.SectionName); FileConfigurationSourceElement e = (FileConfigurationSourceElement)objectConfiguration; this._filePath = objectConfiguration.FilePath; } }
public void CanDeserializeSerializedConfiguration() { string sourceName1 = "source1"; string sourceName2 = "source2"; string sourceFile1 = "file 1"; ConfigurationSourceSection settings = new ConfigurationSourceSection(); ConfigurationSourceElement data1 = new FileConfigurationSourceElement(sourceName1, sourceFile1); ConfigurationSourceElement data2 = new SystemConfigurationSourceElement(sourceName2); settings.Sources.Add(data1); settings.Sources.Add(data2); settings.SelectedSource = sourceName1; IDictionary<string, ConfigurationSection> sections = new Dictionary<string, ConfigurationSection>(); sections[ConfigurationSourceSection.SectionName] = settings; using (var configurationSource = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections)) { ConfigurationSourceSection roSettigs = (ConfigurationSourceSection)configurationSource.GetSection(ConfigurationSourceSection.SectionName); Assert.IsNotNull(roSettigs); Assert.AreEqual(2, roSettigs.Sources.Count); Assert.AreEqual(sourceName1, roSettigs.SelectedSource); Assert.IsNotNull(roSettigs.Sources.Get(sourceName1)); Assert.AreSame(typeof(FileConfigurationSourceElement), roSettigs.Sources.Get(sourceName1).GetType()); Assert.AreEqual(sourceFile1, ((FileConfigurationSourceElement)roSettigs.Sources.Get(sourceName1)).FilePath); Assert.IsNotNull(roSettigs.Sources.Get(sourceName2)); Assert.AreSame(typeof(SystemConfigurationSourceElement), roSettigs.Sources.Get(sourceName2).GetType()); } }
/// <summary> /// Initialize a new instance of the <see cref="FileConfigurationSourceElement"/> class with a <see cref="FileConfigurationSourceElement"/>. /// </summary> /// <param name="element">The <see cref="FileConfigurationSourceElement"/> to initialize.</param> public FileConfigurationSourceElementNode(FileConfigurationSourceElement element) : base(null == element ? string.Empty : element.Name) { if (null == element) { throw new ArgumentNullException("element"); } this.filePath = element.FilePath; this.type = element.Type; }
public void CanReadAndWriteConfigurationSourceSectionInformation() { RemoveSection(); SaveSection(); System.Configuration.Configuration config = OpenFileConfig(); ConfigurationSourceSection section = (ConfigurationSourceSection)config.GetSection(ConfigurationSourceSection.SectionName); FileConfigurationSourceElement elem = (FileConfigurationSourceElement)section.Sources.Get(fileSourceName); Assert.AreEqual(typeof(FileConfigurationSource), elem.Type); Assert.AreEqual(filePath, elem.FilePath); RemoveSection(); }
protected override void Arrange() { base.Arrange(); var resourceHelper = new ResourceHelper <ConfigFiles.ConfigFileLocator>(); mainFilePath = resourceHelper.DumpResourceFileToDisk("empty.config", "ds_abs_path"); mainConfigurationSource = new DesignConfigurationSource(mainFilePath); var mainFileDirectory = Path.GetDirectoryName(mainFilePath); expectedFilePath = Path.Combine(mainFileDirectory, "absolutefile.config"); configurationSourceElement = new FileConfigurationSourceElement("absolutefile", expectedFilePath); }
protected override void Arrange() { base.Arrange(); base.Arrange(); var resourceHelper = new ResourceHelper <ConfigFiles.ConfigFileLocator>(); mainFilePath = resourceHelper.DumpResourceFileToDisk("empty.config", "ds_subdir_path"); mainConfigurationSource = new DesignConfigurationSource(mainFilePath); configurationSourceElement = new FileConfigurationSourceElement("relativefile", "subdir\\relative.config"); var mainFileDirectory = Path.GetDirectoryName(mainFilePath); expectedFilePath = Path.Combine(mainFileDirectory, configurationSourceElement.FilePath); Directory.CreateDirectory(Path.GetDirectoryName(expectedFilePath)); }
/// <summary> /// 取webconfig中的配置 /// </summary> /// <param name="SourceName"></param> /// <returns></returns> private static FileConfigurationSource GetFileConfigurationSource(string SourceName) { //获取App.config //Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~"); //获取资源节点集合 ConfigurationSourceSection section = (ConfigurationSourceSection)config.GetSection(ConfigurationSourceSection.SectionName); //获取重定向配置文件资源配置节点 FileConfigurationSourceElement elem = (FileConfigurationSourceElement)section.Sources.Get(SourceName); //获取重定向配置文件资源 FileConfigurationSource fileSource = new FileConfigurationSource(HttpContext.Current.Server.MapPath(elem.FilePath)); return(fileSource); }