Fixing an issue with output parameters that are of type IntPtr
[castle.git] / MonoRail / Castle.MonoRail.Framework / Services / DefaultControllerContextFactory.cs
blob35899b4ae363be8086b6d1aeb01fcdb54136c20b
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.Services
17 using System.Collections.Generic;
18 using System.IO;
19 using Descriptors;
20 using Routing;
22 /// <summary>
23 /// Pendent
24 /// </summary>
25 public class DefaultControllerContextFactory : IControllerContextFactory
27 /// <summary>
28 /// Pendent
29 /// </summary>
30 /// <param name="area"></param>
31 /// <param name="controller"></param>
32 /// <param name="action"></param>
33 /// <param name="metaDescriptor"></param>
34 /// <returns></returns>
35 public IControllerContext Create(string area, string controller, string action,
36 ControllerMetaDescriptor metaDescriptor)
38 return Create(area, controller, action, metaDescriptor, new RouteMatch());
41 /// <summary>
42 /// Pendent
43 /// </summary>
44 /// <param name="area">The area.</param>
45 /// <param name="controller">The controller.</param>
46 /// <param name="action">The action.</param>
47 /// <param name="metaDescriptor">The meta descriptor.</param>
48 /// <param name="match">The routing match.</param>
49 /// <returns></returns>
50 public IControllerContext Create(string area, string controller, string action,
51 ControllerMetaDescriptor metaDescriptor, RouteMatch match)
53 ControllerContext context = new ControllerContext(controller, area, action, metaDescriptor);
54 context.RouteMatch = match;
55 context.ViewFolder = ResolveViewFolder(context, area, controller, action);
56 context.SelectedViewName = ResolveDefaultViewSelection(context, area, controller, action);
58 foreach(KeyValuePair<string, string> pair in match.Parameters)
60 if (pair.Key == "controller" || pair.Key == "action" || pair.Key == "area")
62 // We skip those only to avoid compatibility issues as
63 // customactionparameters have higher precedence on parameters matching
64 continue;
67 context.CustomActionParameters[pair.Key] = pair.Value;
70 return context;
73 /// <summary>
74 /// Pendent
75 /// </summary>
76 /// <param name="context">The context.</param>
77 /// <param name="area">The area.</param>
78 /// <param name="controller">The controller.</param>
79 /// <param name="action">The action.</param>
80 /// <returns></returns>
81 protected virtual string ResolveViewFolder(ControllerContext context, string area, string controller, string action)
83 if (!string.IsNullOrEmpty(area))
85 return Path.Combine(area, controller);
88 return controller;
91 /// <summary>
92 /// Pendent
93 /// </summary>
94 /// <param name="context">The context.</param>
95 /// <param name="area">The area.</param>
96 /// <param name="controller">The controller.</param>
97 /// <param name="action">The action.</param>
98 /// <returns></returns>
99 protected virtual string ResolveDefaultViewSelection(ControllerContext context, string area, string controller,
100 string action)
102 return Path.Combine(context.ViewFolder, action);