2 // System.Configuration.InternalConfigurationHost.cs
5 // Lluis Sanchez Gual (lluis@novell.com)
7 // Permission is hereby granted, free of charge, to any person obtaining
8 // a copy of this software and associated documentation files (the
9 // "Software"), to deal in the Software without restriction, including
10 // without limitation the rights to use, copy, modify, merge, publish,
11 // distribute, sublicense, and/or sell copies of the Software, and to
12 // permit persons to whom the Software is furnished to do so, subject to
13 // the following conditions:
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
33 using System.Security;
34 using System.Configuration.Internal;
36 namespace System.Configuration
38 abstract class InternalConfigurationHost: IInternalConfigHost
40 public virtual object CreateConfigurationContext (string configPath, string locationSubPath)
45 public virtual object CreateDeprecatedConfigContext (string configPath)
47 throw new NotImplementedException ();
50 public virtual void DeleteStream (string streamName)
52 File.Delete (streamName);
55 string IInternalConfigHost.DecryptSection (string encryptedXml, ProtectedConfigurationProvider protectionProvider, ProtectedConfigurationSection protectedSection)
57 return protectedSection.DecryptSection (encryptedXml, protectionProvider);
60 string IInternalConfigHost.EncryptSection (string clearXml, ProtectedConfigurationProvider protectionProvider, ProtectedConfigurationSection protectedSection)
62 return protectedSection.EncryptSection (clearXml, protectionProvider);
65 public virtual string GetConfigPathFromLocationSubPath (string configPath, string locationSubPath)
70 public virtual Type GetConfigType (string typeName, bool throwOnError)
72 Type type = Type.GetType (typeName);
73 if (type == null && throwOnError)
74 throw new ConfigurationErrorsException ("Type '" + typeName + "' not found.");
78 public virtual string GetConfigTypeName (Type t)
80 return t.AssemblyQualifiedName;
83 public virtual void GetRestrictedPermissions (IInternalConfigRecord configRecord, out PermissionSet permissionSet, out bool isHostReady)
85 throw new NotImplementedException ();
88 public abstract string GetStreamName (string configPath);
89 public abstract void Init (IInternalConfigRoot root, params object[] hostInitParams);
90 public abstract void InitForConfiguration (ref string locationSubPath, out string configPath, out string locationConfigPath, IInternalConfigRoot root, params object[] hostInitConfigurationParams);
92 [MonoTODO ("remote config")]
93 public virtual string GetStreamNameForConfigSource (string streamName, string configSource)
95 throw new NotSupportedException ("mono does not support remote configuration");
98 public virtual object GetStreamVersion (string streamName)
100 throw new NotImplementedException ();
103 public virtual IDisposable Impersonate ()
105 throw new NotImplementedException ();
108 public virtual bool IsAboveApplication (string configPath)
110 throw new NotImplementedException ();
113 public virtual bool IsConfigRecordRequired (string configPath)
115 throw new NotImplementedException ();
118 public virtual bool IsDefinitionAllowed (string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition)
120 switch (allowDefinition) {
121 case ConfigurationAllowDefinition.MachineOnly:
122 return configPath == "machine";
123 case ConfigurationAllowDefinition.MachineToApplication:
124 return configPath == "machine" || configPath == "exe";
130 public virtual bool IsFile (string streamName)
132 throw new NotImplementedException ();
135 public virtual bool IsFullTrustSectionWithoutAptcaAllowed (IInternalConfigRecord configRecord)
137 throw new NotImplementedException ();
140 public virtual bool IsInitDelayed (IInternalConfigRecord configRecord)
142 throw new NotImplementedException ();
145 public virtual bool IsLocationApplicable (string configPath)
147 throw new NotImplementedException ();
150 public virtual bool IsRemote {
152 throw new NotImplementedException ();
156 public virtual bool IsSecondaryRoot (string configPath)
158 throw new NotImplementedException ();
161 public virtual bool IsTrustedConfigPath (string configPath)
163 throw new NotImplementedException ();
166 public virtual Stream OpenStreamForRead (string streamName)
169 if (String.CompareOrdinal (streamName, "/machine.config") == 0)
170 return (Stream) vmw.common.IOUtils.getStreamForGHConfigs (streamName);
172 if (!File.Exists (streamName))
173 throw new ConfigurationException ("File '" + streamName + "' not found");
175 return new FileStream (streamName, FileMode.Open, FileAccess.Read);
178 public virtual Stream OpenStreamForRead (string streamName, bool assertPermissions)
180 throw new NotImplementedException ();
183 public virtual Stream OpenStreamForWrite (string streamName, string templateStreamName, ref object writeContext)
185 return new FileStream (streamName, FileMode.Create, FileAccess.Write);
188 public virtual Stream OpenStreamForWrite (string streamName, string templateStreamName, ref object writeContext, bool assertPermissions)
190 throw new NotImplementedException ();
193 public virtual bool PrefetchAll (string configPath, string streamName)
195 throw new NotImplementedException ();
198 public virtual bool PrefetchSection (string sectionGroupName, string sectionName)
200 throw new NotImplementedException ();
203 public virtual void RequireCompleteInit (IInternalConfigRecord configRecord)
205 throw new NotImplementedException ();
208 public virtual object StartMonitoringStreamForChanges (string streamName, StreamChangeCallback callback)
210 throw new NotImplementedException ();
213 public virtual void StopMonitoringStreamForChanges (string streamName, StreamChangeCallback callback)
215 throw new NotImplementedException ();
218 public virtual void VerifyDefinitionAllowed (string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo)
220 if (!IsDefinitionAllowed (configPath, allowDefinition, allowExeDefinition))
221 throw new ConfigurationErrorsException ("The section can't be defined in this file (the allowed definition context is '" + allowDefinition + "').", errorInfo.Filename, errorInfo.LineNumber);
224 public virtual void WriteCompleted (string streamName, bool success, object writeContext)
228 public virtual void WriteCompleted (string streamName, bool success, object writeContext, bool assertPermissions)
232 public virtual bool SupportsChangeNotifications {
233 get { return false; }
236 public virtual bool SupportsLocation {
237 get { return false; }
240 public virtual bool SupportsPath {
241 get { return false; }
244 public virtual bool SupportsRefresh {
245 get { return false; }
249 class ExeConfigurationHost: InternalConfigurationHost
251 ExeConfigurationFileMap map;
253 public override void Init (IInternalConfigRoot root, params object[] hostInitParams)
255 map = (ExeConfigurationFileMap) hostInitParams [0];
258 public override string GetStreamName (string configPath)
260 switch (configPath) {
261 case "exe": return map.ExeConfigFilename;
262 case "local": return map.LocalUserConfigFilename;
263 case "roaming": return map.LocalUserConfigFilename;
264 case "machine": return map.MachineConfigFilename;
265 default: return map.ExeConfigFilename;
269 public override void InitForConfiguration (ref string locationSubPath, out string configPath, out string locationConfigPath, IInternalConfigRoot root, params object[] hostInitConfigurationParams)
271 map = (ExeConfigurationFileMap) hostInitConfigurationParams [0];
275 locationConfigPath = null;
277 if ((locationSubPath == "exe" || locationSubPath == null) && map.ExeConfigFilename != null) {
280 locationConfigPath = map.ExeConfigFilename;
283 if ((locationSubPath == "local" || configPath == null) && map.LocalUserConfigFilename != null) {
284 configPath = "local";
286 locationConfigPath = map.LocalUserConfigFilename;
289 if ((locationSubPath == "roaming" || configPath == null) && map.RoamingUserConfigFilename != null) {
290 configPath = "roaming";
292 locationConfigPath = map.RoamingUserConfigFilename;
295 if ((locationSubPath == "machine" || configPath == null) && map.MachineConfigFilename != null) {
296 configPath = "machine";
300 locationSubPath = next;
304 class MachineConfigurationHost: InternalConfigurationHost
306 ConfigurationFileMap map;
308 public override void Init (IInternalConfigRoot root, params object[] hostInitParams)
310 map = (ConfigurationFileMap) hostInitParams [0];
313 public override string GetStreamName (string configPath)
315 return map.MachineConfigFilename;
318 public override void InitForConfiguration (ref string locationSubPath, out string configPath, out string locationConfigPath, IInternalConfigRoot root, params object[] hostInitConfigurationParams)
320 map = (ConfigurationFileMap) hostInitConfigurationParams [0];
321 locationSubPath = null;
323 locationConfigPath = null;