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 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 string DecryptSection (string encryptedXml, ProtectedConfigurationProvider protectionProvider, ProtectedConfigurationSection protectedSection)
52 throw new NotImplementedException ();
55 public virtual void DeleteStream (string streamName)
57 File.Delete (streamName);
60 public virtual string EncryptSection (string encryptedXml, ProtectedConfigurationProvider protectionProvider, ProtectedConfigurationSection protectedSection)
62 throw new NotImplementedException ();
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 virtual string GetStreamName (string configPath)
90 throw new NotImplementedException ();
93 public virtual string GetStreamNameForConfigSource (string streamName, string configSource)
95 throw new NotImplementedException ();
98 public virtual object GetStreamVersion (string streamName)
100 throw new NotImplementedException ();
103 public virtual IDisposable Impersonate ()
105 throw new NotImplementedException ();
108 public virtual void Init (IInternalConfigRoot root, params object[] hostInitParams)
112 public virtual void InitForConfiguration (ref string locationSubPath, out string configPath, out string locationConfigPath, IInternalConfigRoot root, params object[] hostInitConfigurationParams)
114 throw new NotImplementedException ();
117 public virtual bool IsAboveApplication (string configPath)
119 throw new NotImplementedException ();
122 public virtual bool IsConfigRecordRequired (string configPath)
124 throw new NotImplementedException ();
127 public virtual bool IsDefinitionAllowed (string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition)
129 switch (allowDefinition) {
130 case ConfigurationAllowDefinition.MachineOnly:
131 return configPath == "machine";
132 case ConfigurationAllowDefinition.MachineToApplication:
133 return configPath == "machine" || configPath == "exe";
139 public virtual bool IsFile (string streamName)
141 throw new NotImplementedException ();
144 public virtual bool IsFullTrustSectionWithoutAptcaAllowed (IInternalConfigRecord configRecord)
146 throw new NotImplementedException ();
149 public virtual bool IsInitDelayed (IInternalConfigRecord configRecord)
151 throw new NotImplementedException ();
154 public virtual bool IsLocationApplicable (string configPath)
156 throw new NotImplementedException ();
159 public virtual bool IsRemote {
161 throw new NotImplementedException ();
165 public virtual bool IsSecondaryRoot (string configPath)
167 throw new NotImplementedException ();
170 public virtual bool IsTrustedConfigPath (string configPath)
172 throw new NotImplementedException ();
175 public virtual Stream OpenStreamForRead (string streamName)
177 if (!File.Exists (streamName))
178 throw new ConfigurationException ("File '" + streamName + "' not found");
180 return new FileStream (streamName, FileMode.Open, FileAccess.Read);
183 public virtual Stream OpenStreamForRead (string streamName, bool assertPermissions)
185 throw new NotImplementedException ();
188 public virtual Stream OpenStreamForWrite (string streamName, string templateStreamName, ref object writeContext)
190 return new FileStream (streamName, FileMode.Create, FileAccess.Write);
193 public virtual Stream OpenStreamForWrite (string streamName, string templateStreamName, ref object writeContext, bool assertPermissions)
195 throw new NotImplementedException ();
198 public virtual bool PrefetchAll (string configPath, string streamName)
200 throw new NotImplementedException ();
203 public virtual bool PrefetchSection (string sectionGroupName, string sectionName)
205 throw new NotImplementedException ();
208 public virtual void RequireCompleteInit (IInternalConfigRecord configRecord)
210 throw new NotImplementedException ();
213 public virtual object StartMonitoringStreamForChanges (string streamName, StreamChangeCallback callback)
215 throw new NotImplementedException ();
218 public virtual void StopMonitoringStreamForChanges (string streamName, StreamChangeCallback callback)
220 throw new NotImplementedException ();
223 public virtual void VerifyDefinitionAllowed (string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo)
225 if (!IsDefinitionAllowed (configPath, allowDefinition, allowExeDefinition))
226 throw new ConfigurationErrorsException ("The section can't be defined in this file (the allowed definition context is '" + allowDefinition + "').", errorInfo.Filename, errorInfo.LineNumber);
229 public virtual void WriteCompleted (string streamName, bool success, object writeContext)
233 public virtual void WriteCompleted (string streamName, bool success, object writeContext, bool assertPermissions)
237 public virtual bool SupportsChangeNotifications {
238 get { return false; }
241 public virtual bool SupportsLocation {
242 get { return false; }
245 public virtual bool SupportsPath {
246 get { return false; }
249 public virtual bool SupportsRefresh {
250 get { return false; }
254 class ExeConfigurationHost: InternalConfigurationHost
256 ExeConfigurationFileMap map;
258 public override void Init (IInternalConfigRoot root, params object[] hostInitParams)
260 map = (ExeConfigurationFileMap) hostInitParams [0];
263 public override string GetStreamName (string configPath)
265 switch (configPath) {
266 case "exe": return map.ExeConfigFilename;
267 case "local": return map.LocalUserConfigFilename;
268 case "roaming": return map.LocalUserConfigFilename;
269 case "machine": return map.MachineConfigFilename;
270 default: return map.ExeConfigFilename;
274 public override void InitForConfiguration (ref string locationSubPath, out string configPath, out string locationConfigPath, IInternalConfigRoot root, params object[] hostInitConfigurationParams)
276 map = (ExeConfigurationFileMap) hostInitConfigurationParams [0];
280 locationConfigPath = null;
282 if ((locationSubPath == "exe" || locationSubPath == null) && map.ExeConfigFilename != null) {
285 locationConfigPath = map.ExeConfigFilename;
288 if ((locationSubPath == "local" || configPath == null) && map.LocalUserConfigFilename != null) {
289 configPath = "local";
291 locationConfigPath = map.LocalUserConfigFilename;
294 if ((locationSubPath == "roaming" || configPath == null) && map.RoamingUserConfigFilename != null) {
295 configPath = "roaming";
297 locationConfigPath = map.RoamingUserConfigFilename;
300 if ((locationSubPath == "machine" || configPath == null) && map.MachineConfigFilename != null) {
301 configPath = "machine";
305 locationSubPath = next;
309 class MachineConfigurationHost: InternalConfigurationHost
311 ConfigurationFileMap map;
313 public override void Init (IInternalConfigRoot root, params object[] hostInitParams)
315 map = (ConfigurationFileMap) hostInitParams [0];
318 public override string GetStreamName (string configPath)
320 return map.MachineConfigFilename;
323 public override void InitForConfiguration (ref string locationSubPath, out string configPath, out string locationConfigPath, IInternalConfigRoot root, params object[] hostInitConfigurationParams)
325 map = (ConfigurationFileMap) hostInitConfigurationParams [0];
326 locationSubPath = null;
328 locationConfigPath = null;