Imported Upstream version 4.6.0.125

Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-08-03 10:59:49 +00:00
parent a569aebcfd
commit e79aa3c0ed
17047 changed files with 3137615 additions and 392334 deletions

View File

@ -0,0 +1,83 @@
//------------------------------------------------------------------------------
// <copyright file="ConfigurationManagerInternal.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Configuration.Internal {
using System.Configuration;
internal sealed class ConfigurationManagerInternal : IConfigurationManagerInternal {
// Created only through reflection
private ConfigurationManagerInternal() {
}
bool IConfigurationManagerInternal.SupportsUserConfig {
get {
return ConfigurationManager.SupportsUserConfig;
}
}
bool IConfigurationManagerInternal.SetConfigurationSystemInProgress {
get {
return ConfigurationManager.SetConfigurationSystemInProgress;
}
}
string IConfigurationManagerInternal.MachineConfigPath {
get {
return ClientConfigurationHost.MachineConfigFilePath;
}
}
string IConfigurationManagerInternal.ApplicationConfigUri {
get {
return ClientConfigPaths.Current.ApplicationConfigUri;
}
}
string IConfigurationManagerInternal.ExeProductName {
get {
return ClientConfigPaths.Current.ProductName;
}
}
string IConfigurationManagerInternal.ExeProductVersion {
get {
return ClientConfigPaths.Current.ProductVersion;
}
}
string IConfigurationManagerInternal.ExeRoamingConfigDirectory {
get {
return ClientConfigPaths.Current.RoamingConfigDirectory;
}
}
string IConfigurationManagerInternal.ExeRoamingConfigPath {
get {
return ClientConfigPaths.Current.RoamingConfigFilename;
}
}
string IConfigurationManagerInternal.ExeLocalConfigDirectory {
get {
return ClientConfigPaths.Current.LocalConfigDirectory;
}
}
string IConfigurationManagerInternal.ExeLocalConfigPath {
get {
return ClientConfigPaths.Current.LocalConfigFilename;
}
}
string IConfigurationManagerInternal.UserConfigFilename {
get {
return ClientConfigPaths.UserConfigFilename;
}
}
}
}

View File

@ -0,0 +1,231 @@
//------------------------------------------------------------------------------
// <copyright file="DelegatingConfigHost.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Configuration.Internal {
using System.Configuration;
using System.IO;
using System.Security.Permissions;
using System.Reflection;
using System.Threading;
using System.Security;
using System.CodeDom.Compiler;
//
// A public implementation of IInternalConfigHost that simply
// delegates all members of the IInternalConfigHost interface to
// another instance of a host. All interface members are marked virtual
// so that a derived class can override just the ones needed to
// implement that specific host, while all others are delegated to
// another implementation such as InternalConfigHost.
//
// The advantages of this arrangement are:
// * The IInternalConfigHost interface can be extended without
// requiring other hosts to be updated.
// * This class that we are making public has no implementation
// of its own that can be exploited. All the hosts with meaningful
// implementation can remain internal.
// * It allows straightforward chaining of host functionality,
// see UpdateConfigHost as an example.
//
public class DelegatingConfigHost : IInternalConfigHost {
IInternalConfigHost _host;
protected DelegatingConfigHost() {}
// The host that is delegated to.
protected IInternalConfigHost Host {
get {return _host;}
set {_host = value;}
}
public virtual void Init(IInternalConfigRoot configRoot, params object[] hostInitParams) {
Host.Init(configRoot, hostInitParams);
}
public virtual void InitForConfiguration(ref string locationSubPath, out string configPath, out string locationConfigPath,
IInternalConfigRoot configRoot, params object[] hostInitConfigurationParams) {
Host.InitForConfiguration(ref locationSubPath, out configPath, out locationConfigPath, configRoot, hostInitConfigurationParams);
}
public virtual bool IsConfigRecordRequired(string configPath) {
return Host.IsConfigRecordRequired(configPath);
}
public virtual bool IsInitDelayed(IInternalConfigRecord configRecord) {
return Host.IsInitDelayed(configRecord);
}
public virtual void RequireCompleteInit(IInternalConfigRecord configRecord) {
Host.RequireCompleteInit(configRecord);
}
// IsSecondaryRoot
//
// Is this a secondary root. This means that it is a node in which
// everything that is defined in it should also be treated as a root.
// So...if a factory record is defined that was already defined above
// then throw since it is not allowed.
//
public virtual bool IsSecondaryRoot(string configPath) {
return Host.IsSecondaryRoot(configPath);
}
public virtual string GetStreamName(string configPath) {
return Host.GetStreamName(configPath);
}
public virtual string GetStreamNameForConfigSource(string streamName, string configSource) {
return Host.GetStreamNameForConfigSource(streamName, configSource);
}
public virtual object GetStreamVersion(string streamName) {
return Host.GetStreamVersion(streamName);
}
public virtual Stream OpenStreamForRead(string streamName) {
return Host.OpenStreamForRead(streamName);
}
public virtual Stream OpenStreamForRead(string streamName, bool assertPermissions) {
return Host.OpenStreamForRead(streamName, assertPermissions);
}
public virtual Stream OpenStreamForWrite(string streamName, string templateStreamName, ref object writeContext) {
return Host.OpenStreamForWrite(streamName, templateStreamName, ref writeContext);
}
public virtual Stream OpenStreamForWrite(string streamName, string templateStreamName, ref object writeContext, bool assertPermissions) {
return Host.OpenStreamForWrite(streamName, templateStreamName, ref writeContext, assertPermissions);
}
public virtual void WriteCompleted(string streamName, bool success, object writeContext) {
Host.WriteCompleted(streamName, success, writeContext);
}
public virtual void WriteCompleted(string streamName, bool success, object writeContext, bool assertPermissions) {
Host.WriteCompleted(streamName, success, writeContext, assertPermissions);
}
public virtual void DeleteStream(string streamName) {
Host.DeleteStream(streamName);
}
public virtual bool IsFile(string streamName) {
return Host.IsFile(streamName);
}
public virtual bool SupportsChangeNotifications {
get {
return Host.SupportsChangeNotifications;
}
}
public virtual object StartMonitoringStreamForChanges(string streamName, StreamChangeCallback callback) {
return Host.StartMonitoringStreamForChanges(streamName, callback);
}
public virtual void StopMonitoringStreamForChanges(string streamName, StreamChangeCallback callback) {
Host.StopMonitoringStreamForChanges(streamName, callback);
}
public virtual bool SupportsRefresh {
get {
return Host.SupportsRefresh;
}
}
public virtual bool SupportsPath {
get {
return Host.SupportsPath;
}
}
public virtual bool SupportsLocation {
get {
return Host.SupportsLocation;
}
}
public virtual bool IsAboveApplication(string configPath) {
return Host.IsAboveApplication(configPath);
}
public virtual bool IsDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition) {
return Host.IsDefinitionAllowed(configPath, allowDefinition, allowExeDefinition);
}
public virtual void VerifyDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo) {
Host.VerifyDefinitionAllowed(configPath, allowDefinition, allowExeDefinition, errorInfo);
}
public virtual string GetConfigPathFromLocationSubPath(string configPath, string locationSubPath) {
return Host.GetConfigPathFromLocationSubPath(configPath, locationSubPath);
}
public virtual bool IsLocationApplicable(string configPath) {
return Host.IsLocationApplicable(configPath);
}
public virtual bool IsTrustedConfigPath(string configPath) {
return Host.IsTrustedConfigPath(configPath);
}
public virtual bool IsFullTrustSectionWithoutAptcaAllowed(IInternalConfigRecord configRecord) {
return Host.IsFullTrustSectionWithoutAptcaAllowed(configRecord);
}
public virtual void GetRestrictedPermissions(IInternalConfigRecord configRecord, out PermissionSet permissionSet, out bool isHostReady) {
Host.GetRestrictedPermissions(configRecord, out permissionSet, out isHostReady);
}
public virtual IDisposable Impersonate() {
return Host.Impersonate();
}
public virtual bool PrefetchAll(string configPath, string streamName) {
return Host.PrefetchAll(configPath, streamName);
}
public virtual bool PrefetchSection(string sectionGroupName, string sectionName) {
return Host.PrefetchSection(sectionGroupName, sectionName);
}
public virtual object CreateDeprecatedConfigContext(string configPath) {
return Host.CreateDeprecatedConfigContext(configPath);
}
public virtual object
CreateConfigurationContext( string configPath, string locationSubPath )
{
return Host.CreateConfigurationContext( configPath, locationSubPath );
}
public virtual string DecryptSection(string encryptedXml, ProtectedConfigurationProvider protectionProvider, ProtectedConfigurationSection protectedConfigSection) {
return Host.DecryptSection(encryptedXml, protectionProvider, protectedConfigSection);
}
public virtual string EncryptSection(string clearTextXml, ProtectedConfigurationProvider protectionProvider, ProtectedConfigurationSection protectedConfigSection) {
return Host.EncryptSection(clearTextXml, protectionProvider, protectedConfigSection);
}
public virtual Type GetConfigType(string typeName, bool throwOnError) {
return Host.GetConfigType(typeName, throwOnError);
}
public virtual string GetConfigTypeName(Type t) {
return Host.GetConfigTypeName(t);
}
public virtual bool IsRemote {
get {
return Host.IsRemote;
}
}
}
}

