You've already forked linux-packaging-mono
Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
parent
a569aebcfd
commit
e79aa3c0ed
@ -0,0 +1,162 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="AppSettingsSection.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Configuration {
|
||||
using System;
|
||||
using System.Xml;
|
||||
using System.Configuration;
|
||||
using System.Collections.Specialized;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
public sealed class AppSettingsSection : ConfigurationSection {
|
||||
private volatile static ConfigurationPropertyCollection s_properties;
|
||||
private volatile static ConfigurationProperty s_propAppSettings;
|
||||
private volatile static ConfigurationProperty s_propFile;
|
||||
|
||||
private KeyValueInternalCollection _KeyValueCollection = null;
|
||||
|
||||
private static ConfigurationPropertyCollection EnsureStaticPropertyBag() {
|
||||
if (s_properties == null) {
|
||||
ConfigurationProperty propAppSettings = new ConfigurationProperty(null, typeof(KeyValueConfigurationCollection), null, ConfigurationPropertyOptions.IsDefaultCollection);
|
||||
ConfigurationProperty propFile = new ConfigurationProperty("file", typeof(string), String.Empty, ConfigurationPropertyOptions.None);
|
||||
|
||||
ConfigurationPropertyCollection properties = new ConfigurationPropertyCollection();
|
||||
properties.Add(propAppSettings);
|
||||
properties.Add(propFile);
|
||||
|
||||
s_propAppSettings = propAppSettings;
|
||||
s_propFile = propFile;
|
||||
s_properties = properties;
|
||||
}
|
||||
|
||||
return s_properties;
|
||||
}
|
||||
|
||||
public AppSettingsSection() {
|
||||
EnsureStaticPropertyBag();
|
||||
}
|
||||
|
||||
protected internal override ConfigurationPropertyCollection Properties {
|
||||
get {
|
||||
return EnsureStaticPropertyBag();
|
||||
}
|
||||
}
|
||||
|
||||
protected internal override object GetRuntimeObject() {
|
||||
SetReadOnly();
|
||||
return this.InternalSettings; // return the read only object
|
||||
}
|
||||
|
||||
internal NameValueCollection InternalSettings {
|
||||
get {
|
||||
if (_KeyValueCollection == null) {
|
||||
_KeyValueCollection = new KeyValueInternalCollection(this);
|
||||
}
|
||||
return (NameValueCollection)_KeyValueCollection;
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty("", IsDefaultCollection = true)]
|
||||
public KeyValueConfigurationCollection Settings {
|
||||
get {
|
||||
return (KeyValueConfigurationCollection)base[s_propAppSettings];
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty("file", DefaultValue = "")]
|
||||
public string File {
|
||||
get {
|
||||
string fileValue = (string)base[s_propFile];
|
||||
if (fileValue == null) {
|
||||
return String.Empty;
|
||||
}
|
||||
return fileValue;
|
||||
}
|
||||
set {
|
||||
base[s_propFile] = value;
|
||||
}
|
||||
}
|
||||
protected internal override void Reset(ConfigurationElement parentSection) {
|
||||
_KeyValueCollection = null;
|
||||
base.Reset(parentSection);
|
||||
if (!String.IsNullOrEmpty((string)base[s_propFile])) { // don't inherit from the parent
|
||||
SetPropertyValue(s_propFile,null,true); // ignore the lock to prevent inheritence
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected internal override bool IsModified() {
|
||||
return base.IsModified();
|
||||
}
|
||||
|
||||
protected internal override string SerializeSection(ConfigurationElement parentElement, string name, ConfigurationSaveMode saveMode) {
|
||||
return base.SerializeSection(parentElement, name, saveMode);
|
||||
}
|
||||
|
||||
protected internal override void DeserializeElement(XmlReader reader, bool serializeCollectionKey) {
|
||||
string ElementName = reader.Name;
|
||||
|
||||
base.DeserializeElement(reader, serializeCollectionKey);
|
||||
if ((File != null) && (File.Length > 0)) {
|
||||
string sourceFileFullPath;
|
||||
string configFileDirectory;
|
||||
string configFile;
|
||||
|
||||
// Determine file location
|
||||
configFile = ElementInformation.Source;
|
||||
|
||||
if (String.IsNullOrEmpty(configFile)) {
|
||||
sourceFileFullPath = File;
|
||||
}
|
||||
else {
|
||||
configFileDirectory = System.IO.Path.GetDirectoryName(configFile);
|
||||
sourceFileFullPath = System.IO.Path.Combine(configFileDirectory, File);
|
||||
}
|
||||
|
||||
if (System.IO.File.Exists(sourceFileFullPath)) {
|
||||
int lineOffset = 0;
|
||||
string rawXml = null;
|
||||
|
||||
using (Stream sourceFileStream = new FileStream(sourceFileFullPath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
|
||||
using (XmlUtil xmlUtil = new XmlUtil(sourceFileStream, sourceFileFullPath, true)) {
|
||||
if (xmlUtil.Reader.Name != ElementName) {
|
||||
throw new ConfigurationErrorsException(
|
||||
SR.GetString(SR.Config_name_value_file_section_file_invalid_root, ElementName),
|
||||
xmlUtil);
|
||||
}
|
||||
|
||||
lineOffset = xmlUtil.Reader.LineNumber;
|
||||
rawXml = xmlUtil.CopySection();
|
||||
|
||||
// Detect if there is any XML left over after the section
|
||||
while (!xmlUtil.Reader.EOF) {
|
||||
XmlNodeType t = xmlUtil.Reader.NodeType;
|
||||
if (t != XmlNodeType.Comment) {
|
||||
throw new ConfigurationErrorsException(SR.GetString(SR.Config_source_file_format), xmlUtil);
|
||||
}
|
||||
|
||||
xmlUtil.Reader.Read();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ConfigXmlReader internalReader = new ConfigXmlReader(rawXml, sourceFileFullPath, lineOffset);
|
||||
internalReader.Read();
|
||||
if (internalReader.MoveToNextAttribute()) {
|
||||
throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_unrecognized_attribute, internalReader.Name), (XmlReader)internalReader);
|
||||
}
|
||||
|
||||
internalReader.MoveToElement();
|
||||
|
||||
base.DeserializeElement(internalReader, serializeCollectionKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
c378f1d68b1844752e4d0e3355a78cd210a1c01c
|
@ -0,0 +1,32 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="CRYPTPROTECT_PROMPTSTRUCT.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Configuration
|
||||
{
|
||||
using System.Collections.Specialized;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Configuration.Provider;
|
||||
using System.Xml;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.Win32;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct CRYPTPROTECT_PROMPTSTRUCT : IDisposable
|
||||
{
|
||||
public int cbSize;
|
||||
public int dwPromptFlags;
|
||||
public IntPtr hwndApp;
|
||||
public string szPrompt;
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
hwndApp = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="CallbackValidator.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Security.Permissions;
|
||||
using System.Xml;
|
||||
using System.Collections.Specialized;
|
||||
using System.Globalization;
|
||||
using System.ComponentModel;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace System.Configuration {
|
||||
|
||||
public sealed class CallbackValidator : ConfigurationValidatorBase {
|
||||
Type _type;
|
||||
ValidatorCallback _callback;
|
||||
|
||||
public CallbackValidator(Type type, ValidatorCallback callback) : this(callback) {
|
||||
if (type == null) {
|
||||
throw new ArgumentNullException("type");
|
||||
}
|
||||
_type = type;
|
||||
}
|
||||
|
||||
// Do not check for null type here to handle the callback attribute case
|
||||
internal CallbackValidator(ValidatorCallback callback) {
|
||||
if (callback == null) {
|
||||
throw new ArgumentNullException("callback");
|
||||
}
|
||||
_type = null;
|
||||
_callback = callback;
|
||||
}
|
||||
|
||||
public override bool CanValidate(Type type) {
|
||||
return (type == _type || _type == null);
|
||||
}
|
||||
public override void Validate(object value) {
|
||||
_callback(value);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="CallbackValidatorAttribute.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Configuration.Internal;
|
||||
using System.Collections;
|
||||
using System.Collections.Specialized;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Security.Permissions;
|
||||
using System.Xml;
|
||||
using System.Globalization;
|
||||
using System.ComponentModel;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
|
||||
namespace System.Configuration {
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public sealed class CallbackValidatorAttribute : ConfigurationValidatorAttribute {
|
||||
private Type _type = null;
|
||||
private String _callbackMethodName = String.Empty;
|
||||
private ValidatorCallback _callbackMethod;
|
||||
|
||||
public override ConfigurationValidatorBase ValidatorInstance {
|
||||
get {
|
||||
if (_callbackMethod == null) {
|
||||
if (_type == null) {
|
||||
throw new ArgumentNullException("Type");
|
||||
}
|
||||
if (!String.IsNullOrEmpty(_callbackMethodName)) {
|
||||
MethodInfo methodInfo = _type.GetMethod(_callbackMethodName, BindingFlags.Public | BindingFlags.Static);
|
||||
if (methodInfo != null) {
|
||||
ParameterInfo[] parameters = methodInfo.GetParameters();
|
||||
if ((parameters.Length == 1) && (parameters[0].ParameterType == typeof(Object))) {
|
||||
// The security here depends on nobody changing the type or callback method once the declaring type has been
|
||||
// set. This currently isn't an issue since the attribute is instantiated then the declaring type is set without
|
||||
// user code having gotten a chance to run in between. But if the behavior of PropertyInfo.GetAttributes ever
|
||||
// changes such that it returns cached attribute instances rather than new instances every time, this assumption is void.
|
||||
_callbackMethod = (ValidatorCallback)TypeUtil.CreateDelegateRestricted(_declaringType, typeof(ValidatorCallback), methodInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_callbackMethod == null) {
|
||||
throw new System.ArgumentException(SR.GetString(SR.Validator_method_not_found, _callbackMethodName));
|
||||
}
|
||||
|
||||
return new CallbackValidator(_callbackMethod);
|
||||
}
|
||||
}
|
||||
|
||||
public CallbackValidatorAttribute() {
|
||||
}
|
||||
|
||||
public Type Type {
|
||||
get {
|
||||
return _type;
|
||||
}
|
||||
set {
|
||||
_type = value;
|
||||
_callbackMethod = null;
|
||||
}
|
||||
}
|
||||
|
||||
public String CallbackMethodName {
|
||||
get {
|
||||
return _callbackMethodName;
|
||||
}
|
||||
set {
|
||||
_callbackMethodName = value;
|
||||
_callbackMethod = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,97 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="ClientConfigPerf.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Configuration {
|
||||
using System.Configuration.Internal;
|
||||
using System.Globalization;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Security;
|
||||
using System.Security.Permissions;
|
||||
using System.Threading;
|
||||
using System.Net;
|
||||
using Assembly = System.Reflection.Assembly;
|
||||
using StringBuilder = System.Text.StringBuilder;
|
||||
|
||||
#if NOPERF
|
||||
internal class ClientConfigPerf {
|
||||
const int SIZE=100;
|
||||
|
||||
long[] _counters;
|
||||
long[] _totals;
|
||||
string[] _names;
|
||||
int _current;
|
||||
bool _enabled;
|
||||
|
||||
static internal ClientConfigPerf ConfigSystem = new ClientConfigPerf(false);
|
||||
static internal ClientConfigPerf ScanSections = new ClientConfigPerf(false);
|
||||
static internal ClientConfigPerf CopySection = new ClientConfigPerf(false);
|
||||
static internal ClientConfigPerf CopyXmlNode = new ClientConfigPerf(false);
|
||||
static internal ClientConfigPerf GetConfig = new ClientConfigPerf(true);
|
||||
|
||||
ClientConfigPerf(bool enabled) {
|
||||
#if PERF
|
||||
_enabled = enabled;
|
||||
if (_enabled) {
|
||||
_counters = new long[SIZE];
|
||||
_totals = new long[SIZE];
|
||||
_names = new string[SIZE];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
internal void Reset() {
|
||||
#if PERF
|
||||
_current = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
internal void Record(string name) {
|
||||
#if PERF
|
||||
if (_enabled && _current < _counters.Length) {
|
||||
_names[_current] = name;
|
||||
Microsoft.Win32.SafeNativeMethods.QueryPerformanceCounter(out _counters[_current]);
|
||||
if (_current > 0) {
|
||||
_totals[_current] += _counters[_current] - _counters[_current - 1];
|
||||
}
|
||||
|
||||
_current++;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void DoPrint() {
|
||||
#if PERF
|
||||
if (_enabled) {
|
||||
long lfreq = 0;
|
||||
Microsoft.Win32.SafeNativeMethods.QueryPerformanceFrequency(out lfreq);
|
||||
double freq = (double) lfreq;
|
||||
double grandtotal = 0;
|
||||
|
||||
for (int i = 0; i < _current; i++) {
|
||||
double time = ((double)_totals[i]) / freq;
|
||||
grandtotal += time;
|
||||
Console.WriteLine("{0,-20} : {1:F6}", _names[i], time);
|
||||
}
|
||||
|
||||
Console.WriteLine("{0,-20} : {1:F6}\n", "TOTAL", grandtotal);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void Print() {
|
||||
#if PERF
|
||||
ConfigSystem.DoPrint();
|
||||
ScanSections.DoPrint();
|
||||
CopySection.DoPrint();
|
||||
CopyXmlNode.DoPrint();
|
||||
GetConfig.DoPrint();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,235 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="ClientConfigurationSystem.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Configuration {
|
||||
using System.Configuration.Internal;
|
||||
using System.Globalization;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Security;
|
||||
using System.Security.Permissions;
|
||||
using System.Threading;
|
||||
using System.Net;
|
||||
using Assembly = System.Reflection.Assembly;
|
||||
using StringBuilder = System.Text.StringBuilder;
|
||||
|
||||
internal sealed class ClientConfigurationSystem : IInternalConfigSystem {
|
||||
private const string SystemDiagnosticsConfigKey = "system.diagnostics";
|
||||
private const string SystemNetGroupKey = "system.net/";
|
||||
|
||||
private IConfigSystem _configSystem;
|
||||
private IInternalConfigRoot _configRoot;
|
||||
private ClientConfigurationHost _configHost;
|
||||
private IInternalConfigRecord _machineConfigRecord;
|
||||
private IInternalConfigRecord _completeConfigRecord;
|
||||
private Exception _initError;
|
||||
private bool _isInitInProgress;
|
||||
private bool _isMachineConfigInited;
|
||||
private bool _isUserConfigInited;
|
||||
private bool _isAppConfigHttp;
|
||||
|
||||
|
||||
internal ClientConfigurationSystem() {
|
||||
_configSystem = new ConfigSystem();
|
||||
_configSystem.Init(typeof(ClientConfigurationHost), null, null);
|
||||
|
||||
_configHost = (ClientConfigurationHost) _configSystem.Host;
|
||||
_configRoot = _configSystem.Root;
|
||||
|
||||
_configRoot.ConfigRemoved += OnConfigRemoved;
|
||||
|
||||
_isAppConfigHttp = _configHost.IsAppConfigHttp;
|
||||
|
||||
// VSWhidbey 606116: Config has a dependency on Uri class which has
|
||||
// a new static constructor that calls config. We need a dummy reference
|
||||
// to Uri class so the static constructor would be involved first to
|
||||
// initialize config.
|
||||
string dummy = System.Uri.SchemeDelimiter;
|
||||
}
|
||||
|
||||
// Return true if the section might be used during initialization of the configuration system,
|
||||
// and thus lead to deadlock if appropriate measures are not taken.
|
||||
bool IsSectionUsedInInit(string configKey) {
|
||||
return configKey == SystemDiagnosticsConfigKey || (_isAppConfigHttp && configKey.StartsWith(SystemNetGroupKey, StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
// Return true if the section should only use the machine configuration and not use the
|
||||
// application configuration. This is only true for system.net sections when the configuration
|
||||
// file for the application is downloaded via http using System.Net.WebClient.
|
||||
bool DoesSectionOnlyUseMachineConfig(string configKey) {
|
||||
return _isAppConfigHttp && configKey.StartsWith(SystemNetGroupKey, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
// Ensure that initialization has completed, while handling re-entrancy issues
|
||||
// for certain sections that may be used during initialization itself.
|
||||
void EnsureInit(string configKey) {
|
||||
bool doInit = false;
|
||||
|
||||
lock (this) {
|
||||
// If the user config is not initialized, then we must either:
|
||||
// a. Perform the initialization ourselves if no other thread is doing it, or
|
||||
// b. Wait for the initialization to complete if we know the section is not used during initialization itself, or
|
||||
// c. Ignore initialization if the section can be used during initialization. Note that GetSection()
|
||||
// returns null is initialization has not completed.
|
||||
if (!_isUserConfigInited) {
|
||||
if (!_isInitInProgress) {
|
||||
_isInitInProgress = true;
|
||||
doInit = true;
|
||||
}
|
||||
else if (!IsSectionUsedInInit(configKey)) {
|
||||
// Wait for initialization to complete.
|
||||
Monitor.Wait(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (doInit) {
|
||||
try {
|
||||
try {
|
||||
try {
|
||||
// Initialize machine configuration.
|
||||
_machineConfigRecord = _configRoot.GetConfigRecord(
|
||||
ClientConfigurationHost.MachineConfigPath);
|
||||
|
||||
_machineConfigRecord.ThrowIfInitErrors();
|
||||
|
||||
// Make machine configuration available to system.net sections
|
||||
// when application configuration is downloaded via http.
|
||||
_isMachineConfigInited = true;
|
||||
|
||||
//
|
||||
// Prevent deadlocks in the networking classes by loading
|
||||
// networking config before making a networking request.
|
||||
// Any requests for sections used in initialization during
|
||||
// the call to EnsureConfigLoaded() will be served by
|
||||
// _machine.config or will return null.
|
||||
//
|
||||
if (_isAppConfigHttp) {
|
||||
ConfigurationManagerHelperFactory.Instance.EnsureNetConfigLoaded();
|
||||
}
|
||||
|
||||
//
|
||||
// Now load the rest of configuration
|
||||
//
|
||||
_configHost.RefreshConfigPaths();
|
||||
string configPath;
|
||||
if (_configHost.HasLocalConfig) {
|
||||
configPath = ClientConfigurationHost.LocalUserConfigPath;
|
||||
}
|
||||
else if (_configHost.HasRoamingConfig) {
|
||||
configPath = ClientConfigurationHost.RoamingUserConfigPath;
|
||||
}
|
||||
else {
|
||||
configPath = ClientConfigurationHost.ExeConfigPath;
|
||||
}
|
||||
|
||||
_completeConfigRecord = _configRoot.GetConfigRecord(configPath);
|
||||
_completeConfigRecord.ThrowIfInitErrors();
|
||||
|
||||
_isUserConfigInited = true;
|
||||
}
|
||||
catch (Exception e) {
|
||||
_initError = new ConfigurationErrorsException(SR.GetString(SR.Config_client_config_init_error), e);
|
||||
throw _initError;
|
||||
}
|
||||
}
|
||||
catch {
|
||||
ConfigurationManager.SetInitError(_initError);
|
||||
_isMachineConfigInited = true;
|
||||
_isUserConfigInited = true;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
lock (this) {
|
||||
try {
|
||||
// Notify ConfigurationSettings that initialization has fully completed,
|
||||
// even if unsuccessful.
|
||||
ConfigurationManager.CompleteConfigInit();
|
||||
|
||||
_isInitInProgress = false;
|
||||
|
||||
}
|
||||
finally {
|
||||
// Wake up all threads waiting for initialization to complete.
|
||||
Monitor.PulseAll(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void PrepareClientConfigSystem(string sectionName) {
|
||||
// Ensure the configuration system is inited for this section.
|
||||
if (!_isUserConfigInited) {
|
||||
EnsureInit(sectionName);
|
||||
}
|
||||
|
||||
// If an error occurred during initialzation, throw it.
|
||||
if (_initError != null) {
|
||||
throw _initError;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// If config has been removed because initialization was not complete,
|
||||
// fetch a new configuration record. The record will be created and
|
||||
// completely initialized as RequireCompleteInit() will have been called
|
||||
// on the ClientConfigurationHost before we receive this event.
|
||||
//
|
||||
private void OnConfigRemoved(object sender, InternalConfigEventArgs e) {
|
||||
try {
|
||||
IInternalConfigRecord newConfigRecord = _configRoot.GetConfigRecord(_completeConfigRecord.ConfigPath);
|
||||
_completeConfigRecord = newConfigRecord;
|
||||
_completeConfigRecord.ThrowIfInitErrors();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
_initError = new ConfigurationErrorsException(SR.GetString(SR.Config_client_config_init_error), ex);
|
||||
ConfigurationManager.SetInitError(_initError);
|
||||
throw _initError;
|
||||
}
|
||||
}
|
||||
|
||||
object IInternalConfigSystem.GetSection(string sectionName) {
|
||||
PrepareClientConfigSystem(sectionName);
|
||||
|
||||
// Get the appropriate config record for the section.
|
||||
IInternalConfigRecord configRecord = null;
|
||||
if (DoesSectionOnlyUseMachineConfig(sectionName)) {
|
||||
if (_isMachineConfigInited) {
|
||||
configRecord = _machineConfigRecord;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (_isUserConfigInited) {
|
||||
configRecord = _completeConfigRecord;
|
||||
}
|
||||
}
|
||||
|
||||
// Call GetSection(), or return null if no configuration is yet available.
|
||||
if (configRecord != null) {
|
||||
return configRecord.GetSection(sectionName);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
void IInternalConfigSystem.RefreshConfig(string sectionName) {
|
||||
PrepareClientConfigSystem(sectionName);
|
||||
|
||||
if (_isMachineConfigInited) {
|
||||
_machineConfigRecord.RefreshSection(sectionName);
|
||||
}
|
||||
}
|
||||
|
||||
// Supports user config
|
||||
bool IInternalConfigSystem.SupportsUserConfig {
|
||||
get {return true;}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="CommaDelimitedStringCollectionConverter.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Security.Permissions;
|
||||
using System.Xml;
|
||||
using System.Collections.Specialized;
|
||||
using System.Globalization;
|
||||
using System.ComponentModel;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
|
||||
namespace System.Configuration {
|
||||
|
||||
public sealed class CommaDelimitedStringCollectionConverter : ConfigurationConverterBase {
|
||||
|
||||
public override object ConvertTo(ITypeDescriptorContext ctx, CultureInfo ci, object value, Type type) {
|
||||
|
||||
ValidateType(value, typeof(CommaDelimitedStringCollection));
|
||||
CommaDelimitedStringCollection internalValue = value as CommaDelimitedStringCollection;
|
||||
if (internalValue != null) {
|
||||
return internalValue.ToString();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public override object ConvertFrom(ITypeDescriptorContext ctx, CultureInfo ci, object data) {
|
||||
CommaDelimitedStringCollection attributeCollection = new CommaDelimitedStringCollection();
|
||||
attributeCollection.FromString((string)data);
|
||||
return attributeCollection;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="ConfigDefinitionUpdates.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Configuration {
|
||||
using System.Collections;
|
||||
|
||||
//
|
||||
// Contains all the updates to section definitions across all location sections.
|
||||
//
|
||||
internal class ConfigDefinitionUpdates {
|
||||
private ArrayList _locationUpdatesList;
|
||||
private bool _requireLocationWritten;
|
||||
|
||||
internal ConfigDefinitionUpdates() {
|
||||
_locationUpdatesList = new ArrayList();
|
||||
}
|
||||
|
||||
//
|
||||
// Find the location update with a certain set of location attributes.
|
||||
//
|
||||
internal LocationUpdates FindLocationUpdates(OverrideModeSetting overrideMode, bool inheritInChildApps) {
|
||||
foreach (LocationUpdates locationUpdates in _locationUpdatesList) {
|
||||
if ( OverrideModeSetting.CanUseSameLocationTag(locationUpdates.OverrideMode, overrideMode) &&
|
||||
locationUpdates.InheritInChildApps == inheritInChildApps) {
|
||||
return locationUpdates;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
//
|
||||
// Add a section definition update to the correct location update.
|
||||
//
|
||||
internal DefinitionUpdate AddUpdate(OverrideModeSetting overrideMode, bool inheritInChildApps, bool moved, string updatedXml, SectionRecord sectionRecord) {
|
||||
LocationUpdates locationUpdates = FindLocationUpdates(overrideMode, inheritInChildApps);
|
||||
if (locationUpdates == null) {
|
||||
locationUpdates = new LocationUpdates(overrideMode, inheritInChildApps);
|
||||
_locationUpdatesList.Add(locationUpdates);
|
||||
}
|
||||
|
||||
DefinitionUpdate definitionUpdate = new DefinitionUpdate(sectionRecord.ConfigKey, moved, updatedXml, sectionRecord);
|
||||
locationUpdates.SectionUpdates.AddSection(definitionUpdate);
|
||||
return definitionUpdate;
|
||||
}
|
||||
|
||||
//
|
||||
// Determine which section definition updates are new.
|
||||
//
|
||||
internal void CompleteUpdates() {
|
||||
foreach (LocationUpdates locationUpdates in _locationUpdatesList) {
|
||||
locationUpdates.CompleteUpdates();
|
||||
}
|
||||
}
|
||||
|
||||
internal ArrayList LocationUpdatesList {
|
||||
get {return _locationUpdatesList;}
|
||||
}
|
||||
|
||||
internal bool RequireLocation {
|
||||
get { return _requireLocationWritten; }
|
||||
set { _requireLocationWritten = value; }
|
||||
}
|
||||
|
||||
internal void FlagLocationWritten() {
|
||||
_requireLocationWritten = false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="ConfigXmlAttribute.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Configuration
|
||||
{
|
||||
using System.Configuration.Internal;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Security.Permissions;
|
||||
|
||||
internal sealed class ConfigXmlAttribute : XmlAttribute, IConfigErrorInfo {
|
||||
int _line;
|
||||
string _filename;
|
||||
|
||||
public ConfigXmlAttribute( string filename, int line, string prefix, string localName, string namespaceUri, XmlDocument doc )
|
||||
: base( prefix, localName, namespaceUri, doc ) {
|
||||
_line = line;
|
||||
_filename = filename;
|
||||
}
|
||||
int IConfigErrorInfo.LineNumber {
|
||||
get { return _line; }
|
||||
}
|
||||
string IConfigErrorInfo.Filename {
|
||||
get { return _filename; }
|
||||
}
|
||||
public override XmlNode CloneNode(bool deep) {
|
||||
XmlNode cloneNode = base.CloneNode(deep);
|
||||
ConfigXmlAttribute clone = cloneNode as ConfigXmlAttribute;
|
||||
if (clone != null) {
|
||||
clone._line = _line;
|
||||
clone._filename = _filename;
|
||||
}
|
||||
return cloneNode;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="ConfigXmlCDataSection.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Configuration
|
||||
{
|
||||
using System.Configuration.Internal;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Security.Permissions;
|
||||
|
||||
internal sealed class ConfigXmlCDataSection : XmlCDataSection, IConfigErrorInfo {
|
||||
int _line;
|
||||
string _filename;
|
||||
|
||||
public ConfigXmlCDataSection( string filename, int line, string data, XmlDocument doc )
|
||||
: base( data, doc) {
|
||||
_line = line;
|
||||
_filename = filename;
|
||||
}
|
||||
int IConfigErrorInfo.LineNumber {
|
||||
get { return _line; }
|
||||
}
|
||||
string IConfigErrorInfo.Filename {
|
||||
get { return _filename; }
|
||||
}
|
||||
public override XmlNode CloneNode(bool deep) {
|
||||
XmlNode cloneNode = base.CloneNode(deep);
|
||||
ConfigXmlCDataSection clone = cloneNode as ConfigXmlCDataSection;
|
||||
if (clone != null) {
|
||||
clone._line = _line;
|
||||
clone._filename = _filename;
|
||||
}
|
||||
return cloneNode;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="ConfigXmlComment.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Configuration
|
||||
{
|
||||
using System.Configuration.Internal;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Security.Permissions;
|
||||
|
||||
internal sealed class ConfigXmlComment : XmlComment, IConfigErrorInfo {
|
||||
int _line;
|
||||
string _filename;
|
||||
|
||||
public ConfigXmlComment( string filename, int line, string comment, XmlDocument doc )
|
||||
: base( comment, doc ) {
|
||||
_line = line;
|
||||
_filename = filename;
|
||||
}
|
||||
int IConfigErrorInfo.LineNumber {
|
||||
get { return _line; }
|
||||
}
|
||||
string IConfigErrorInfo.Filename {
|
||||
get { return _filename; }
|
||||
}
|
||||
public override XmlNode CloneNode(bool deep) {
|
||||
XmlNode cloneNode = base.CloneNode(deep);
|
||||
ConfigXmlComment clone = cloneNode as ConfigXmlComment;
|
||||
if (clone != null) {
|
||||
clone._line = _line;
|
||||
clone._filename = _filename;
|
||||
}
|
||||
return cloneNode;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="ConfigXmlElement.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Configuration
|
||||
{
|
||||
using System.Configuration.Internal;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Security.Permissions;
|
||||
|
||||
internal sealed class ConfigXmlElement : XmlElement, IConfigErrorInfo {
|
||||
int _line;
|
||||
string _filename;
|
||||
|
||||
public ConfigXmlElement( string filename, int line, string prefix, string localName, string namespaceUri, XmlDocument doc )
|
||||
: base( prefix, localName, namespaceUri, doc) {
|
||||
_line = line;
|
||||
_filename = filename;
|
||||
}
|
||||
int IConfigErrorInfo.LineNumber {
|
||||
get { return _line; }
|
||||
}
|
||||
string IConfigErrorInfo.Filename {
|
||||
get { return _filename; }
|
||||
}
|
||||
public override XmlNode CloneNode(bool deep) {
|
||||
XmlNode cloneNode = base.CloneNode(deep);
|
||||
ConfigXmlElement clone = cloneNode as ConfigXmlElement;
|
||||
if (clone != null) {
|
||||
clone._line = _line;
|
||||
clone._filename = _filename;
|
||||
}
|
||||
return cloneNode;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="ConfigXmlReader.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Configuration {
|
||||
using System.Configuration.Internal;
|
||||
using System.Collections;
|
||||
using System.Collections.Specialized;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Security.Permissions;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Net;
|
||||
|
||||
internal sealed class ConfigXmlReader : XmlTextReader, IConfigErrorInfo {
|
||||
string _rawXml;
|
||||
int _lineOffset;
|
||||
string _filename;
|
||||
|
||||
// Used in a decrypted configuration section to locate
|
||||
// the line where the ecnrypted section begins.
|
||||
bool _lineNumberIsConstant;
|
||||
|
||||
internal ConfigXmlReader(string rawXml, string filename, int lineOffset) :
|
||||
this(rawXml, filename, lineOffset, false) {
|
||||
}
|
||||
|
||||
internal ConfigXmlReader(string rawXml, string filename, int lineOffset, bool lineNumberIsConstant) :
|
||||
base(new StringReader(rawXml)) {
|
||||
|
||||
_rawXml = rawXml;
|
||||
_filename = filename;
|
||||
_lineOffset = lineOffset;
|
||||
_lineNumberIsConstant = lineNumberIsConstant;
|
||||
|
||||
Debug.Assert(!_lineNumberIsConstant || _lineOffset > 0,
|
||||
"!_lineNumberIsConstant || _lineOffset > 0");
|
||||
}
|
||||
|
||||
internal ConfigXmlReader Clone() {
|
||||
return new ConfigXmlReader(_rawXml, _filename, _lineOffset, _lineNumberIsConstant);
|
||||
}
|
||||
|
||||
int IConfigErrorInfo.LineNumber {
|
||||
get {
|
||||
if (_lineNumberIsConstant) {
|
||||
return _lineOffset;
|
||||
}
|
||||
else if (_lineOffset > 0) {
|
||||
return base.LineNumber + (_lineOffset - 1);
|
||||
}
|
||||
else {
|
||||
return base.LineNumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string IConfigErrorInfo.Filename {
|
||||
get {
|
||||
return _filename;
|
||||
}
|
||||
}
|
||||
|
||||
internal string RawXml {
|
||||
get {
|
||||
return _rawXml;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="ConfigXmlSignificantWhitespace.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Configuration
|
||||
{
|
||||
using System.Configuration.Internal;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Security.Permissions;
|
||||
|
||||
internal sealed class ConfigXmlSignificantWhitespace : XmlSignificantWhitespace, IConfigErrorInfo {
|
||||
public ConfigXmlSignificantWhitespace(string filename, int line, string strData, XmlDocument doc)
|
||||
: base(strData, doc) {
|
||||
_line = line;
|
||||
_filename = filename;
|
||||
}
|
||||
int _line;
|
||||
string _filename;
|
||||
|
||||
int IConfigErrorInfo.LineNumber {
|
||||
get { return _line; }
|
||||
}
|
||||
string IConfigErrorInfo.Filename {
|
||||
get { return _filename; }
|
||||
}
|
||||
public override XmlNode CloneNode(bool deep) {
|
||||
XmlNode cloneNode = base.CloneNode(deep);
|
||||
ConfigXmlSignificantWhitespace clone = cloneNode as ConfigXmlSignificantWhitespace;
|
||||
if (clone != null) {
|
||||
clone._line = _line;
|
||||
clone._filename = _filename;
|
||||
}
|
||||
return cloneNode;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="ConfigXmlText.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Configuration
|
||||
{
|
||||
using System.Configuration.Internal;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Security.Permissions;
|
||||
|
||||
internal sealed class ConfigXmlText : XmlText, IConfigErrorInfo {
|
||||
int _line;
|
||||
string _filename;
|
||||
|
||||
public ConfigXmlText( string filename, int line, string strData, XmlDocument doc )
|
||||
: base( strData, doc ) {
|
||||
_line = line;
|
||||
_filename = filename;
|
||||
}
|
||||
int IConfigErrorInfo.LineNumber {
|
||||
get { return _line; }
|
||||
}
|
||||
string IConfigErrorInfo.Filename {
|
||||
get { return _filename; }
|
||||
}
|
||||
public override XmlNode CloneNode(bool deep) {
|
||||
XmlNode cloneNode = base.CloneNode(deep);
|
||||
ConfigXmlText clone = cloneNode as ConfigXmlText;
|
||||
if (clone != null) {
|
||||
clone._line = _line;
|
||||
clone._filename = _filename;
|
||||
}
|
||||
return cloneNode;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="ConfigXmlWhitespace.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Configuration
|
||||
{
|
||||
using System.Configuration.Internal;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Security.Permissions;
|
||||
|
||||
internal sealed class ConfigXmlWhitespace : XmlWhitespace, IConfigErrorInfo {
|
||||
public ConfigXmlWhitespace( string filename, int line, string comment, XmlDocument doc )
|
||||
: base( comment, doc ) {
|
||||
_line = line;
|
||||
_filename = filename;
|
||||
}
|
||||
int _line;
|
||||
string _filename;
|
||||
|
||||
int IConfigErrorInfo.LineNumber {
|
||||
get { return _line; }
|
||||
}
|
||||
string IConfigErrorInfo.Filename {
|
||||
get { return _filename; }
|
||||
}
|
||||
public override XmlNode CloneNode(bool deep) {
|
||||
XmlNode cloneNode = base.CloneNode(deep);
|
||||
ConfigXmlWhitespace clone = cloneNode as ConfigXmlWhitespace;
|
||||
if (clone != null) {
|
||||
clone._line = _line;
|
||||
clone._filename = _filename;
|
||||
}
|
||||
return cloneNode;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,314 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="Configuration.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
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;
|
||||
using System.Runtime.Versioning;
|
||||
|
||||
namespace System.Configuration {
|
||||
|
||||
//
|
||||
// An instance of the Configuration class represents a single level
|
||||
// in the configuration hierarchy. Its contents can be edited and
|
||||
// saved to disk.
|
||||
//
|
||||
// It is not thread safe for writing.
|
||||
//
|
||||
public sealed class Configuration {
|
||||
private Type _typeConfigHost; // type of config host
|
||||
private object[] _hostInitConfigurationParams; // params to init config host
|
||||
private InternalConfigRoot _configRoot; // root of this configuration hierarchy
|
||||
private MgmtConfigurationRecord _configRecord; // config record for this level in the hierarchy
|
||||
private ConfigurationSectionGroup _rootSectionGroup; // section group for the root of all sections
|
||||
private ConfigurationLocationCollection _locations; // support for ConfigurationLocationsCollection
|
||||
private ContextInformation _evalContext; // evaluation context
|
||||
private Func<string, string> _TypeStringTransformer = null;
|
||||
private Func<string, string> _AssemblyStringTransformer = null;
|
||||
private bool _TypeStringTransformerIsSet = false;
|
||||
private bool _AssemblyStringTransformerIsSet = false;
|
||||
private FrameworkName _TargetFramework = null;
|
||||
private Stack _SectionsStack = null;
|
||||
|
||||
internal Configuration(string locationSubPath, Type typeConfigHost, params object[] hostInitConfigurationParams) {
|
||||
_typeConfigHost = typeConfigHost;
|
||||
_hostInitConfigurationParams = hostInitConfigurationParams;
|
||||
|
||||
_configRoot = new InternalConfigRoot(this);
|
||||
|
||||
IInternalConfigHost configHost = (IInternalConfigHost) TypeUtil.CreateInstanceWithReflectionPermission(typeConfigHost);
|
||||
|
||||
// Wrap the host with the UpdateConfigHost to support SaveAs.
|
||||
IInternalConfigHost updateConfigHost = new UpdateConfigHost(configHost);
|
||||
|
||||
((IInternalConfigRoot)_configRoot).Init(updateConfigHost, true);
|
||||
|
||||
//
|
||||
// Set the configuration paths for this Configuration.
|
||||
// We do this in a separate step so that the WebConfigurationHost
|
||||
// can use this object's _configRoot to get the <sites> section,
|
||||
// which is used in it's MapPath implementation.
|
||||
//
|
||||
string configPath, 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");
|
||||
}
|
||||
|
||||
// Get the configuration record for this config file.
|
||||
_configRecord = (MgmtConfigurationRecord) _configRoot.GetConfigRecord(configPath);
|
||||
|
||||
//
|
||||
// Create another MgmtConfigurationRecord for the location that is a child of the above record.
|
||||
// Note that this does not match the resolution hiearchy that is used at runtime.
|
||||
//
|
||||
if (!String.IsNullOrEmpty(locationSubPath)) {
|
||||
_configRecord = MgmtConfigurationRecord.Create(
|
||||
_configRoot, _configRecord, locationConfigPath, locationSubPath);
|
||||
}
|
||||
|
||||
//
|
||||
// Throw if the config record we created contains global errors.
|
||||
//
|
||||
_configRecord.ThrowIfInitErrors();
|
||||
}
|
||||
|
||||
//
|
||||
// Create a new instance of Configuration for the locationSubPath,
|
||||
// with the initialization parameters that were used to create this configuration.
|
||||
//
|
||||
internal Configuration OpenLocationConfiguration(string locationSubPath) {
|
||||
return new Configuration(locationSubPath, _typeConfigHost, _hostInitConfigurationParams);
|
||||
}
|
||||
|
||||
// public properties
|
||||
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 methods
|
||||
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;
|
||||
}
|
||||
|
||||
// NamespaceDeclared
|
||||
//
|
||||
// Is the namespace declared in the file or not?
|
||||
//
|
||||
// ie. xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"
|
||||
// (currently this is the only one we allow)
|
||||
//
|
||||
// get - Return if it was declared in the file.
|
||||
// set - Set if we should save the namespace or not
|
||||
//
|
||||
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);
|
||||
}
|
||||
|
||||
// Force all sections and section groups to be instantiated.
|
||||
private void ForceGroupsRecursive(ConfigurationSectionGroup group) {
|
||||
foreach (ConfigurationSection configSection in group.Sections) {
|
||||
// Force the section to be read into the cache
|
||||
ConfigurationSection section = group.Sections[configSection.SectionInformation.Name];
|
||||
}
|
||||
|
||||
foreach (ConfigurationSectionGroup sectionGroup in group.SectionGroups) {
|
||||
ForceGroupsRecursive(group.SectionGroups[sectionGroup.Name]);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public System.Func<string, string> TypeStringTransformer {
|
||||
get {
|
||||
return _TypeStringTransformer;
|
||||
}
|
||||
[ConfigurationPermission(SecurityAction.Demand, Unrestricted=true)]
|
||||
set {
|
||||
if (_TypeStringTransformer != value) {
|
||||
_TypeStringTransformerIsSet = (value != null);
|
||||
_TypeStringTransformer = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public System.Func<string, string> AssemblyStringTransformer {
|
||||
get {
|
||||
return _AssemblyStringTransformer;
|
||||
}
|
||||
[ConfigurationPermission(SecurityAction.Demand, Unrestricted=true)]
|
||||
set {
|
||||
if (_AssemblyStringTransformer != value) {
|
||||
_AssemblyStringTransformerIsSet = (value != null);
|
||||
_AssemblyStringTransformer = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public FrameworkName TargetFramework {
|
||||
get {
|
||||
return _TargetFramework;
|
||||
}
|
||||
[ConfigurationPermission(SecurityAction.Demand, Unrestricted=true)]
|
||||
set {
|
||||
_TargetFramework = value;
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
internal bool TypeStringTransformerIsSet { get { return _TypeStringTransformerIsSet; }}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
internal bool AssemblyStringTransformerIsSet { get { return _AssemblyStringTransformerIsSet; }}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
internal Stack SectionsStack {
|
||||
get {
|
||||
if (_SectionsStack == null)
|
||||
_SectionsStack = new Stack();
|
||||
return _SectionsStack;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user