forked from microsoft/referencesource
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding reference source for System.Configuration
- Loading branch information
1 parent
0055506
commit 7470633
Showing
179 changed files
with
32,097 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
[module: SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope="member", Target="System.Configuration.SR.GetString(System.String,System.Boolean&):System.String")] |
36 changes: 36 additions & 0 deletions
36
System.Configuration/Microsoft/Win32/SafeCryptContextHandle.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//------------------------------------------------------------------------------ | ||
// <copyright file="UnsafeNativeMethods.cs" company="Microsoft"> | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// </copyright> | ||
//------------------------------------------------------------------------------ | ||
|
||
namespace Microsoft.Win32 { | ||
using System; | ||
using System.Security.Permissions; | ||
using Microsoft.Win32.SafeHandles; | ||
using System.Configuration; | ||
|
||
// Safehandle for crypt context handles | ||
[System.Security.SuppressUnmanagedCodeSecurityAttribute()] | ||
internal sealed class SafeCryptContextHandle : SafeHandleZeroOrMinusOneIsInvalid { | ||
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)] | ||
internal SafeCryptContextHandle() | ||
: base(true) { | ||
} | ||
|
||
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)] | ||
internal SafeCryptContextHandle(IntPtr handle, bool ownsHandle) | ||
: base(ownsHandle) { | ||
SetHandle(handle); | ||
} | ||
|
||
override protected bool ReleaseHandle() { | ||
if (handle != IntPtr.Zero) { | ||
UnsafeNativeMethods.CryptReleaseContext(this, 0); | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
} | ||
|
53 changes: 53 additions & 0 deletions
53
System.Configuration/Microsoft/Win32/SafeNativeMemoryHandle.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//------------------------------------------------------------------------------ | ||
// <copyright file="UnsafeNativeMethods.cs" company="Microsoft"> | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// </copyright> | ||
//------------------------------------------------------------------------------ | ||
|
||
namespace Microsoft.Win32 { | ||
using System.Runtime.InteropServices; | ||
using System; | ||
using System.Security.Permissions; | ||
using Microsoft.Win32.SafeHandles; | ||
using System.Configuration; | ||
|
||
// Safehandle for memory handles | ||
[System.Security.SuppressUnmanagedCodeSecurityAttribute()] | ||
internal sealed class SafeNativeMemoryHandle : SafeHandleZeroOrMinusOneIsInvalid { | ||
private bool _useLocalFree = false; | ||
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)] | ||
internal SafeNativeMemoryHandle() | ||
: this(false) { | ||
} | ||
|
||
internal SafeNativeMemoryHandle(bool useLocalFree) | ||
: base(true) { | ||
_useLocalFree = useLocalFree; | ||
} | ||
|
||
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)] | ||
internal SafeNativeMemoryHandle(IntPtr handle, bool ownsHandle) | ||
: base(ownsHandle) { | ||
SetHandle(handle); | ||
} | ||
|
||
internal void SetDataHandle(IntPtr handle) { | ||
SetHandle(handle); | ||
} | ||
|
||
override protected bool ReleaseHandle() { | ||
if (handle != IntPtr.Zero) { | ||
if (_useLocalFree == true) | ||
UnsafeNativeMethods.LocalFree(handle); | ||
else | ||
Marshal.FreeHGlobal(handle); | ||
handle = IntPtr.Zero; | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
|
||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//------------------------------------------------------------------------------ | ||
// <copyright file="SafeNativeMethods.cs" company="Microsoft"> | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// </copyright> | ||
//------------------------------------------------------------------------------ | ||
|
||
namespace Microsoft.Win32 { | ||
using System.Runtime.InteropServices; | ||
using System; | ||
using System.Security.Permissions; | ||
using System.Collections; | ||
using System.IO; | ||
using System.Text; | ||
using System.Threading; | ||
using Microsoft.Win32.SafeHandles; | ||
|
||
[ | ||
System.Security.SuppressUnmanagedCodeSecurityAttribute() | ||
] | ||
internal static class SafeNativeMethods { | ||
#if NOPERF | ||
[DllImport(ExternDll.Kernel32, SetLastError=true)] | ||
internal static extern bool QueryPerformanceCounter(out long value); | ||
|
||
[DllImport(ExternDll.Kernel32, SetLastError=true)] | ||
internal static extern bool QueryPerformanceFrequency(out long value); | ||
#endif | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
System.Configuration/Microsoft/Win32/UnsafeNativeMethods.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
//------------------------------------------------------------------------------ | ||
// <copyright file="UnsafeNativeMethods.cs" company="Microsoft"> | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// </copyright> | ||
//------------------------------------------------------------------------------ | ||
|
||
namespace Microsoft.Win32 { | ||
using System.Runtime.InteropServices; | ||
using System.Threading; | ||
using System; | ||
using System.Security.Permissions; | ||
using System.Collections; | ||
using System.IO; | ||
using System.Text; | ||
using Microsoft.Win32.SafeHandles; | ||
using System.Configuration; | ||
|
||
[ | ||
System.Security.SuppressUnmanagedCodeSecurityAttribute() | ||
] | ||
internal static class UnsafeNativeMethods { | ||
[DllImport(ExternDll.Kernel32, SetLastError=true, CharSet=CharSet.Auto, BestFitMapping=false)] | ||
internal static extern bool GetFileAttributesEx(string name, int fileInfoLevel, out WIN32_FILE_ATTRIBUTE_DATA data); | ||
|
||
internal const int GetFileExInfoStandard = 0; | ||
|
||
[StructLayout(LayoutKind.Sequential)] | ||
internal struct WIN32_FILE_ATTRIBUTE_DATA { | ||
internal int fileAttributes; | ||
internal uint ftCreationTimeLow; | ||
internal uint ftCreationTimeHigh; | ||
internal uint ftLastAccessTimeLow; | ||
internal uint ftLastAccessTimeHigh; | ||
internal uint ftLastWriteTimeLow; | ||
internal uint ftLastWriteTimeHigh; | ||
internal uint fileSizeHigh; | ||
internal uint fileSizeLow; | ||
} | ||
|
||
[DllImport(ExternDll.Kernel32, CharSet=CharSet.Auto, BestFitMapping=false)] | ||
internal static extern int GetModuleFileName(HandleRef hModule, StringBuilder buffer, int length); | ||
|
||
#if !FEATURE_PAL | ||
[DllImport(ExternDll.Crypt32, SetLastError=true, CharSet=CharSet.Unicode)] | ||
internal extern static bool CryptProtectData(ref DATA_BLOB inputData, string description, ref DATA_BLOB entropy, IntPtr pReserved, ref CRYPTPROTECT_PROMPTSTRUCT promptStruct, UInt32 flags, ref DATA_BLOB outputData); | ||
|
||
[DllImport(ExternDll.Crypt32, SetLastError= true, CharSet=CharSet.Unicode)] | ||
internal extern static bool CryptUnprotectData(ref DATA_BLOB inputData, IntPtr description, ref DATA_BLOB entropy, IntPtr pReserved, ref CRYPTPROTECT_PROMPTSTRUCT promptStruct, UInt32 flags, ref DATA_BLOB outputData); | ||
|
||
[DllImport(ExternDll.Advapi32, SetLastError=true, CharSet=CharSet.Unicode)] | ||
internal extern static int CryptAcquireContext(out SafeCryptContextHandle phProv, string pszContainer, string pszProvider, uint dwProvType, uint dwFlags); | ||
|
||
[DllImport(ExternDll.Advapi32, SetLastError=true, CharSet=CharSet.Unicode)] | ||
internal extern static int CryptReleaseContext(SafeCryptContextHandle hProv, uint dwFlags); | ||
|
||
[DllImport(ExternDll.Kernel32, CharSet=CharSet.Auto)] | ||
internal extern static IntPtr LocalFree(IntPtr buf); | ||
#endif | ||
|
||
// MoveFile Parameter | ||
internal const int MOVEFILE_REPLACE_EXISTING = 0x00000001; | ||
|
||
[DllImport(ExternDll.Kernel32, CharSet=CharSet.Auto, BestFitMapping=false)] | ||
internal static extern bool MoveFileEx(string lpExistingFileName, string lpNewFileName, int dwFlags); | ||
} | ||
} |
162 changes: 162 additions & 0 deletions
162
System.Configuration/System/Configuration/AppSettingsSection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.