View File

@ -0,0 +1,47 @@
//------------------------------------------------------------------------------
// <copyright file="FileVersion.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Configuration.Internal {
using System.Configuration;
using System.IO;
using System.Security.Permissions;
using System.Reflection;
using System.Threading;
using System.Security;
using System.CodeDom.Compiler;
using Microsoft.Win32;
#if !FEATURE_PAL
using System.Security.AccessControl;
#endif
internal class FileVersion {
bool _exists;
long _fileSize;
DateTime _utcCreationTime;
DateTime _utcLastWriteTime;
internal FileVersion(bool exists, long fileSize, DateTime utcCreationTime, DateTime utcLastWriteTime) {
_exists = exists;
_fileSize = fileSize;
_utcCreationTime = utcCreationTime;
_utcLastWriteTime = utcLastWriteTime;
}
public override bool Equals(Object obj) {
FileVersion other = obj as FileVersion;
return
other != null
&& _exists == other._exists
&& _fileSize == other._fileSize
&& _utcCreationTime == other._utcCreationTime
&& _utcLastWriteTime == other._utcLastWriteTime;
}
public override int GetHashCode() {
return base.GetHashCode();
}
}
}

View File

@ -0,0 +1,13 @@
//------------------------------------------------------------------------------
// <copyright file="IConfigErrorInfo.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Configuration.Internal {
public interface IConfigErrorInfo {
string Filename { get; }
int LineNumber { get; }
}
}

View File

@ -0,0 +1,34 @@
//------------------------------------------------------------------------------
// <copyright file="IConfigurationManagerHelper.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.IO;
using System.Security;
using System.Collections.Specialized;
using System.Configuration;
using ClassConfiguration=System.Configuration.Configuration;
//
// This file contains most of the interfaces that allow System.Web, Venus, and
// Whitehorse to customize configuration in some way.
//
// The goal of the design of customization is to only require other MS assemblies
// to create an instance of an internal object via Activator.CreateInstance(), and then
// use these objects through *public* System.Configuration.Internal interfaces.
// We do not want extenders to have to use reflection to call a method - it is slow,
// not typesafe, and more difficult to promote correct use of the internal object.
//
namespace System.Configuration.Internal {
//
// Exposes support in System.dll for functionality that has
// been moved to System.Configuration.dll
//
[System.Runtime.InteropServices.ComVisible(false)]
public interface IConfigurationManagerHelper {
void EnsureNetConfigLoaded();
}
}

View File

@ -0,0 +1,44 @@
//------------------------------------------------------------------------------
// <copyright file="IConfigurationManagerInternal.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.IO;
using System.Security;
using System.Collections.Specialized;
using System.Configuration;
using ClassConfiguration=System.Configuration.Configuration;
//
// This file contains most of the interfaces that allow System.Web, Venus, and
// Whitehorse to customize configuration in some way.
//
// The goal of the design of customization is to only require other MS assemblies
// to create an instance of an internal object via Activator.CreateInstance(), and then
// use these objects through *public* System.Configuration.Internal interfaces.
// We do not want extenders to have to use reflection to call a method - it is slow,
// not typesafe, and more difficult to promote correct use of the internal object.
//
namespace System.Configuration.Internal {
//
// Exposes support in System.Configuration for functions that were
// once available in System.dll
//
[System.Runtime.InteropServices.ComVisible(false)]
public interface IConfigurationManagerInternal {
bool SupportsUserConfig {get;}
bool SetConfigurationSystemInProgress {get;}
string MachineConfigPath {get;}
string ApplicationConfigUri {get;}
string ExeProductName {get;}
string ExeProductVersion {get;}
string ExeRoamingConfigDirectory {get;}
string ExeRoamingConfigPath {get;}
string ExeLocalConfigDirectory {get;}
string ExeLocalConfigPath {get;}
string UserConfigFilename {get;}
}
}

View File

@ -0,0 +1,39 @@
//------------------------------------------------------------------------------
// <copyright file="IInternalConfigClientHost.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.IO;
using System.Security;
using System.Collections.Specialized;
using System.Configuration;
using ClassConfiguration=System.Configuration.Configuration;
//
// This file contains most of the interfaces that allow System.Web, Venus, and
// Whitehorse to customize configuration in some way.
//
// The goal of the design of customization is to only require other MS assemblies
// to create an instance of an internal object via Activator.CreateInstance(), and then
// use these objects through *public* System.Configuration.Internal interfaces.
// We do not want extenders to have to use reflection to call a method - it is slow,
// not typesafe, and more difficult to promote correct use of the internal object.
//
namespace System.Configuration.Internal {
//
// Provide support to Whitehorse for manipulating the configuration path,
// so the details of the path do not have to be known by Whitehorse.
//
[System.Runtime.InteropServices.ComVisible(false)]
public interface IInternalConfigClientHost {
bool IsExeConfig(string configPath);
bool IsRoamingUserConfig(string configPath);
bool IsLocalUserConfig(string configPath);
string GetExeConfigPath();
string GetRoamingUserConfigPath();
string GetLocalUserConfigPath();
}
}

