Fixing an issue with output parameters that are of type IntPtr
[castle.git] / MonoRail / Castle.MonoRail.Framework / Adapters / DefaultEngineContext.cs
blob0fc10a550060262ffc2e6045e3c79b9900022f93
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.MonoRail.Framework.Adapters
17 using System;
18 using System.Security.Principal;
19 using System.Web;
20 using System.Collections;
21 using Castle.MonoRail.Framework;
22 using Castle.MonoRail.Framework.Container;
24 /// <summary>
25 /// Adapter to expose a valid <see cref="IEngineContext"/>
26 /// implementation on top of <c>HttpContext</c>.
27 /// </summary>
28 public class DefaultEngineContext : AbstractServiceContainer, IEngineContext
30 private readonly IMonoRailContainer container;
31 private readonly HttpContext context;
32 private readonly UrlInfo urlInfo;
33 private readonly IServerUtility server;
34 private readonly IRequest request;
35 private readonly IResponse response;
36 private Flash flash;
37 private IDictionary session;
38 private ITrace trace;
39 private Exception lastException;
40 // private IDictionary _session;
41 // private String _url;
42 // private ICacheProvider _cache;
43 // private IServiceProvider container;
44 // private bool customSessionSet;
45 private IController currentController;
46 private IControllerContext controllerContext;
48 /// <summary>
49 /// Initializes a new instance of the <see cref="DefaultEngineContext"/> class.
50 /// </summary>
51 /// <param name="container">The container.</param>
52 /// <param name="urlInfo">Url information</param>
53 /// <param name="context">The context.</param>
54 /// <param name="server">The server.</param>
55 /// <param name="request">The request.</param>
56 /// <param name="response">The response.</param>
57 /// <param name="trace">The trace.</param>
58 /// <param name="session">The session.</param>
59 public DefaultEngineContext(IMonoRailContainer container, UrlInfo urlInfo,
60 HttpContext context, IServerUtility server,
61 IRequest request, IResponse response, ITrace trace,
62 IDictionary session)
63 : base(container)
65 this.container = container;
66 this.context = context;
67 this.urlInfo = urlInfo;
68 this.request = request;
69 this.response = response;
70 this.session = session;
71 this.server = server;
72 this.trace = trace;
75 /// <summary>
76 /// Gets the underlying context of the API being used.
77 /// </summary>
78 /// <value></value>
79 public HttpContext UnderlyingContext
81 get { return context; }
84 /// <summary>
85 /// Gets a reference to the MonoRail services.
86 /// </summary>
87 /// <value>The services.</value>
88 public IMonoRailServices Services
90 get { return container; }
93 /// <summary>
94 /// Gets the last exception raised during
95 /// the execution of an action.
96 /// </summary>
97 /// <value></value>
98 public Exception LastException
100 get { return lastException; }
101 set { lastException = value; }
104 // /// <summary>
105 // /// Gets the request type (GET, POST, etc)
106 // /// </summary>
107 // /// <value></value>
108 // public String RequestType
109 // {
110 // get { return _context.Request.RequestType; }
111 // }
113 // /// <summary>
114 // /// Gets the request URL.
115 // /// </summary>
116 // /// <value></value>
117 // public String Url
118 // {
119 // get { return _url; }
120 // set { _url = value; }
121 // }
123 /// <summary>
124 /// Access the session objects.
125 /// </summary>
126 /// <value></value>
127 public IDictionary Session
129 get { return session; }
130 set { session = value; }
133 /// <summary>
134 /// Gets the request object.
135 /// </summary>
136 /// <value></value>
137 public IRequest Request
139 get { return request; }
142 /// <summary>
143 /// Gets the response object.
144 /// </summary>
145 /// <value></value>
146 public IResponse Response
148 get { return response; }
151 /// <summary>
152 /// Gets the trace object.
153 /// </summary>
154 /// <value></value>
155 public ITrace Trace
157 get { return trace; }
160 /// <summary>
161 /// Returns an <see cref="IServerUtility"/>.
162 /// </summary>
163 /// <value></value>
164 public IServerUtility Server
166 get { return server; }
169 // /// <summary>
170 // /// Access the Cache associated with this
171 // /// web execution context.
172 // /// </summary>
173 // /// <value></value>
174 // public ICacheProvider Cache
175 // {
176 // get { return _cache; }
177 // }
179 /// <summary>
180 /// Access a dictionary of volative items.
181 /// </summary>
182 /// <value></value>
183 public Flash Flash
185 get { return flash; }
186 set { flash = value; }
189 // /// <summary>
190 // /// Transfer the execution to another resource.
191 // /// </summary>
192 // /// <param name="path"></param>
193 // /// <param name="preserveForm"></param>
194 // public void Transfer(String path, bool preserveForm)
195 // {
196 // _context.Server.Transfer(path, preserveForm);
197 // }
199 /// <summary>
200 /// Gets or sets the current user.
201 /// </summary>
202 /// <value></value>
203 public IPrincipal CurrentUser
205 get { return context.User; }
206 set { context.User = value; }
209 /// <summary>
210 /// Returns the <see cref="UrlInfo"/> of the the current request.
211 /// </summary>
212 /// <value></value>
213 public UrlInfo UrlInfo
215 get { return urlInfo; }
218 /// <summary>
219 /// Returns the application virtual path.
220 /// </summary>
221 /// <value></value>
222 public String ApplicationPath
226 String path;
228 if (UnderlyingContext != null)
230 path = UnderlyingContext.Request.ApplicationPath;
232 if ("/".Equals(path))
234 path = String.Empty;
237 else
239 // Huh? That is supposed to be the virtual path
240 path = AppDomain.CurrentDomain.BaseDirectory;
243 return path;
247 /// <summary>
248 /// Returns the physical application path.
249 /// </summary>
250 public String ApplicationPhysicalPath
252 get
254 String path;
256 if (UnderlyingContext != null)
258 path = UnderlyingContext.Request.PhysicalApplicationPath;
260 else
262 path = AppDomain.CurrentDomain.BaseDirectory;
265 return path;
269 /// <summary>
270 /// Returns the Items collection from the current HttpContext.
271 /// </summary>
272 /// <value></value>
273 public IDictionary Items
275 get { return UnderlyingContext.Items; }
278 /// <summary>
279 /// Gets or sets the current controller.
280 /// </summary>
281 /// <value>The current controller.</value>
282 public IController CurrentController
284 get { return currentController; }
285 set { currentController = value; }
288 /// <summary>
289 /// Gets or sets the current controller context.
290 /// </summary>
291 /// <value>The current controller context.</value>
292 public IControllerContext CurrentControllerContext
294 get { return controllerContext; }
295 set { controllerContext = value; }
298 // /// <summary>
299 // /// If a container is available for the app, this
300 // /// property exposes its instance.
301 // /// </summary>
302 // public IServiceProvider Container
303 // {
304 // get { return container; }
305 // }