/// <summary> /// /// </summary> /// <param name="pConfiguration">Configuration del app.config</param> /// <param name="pSectionName">Seccion</param> /// <param name="pSectionGroupName">Grupo</param> internal static void AddSection(Configuration pConfiguration, String pSectionName, String pSectionGroupName, String pSettingTemplateName) { ConfigurationSectionGroup wConfigurationSectionGroup = null; SettingElement wSettingElement = null; XmlDocument doc = new XmlDocument(); XmlNode xmlValue = doc.CreateNode(XmlNodeType.Element, "value", String.Empty); ConfigurationSectionCollection wSections = null; if (pSectionGroupName.Length == 0) { AddSectionFromAssembly(pConfiguration, pSectionName); return; } else { wConfigurationSectionGroup = pConfiguration.GetSectionGroup(pSectionGroupName); if (wConfigurationSectionGroup == null) { wConfigurationSectionGroup = AddSectionGroup(pConfiguration, pSectionGroupName); } wSections = wConfigurationSectionGroup.Sections; } if (wSections.Get(pSectionName) != null) { return; } ClientSettingsSection wClientSettingsSection = new ClientSettingsSection(); wClientSettingsSection.SectionInformation.RequirePermission = false; wClientSettingsSection.SectionInformation.ForceSave = true; #region Settings Dictionary <String, String> wSettings = TemplateProvider.GetSettingDic(pSettingTemplateName); if (wSettings != null) { foreach (KeyValuePair <string, string> seting in wSettings) { wSettingElement = new SettingElement(); wSettingElement.Name = seting.Key; xmlValue.InnerXml = seting.Value; wSettingElement.Value.ValueXml = xmlValue.Clone(); wClientSettingsSection.Settings.Add(wSettingElement); } } #endregion wSections.Add(pSectionName, wClientSettingsSection); }
internal static void Add_SettingInSection(Configuration pConfiguration, String pSectionName, String pSectionGroupName, String pSettingName, String settingValue) { ConfigurationSectionGroup wConfigurationSectionGroup = null; //SettingElement wSettingElement = null; XmlDocument doc = new XmlDocument(); XmlNode xmlValue = doc.CreateNode(XmlNodeType.Element, "value", String.Empty); ConfigurationSectionCollection wSections = null; if (pSectionGroupName.Length == 0) { AddSectionFromAssembly(pConfiguration, pSectionName); return; } else { wConfigurationSectionGroup = pConfiguration.GetSectionGroup(pSectionGroupName); if (wConfigurationSectionGroup == null) { wConfigurationSectionGroup = AddSectionGroup(pConfiguration, pSectionGroupName); } wSections = wConfigurationSectionGroup.Sections; } ConfigurationSection wConfigurationSection = wSections.Get(pSectionName); ClientSettingsSection wClientSettingsSection = (ClientSettingsSection)wConfigurationSection; wClientSettingsSection.SectionInformation.RequirePermission = false; wClientSettingsSection.SectionInformation.ForceSave = true; #region Settings //wClientSettingsSection.Settings.Get(pSettingName); SettingElement wSettingElement = new SettingElement(); wSettingElement.Name = pSettingName; xmlValue.InnerXml = settingValue; wSettingElement.Value.ValueXml = xmlValue.Clone(); wClientSettingsSection.Settings.Add(wSettingElement); #endregion }
public BrowserCollection AssertNotNull(Configuration config) { ConfigurationSectionCollection sections = config.Sections; Assert.IsNotNull(sections); ConfigurationSection section = sections.Get("linkCheckerConfig"); Assert.IsNotNull(section); LinkCheckerConfigSection linkSection = (LinkCheckerConfigSection)section; Assert.IsNotNull(linkSection); Assert.IsNotNull(linkSection.RecursionLimit); Assert.IsNotNull(linkSection.MaxCrawlTime); Assert.IsNotNull(linkSection.RequestTimeout); BrowserCollection browsers = linkSection.Browsers; Assert.IsNotNull(browsers); return(browsers); }
/// <summary> /// 更改section内容 /// </summary> /// <param name="section">自定义节名</param> /// <param name="AppKey">键名</param> /// <param name="AppValue">键值</param> public static string GetAppSettings(string SectionName, string SettingName) { string value = string.Empty; System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None); ConfigurationSectionCollection sections = config.Sections; ConfigurationSection section = sections.Get(SectionName); if (section != null) { value = section.SectionInformation.SectionName; } //foreach (string key in sections.Keys) //{ // Console.WriteLine( // "Key value: {0}", key); //} return(value); }
public int Execute() { if (Args.Length == 0) { Console.WriteLine(HELP_MESSAGE); return(1); } else if (Args.Length != 1) { Console.WriteLine(HELP_MESSAGE); return(1); } else { string arg = Args[0]; string configFile = null; foreach (var argPrefix in CONFIG_ARG_PREFIXES) { if (arg.StartsWith(argPrefix)) { configFile = arg.Substring(argPrefix.Length); break; } } if (String.IsNullOrEmpty(configFile)) { Console.WriteLine(HELP_MESSAGE); return(1); } else { if (!File.Exists(configFile)) { Console.WriteLine(MISSING_CONFIG_FILE_MESSAGE, configFile); return(1); } Configuration config = null; try { ExeConfigurationFileMap map = new ExeConfigurationFileMap(); map.ExeConfigFilename = configFile; config = ConfigurationManager.OpenMappedExeConfiguration( map , ConfigurationUserLevel.None ); } catch (ConfigurationErrorsException) { Console.WriteLine(CONFIG_FILE_ERROR_MESSAGE); return(1); } if (config == null) { Console.WriteLine(CONFIG_FILE_ERROR_MESSAGE); return(1); } ConfigurationSectionCollection sections = config.Sections; if (sections == null) { Console.WriteLine(CONFIG_FILE_ERROR_MESSAGE); return(1); } LinkCheckerConfigSection section = null; try { section = (LinkCheckerConfigSection)sections.Get("linkCheckerConfig"); } catch (InvalidCastException) { Console.WriteLine(MISSING_CONFIG_SECTIONS_MESSAGE); return(1); } catch (ConfigurationErrorsException) { Console.WriteLine(CONFIG_FILE_ERROR_MESSAGE); return(1); } if (section == null) { Console.WriteLine(CONFIG_FILE_ERROR_MESSAGE); return(1); } WebSiteTestSuiteGenerator generator = new WebSiteTestSuiteGenerator(section); generator.GenerateTests(); } } return(0); }