View File

@ -0,0 +1,34 @@
//------------------------------------------------------------------------------
// <copyright file="IInternalConfigConfigurationFactory.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.IO;
using System.Security;
using System.Collections.Specialized;
using System.Configuration;
using ClassConfiguration=System.Configuration.Configuration;
//
// This file contains most of the interfaces that allow System.Web, Venus, and
// Whitehorse to customize configuration in some way.
//
// The goal of the design of customization is to only require other MS assemblies
// to create an instance of an internal object via Activator.CreateInstance(), and then
// use these objects through *public* System.Configuration.Internal interfaces.
// We do not want extenders to have to use reflection to call a method - it is slow,
// not typesafe, and more difficult to promote correct use of the internal object.
//
namespace System.Configuration.Internal {
//
// Call into System.Configuration.dll to create and initialize a Configuration object.
//
[System.Runtime.InteropServices.ComVisible(false)]
public interface IInternalConfigConfigurationFactory {
ClassConfiguration Create(Type typeConfigHost, params object[] hostInitConfigurationParams);
string NormalizeLocationSubPath(string subPath, IConfigErrorInfo errorInfo);
}
}

View File

@ -0,0 +1,112 @@
//------------------------------------------------------------------------------
// <copyright file="IInternalConfigHost.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Security;
using System.Collections.Specialized;
using System.Configuration;
using ClassConfiguration=System.Configuration.Configuration;
//
// This file contains most of the interfaces that allow System.Web, Venus, and
// Whitehorse to customize configuration in some way.
//
// The goal of the design of customization is to only require other MS assemblies
// to create an instance of an internal object via Activator.CreateInstance(), and then
// use these objects through *public* System.Configuration.Internal interfaces.
// We do not want extenders to have to use reflection to call a method - it is slow,
// not typesafe, and more difficult to promote correct use of the internal object.
//
namespace System.Configuration.Internal {
//
// The functionality required of a configuration host.
//
[System.Runtime.InteropServices.ComVisible(false)]
public interface IInternalConfigHost {
void Init(IInternalConfigRoot configRoot, params object[] hostInitParams);
void InitForConfiguration(ref string locationSubPath, out string configPath, out string locationConfigPath,
IInternalConfigRoot configRoot, params object[] hostInitConfigurationParams);
// To support creation of new config record - whether that path requires a configRecord.
bool IsConfigRecordRequired(string configPath);
bool IsInitDelayed(IInternalConfigRecord configRecord);
void RequireCompleteInit(IInternalConfigRecord configRecord);
bool IsSecondaryRoot(string configPath);
// stream support
string GetStreamName(string configPath);
string GetStreamNameForConfigSource(string streamName, string configSource);
object GetStreamVersion(string streamName);
// default impl treats name as a file name
// null means stream doesn't exist for this name
Stream OpenStreamForRead(string streamName);
Stream OpenStreamForRead(string streamName, bool assertPermissions);
[SuppressMessage("Microsoft.Design", "CA1045:DoNotPassTypesByReference", MessageId="2#")]
Stream OpenStreamForWrite(string streamName, string templateStreamName, ref object writeContext);
[SuppressMessage("Microsoft.Design", "CA1045:DoNotPassTypesByReference", MessageId="2#")]
Stream OpenStreamForWrite(string streamName, string templateStreamName, ref object writeContext, bool assertPermissions);
void WriteCompleted(string streamName, bool success, object writeContext);
void WriteCompleted(string streamName, bool success, object writeContext, bool assertPermissions);
void DeleteStream(string streamName);
// ConfigurationErrorsException support
bool IsFile(string streamName);
// change notification support - runtime only
bool SupportsChangeNotifications {get;}
object StartMonitoringStreamForChanges(string streamName, StreamChangeCallback callback);
void StopMonitoringStreamForChanges(string streamName, StreamChangeCallback callback);
// RefreshConfig support - runtime only
bool SupportsRefresh {get;}
// path support: whether we support Path attribute in location.
bool SupportsPath {get;}
// location support
bool SupportsLocation {get;}
bool IsAboveApplication(string configPath);
string GetConfigPathFromLocationSubPath(string configPath, string locationSubPath);
bool IsLocationApplicable(string configPath);
// definition support
bool IsDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition);
void VerifyDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo);
// security support
bool IsTrustedConfigPath(string configPath);
bool IsFullTrustSectionWithoutAptcaAllowed(IInternalConfigRecord configRecord);
void GetRestrictedPermissions(IInternalConfigRecord configRecord, out PermissionSet permissionSet, out bool isHostReady);
IDisposable Impersonate();
// prefetch support
bool PrefetchAll(string configPath, string streamName); // E.g. If the config file is downloaded from HTTP, we want to prefetch everything.
bool PrefetchSection(string sectionGroupName, string sectionName);
// context support
object CreateDeprecatedConfigContext(string configPath);
object CreateConfigurationContext(string configPath, string locationSubPath);
// Encrypt/decrypt support
string DecryptSection(string encryptedXml, ProtectedConfigurationProvider protectionProvider, ProtectedConfigurationSection protectedConfigSection);
string EncryptSection(string clearTextXml, ProtectedConfigurationProvider protectionProvider, ProtectedConfigurationSection protectedConfigSection);
// Type name support
// E.g. to support type defined in app_code
Type GetConfigType(string typeName, bool throwOnError);
string GetConfigTypeName(Type t);
// Remote support
// Used by MgmtConfigurationRecord during SaveAs
bool IsRemote {get;}
}
}

View File

@ -0,0 +1,38 @@
//------------------------------------------------------------------------------
// <copyright file="IInternalConfigRecord.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.IO;
using System.Security;
using System.Collections.Specialized;
using System.Configuration;
using ClassConfiguration=System.Configuration.Configuration;
//
// This file contains most of the interfaces that allow System.Web, Venus, and
// Whitehorse to customize configuration in some way.
//
// The goal of the design of customization is to only require other MS assemblies
// to create an instance of an internal object via Activator.CreateInstance(), and then
// use these objects through *public* System.Configuration.Internal interfaces.
// We do not want extenders to have to use reflection to call a method - it is slow,
// not typesafe, and more difficult to promote correct use of the internal object.
//
namespace System.Configuration.Internal {
// Exposes the functionality of BaseConfigurationRecord.
[System.Runtime.InteropServices.ComVisible(false)]
public interface IInternalConfigRecord {
string ConfigPath {get;}
string StreamName {get;}
bool HasInitErrors {get;}
void ThrowIfInitErrors();
object GetSection(string configKey);
object GetLkgSection(string configKey);
void RefreshSection(string configKey);
void Remove();
}
}

