Changed the Namespace on some Enums from mono.System.Data to System.Data
[mono.git] / mcs / class / System.Web / System.Web / HttpRuntime.cs
1 /**\r
2  * Namespace: System.Web\r
3  * Class:     HttpRuntime\r
4  * \r
5  * Author:  Gaurav Vaish\r
6  * Contact: <gvaish@iitk.ac.in>\r
7  * Status:  ?%\r
8  * \r
9  * (C) Gaurav Vaish (2001)\r
10  */\r
11 \r
12 using System;\r
13 using System.Security;\r
14 using System.Security.Permissions;\r
15 using System.Web.Caching;\r
16 using System.Web.UI;\r
17 using System.Web.Utils;\r
18 \r
19 namespace System.Web\r
20 {\r
21         public sealed class HttpRuntime\r
22         {\r
23                 internal static byte[]  autogenKeys;\r
24 \r
25                 private static bool        initialized;\r
26                 private static string      installDir;\r
27                 private static HttpRuntime runtime;\r
28                 \r
29                 /// <summary>\r
30                 /// Loading of ISAPI\r
31                 /// </summary>\r
32                 private static bool        isapiLoaded;\r
33                 \r
34                 private Cache cache;\r
35                 \r
36                 // Security permission helper objects\r
37                 private static IStackWalk appPathDiscoveryStackWalk;\r
38                 private static IStackWalk ctrlPrincipalStackWalk;\r
39                 private static IStackWalk sensitiveInfoStackWalk;\r
40                 private static IStackWalk unmgdCodeStackWalk;\r
41                 private static IStackWalk unrestrictedStackWalk;\r
42                 private static IStackWalk reflectionStackWalk;\r
43                                 \r
44                 private string appDomainAppPath;\r
45                 private string appDomainAppVirtualPath;\r
46                 \r
47                 private FileChangesMonitor fcm;\r
48                 \r
49                 private Exception initErrorException;\r
50                 \r
51                 static HttpRuntime()\r
52                 {\r
53                         autogenKeys = new byte[88];\r
54                         initialized = false;\r
55                         isapiLoaded = false;\r
56 \r
57                         appPathDiscoveryStackWalk = null;\r
58                         ctrlPrincipalStackWalk    = null;\r
59                         sensitiveInfoStackWalk    = null;\r
60                         unmgdCodeStackWalk        = null;\r
61                         unrestrictedStackWalk     = null;\r
62                         \r
63                         if(!DesignTimeParseData.InDesigner)\r
64                                 Initialize();\r
65                         runtime     = new HttpRuntime();\r
66                         if(!DesignTimeParseData.InDesigner)\r
67                                 runtime.Init();\r
68                 }\r
69                 \r
70                 //FIXME: IIS specific code. Need information on what to do for Apache?\r
71                 internal static void Initialize()\r
72                 {\r
73                         if(!initialized)\r
74                         {\r
75                                 bool moduleObtained = false;\r
76                                 string file = IISVersionInfo.GetLoadedModuleFilename("aspnet_isapi.dll");\r
77                                 string dir = null;\r
78                                 string version = null;\r
79                                 if(file!=null)\r
80                                 {\r
81                                         dir = file.Substring(0, file.LastIndexOf('\\'));\r
82                                         moduleObtained = true;\r
83                                 }\r
84                                 if(dir!=null && dir.Length > 0)\r
85                                 {\r
86                                         try\r
87                                         {\r
88                                                 version = IISVersionInfo.SystemWebVersion;\r
89                                                 /* TODO: I need the code to read registry\r
90                                                  * I need LOCAL_MACHINE\Software\Micorosoft\ASP.NET\<version>\r
91                                                 */\r
92                                         } catch\r
93                                         {\r
94                                                 dir = null;\r
95                                         }\r
96                                 }\r
97                                 if(dir==null || dir.Length == 0)\r
98                                 {\r
99                                         string modulefile = (typeof(HttpRuntime)).Module.FullyQualifiedName;\r
100                                         dir = modulefile.Substring(0, modulefile.LastIndexOf('\\'));\r
101                                 }\r
102                                 if(!moduleObtained)\r
103                                 {\r
104                                         //TODO: Now what? Module still not obtained\r
105                                         // Try loading using native calls. something like LoadLibrary(...) in *java*\r
106                                         // LoadLibrary(dir+"\\aspnet_asp.dll)\r
107                                 }\r
108                                 if(moduleObtained)\r
109                                 {\r
110                                         //TODO: Initialize the library\r
111                                         // InitIsapiLibrary();\r
112                                 }\r
113                                 installDir  = dir;\r
114                                 isapiLoaded = moduleObtained;\r
115                                 initialized = true;\r
116                         }\r
117                 }\r
118                 \r
119                 [MonoTODO("Init")]\r
120                 private void Init()\r
121                 {\r
122                         initErrorException = null;\r
123                         cache = new Cache();\r
124                         appDomainAppPath = "";\r
125 \r
126                         try\r
127                         {\r
128                                 //FIXME: OS Check?\r
129                                 //if(false)\r
130                                 //      throw new PlatformNotSupportedException();\r
131                                 //I am here <gvaish>\r
132                                 throw new NotImplementedException();\r
133                         } catch(Exception e)\r
134                         {\r
135                                 initErrorException = e;\r
136                         }\r
137                 }\r
138 \r
139                 [MonoTODO("FormatResourceString(string, string, string)")]\r
140                 internal static string FormatResourceString(string key, string arg0, string type)\r
141                 {\r
142                         throw new NotImplementedException();\r
143                 }\r
144                 \r
145                 internal static string FormatResourceString(string key, string arg0)\r
146                 {\r
147                         string format = GetResourceString(key);\r
148                         if(format==null)\r
149                                 return null;\r
150                         return String.Format(format, arg0);\r
151                 }\r
152                 \r
153                 internal static string FormatResourceString(string key)\r
154                 {\r
155                         return GetResourceString(key);\r
156                 }\r
157                 \r
158                 private static string GetResourceString(string key)\r
159                 {\r
160                         return runtime.GetResourceStringFromResourceManager(key);\r
161                 }\r
162                 \r
163                 [MonoTODO("GetResourceStringFromResourceManager(string)")]\r
164                 private string GetResourceStringFromResourceManager(string key)\r
165                 {\r
166                         throw new NotImplementedException();\r
167                 }\r
168                 \r
169                 public static Cache Cache\r
170                 {\r
171                         get\r
172                         {\r
173                                 return runtime.cache;\r
174                         }\r
175                 }\r
176                 \r
177                 [MonoTODO]\r
178                 public static string AppDomainAppId\r
179                 {\r
180                         get\r
181                         {\r
182                                 throw new NotImplementedException();\r
183                         }\r
184                 }\r
185                 \r
186                 [MonoTODO]\r
187                 public static string AppDomainAppPath\r
188                 {\r
189                         get\r
190                         {\r
191                                 throw new NotImplementedException();\r
192                         }\r
193                 }\r
194                 \r
195                 [MonoTODO]\r
196                 public static string AppDomainAppVirtualPath\r
197                 {\r
198                         get\r
199                         {\r
200                                 throw new NotImplementedException();\r
201                         }\r
202                 }\r
203                 \r
204                 [MonoTODO]\r
205                 public static string AppDomainId\r
206                 {\r
207                         get\r
208                         {\r
209                                 throw new NotImplementedException();\r
210                         }\r
211                 }\r
212                 \r
213                 [MonoTODO]\r
214                 public static string AspInstallDirectory\r
215                 {\r
216                         get\r
217                         {\r
218                                 throw new NotImplementedException();\r
219                         }\r
220                 }\r
221                 \r
222                 [MonoTODO]\r
223                 public static string BinDirectory\r
224                 {\r
225                         get\r
226                         {\r
227                                 throw new NotImplementedException();\r
228                         }\r
229                 }\r
230                 \r
231                 [MonoTODO]\r
232                 public static string ClrInstallDirectory\r
233                 {\r
234                         get\r
235                         {\r
236                                 throw new NotImplementedException();\r
237                         }\r
238                 }\r
239                 \r
240                 [MonoTODO]\r
241                 public static string CodegenDir\r
242                 {\r
243                         get\r
244                         {\r
245                                 throw new NotImplementedException();\r
246                         }\r
247                 }\r
248                 \r
249                 [MonoTODO]\r
250                 public static bool IsOnUNCShare\r
251                 {\r
252                         get\r
253                         {\r
254                                 throw new NotImplementedException();\r
255                         }\r
256                 }\r
257                 \r
258                 [MonoTODO]\r
259                 public static string MachineConfigurationDirectory\r
260                 {\r
261                         get\r
262                         {\r
263                                 throw new NotImplementedException();\r
264                         }\r
265                 }\r
266                 \r
267                 [MonoTODO]\r
268                 public static void Close()\r
269                 {\r
270                         throw new NotImplementedException();\r
271                 }\r
272                 \r
273                 internal static IStackWalk AppPathDiscovery\r
274                 {\r
275                         get\r
276                         {\r
277                                 if(appPathDiscoveryStackWalk == null)\r
278                                 {\r
279                                         appPathDiscoveryStackWalk = new FileIOPermission(FileIOPermissionAccess.PathDiscovery, runtime.appDomainAppPath);\r
280                                 }\r
281                                 return appPathDiscoveryStackWalk;\r
282                         }\r
283                 }\r
284                 \r
285                 internal static IStackWalk ControlPrincipal\r
286                 {\r
287                         get\r
288                         {\r
289                                 if(ctrlPrincipalStackWalk == null)\r
290                                 {\r
291                                         ctrlPrincipalStackWalk = new SecurityPermission(SecurityPermissionFlag.ControlPrincipal);\r
292                                 }\r
293                                 return ctrlPrincipalStackWalk;\r
294                         }\r
295                 }\r
296                 \r
297                 internal static IStackWalk Reflection\r
298                 {\r
299                         get\r
300                         {\r
301                                 if(reflectionStackWalk == null)\r
302                                 {\r
303                                         reflectionStackWalk = new ReflectionPermission(ReflectionPermissionFlag.TypeInformation | ReflectionPermissionFlag.MemberAccess);\r
304                                 }\r
305                                 return reflectionStackWalk;\r
306                         }\r
307                 }\r
308                 \r
309                 internal static IStackWalk SensitiveInformation\r
310                 {\r
311                         get\r
312                         {\r
313                                 if(sensitiveInfoStackWalk == null)\r
314                                 {\r
315                                         sensitiveInfoStackWalk = new EnvironmentPermission(PermissionState.Unrestricted);\r
316                                 }\r
317                                 return sensitiveInfoStackWalk;\r
318                         }\r
319                 }\r
320                 \r
321                 internal static IStackWalk UnmanagedCode\r
322                 {\r
323                         get\r
324                         {\r
325                                 if(unmgdCodeStackWalk == null)\r
326                                 {\r
327                                         unmgdCodeStackWalk = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);\r
328                                 }\r
329                                 return unmgdCodeStackWalk;\r
330                         }\r
331                 }\r
332                 \r
333                 internal static IStackWalk Unrestricted\r
334                 {\r
335                         get\r
336                         {\r
337                                 if(unrestrictedStackWalk == null)\r
338                                 {\r
339                                         unrestrictedStackWalk = new PermissionSet(PermissionState.Unrestricted);\r
340                                 }\r
341                                 return unrestrictedStackWalk;\r
342                         }\r
343                 }\r
344                                 \r
345                 internal static IStackWalk FileReadAccess(string file)\r
346                 {\r
347                         return new FileIOPermission(FileIOPermissionAccess.Read, file);\r
348                 }\r
349                 \r
350                 internal static IStackWalk PathDiscoveryAccess(string path)\r
351                 {\r
352                         return new FileIOPermission(FileIOPermissionAccess.PathDiscovery, path);\r
353                 }\r
354         }\r
355 }\r