using System.IO;
using System.Security;
using System.Configuration.Internal;
+using System.Runtime.CompilerServices;
namespace System.Configuration
{
- class InternalConfigurationHost: IInternalConfigHost
+ abstract class InternalConfigurationHost: IInternalConfigHost
{
public virtual object CreateConfigurationContext (string configPath, string locationSubPath)
{
public virtual object CreateDeprecatedConfigContext (string configPath)
{
- throw new NotImplementedException ();
+ return null;
}
- public virtual string DecryptSection (string encryptedXml, ProtectedConfigurationProvider protectionProvider, ProtectedConfigurationSection protectedSection)
+ public virtual void DeleteStream (string streamName)
{
- throw new NotImplementedException ();
+ File.Delete (streamName);
}
- public virtual void DeleteStream (string streamName)
+ string IInternalConfigHost.DecryptSection (string encryptedXml, ProtectedConfigurationProvider protectionProvider, ProtectedConfigurationSection protectedSection)
{
- File.Delete (streamName);
+ return protectedSection.DecryptSection (encryptedXml, protectionProvider);
}
- public virtual string EncryptSection (string encryptedXml, ProtectedConfigurationProvider protectionProvider, ProtectedConfigurationSection protectedSection)
+ string IInternalConfigHost.EncryptSection (string clearXml, ProtectedConfigurationProvider protectionProvider, ProtectedConfigurationSection protectedSection)
{
- throw new NotImplementedException ();
+ return protectedSection.EncryptSection (clearXml, protectionProvider);
}
public virtual string GetConfigPathFromLocationSubPath (string configPath, string locationSubPath)
throw new NotImplementedException ();
}
- public virtual string GetStreamName (string configPath)
- {
- throw new NotImplementedException ();
- }
-
+ public abstract string GetStreamName (string configPath);
+ public abstract void Init (IInternalConfigRoot root, params object[] hostInitParams);
+ public abstract void InitForConfiguration (ref string locationSubPath, out string configPath, out string locationConfigPath, IInternalConfigRoot root, params object[] hostInitConfigurationParams);
+
+ [MonoNotSupported ("mono does not support remote configuration")]
public virtual string GetStreamNameForConfigSource (string streamName, string configSource)
{
- throw new NotImplementedException ();
+ throw new NotSupportedException ("mono does not support remote configuration");
}
public virtual object GetStreamVersion (string streamName)
throw new NotImplementedException ();
}
- public virtual void Init (IInternalConfigRoot root, params object[] hostInitParams)
- {
- }
-
- public virtual void InitForConfiguration (ref string locationSubPath, out string configPath, out string locationConfigPath, IInternalConfigRoot root, params object[] hostInitConfigurationParams)
- {
- throw new NotImplementedException ();
- }
-
public virtual bool IsAboveApplication (string configPath)
{
throw new NotImplementedException ();
{
throw new NotImplementedException ();
}
+#if !TARGET_JVM
+ [MethodImplAttribute(MethodImplOptions.InternalCall)]
+ extern private static string get_bundled_machine_config ();
+#endif
public virtual Stream OpenStreamForRead (string streamName)
{
+ if (String.CompareOrdinal (streamName, System.Runtime.InteropServices.RuntimeEnvironment.SystemConfigurationFile) == 0) {
+#if TARGET_JVM
+ return (Stream) vmw.common.IOUtils.getStreamForGHConfigs (streamName);
+#else
+ string bundle = get_bundled_machine_config ();
+ if (bundle != null)
+ return new MemoryStream (System.Text.Encoding.UTF8.GetBytes (bundle));
+#endif
+ }
+
if (!File.Exists (streamName))
throw new ConfigurationException ("File '" + streamName + "' not found");
public virtual Stream OpenStreamForWrite (string streamName, string templateStreamName, ref object writeContext)
{
+ string dir = Path.GetDirectoryName (streamName);
+ if (!Directory.Exists (dir))
+ Directory.CreateDirectory (dir);
return new FileStream (streamName, FileMode.Create, FileAccess.Write);
}
class ExeConfigurationHost: InternalConfigurationHost
{
ExeConfigurationFileMap map;
+ ConfigurationUserLevel level;
public override void Init (IInternalConfigRoot root, params object[] hostInitParams)
{
map = (ExeConfigurationFileMap) hostInitParams [0];
+ level = (ConfigurationUserLevel) hostInitParams [1];
}
public override string GetStreamName (string configPath)
switch (configPath) {
case "exe": return map.ExeConfigFilename;
case "local": return map.LocalUserConfigFilename;
- case "roaming": return map.LocalUserConfigFilename;
+ case "roaming": return map.RoamingUserConfigFilename;
case "machine": return map.MachineConfigFilename;
- default: return map.ExeConfigFilename;
+ default://return map.ExeConfigFilename;
+ switch (level) {
+ case ConfigurationUserLevel.None:
+ return map.ExeConfigFilename;
+ case ConfigurationUserLevel.PerUserRoaming:
+ return map.RoamingUserConfigFilename;
+ case ConfigurationUserLevel.PerUserRoamingAndLocal:
+ return map.LocalUserConfigFilename;
+ default:
+ return map.MachineConfigFilename;
+ }
}
}
public override void InitForConfiguration (ref string locationSubPath, out string configPath, out string locationConfigPath, IInternalConfigRoot root, params object[] hostInitConfigurationParams)
{
map = (ExeConfigurationFileMap) hostInitConfigurationParams [0];
+
+ if (hostInitConfigurationParams.Length > 1 &&
+ hostInitConfigurationParams [1] is ConfigurationUserLevel)
+ level = (ConfigurationUserLevel) hostInitConfigurationParams [1];
+ if (locationSubPath == null)
+ switch (level) {
+ case ConfigurationUserLevel.PerUserRoaming:
+ if (map.RoamingUserConfigFilename == null)
+ throw new ArgumentException ("RoamingUserConfigFilename must be set correctly");
+ locationSubPath = "roaming";
+ break;
+ case ConfigurationUserLevel.PerUserRoamingAndLocal:
+ if (map.LocalUserConfigFilename == null)
+ throw new ArgumentException ("LocalUserConfigFilename must be set correctly");
+ locationSubPath = "local";
+ break;
+ }
+
configPath = null;
string next = null;
locationConfigPath = null;
- if ((locationSubPath == "exe" || locationSubPath == null) && map.ExeConfigFilename != null) {
+ if (locationSubPath == "exe" || locationSubPath == null && map.ExeConfigFilename != null) {
configPath = "exe";
next = "local";
locationConfigPath = map.ExeConfigFilename;
}
- if ((locationSubPath == "local" || configPath == null) && map.LocalUserConfigFilename != null) {
+ if (locationSubPath == "local" && map.LocalUserConfigFilename != null) {
configPath = "local";
next = "roaming";
locationConfigPath = map.LocalUserConfigFilename;
}
- if ((locationSubPath == "roaming" || configPath == null) && map.RoamingUserConfigFilename != null) {
+ if (locationSubPath == "roaming" && map.RoamingUserConfigFilename != null) {
configPath = "roaming";
next = "machine";
locationConfigPath = map.RoamingUserConfigFilename;
configPath = "machine";
next = null;
}
-
locationSubPath = next;
}
}
configPath = null;
locationConfigPath = null;
}
- }
+
+ public override bool IsDefinitionAllowed (string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition)
+ {
+ return true;
+ }
+ }
}
#endif