View File

@ -0,0 +1,42 @@
//------------------------------------------------------------------------------
// <copyright file="IInternalConfigRoot.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.IO;
using System.Security;
using System.Collections.Specialized;
using System.Configuration;
using ClassConfiguration=System.Configuration.Configuration;
//
// This file contains most of the interfaces that allow System.Web, Venus, and
// Whitehorse to customize configuration in some way.
//
// The goal of the design of customization is to only require other MS assemblies
// to create an instance of an internal object via Activator.CreateInstance(), and then
// use these objects through *public* System.Configuration.Internal interfaces.
// We do not want extenders to have to use reflection to call a method - it is slow,
// not typesafe, and more difficult to promote correct use of the internal object.
//
namespace System.Configuration.Internal {
// Exposes the functionality of InternalConfigRoot.
[System.Runtime.InteropServices.ComVisible(false)]
public interface IInternalConfigRoot {
void Init(IInternalConfigHost host, bool isDesignTime);
bool IsDesignTime {get;}
event InternalConfigEventHandler ConfigChanged;
event InternalConfigEventHandler ConfigRemoved;
object GetSection(string section, string configPath);
// Get the configPath of the nearest ancestor that has the config data
string GetUniqueConfigPath(string configPath);
IInternalConfigRecord GetUniqueConfigRecord(string configPath);
IInternalConfigRecord GetConfigRecord(string configPath);
void RemoveConfig(string configPath);
}
}

View File

@ -0,0 +1,35 @@
//------------------------------------------------------------------------------
// <copyright file="IInternalConfigSettingsFactory.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.IO;
using System.Security;
using System.Collections.Specialized;
using System.Configuration;
using ClassConfiguration=System.Configuration.Configuration;
//
// This file contains most of the interfaces that allow System.Web, Venus, and
// Whitehorse to customize configuration in some way.
//
// The goal of the design of customization is to only require other MS assemblies
// to create an instance of an internal object via Activator.CreateInstance(), and then
// use these objects through *public* System.Configuration.Internal interfaces.
// We do not want extenders to have to use reflection to call a method - it is slow,
// not typesafe, and more difficult to promote correct use of the internal object.
//
namespace System.Configuration.Internal {
//
// Used by System.Web.Configuration.HttpConfigurationSystem to set the
// configuration system for the ConfigurationSettings class.
//
[System.Runtime.InteropServices.ComVisible(false)]
public interface IInternalConfigSettingsFactory {
void SetConfigurationSystem(IInternalConfigSystem internalConfigSystem, bool initComplete);
void CompleteInit();
}
}

View File

@ -0,0 +1,42 @@
//------------------------------------------------------------------------------
// <copyright file="IInternalConfigSystem.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.IO;
using System.Security;
using System.Collections.Specialized;
using System.Configuration;
using ClassConfiguration=System.Configuration.Configuration;
//
// This file contains most of the interfaces that allow System.Web, Venus, and
// Whitehorse to customize configuration in some way.
//
// The goal of the design of customization is to only require other MS assemblies
// to create an instance of an internal object via Activator.CreateInstance(), and then
// use these objects through *public* System.Configuration.Internal interfaces.
// We do not want extenders to have to use reflection to call a method - it is slow,
// not typesafe, and more difficult to promote correct use of the internal object.
//
namespace System.Configuration.Internal {
//
// Methods called by ConfigurationSettings on the configuration system.
//
[System.Runtime.InteropServices.ComVisible(false)]
public interface IInternalConfigSystem {
// Returns the config object for the specified key.
// It's actually GetSection
object GetSection(string configKey);
// Refreshes the configuration system.
// It's actually RefreshSection
void RefreshConfig(string sectionName);
// Supports user config
bool SupportsUserConfig {get;}
}
}

View File

@ -0,0 +1,36 @@
//------------------------------------------------------------------------------
// <copyright file="InternalConfigConfigurationFactory.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;
namespace System.Configuration.Internal {
//
// Class used to create and initialize an instance of the Configuration class
// from assemblies other than System.
//
internal sealed class InternalConfigConfigurationFactory : IInternalConfigConfigurationFactory {
private InternalConfigConfigurationFactory() {}
ClassConfiguration IInternalConfigConfigurationFactory.Create(Type typeConfigHost, params object[] hostInitConfigurationParams) {
return new ClassConfiguration(null, typeConfigHost, hostInitConfigurationParams);
}
// Normalize a locationSubpath argument
string IInternalConfigConfigurationFactory.NormalizeLocationSubPath(string subPath, IConfigErrorInfo errorInfo) {
return BaseConfigurationRecord.NormalizeLocationSubPath(subPath, errorInfo);
}
}
}

View File

@ -0,0 +1,36 @@
//------------------------------------------------------------------------------
// <copyright file="InternalConfigEventArgs.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Configuration.Internal {
using System.Configuration.Internal;
using System.Collections;
using System.Collections.Specialized;
using System.Configuration;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Security;
using System.Text;
using System.Xml;
using System.Threading;
//
// Event arguments for Configuration events.
//
public sealed class InternalConfigEventArgs : EventArgs {
string _configPath;
public InternalConfigEventArgs(string configPath) {
_configPath = configPath;
}
public string ConfigPath {
get {return _configPath;}
set {_configPath = value;}
}
}
}

View File

@ -0,0 +1,28 @@
//------------------------------------------------------------------------------
// <copyright file="InternalConfigEventHandler.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.IO;
using System.Security;
using System.Collections.Specialized;
using System.Configuration;
using ClassConfiguration=System.Configuration.Configuration;
//
// This file contains most of the interfaces that allow System.Web, Venus, and
// Whitehorse to customize configuration in some way.
//
// The goal of the design of customization is to only require other MS assemblies
// to create an instance of an internal object via Activator.CreateInstance(), and then
// use these objects through *public* System.Configuration.Internal interfaces.
// We do not want extenders to have to use reflection to call a method - it is slow,
// not typesafe, and more difficult to promote correct use of the internal object.
//
namespace System.Configuration.Internal {
// Event handler for configuration events.
public delegate void InternalConfigEventHandler(object sender, InternalConfigEventArgs e);
}

View File

