We need you! We're working hard on the next version of Developer Fusion -
Let us know what you think we should be up to!
- using ClassConfiguration = System.Configuration.Configuration;
- using System.Collections;
- using System.Configuration;
- using System.Configuration.Internal;
- using System.IO;
- using System.Reflection;
- using System.Security;
- using System.Security.Permissions;
- using System.Threading;
- namespace System.Configuration
- {
-
-
-
-
-
-
-
-
- public sealed class Configuration
- {
- private Type _typeConfigHost;
-
- private object[] _hostInitConfigurationParams;
-
- private IInternalConfigRoot _configRoot;
-
- private MgmtConfigurationRecord _configRecord;
-
- private ConfigurationSectionGroup _rootSectionGroup;
-
- private ConfigurationLocationCollection _locations;
-
- private ContextInformation _evalContext;
-
- internal Configuration(string locationSubPath, Type typeConfigHost, params object[] hostInitConfigurationParams)
- {
- _typeConfigHost = typeConfigHost;
- _hostInitConfigurationParams = hostInitConfigurationParams;
-
- _configRoot = new InternalConfigRoot();
-
- IInternalConfigHost configHost = (IInternalConfigHost)TypeUtil.CreateInstanceWithReflectionPermission(typeConfigHost);
-
-
- IInternalConfigHost updateConfigHost = new UpdateConfigHost(configHost);
-
- _configRoot.Init(updateConfigHost, true);
-
-
-
-
-
-
-
- string configPath;
- string locationConfigPath;
- configHost.InitForConfiguration(ref locationSubPath, out configPath, out locationConfigPath, _configRoot, hostInitConfigurationParams);
-
- if (!String.IsNullOrEmpty(locationSubPath) && !updateConfigHost.SupportsLocation) {
- throw ExceptionUtil.UnexpectedError("Configuration::ctor");
- }
-
- if (String.IsNullOrEmpty(locationSubPath) != String.IsNullOrEmpty(locationConfigPath)) {
- throw ExceptionUtil.UnexpectedError("Configuration::ctor");
- }
-
-
- _configRecord = (MgmtConfigurationRecord)_configRoot.GetConfigRecord(configPath);
-
-
-
-
-
- if (!String.IsNullOrEmpty(locationSubPath)) {
- _configRecord = MgmtConfigurationRecord.Create(_configRoot, _configRecord, locationConfigPath, locationSubPath);
- }
-
-
-
-
- _configRecord.ThrowIfInitErrors();
- }
-
-
-
-
-
- internal Configuration OpenLocationConfiguration(string locationSubPath)
- {
- return new Configuration(locationSubPath, _typeConfigHost, _hostInitConfigurationParams);
- }
-
-
- public AppSettingsSection AppSettings {
- get { return (AppSettingsSection)GetSection("appSettings"); }
- }
-
- public ConnectionStringsSection ConnectionStrings {
- get { return (ConnectionStringsSection)GetSection("connectionStrings"); }
- }
-
- public string FilePath {
- get { return _configRecord.ConfigurationFilePath; }
- }
-
- public bool HasFile {
- get { return _configRecord.HasStream; }
- }
-
- public ConfigurationLocationCollection Locations {
- get {
- if (_locations == null) {
- _locations = _configRecord.GetLocationCollection(this);
- }
-
- return _locations;
- }
- }
-
- public ContextInformation EvaluationContext {
- get {
- if (_evalContext == null) {
- _evalContext = new ContextInformation(_configRecord);
- }
-
- return _evalContext;
- }
- }
-
- public ConfigurationSectionGroup RootSectionGroup {
- get {
- if (_rootSectionGroup == null) {
- _rootSectionGroup = new ConfigurationSectionGroup();
- _rootSectionGroup.RootAttachToConfigurationRecord(_configRecord);
- }
-
- return _rootSectionGroup;
- }
- }
-
- public ConfigurationSectionCollection Sections {
- get { return RootSectionGroup.Sections; }
- }
-
- public ConfigurationSectionGroupCollection SectionGroups {
- get { return RootSectionGroup.SectionGroups; }
- }
-
-
- public ConfigurationSection GetSection(string sectionName)
- {
- ConfigurationSection section = (ConfigurationSection)_configRecord.GetSection(sectionName);
-
- return section;
- }
-
- public ConfigurationSectionGroup GetSectionGroup(string sectionGroupName)
- {
- ConfigurationSectionGroup sectionGroup = _configRecord.GetSectionGroup(sectionGroupName);
-
- return sectionGroup;
- }
-
-
-
-
-
-
-
-
-
-
-
- public bool NamespaceDeclared {
- get { return _configRecord.NamespacePresent; }
- set { _configRecord.NamespacePresent = value; }
- }
-
- public void Save()
- {
- SaveAsImpl(null, ConfigurationSaveMode.Modified, false);
- }
-
- public void Save(ConfigurationSaveMode saveMode)
- {
- SaveAsImpl(null, saveMode, false);
- }
-
- public void Save(ConfigurationSaveMode saveMode, bool forceSaveAll)
- {
- SaveAsImpl(null, saveMode, forceSaveAll);
- }
-
- public void SaveAs(string filename)
- {
- SaveAs(filename, ConfigurationSaveMode.Modified, false);
- }
-
- public void SaveAs(string filename, ConfigurationSaveMode saveMode)
- {
- SaveAs(filename, saveMode, false);
- }
-
- public void SaveAs(string filename, ConfigurationSaveMode saveMode, bool forceSaveAll)
- {
- if (String.IsNullOrEmpty(filename)) {
- throw ExceptionUtil.ParameterNullOrEmpty("filename");
- }
-
- SaveAsImpl(filename, saveMode, forceSaveAll);
- }
-
- private void SaveAsImpl(string filename, ConfigurationSaveMode saveMode, bool forceSaveAll)
- {
- if (String.IsNullOrEmpty(filename)) {
- filename = null;
- }
- else {
- filename = System.IO.Path.GetFullPath(filename);
- }
-
- if (forceSaveAll) {
- ForceGroupsRecursive(RootSectionGroup);
- }
-
- _configRecord.SaveAs(filename, saveMode, forceSaveAll);
- }
-
-
- private void ForceGroupsRecursive(ConfigurationSectionGroup group)
- {
- foreach (ConfigurationSection configSection in group.Sections) {
-
- ConfigurationSection section = group.Sections[configSection.SectionInformation.Name];
- }
-
- foreach (ConfigurationSectionGroup sectionGroup in group.SectionGroups) {
- ForceGroupsRecursive(group.SectionGroups[sectionGroup.Name]);
- }
- }
- }
- }