imported everything from my branch (which is slightly harmless).
[mono.git] / mcs / class / System.Configuration / System.Configuration / InternalConfigurationHost.cs
1 //
2 // System.Configuration.InternalConfigurationHost.cs
3 //
4 // Authors:
5 //  Lluis Sanchez Gual (lluis@novell.com)
6 //
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:
14 // 
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the Software.
17 // 
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.
25 //
26 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
27 //
28
29 #if NET_2_0
30
31 using System;
32 using System.IO;
33 using System.Security;
34 using System.Configuration.Internal;
35
36 namespace System.Configuration
37 {
38         class InternalConfigurationHost: IInternalConfigHost
39         {
40                 public virtual object CreateConfigurationContext (string configPath, string locationSubPath)
41                 {
42                         return null;
43                 }
44                 
45                 public virtual object CreateDeprecatedConfigContext (string configPath)
46                 {
47                         throw new NotImplementedException ();
48                 }
49                 
50                 public virtual string DecryptSection (string encryptedXml, ProtectedConfigurationProvider protectionProvider, ProtectedConfigurationSection protectedSection)
51                 {
52                         throw new NotImplementedException ();
53                 }
54                 
55                 public virtual void DeleteStream (string streamName)
56                 {
57                         File.Delete (streamName);
58                 }
59                 
60                 public virtual string EncryptSection (string encryptedXml, ProtectedConfigurationProvider protectionProvider, ProtectedConfigurationSection protectedSection)
61                 {
62                         throw new NotImplementedException ();
63                 }
64                 
65                 public virtual string GetConfigPathFromLocationSubPath (string configPath, string locatinSubPath)
66                 {
67                         throw new NotImplementedException ();
68                 }
69                 
70                 public virtual Type GetConfigType (string typeName, bool throwOnError)
71                 {
72                         throw new NotImplementedException ();
73                 }
74                 
75                 public virtual string GetConfigTypeName (Type t)
76                 {
77                         throw new NotImplementedException ();
78                 }
79                 
80                 public virtual void GetRestrictedPermissions (IInternalConfigRecord configRecord, out PermissionSet permissionSet, out bool isHostReady)
81                 {
82                         throw new NotImplementedException ();
83                 }
84                 
85                 public virtual string GetStreamName (string configPath)
86                 {
87                         throw new NotImplementedException ();
88                 }
89                 
90                 public virtual string GetStreamNameForConfigSource (string streamName, string configSource)
91                 {
92                         throw new NotImplementedException ();
93                 }
94                 
95                 public virtual object GetStreamVersion (string streamName)
96                 {
97                         throw new NotImplementedException ();
98                 }
99                 
100                 public virtual IDisposable Impersonate ()
101                 {
102                         throw new NotImplementedException ();
103                 }
104                 
105                 public virtual void Init (IInternalConfigRoot root, params object[] hostInitParams)
106                 {
107                 }
108                 
109                 public virtual void InitForConfiguration (ref string locationSubPath, out string configPath, out string locationConfigPath, IInternalConfigRoot root, params object[] hostInitConfigurationParams)
110                 {
111                         throw new NotImplementedException ();
112                 }
113                 
114                 public virtual bool IsAboveApplication (string configPath)
115                 {
116                         throw new NotImplementedException ();
117                 }
118                 
119                 public virtual bool IsConfigRecordRequired (string configPath)
120                 {
121                         throw new NotImplementedException ();
122                 }
123                 
124                 public virtual bool IsDefinitionAllowed (string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition)
125                 {
126                         throw new NotImplementedException ();
127                 }
128                 
129                 public virtual bool IsFile (string streamName)
130                 {
131                         throw new NotImplementedException ();
132                 }
133                 
134                 public virtual bool IsLocationApplicable (string configPath)
135                 {
136                         throw new NotImplementedException ();
137                 }
138                 
139                 public virtual Stream OpenStreamForRead (string streamName)
140                 {
141                         if (!File.Exists (streamName))
142                                 throw new ConfigurationException ("File '" + streamName + "' not found");
143                                 
144                         return new FileStream (streamName, FileMode.Open, FileAccess.Read);
145                 }
146                 
147                 public virtual Stream OpenStreamForWrite (string streamName, string templateStreamName, ref object writeContext)
148                 {
149                         return new FileStream (streamName, FileMode.Create, FileAccess.Write);
150                 }
151                 
152                 public virtual bool PrefetchAll (string configPath, string streamName)
153                 {
154                         throw new NotImplementedException ();
155                 }
156                 
157                 public virtual bool PrefetchSection (string sectionGroupName, string sectionName)
158                 {
159                         throw new NotImplementedException ();
160                 }
161                 
162                 public virtual object StartMonitoringStreamForChanges (string streamName, StreamChangeCallback callback)
163                 {
164                         throw new NotImplementedException ();
165                 }
166                 
167                 public virtual void StopMonitoringStreamForChanges (string streamName, StreamChangeCallback callback)
168                 {
169                         throw new NotImplementedException ();
170                 }
171                 
172                 public virtual void VerifyDefinitionAllowed (string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo)
173                 {
174                         throw new NotImplementedException ();
175                 }
176                 
177                 public virtual void WriteCompleted (string streamName, bool success, object writeContext)
178                 {
179                 }
180                 
181                 public virtual bool SupportsChangeNotifications {
182                         get { return false; }
183                 }
184                 
185                 public virtual bool SupportsLocation {
186                         get { return false; }
187                 }
188                 
189                 public virtual bool SupportsPath {
190                         get { return false; }
191                 }
192                 
193                 public virtual bool SupportsRefresh {
194                         get { return false; }
195                 }
196         }
197         
198         class ExeConfigurationHost: InternalConfigurationHost
199         {
200                 ExeConfigurationFileMap map;
201                 
202                 public override void Init (IInternalConfigRoot root, params object[] hostInitParams)
203                 {
204                         map = (ExeConfigurationFileMap) hostInitParams [0];
205                 }
206                 
207                 public override string GetStreamName (string configPath)
208                 {
209                         switch (configPath) {
210                                 case "exe": return map.ExeConfigFilename; 
211                                 case "local": return map.LocalUserConfigFilename;
212                                 case "roaming": return map.LocalUserConfigFilename;
213                                 case "machine": return map.MachineConfigFilename;
214                                 default: return map.ExeConfigFilename;
215                         }
216                 }
217                 
218                 public override void InitForConfiguration (ref string locationSubPath, out string configPath, out string locationConfigPath, IInternalConfigRoot root, params object[] hostInitConfigurationParams)
219                 {
220                         map = (ExeConfigurationFileMap) hostInitConfigurationParams [0];
221                         configPath = null;
222                         string next = null;
223                         
224                         if ((locationSubPath == "exe" || locationSubPath == null) && map.ExeConfigFilename != null) {
225                                 configPath = "exe";
226                                 next = "local";
227                         }
228                         
229                         if ((locationSubPath == "local" || configPath == null) && map.LocalUserConfigFilename != null) {
230                                 configPath = "local";
231                                 next = "roaming";
232                         }
233                         
234                         if ((locationSubPath == "roaming" || configPath == null) && map.RoamingUserConfigFilename != null) {
235                                 configPath = "roaming";
236                                 next = "machine";
237                         }
238                         
239                         if ((locationSubPath == "machine" || configPath == null) && map.MachineConfigFilename != null) {
240                                 configPath = "machine";
241                                 next = null;
242                         }
243                         
244                         locationSubPath = next;
245                         locationConfigPath = null;
246                 }
247         }
248         
249         class MachineConfigurationHost: InternalConfigurationHost
250         {
251                 ConfigurationFileMap map;
252                 
253                 public override void Init (IInternalConfigRoot root, params object[] hostInitParams)
254                 {
255                         map = (ConfigurationFileMap) hostInitParams [0];
256                 }
257                 
258                 public override string GetStreamName (string configPath)
259                 {
260                         return map.MachineConfigFilename;
261                 }
262                 
263                 public override void InitForConfiguration (ref string locationSubPath, out string configPath, out string locationConfigPath, IInternalConfigRoot root, params object[] hostInitConfigurationParams)
264                 {
265                         map = (ConfigurationFileMap) hostInitConfigurationParams [0];
266                         locationSubPath = null;
267                         configPath = null;
268                         locationConfigPath = null;
269                 }
270         }       
271 }
272
273 #endif