@ -0,0 +1,452 @@
//------------------------------------------------------------------------------
// <copyright file="InternalConfigHost.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Configuration.Internal {
using Microsoft.Win32;
using System.Diagnostics.CodeAnalysis;
using System.CodeDom.Compiler;
using System.Configuration;
using System.IO;
using System.Reflection;
using System.Security;
#if !FEATURE_PAL
using System.Security.AccessControl;
#endif
using System.Security.Permissions;
using System.Security.Policy;
using System.Threading;
//
// An IInternalConfigHost with common implementations of some file functions.
//
internal sealed class InternalConfigHost : IInternalConfigHost {
private IInternalConfigRoot _configRoot;
internal InternalConfigHost() {
}
void IInternalConfigHost.Init(IInternalConfigRoot configRoot, params object[] hostInitParams) {
_configRoot = configRoot;
}
void IInternalConfigHost.InitForConfiguration(ref string locationSubPath, out string configPath, out string locationConfigPath,
IInternalConfigRoot configRoot, params object[] hostInitConfigurationParams) {
_configRoot = configRoot;
configPath = null;
locationConfigPath = null;
}
// config path support
bool IInternalConfigHost.IsConfigRecordRequired(string configPath) {
return true;
}
bool IInternalConfigHost.IsInitDelayed(IInternalConfigRecord configRecord) {
return false;
}
void IInternalConfigHost.RequireCompleteInit(IInternalConfigRecord configRecord) {
}
// IsSecondaryRoot
//
// In the default there are no secondary root's
//
public bool IsSecondaryRoot(string configPath) {
return false;
}
// stream support
string IInternalConfigHost.GetStreamName(string configPath) {
throw ExceptionUtil.UnexpectedError("IInternalConfigHost.GetStreamName");
}
[FileIOPermission(SecurityAction.Assert, AllFiles = FileIOPermissionAccess.PathDiscovery)]
[SuppressMessage("Microsoft.Security", "CA2106:SecureAsserts", Justification = "The callers don't leak this information.")]
static internal string StaticGetStreamNameForConfigSource(string streamName, string configSource) {
//
// Note ([....] 7/08/05):
// RemoteWebConfigurationHost also redirects GetStreamNameForConfigSource to this
// method, and that means streamName is referring to a path that's on the remote
// machine. The problem is that Path.GetFullPath will demand FileIOPermission on
// that file and *assume* the file is referring to one on the local machine.
// This can be a potential problem for RemoteWebConfigurationHost. However, since
// we Assert the PathDiscovery permission at this method, so this problem is handled
// and we're okay. But in the future if we modify this method to handle anything
// that assumes streamName is a local path, then RemoteWebConfigurationHost has to
// override GetStreamNameForConfigSource.
//
// don't allow relative paths for stream name
if (!Path.IsPathRooted(streamName)) {
throw ExceptionUtil.ParameterInvalid("streamName");
}
// get the path part of the original stream
streamName = Path.GetFullPath(streamName);
string dirStream = UrlPath.GetDirectoryOrRootName(streamName);
// combine with the new config source
string result = Path.Combine(dirStream, configSource);
result = Path.GetFullPath(result);
// ensure the result is in or under the directory of the original source
string dirResult = UrlPath.GetDirectoryOrRootName(result);
if (!UrlPath.IsEqualOrSubdirectory(dirStream, dirResult)) {
throw new ArgumentException(SR.GetString(SR.Config_source_not_under_config_dir, configSource));
}
return result;
}
string IInternalConfigHost.GetStreamNameForConfigSource(string streamName, string configSource) {
return StaticGetStreamNameForConfigSource(streamName, configSource);
}
static internal object StaticGetStreamVersion(string streamName) {
bool exists = false;
long fileSize = 0;
DateTime utcCreationTime = DateTime.MinValue;
DateTime utcLastWriteTime = DateTime.MinValue;
UnsafeNativeMethods.WIN32_FILE_ATTRIBUTE_DATA data;
if ( UnsafeNativeMethods.GetFileAttributesEx(streamName, UnsafeNativeMethods.GetFileExInfoStandard, out data) &&
(data.fileAttributes & (int) FileAttributes.Directory) == 0) {
exists = true;
fileSize = (long)(uint)data.fileSizeHigh << 32 | (long)(uint)data.fileSizeLow;
utcCreationTime = DateTime.FromFileTimeUtc(((long)data.ftCreationTimeHigh) << 32 | (long)data.ftCreationTimeLow);
utcLastWriteTime = DateTime.FromFileTimeUtc(((long)data.ftLastWriteTimeHigh) << 32 | (long)data.ftLastWriteTimeLow);
}
return new FileVersion(exists, fileSize, utcCreationTime, utcLastWriteTime);
}
object IInternalConfigHost.GetStreamVersion(string streamName) {
return StaticGetStreamVersion(streamName);
}
// default impl treats name as a file name
// null means stream doesn't exist for this name
static internal Stream StaticOpenStreamForRead(string streamName) {
if (string.IsNullOrEmpty(streamName)) {
throw ExceptionUtil.UnexpectedError("InternalConfigHost::StaticOpenStreamForRead");
}
if (!FileUtil.FileExists(streamName, true))
return null;
// consider: FileShare.Delete is not exposed by FileShare enumeration
return new FileStream(streamName, FileMode.Open, FileAccess.Read, FileShare.Read);
}
Stream IInternalConfigHost.OpenStreamForRead(string streamName) {
return ((IInternalConfigHost)this).OpenStreamForRead(streamName, false);
}
// Okay to suppress, since this is callable only through internal interfaces.
[SuppressMessage("Microsoft.Security", "CA2103:ReviewImperativeSecurity")]
Stream IInternalConfigHost.OpenStreamForRead(string streamName, bool assertPermissions) {
Stream stream = null;
bool revertAssert = false;
//
// Runtime config: assert access to the file
// Designtime config: require caller to have all required permissions
//
// assertPermissions: if true, we'll assert permission. Used by ClientSettingsConfigurationHost.
//
if (assertPermissions || !_configRoot.IsDesignTime) {
new FileIOPermission(FileIOPermissionAccess.Read | FileIOPermissionAccess.PathDiscovery, streamName).Assert();
revertAssert = true;
}
try {
stream = StaticOpenStreamForRead(streamName);
}
finally {
if (revertAssert) {
CodeAccessPermission.RevertAssert();
}
}
return stream;
}
const FileAttributes InvalidAttributesForWrite = (FileAttributes.ReadOnly | FileAttributes.Hidden);
// This method doesn't really open the streamName for write. Instead, using WriteFileContext
// it opens a stream on a temporary file created in the same directory as streamName.
//
// Parameters:
// assertPermissions - If true, then we'll assert all required permissions. Used by ClientSettingsConfigurationHost.
// to allow low-trust apps to use ClientSettingsStore.
static internal Stream StaticOpenStreamForWrite(string streamName, string templateStreamName, ref object writeContext, bool assertPermissions) {
bool revertAssert = false;
if (string.IsNullOrEmpty(streamName)) {
throw new ConfigurationErrorsException(SR.GetString(SR.Config_no_stream_to_write));
}
// Create directory if it does not exist.
// Ignore errors, allow any failure to come when trying to open the file.
string dir = Path.GetDirectoryName(streamName);
try {
if (!Directory.Exists(dir)) {
//
if (assertPermissions) {
new FileIOPermission(PermissionState.Unrestricted).Assert();
revertAssert = true;
}
Directory.CreateDirectory(dir);
}
}
catch {
}
finally {
if (revertAssert) {
CodeAccessPermission.RevertAssert();
}
}
Stream stream;
WriteFileContext writeFileContext = null;
revertAssert = false;
if (assertPermissions) {
// If we're asked to assert permission, we will assert allAccess on the directory (instead of just the file).
// We need to assert for the whole directory because WriteFileContext will call TempFileCollection.AddExtension,
// which will generate a temporary file and make a AllAccess Demand on that file.
// Since we don't know the name of the temporary file right now, we need to assert for the whole dir.
new FileIOPermission(FileIOPermissionAccess.AllAccess, dir).Assert();
revertAssert = true;
}
try {
writeFileContext = new WriteFileContext(streamName, templateStreamName);
if (File.Exists(streamName)) {
FileInfo fi = new FileInfo(streamName);
FileAttributes attrs = fi.Attributes;
if ((int)(attrs & InvalidAttributesForWrite) != 0) {
throw new IOException(SR.GetString(SR.Config_invalid_attributes_for_write, streamName));
}
}
try {
stream = new FileStream(writeFileContext.TempNewFilename, FileMode.Create, FileAccess.Write, FileShare.Read);
}
// Wrap all exceptions so that we provide a meaningful filename - otherwise the end user
// will just see the temporary file name, which is meaningless.
catch (Exception e) {
throw new ConfigurationErrorsException(SR.GetString(SR.Config_write_failed, streamName), e);
}
}
catch {
if (writeFileContext != null) {
writeFileContext.Complete(streamName, false);
}
throw;
}
finally {
if (revertAssert) {
CodeAccessPermission.RevertAssert();
}
}
writeContext = writeFileContext;
return stream;
}
Stream IInternalConfigHost.OpenStreamForWrite(string streamName, string templateStreamName, ref object writeContext) {
return ((IInternalConfigHost)this).OpenStreamForWrite(streamName, templateStreamName, ref writeContext, false);
}
Stream IInternalConfigHost.OpenStreamForWrite(string streamName, string templateStreamName, ref object writeContext, bool assertPermissions) {
return StaticOpenStreamForWrite(streamName, templateStreamName, ref writeContext, assertPermissions);
}
// Parameters:
// assertPermissions - If true, then we'll assert all required permissions. Used by ClientSettingsConfigurationHost.
// to allow low-trust apps to use ClientSettingsStore.
static internal void StaticWriteCompleted(string streamName, bool success, object writeContext, bool assertPermissions) {
WriteFileContext writeFileContext = (WriteFileContext) writeContext;
bool revertAssert = false;
if (assertPermissions) {
// If asked to assert permissions, we will assert allAccess on the streamName, the temporary file
// created by WriteContext, and also the directory itself. The last one is needed because
// WriteFileContext will call TempFileCollection.Dispose, which will remove a .tmp file it created.
string dir = Path.GetDirectoryName(streamName);
string[] filePaths = new string[] {streamName, writeFileContext.TempNewFilename, dir};
FileIOPermission fileIOPerm = new FileIOPermission(FileIOPermissionAccess.AllAccess, AccessControlActions.View | AccessControlActions.Change, filePaths);
fileIOPerm.Assert();
revertAssert = true;
}
try {
writeFileContext.Complete(streamName, success);
}
finally {
if (revertAssert) {
CodeAccessPermission.RevertAssert();
}
}
}
void IInternalConfigHost.WriteCompleted(string streamName, bool success, object writeContext) {
((IInternalConfigHost)this).WriteCompleted(streamName, success, writeContext, false);
}
void IInternalConfigHost.WriteCompleted(string streamName, bool success, object writeContext, bool assertPermissions) {
StaticWriteCompleted(streamName, success, writeContext, assertPermissions);
}
static internal void StaticDeleteStream(string streamName) {
File.Delete(streamName);
}
void IInternalConfigHost.DeleteStream(string streamName) {
StaticDeleteStream(streamName);
}
// ConfigurationErrorsException support
static internal bool StaticIsFile(string streamName) {
// We want to avoid loading configuration before machine.config
// is instantiated. Referencing the Uri class will cause config
// to be loaded, so we use Path.IsPathRooted.
return Path.IsPathRooted(streamName);
}
bool IInternalConfigHost.IsFile(string streamName) {
return StaticIsFile(streamName);
}
// change notification support - runtime only
bool IInternalConfigHost.SupportsChangeNotifications {
get {return false;}
}
object IInternalConfigHost.StartMonitoringStreamForChanges(string streamName, StreamChangeCallback callback) {
throw ExceptionUtil.UnexpectedError("IInternalConfigHost.StartMonitoringStreamForChanges");
}
void IInternalConfigHost.StopMonitoringStreamForChanges(string streamName, StreamChangeCallback callback) {
throw ExceptionUtil.UnexpectedError("IInternalConfigHost.StopMonitoringStreamForChanges");
}
// RefreshConfig support - runtime only
bool IInternalConfigHost.SupportsRefresh {
get {return false;}
}
// path support
bool IInternalConfigHost.SupportsPath {
get {return false;}
}
bool IInternalConfigHost.IsDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition) {
return true;
}
void IInternalConfigHost.VerifyDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo) {
}
// Do we support location tags?
bool IInternalConfigHost.SupportsLocation {
get {return false;}
}
bool IInternalConfigHost.IsAboveApplication(string configPath) {
throw ExceptionUtil.UnexpectedError("IInternalConfigHost.IsAboveApplication");
}
string IInternalConfigHost.GetConfigPathFromLocationSubPath(string configPath, string locationSubPath) {
throw ExceptionUtil.UnexpectedError("IInternalConfigHost.GetConfigPathFromLocationSubPath");
}
bool IInternalConfigHost.IsLocationApplicable(string configPath) {
throw ExceptionUtil.UnexpectedError("IInternalConfigHost.IsLocationApplicable");
}
bool IInternalConfigHost.IsTrustedConfigPath(string configPath) {
throw ExceptionUtil.UnexpectedError("IInternalConfigHost.IsTrustedConfigPath");
}
// Default implementation: ensure that the caller has full trust.
bool IInternalConfigHost.IsFullTrustSectionWithoutAptcaAllowed(IInternalConfigRecord configRecord) {
return TypeUtil.IsCallerFullTrust;
}
// security support
void IInternalConfigHost.GetRestrictedPermissions(IInternalConfigRecord configRecord, out PermissionSet permissionSet, out bool isHostReady) {
permissionSet = null;
isHostReady = true;
}
IDisposable IInternalConfigHost.Impersonate() {
return null;
}
// prefetch support
bool IInternalConfigHost.PrefetchAll(string configPath, string streamName) {
return false;
}
bool IInternalConfigHost.PrefetchSection(string sectionGroupName, string sectionName) {
return false;
}
// context support
object IInternalConfigHost.CreateDeprecatedConfigContext(string configPath) {
throw ExceptionUtil.UnexpectedError("IInternalConfigHost.CreateDeprecatedConfigContext");
}
// New Context
//
object
IInternalConfigHost.CreateConfigurationContext( string configPath,
string locationSubPath )
{
throw ExceptionUtil.UnexpectedError("IInternalConfigHost.CreateConfigurationContext");
}
// Encrypt/decrypt support
string IInternalConfigHost.DecryptSection(string encryptedXml, ProtectedConfigurationProvider protectionProvider, ProtectedConfigurationSection protectedConfigSection) {
return ProtectedConfigurationSection.DecryptSection(encryptedXml, protectionProvider);
}
string IInternalConfigHost.EncryptSection(string clearTextXml, ProtectedConfigurationProvider protectionProvider, ProtectedConfigurationSection protectedConfigSection) {
return ProtectedConfigurationSection.EncryptSection(clearTextXml, protectionProvider);
}
// Type name support
Type IInternalConfigHost.GetConfigType(string typeName, bool throwOnError) {
return Type.GetType(typeName, throwOnError);
}
string IInternalConfigHost.GetConfigTypeName(Type t) {
return t.AssemblyQualifiedName;
}
bool IInternalConfigHost.IsRemote {
get {
return false;
}
}
}
}

