Stubs for missed public APIs.
[mono.git] / mcs / class / System.Web / System.Web.Hosting / HostingEnvironment.cs
1 //
2 // System.Web.Hosting.HostingEnvironment.cs
3 //
4 // Author:
5 //      Chris Toshok (toshok@ximian.com)
6 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 //
8
9 //
10 // Copyright (C) 2005,2006 Novell, Inc (http://www.novell.com)
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31
32 #if NET_2_0
33
34 using System;
35 using System.Globalization;
36 using System.Security.Permissions;
37 using System.Threading;
38 using System.Web.Configuration;
39 using System.Web.Caching;
40 using System.Web.Util;
41
42 namespace System.Web.Hosting {
43
44         [AspNetHostingPermission (SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Medium)]
45         [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.High)]
46         public sealed class HostingEnvironment : MarshalByRefObject
47         {
48                 static bool is_hosted;
49                 static string site_name;
50                 static ApplicationShutdownReason shutdown_reason;
51                 internal static BareApplicationHost Host;
52                 static VirtualPathProvider vpath_provider = (HttpRuntime.AppDomainAppVirtualPath == null) ? null :
53                                                                 new DefaultVirtualPathProvider ();
54                 static int busy_count;
55
56                 public HostingEnvironment ()
57                 {
58                         // The documentation says that this is called once per domain by the ApplicationManager and
59                         // then it throws InvalidOperationException whenever called.
60                         throw new InvalidOperationException ();
61                 }
62
63                 public static string ApplicationID {
64                         get { return HttpRuntime.AppDomainAppId; }
65                 }
66
67                 public static string ApplicationPhysicalPath {
68                         get { return HttpRuntime.AppDomainAppPath; }
69                 }
70
71                 public static string ApplicationVirtualPath {
72                         get { return HttpRuntime.AppDomainAppVirtualPath; }
73                 }
74
75                 public static Cache Cache {
76                         get { return HttpRuntime.Cache; }
77                 }
78
79                 public static Exception InitializationException {
80                         get { return HttpApplication.InitializationException; }
81                 }
82
83                 public static bool IsHosted {
84                         get { return is_hosted; }
85                 }
86
87                 public static ApplicationShutdownReason ShutdownReason {
88                         get { return shutdown_reason; }
89                 }
90
91                 public static string SiteName {
92                         get { return site_name; }
93                 }
94
95                 public static VirtualPathProvider VirtualPathProvider {
96                         get { return vpath_provider; }
97                 }
98
99                 public static void DecrementBusyCount ()
100                 {
101                         Interlocked.Decrement (ref busy_count);
102                 }
103
104                 [MonoTODO ("Not implemented")]
105                 public static IDisposable Impersonate ()
106                 {
107                         throw new NotImplementedException ();
108                 }
109
110                 [MonoTODO ("Not implemented")]
111                 public static IDisposable Impersonate (IntPtr token)
112                 {
113                         throw new NotImplementedException ();
114                 }
115
116                 [MonoTODO ("Not implemented")]
117                 public static IDisposable Impersonate (IntPtr userToken, string virtualPath)
118                 {
119                         throw new NotImplementedException ();
120                 }
121
122                 public static void IncrementBusyCount ()
123                 {
124                         Interlocked.Increment (ref busy_count);
125                 }
126
127                 public override object InitializeLifetimeService ()
128                 {
129                         return null;
130                 }
131
132                 public static void InitiateShutdown ()
133                 {
134                         HttpRuntime.UnloadAppDomain ();
135                 }
136
137                 public static string MapPath (string virtualPath)
138                 {
139                         if (virtualPath == null || virtualPath == "")
140                                 throw new ArgumentNullException ("virtualPath");
141                         
142                         HttpContext context = HttpContext.Current;
143                         if (context == null)
144                                 return null;
145
146                         return context.Request.MapPath (virtualPath);
147                 }
148
149                 public static void RegisterObject (IRegisteredObject obj)
150                 {
151                         if (obj == null)
152                                 throw new ArgumentNullException ("obj");
153                         Host.RegisterObject (obj, false);
154                 }
155
156                 public static void RegisterVirtualPathProvider (VirtualPathProvider virtualPathProvider)
157                 {
158                         if (HttpRuntime.AppDomainAppVirtualPath == null)
159                                 throw new InvalidOperationException ();
160
161                         if (virtualPathProvider == null)
162                                 throw new ArgumentNullException ("virtualPathProvider");
163
164                         virtualPathProvider.SetPrevious (vpath_provider);
165                         vpath_provider = virtualPathProvider;
166                 }
167                 
168                 public static IDisposable SetCultures (string virtualPath)
169                 {
170                         GlobalizationSection gs = WebConfigurationManager.GetSection ("system.web/globalization", virtualPath) as GlobalizationSection;
171                         IDisposable ret = Thread.CurrentThread.CurrentCulture as IDisposable;
172                         string culture = gs.Culture;
173                         if (String.IsNullOrEmpty (culture))
174                                 return ret;
175                         Thread.CurrentThread.CurrentCulture = new CultureInfo (culture);
176                         return ret;
177                 }
178
179                 public static IDisposable SetCultures ()
180                 {
181                         return SetCultures ("~/");
182                 }
183
184                 public static void UnregisterObject (IRegisteredObject obj)
185                 {
186                         if (obj == null)
187                                 throw new ArgumentNullException ("obj");
188                         Host.UnregisterObject (obj);
189                 }
190         }
191 }
192
193 #endif