本文整理汇总了C#中System.GetSection方法的典型用法代码示例。如果您正苦于以下问题:C# System.GetSection方法的具体用法?C# System.GetSection怎么用?C# System.GetSection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System
的用法示例。
在下文中一共展示了System.GetSection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetConfigSection
private ClientSettingsSection GetConfigSection(System.Configuration.Configuration config, string sectionName, bool declare)
{
string str = "userSettings/" + sectionName;
ClientSettingsSection section = null;
if (config != null)
{
section = config.GetSection(str) as ClientSettingsSection;
if ((section == null) && declare)
{
this.DeclareSection(config, sectionName);
section = config.GetSection(str) as ClientSettingsSection;
}
}
return section;
}
示例2: GetCurrent
public static SecurityTokenServicesSection GetCurrent(System.Configuration.Configuration config)
{
var section = config.GetSection(SectionName) as SecurityTokenServicesSection;
if (null == section)
throw new InvalidOperationException("Configuration section for Security Token Services not found.");
return section;
}
示例3: Init
private void Init(System.Configuration.Configuration config)
{
HotkeysSection hotkeys;
if (config.GetSection("Hotkeys") == null)
{
hotkeys = new HotkeysSection();
hotkeys.SectionInformation.ForceSave = true;
config.Sections.Add("Hotkeys", hotkeys);
}
else
{
hotkeys = config.Sections["Hotkeys"] as HotkeysSection;
}
if (hotkeys.Select.Key == "")
{
hotkeys.Select = new HotkeyElement("R", "Alt+Shift");
}
StoragesSection storages;
if (config.GetSection("Storages") == null)
{
storages = new StoragesSection();
storages.SectionInformation.ForceSave = true;
config.Sections.Add("Storages", storages);
}
}
示例4: GetSection
public static StandardEndpointsSection GetSection(System.Configuration.Configuration config)
{
if (config == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("config");
}
return (StandardEndpointsSection) config.GetSection(ConfigurationStrings.StandardEndpointsSectionPath);
}
示例5: GetSection
public static BindingsSection GetSection(System.Configuration.Configuration config)
{
if (config == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("config");
}
return (BindingsSection) config.GetSection(ConfigurationStrings.BindingsSectionGroupPath);
}
示例6: CreateDefaultProvider
internal static MemcachedDistributeCacheProvider CreateDefaultProvider(System.Configuration.Configuration configuration)
{
MemcachedDistributeCacheProvider provider = new MemcachedDistributeCacheProvider(configuration);
IMemcachedClientConfiguration section = (IMemcachedClientConfiguration)configuration.GetSection("memcachedClient");
if (section == null)
{
throw new ConfigurationErrorsException(String.Format("未找到适用于 MemcachedDistributeCacheProvider 的配置节 {0}", "memcachedClient"));
}
provider.client = new CustomMemcachedClient(section);
return provider;
}
示例7: Configure
public override void Configure(IServiceCollection services, System.Configuration.Configuration moduleConfiguration)
{
IAuthorizationRulesService authorizationRuleService = services.Get<IAuthorizationRulesService>();
if (authorizationRuleService != null)
{
AuthorizationConfigurationSection authorizationSection = moduleConfiguration.GetSection(AuthorizationSection) as AuthorizationConfigurationSection;
if (authorizationSection != null)
{
foreach (AuthorizationRuleElement ruleElement in authorizationSection.ModuleRules)
{
authorizationRuleService.RegisterAuthorizationRule(ruleElement.AbsolutePath, ruleElement.RuleName);
}
}
}
}
示例8: Build
public IEnumerable<BuiltComponents> Build(System.Configuration.Configuration configuration)
{
var components = new List<BuiltComponents>();
var simpleCounterConfiguration = configuration.GetSection("simplePerformanceCounterSources") as SimplePerformanceCounterSourceConfiguration;
if (simpleCounterConfiguration != null)
{
foreach (SimpleCounterElement config in simpleCounterConfiguration.Counters)
{
components.Add(Build(config));
}
}
return components;
}
示例9: Build
public IEnumerable<BuiltComponents> Build(System.Configuration.Configuration configuration)
{
var components = new List<BuiltComponents>();
var simpleProcessUptimeConfiguration = configuration.GetSection("simpleProcessUptimeSources") as SimpleProcessUptimeConfiguration;
if (simpleProcessUptimeConfiguration != null)
{
foreach (SimpleProcessElement config in simpleProcessUptimeConfiguration.Processes)
{
components.Add(Build(config));
}
}
return components;
}
示例10: Build
public IEnumerable<BuiltComponents> Build(System.Configuration.Configuration configuration)
{
var schedules = new List<BuiltComponents>();
var simpleProcessCounterConfiguration = configuration.GetSection("simpleProcessCountingSources") as SimpleProcessCountingConfiguration;
if (simpleProcessCounterConfiguration != null)
{
foreach (SimpleProcessElement config in simpleProcessCounterConfiguration.Processes)
{
schedules.Add(Build(config));
}
}
return schedules;
}
示例11: AddWebModules
private static void AddWebModules(System.Configuration.Configuration config, string name, string type)
{
// Get the <httpModules> section.
HttpModulesSection sectionSystemWeb = (HttpModulesSection)config.GetSection("system.web/httpModules");
// Create a new module action object.
HttpModuleAction myHttpModuleAction = new HttpModuleAction(name, type);
int indexOfHttpModule = sectionSystemWeb.Modules.IndexOf(myHttpModuleAction);
if (indexOfHttpModule == -1)
{
sectionSystemWeb.Modules.Add(myHttpModuleAction);
if (!sectionSystemWeb.SectionInformation.IsLocked)
{
config.Save();
}
}
}
示例12: Build
public IEnumerable<ISchedule> Build(System.Configuration.Configuration configuration, IEnumerable<ISnapshotProvider> sources)
{
var simplePlotterConfiguration = configuration.GetSection("simplePlotters") as SimplePlotterConfiguration;
var schedules = new List<ISchedule>();
if (simplePlotterConfiguration != null)
{
var copiedSources = sources;
foreach (SimplePlotterElement config in simplePlotterConfiguration.Plotters)
{
schedules.Add(Build(config, copiedSources));
}
}
return schedules;
}
示例13: ReadSettings
private Dictionary<string, SettingElement> ReadSettings(System.Configuration.Configuration clientConfig, string sectionName)
{
Dictionary<string, SettingElement> dictionary = new Dictionary<string, SettingElement>();
ClientSettingsSection section = this.ReadClientSettingsSection(clientConfig.GetSection(sectionName));
if (section != null)
{
foreach (SettingElement element in section.Settings)
{
dictionary.Add(element.Name, element);
}
}
return dictionary;
}
示例14: InitFromConfiguration
private void InitFromConfiguration(System.Configuration.Configuration configuration)
{
if (configuration != null)
{
CacheSettingsSection section = (CacheSettingsSection)configuration.GetSection("cacheSettings");
if (section != null)
{
this.DefaultCacheName = section.DefaultCache.Name;
this.EnableDistributeCache = section.EnableDistributeCache.Value;
if (!String.IsNullOrEmpty(section.Failover.RetryingInterval))
{
this.FailoverRetryingInterval = TimeSpan.Parse(section.Failover.RetryingInterval);
}
if (!String.IsNullOrEmpty(section.Failover.ToLocalCache))
{
this.FailoverToLocalCache = Boolean.Parse(section.Failover.ToLocalCache);
}
for (int i = 0; i < section.Caches.Count; i++)
{
bool isAbsoluteLocalCache = section.Caches[i].CacheName.ToLower().Equals("local");
CacheSetting cacheSetting = new CacheSetting();
CachePosition cachePosition = isAbsoluteLocalCache ? CachePosition.Local : (CachePosition)Enum.Parse(typeof(CachePosition), section.Caches[i].Position, true);
if (cachePosition == CachePosition.Inherit)
{
cachePosition = this.defaultPosition;
}
cacheSetting.Position = cachePosition;
if (!String.IsNullOrEmpty(section.Caches[i].DependencyFile))
{
cacheSetting.DependencyFile = AppDomain.CurrentDomain.MapPhysicalPath("conf/", section.Caches[i].DependencyFile);
}
cacheSetting.Capacity = String.IsNullOrEmpty(section.Caches[i].Capacity) ? defaultCacheCapacity : Int32.Parse(section.Caches[i].Capacity);
cacheSetting.AsyncUpdateInterval = String.IsNullOrEmpty(section.Caches[i].AsyncUpdateInterval) ? defaultAsyncUpdateInterval : (int)TimeSpan.Parse(section.Caches[i].AsyncUpdateInterval).TotalSeconds;
RegionElementCollection regionElements = section.Caches[i].Regions;
if (regionElements.Count > 0)
{
for (int j = 0; j < regionElements.Count; j++)
{
RegionSetting regionSetting = new RegionSetting();
CachePosition regionPosition = isAbsoluteLocalCache ? CachePosition.Local : (CachePosition)Enum.Parse(typeof(CachePosition), regionElements[j].Position, true);
if (regionPosition == CachePosition.Inherit)
{
regionPosition = cachePosition;
}
regionSetting.Position = regionPosition;
regionSetting.DependencyFile = String.IsNullOrEmpty(regionElements[j].DependencyFile) ? cacheSetting.DependencyFile : AppDomain.CurrentDomain.MapPhysicalPath("conf/", regionElements[j].DependencyFile);
regionSetting.Capacity = String.IsNullOrEmpty(regionElements[j].Capacity) ? cacheSetting.Capacity : Int32.Parse(regionElements[j].Capacity);
regionSetting.AsyncUpdateInterval = String.IsNullOrEmpty(regionElements[j].AsyncUpdateInterval) ? cacheSetting.AsyncUpdateInterval : (int)TimeSpan.Parse(regionElements[j].AsyncUpdateInterval).TotalSeconds;
cacheSetting.Regions.Add(regionElements[j].RegionName, regionSetting);
}
}
this.Caches.Add(section.Caches[i].CacheName, cacheSetting);
}
}
}
if (!this.Caches.ContainsKey(this.DefaultCacheName))
{
this.Caches.Add(this.DefaultCacheName, new CacheSetting(this.defaultPosition, this.defaultCacheCapacity, this.defaultAsyncUpdateInterval));
}
if (!this.Caches.ContainsKey("local"))
{
this.Caches.Add("local", new CacheSetting(CachePosition.Local, this.defaultCacheCapacity, this.defaultAsyncUpdateInterval));
}
}
示例15: CheckWebServerModule
// Helper method to parse and check the module name in the system.webServer section
private void CheckWebServerModule(System.Configuration.Configuration cfg, string moduleName)
{
IgnoreSection webServerSection = cfg.GetSection("system.webServer") as IgnoreSection;
if (webServerSection != null)
{
SectionInformation sectionInformation = webServerSection.SectionInformation;
string rawXml = sectionInformation == null ? null : sectionInformation.GetRawXml();
Assert.IsFalse(string.IsNullOrEmpty(rawXml), "Did not expect empty system.webServer xml");
XDocument xdoc = null;
using (StringReader sr = new StringReader(rawXml))
{
using (XmlReader xmlReader = XmlReader.Create(sr))
{
xdoc = XDocument.Load(xmlReader);
}
}
XElement xelem = xdoc.Element("system.webServer");
Assert.IsNotNull(xelem, "system.webServer Xelement was null");
xelem = xelem.Element("modules");
Assert.IsNotNull(xelem, "system.webServer modules Xelement was null");
XAttribute runAllManagedAttr = xelem.Attribute("runAllManagedModulesForAllRequests");
Assert.IsNotNull(runAllManagedAttr, "Did not find attribute for runAllManagedModulesForAllRequests");
Assert.AreEqual("true", runAllManagedAttr.Value, "runAllManagedModulesForAllRequests should have been true");
IEnumerable<XElement> xelems = xelem.Elements("add");
Assert.IsNotNull(xelems, "system.webServer modules add elements null");
xelem = xelems.FirstOrDefault(e => (string)e.Attribute("name") == BusinessLogicClassConstants.DomainServiceModuleName);
Assert.IsNotNull(xelem, "Did not find DomainServiceModule attribute");
Assert.AreEqual(moduleName, (string)xelem.Attribute("type"), "DomainServiceModule name is incorrect");
}
}