View File

@ -0,0 +1,364 @@
//------------------------------------------------------------------------------
// <copyright file="InternalConfigRoot.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Configuration.Internal {
using System.Configuration.Internal;
using System.Collections;
using System.Collections.Specialized;
using System.Configuration;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Security;
using System.Text;
using System.Xml;
using System.Threading;
//
// InternalConfigRoot holds the root of a configuration hierarchy.
// It managed creation, removal, and the search for BaseConfigurationRecord's.
// in a thread-safe manner.
//
// The BaseConfigurationRecord hierarchy is protected with the
// _hierarchyLock. Functions that assume that the lock as been
// taken begin with the prefix "hl", for example, "hlFindConfigRecord".
//
internal sealed class InternalConfigRoot : IInternalConfigRoot {
IInternalConfigHost _host; // host, need to create records
ReaderWriterLock _hierarchyLock; // lock to protect hierarchy
BaseConfigurationRecord _rootConfigRecord; // root config record, one level above machine.config.
bool _isDesignTime; // Is the hierarchy for runtime or designtime?
private Configuration _CurrentConfiguration = null;
public event InternalConfigEventHandler ConfigChanged;
public event InternalConfigEventHandler ConfigRemoved;
internal InternalConfigRoot() { }
internal InternalConfigRoot(Configuration currentConfiguration) {
_CurrentConfiguration = currentConfiguration;
}
void IInternalConfigRoot.Init(IInternalConfigHost host, bool isDesignTime) {
_host = host;
_isDesignTime = isDesignTime;
_hierarchyLock = new ReaderWriterLock();
// Dummy record to hold _children for root
if (_isDesignTime) {
_rootConfigRecord = MgmtConfigurationRecord.Create(this, null, string.Empty, null);
}
else {
_rootConfigRecord = (BaseConfigurationRecord) RuntimeConfigurationRecord.Create(this, null, string.Empty);
}
}
internal IInternalConfigHost Host {
get {return _host;}
}
internal BaseConfigurationRecord RootConfigRecord {
get {return _rootConfigRecord;}
}
bool IInternalConfigRoot.IsDesignTime {
get {return _isDesignTime;}
}
private void AcquireHierarchyLockForRead() {
// Protect against unexpected recursive entry on this thread.
// We do this in retail, too, because the results would be very bad if this were to fail,
// and the testing for this is not easy for all scenarios.
Debug.Assert(!_hierarchyLock.IsReaderLockHeld, "!_hierarchyLock.IsReaderLockHeld");
if (_hierarchyLock.IsReaderLockHeld) {
throw ExceptionUtil.UnexpectedError("System.Configuration.Internal.InternalConfigRoot::AcquireHierarchyLockForRead - reader lock already held by this thread");
}
Debug.Assert(!_hierarchyLock.IsWriterLockHeld, "!_hierarchyLock.IsWriterLockHeld");
if (_hierarchyLock.IsWriterLockHeld) {
throw ExceptionUtil.UnexpectedError("System.Configuration.Internal.InternalConfigRoot::AcquireHierarchyLockForRead - writer lock already held by this thread");
}
_hierarchyLock.AcquireReaderLock(-1);
}
private void ReleaseHierarchyLockForRead() {
Debug.Assert(!_hierarchyLock.IsWriterLockHeld, "!_hierarchyLock.IsWriterLockHeld");
if (_hierarchyLock.IsReaderLockHeld) {
_hierarchyLock.ReleaseReaderLock();
}
}
private void AcquireHierarchyLockForWrite() {
// Protect against unexpected recursive entry on this thread.
// We do this in retail, too, because the results would be very bad if this were to fail,
// and the testing for this is not easy for all scenarios.
if (_hierarchyLock.IsReaderLockHeld) {
throw ExceptionUtil.UnexpectedError("System.Configuration.Internal.InternalConfigRoot::AcquireHierarchyLockForWrite - reader lock already held by this thread");
}
if (_hierarchyLock.IsWriterLockHeld) {
throw ExceptionUtil.UnexpectedError("System.Configuration.Internal.InternalConfigRoot::AcquireHierarchyLockForWrite - writer lock already held by this thread");
}
_hierarchyLock.AcquireWriterLock(-1);
}
private void ReleaseHierarchyLockForWrite() {
Debug.Assert(!_hierarchyLock.IsReaderLockHeld, "!_hierarchyLock.IsReaderLockHeld");
if (_hierarchyLock.IsWriterLockHeld) {
_hierarchyLock.ReleaseWriterLock();
}
}
//
// Find a config record.
// If found, nextIndex == parts.Length and the resulting record is in currentRecord.
// If not found, nextIndex is the index of the part of the path not found, and currentRecord
// is the record that has been found so far (nexIndex - 1).
//
private void hlFindConfigRecord(string[] parts, out int nextIndex, out BaseConfigurationRecord currentRecord) {
currentRecord = _rootConfigRecord;
nextIndex = 0;
for (; nextIndex < parts.Length; nextIndex++) {
BaseConfigurationRecord childRecord = currentRecord.hlGetChild(parts[nextIndex]);
if (childRecord == null)
break;
currentRecord = childRecord;
}
}
//
// Get a config section.
//
public object GetSection(string section, string configPath) {
BaseConfigurationRecord configRecord = (BaseConfigurationRecord) GetUniqueConfigRecord(configPath);
object result = configRecord.GetSection(section);
return result;
}
//
// Get the nearest ancestor path (including self) which contains unique configuration information.
//
public string GetUniqueConfigPath(string configPath) {
IInternalConfigRecord configRecord = GetUniqueConfigRecord(configPath);
if (configRecord == null) {
return null;
}
return configRecord.ConfigPath;
}
//
// Get the nearest ancestor record (including self) which contains unique configuration information.
//
public IInternalConfigRecord GetUniqueConfigRecord(string configPath) {
BaseConfigurationRecord configRecord = (BaseConfigurationRecord) GetConfigRecord(configPath);
while (configRecord.IsEmpty) {
BaseConfigurationRecord parentConfigRecord = configRecord.Parent;
// If all config records are empty, return the immediate child of the
// root placeholder (e.g. machine.config)
if (parentConfigRecord.IsRootConfig) {
break;
}
configRecord = parentConfigRecord;
}
return configRecord;
}
//
// Get the config record for a path.
// If the record does not exist, create it if it is needed.
//
public IInternalConfigRecord GetConfigRecord(string configPath) {
if (!ConfigPathUtility.IsValid(configPath)) {
throw ExceptionUtil.ParameterInvalid("configPath");
}
string[] parts = ConfigPathUtility.GetParts(configPath);
//
// First search under the reader lock, so that multiple searches
// can proceed in parallel.
//
try {
int index;
BaseConfigurationRecord currentRecord;
AcquireHierarchyLockForRead();
hlFindConfigRecord(parts, out index, out currentRecord);
// check if found
if (index == parts.Length || !currentRecord.hlNeedsChildFor(parts[index])) {
return currentRecord;
}
}
finally {
ReleaseHierarchyLockForRead();
}
//
// Not found, so search again under exclusive writer lock so that
// we can create the record.
//
try {
int index;
BaseConfigurationRecord currentRecord;
AcquireHierarchyLockForWrite();
hlFindConfigRecord(parts, out index, out currentRecord);
if (index == parts.Length) {
return currentRecord;
}
string currentConfigPath = String.Join(BaseConfigurationRecord.ConfigPathSeparatorString, parts, 0, index);
//
// create new records
//
while (index < parts.Length && currentRecord.hlNeedsChildFor(parts[index])) {
string configName = parts[index];
currentConfigPath = ConfigPathUtility.Combine(currentConfigPath, configName);
BaseConfigurationRecord childRecord;
Debug.Trace("ConfigurationCreate", "Creating config record for " + currentConfigPath);
if (_isDesignTime) {
childRecord = MgmtConfigurationRecord.Create(this, currentRecord, currentConfigPath, null);
}
else {
childRecord = (BaseConfigurationRecord) RuntimeConfigurationRecord.Create(this, currentRecord, currentConfigPath);
}
currentRecord.hlAddChild(configName, childRecord);
index++;
currentRecord = childRecord;
}
return currentRecord;
}
finally {
ReleaseHierarchyLockForWrite();
}
}
//
// Find and remove the config record and all its children for the config path.
// Optionally ensure the config record matches a desired config record.
//
void RemoveConfigImpl(string configPath, BaseConfigurationRecord configRecord) {
if (!ConfigPathUtility.IsValid(configPath)) {
throw ExceptionUtil.ParameterInvalid("configPath");
}
string[] parts = ConfigPathUtility.GetParts(configPath);
BaseConfigurationRecord currentRecord;
// search under exclusive writer lock
try {
int index;
AcquireHierarchyLockForWrite();
hlFindConfigRecord(parts, out index, out currentRecord);
// Return if not found, or does not match the one we are trying to remove.
if (index != parts.Length || (configRecord != null && !Object.ReferenceEquals(configRecord, currentRecord)))
return;
// Remove it from the hierarchy.
currentRecord.Parent.hlRemoveChild(parts[parts.Length - 1]);
}
finally {
ReleaseHierarchyLockForWrite();
}
OnConfigRemoved(new InternalConfigEventArgs(configPath));
// Close the record. This is safe to do outside the lock.
currentRecord.CloseRecursive();
}
//
// Find and remove the config record and all its children for the config path.
//
public void RemoveConfig(string configPath) {
RemoveConfigImpl(configPath, null);
}
//
// Remove the config record and all its children for the config path.
//
public void RemoveConfigRecord(BaseConfigurationRecord configRecord) {
RemoveConfigImpl(configRecord.ConfigPath, configRecord);
}
//
// Clear the result of a configSection evaluation at a particular point
// in the hierarchy.
//
public void ClearResult(BaseConfigurationRecord configRecord, string configKey, bool forceEvaluation) {
string[] parts = ConfigPathUtility.GetParts(configRecord.ConfigPath);
try {
int index;
BaseConfigurationRecord currentRecord;
AcquireHierarchyLockForRead();
hlFindConfigRecord(parts, out index, out currentRecord);
// clear result only if configRecord it is still in the hierarchy
if (index == parts.Length && Object.ReferenceEquals(configRecord, currentRecord)) {
currentRecord.hlClearResultRecursive(configKey, forceEvaluation);
}
}
finally {
ReleaseHierarchyLockForRead();
}
}
// Fire the ConfigRemoved event.
private void OnConfigRemoved(InternalConfigEventArgs e) {
InternalConfigEventHandler handler = ConfigRemoved;
if (handler != null) {
handler(this, e);
}
}
// Fire the ConfigChanged event for a configPath.
internal void FireConfigChanged(string configPath) {
OnConfigChanged(new InternalConfigEventArgs(configPath));
}
// Fire the ConfigChanged event.
private void OnConfigChanged(InternalConfigEventArgs e) {
InternalConfigEventHandler handler = ConfigChanged;
if (handler != null) {
handler(this, e);
}
}
internal Configuration CurrentConfiguration {
get {
return _CurrentConfiguration;
}
}
}
}

View File

@ -0,0 +1,26 @@
//------------------------------------------------------------------------------
// <copyright file="InternalConfigSettingsFactory.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Configuration.Internal {
using System.Configuration;
//
// Called by System.Web.HttpConfigurationSystem to set the configuration system
// in the ConfigurationSettings class.
//
internal sealed class InternalConfigSettingsFactory : IInternalConfigSettingsFactory {
private InternalConfigSettingsFactory() {}
void IInternalConfigSettingsFactory.SetConfigurationSystem(IInternalConfigSystem configSystem, bool initComplete) {
ConfigurationManager.SetConfigurationSystem(configSystem, initComplete);
}
void IInternalConfigSettingsFactory.CompleteInit() {
ConfigurationManager.CompleteConfigInit();
}
}
}

View File

@ -0,0 +1,28 @@
//------------------------------------------------------------------------------
// <copyright file="StreamChangeCallback.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.IO;
using System.Security;
using System.Collections.Specialized;
using System.Configuration;
using ClassConfiguration=System.Configuration.Configuration;
//
// This file contains most of the interfaces that allow System.Web, Venus, and
// Whitehorse to customize configuration in some way.
//
// The goal of the design of customization is to only require other MS assemblies
// to create an instance of an internal object via Activator.CreateInstance(), and then
// use these objects through *public* System.Configuration.Internal interfaces.
// We do not want extenders to have to use reflection to call a method - it is slow,
// not typesafe, and more difficult to promote correct use of the internal object.
//
namespace System.Configuration.Internal {
// Callback for hosts to call when a stream that is being monitored has changed.
public delegate void StreamChangeCallback(string streamName);
}

Some files were not shown because too many files have changed in this diff Show More