コード例 #1
0
        /// <summary>
        /// Pendent
        /// </summary>
        /// <param name="area">The area.</param>
        /// <param name="controller">The controller.</param>
        /// <param name="action">The action.</param>
        /// <param name="metaDescriptor">The meta descriptor.</param>
        /// <param name="match">The routing match.</param>
        /// <returns></returns>
        public IControllerContext Create(string area, string controller, string action,
                                         ControllerMetaDescriptor metaDescriptor, RouteMatch match)
        {
            var context = new ControllerContext(controller, area, action, metaDescriptor)
            {
                RouteMatch = match
            };

            context.ViewFolder       = ResolveViewFolder(context, area, controller, action);
            context.SelectedViewName = ResolveDefaultViewSelection(context, area, controller, action);

            foreach (var pair in match.Parameters)
            {
                if (pair.Value == null || pair.Key == "controller" || pair.Key == "action" || pair.Key == "area")
                {
                    // We skip those only to avoid compatibility issues as
                    // customactionparameters have higher precedence on parameters matching
                    continue;
                }

                context.CustomActionParameters[pair.Key] = pair.Value;
            }

            return(context);
        }
コード例 #2
0
        public void Request_CreatesSessionfulHandler()
        {
            StringWriter writer = new StringWriter();

            HttpResponse res = new HttpResponse(writer);
            HttpRequest  req = new HttpRequest(Path.Combine(
                                                   AppDomain.CurrentDomain.BaseDirectory, "Handlers/Files/simplerequest.txt"),
                                               "http://localhost:1333/home/something", "");
            RouteMatch  routeMatch = new RouteMatch();
            HttpContext httpCtx    = new HttpContext(req, res);

            httpCtx.Items[RouteMatch.RouteMatchKey] = routeMatch;

            using (_MockRepository.Record())
            {
                ControllerMetaDescriptor controllerDesc = new ControllerMetaDescriptor();
                controllerDesc.ControllerDescriptor = new ControllerDescriptor(typeof(Controller), "home", "", false);

                Expect.Call(_ControllerFactoryMock.CreateController("", "home")).IgnoreArguments().Return(_ControllerMock);
                Expect.Call(_ControllerDescriptorProviderMock.BuildDescriptor(_ControllerMock)).Return(controllerDesc);
                Expect.Call(_ControllerContextFactoryMock.Create("", "home", "something", controllerDesc, routeMatch)).
                Return(new ControllerContext());
            }

            using (_MockRepository.Playback())
            {
                IHttpHandler handler = _HandlerFactory.GetHandler(httpCtx, "GET", "", "");

                Assert.IsNotNull(handler);
                Assert.IsInstanceOfType(typeof(MonoRailHttpHandler), handler);
            }
        }
コード例 #3
0
		public void Request_CreatesSessionfulHandler()
		{
			StringWriter writer = new StringWriter();
			
			HttpResponse res = new HttpResponse(writer);
			HttpRequest req = new HttpRequest(Path.Combine(
			                                  	AppDomain.CurrentDomain.BaseDirectory, "Handlers/Files/simplerequest.txt"),
			                                  "http://localhost:1333/home/something", "");
			RouteMatch routeMatch = new RouteMatch();
			HttpContext httpCtx = new HttpContext(req, res);
			httpCtx.Items[RouteMatch.RouteMatchKey] = routeMatch;

			using(mockRepository.Record())
			{
				ControllerMetaDescriptor controllerDesc = new ControllerMetaDescriptor();
				controllerDesc.ControllerDescriptor = new ControllerDescriptor(typeof(Controller), "home", "", false);

				Expect.Call(controllerFactoryMock.CreateController("", "home")).IgnoreArguments().Return(controllerMock);
				Expect.Call(controllerDescriptorProviderMock.BuildDescriptor(controllerMock)).Return(controllerDesc);
				ControllerContext controllerContext = new ControllerContext();
				controllerContext.ControllerDescriptor = new ControllerMetaDescriptor();
				Expect.Call(controllerContextFactoryMock.Create("", "home", "something", controllerDesc, routeMatch)).
					Return(controllerContext);
			}

			using(mockRepository.Playback())
			{
				IHttpHandler handler = handlerFactory.GetHandler(httpCtx, "GET", "", "");

				Assert.IsNotNull(handler);
				Assert.IsInstanceOf(typeof(MonoRailHttpHandler), handler);
			}
		}
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ControllerContext"/> class.
 /// </summary>
 /// <param name="name">The controller name.</param>
 /// <param name="areaName">The area name.</param>
 /// <param name="action">The action name.</param>
 /// <param name="metaDescriptor">The meta descriptor.</param>
 public ControllerContext(string name, string areaName, string action, ControllerMetaDescriptor metaDescriptor)
 {
     this.Name                 = name;
     this.AreaName             = areaName;
     this.Action               = action;
     this.ControllerDescriptor = metaDescriptor;
 }
コード例 #5
0
        public void ExecuteMethodUntilSignal()
        {
            startEvent.WaitOne(int.MaxValue, false);

            while (!stopEvent.WaitOne(1, false))
            {
                ControllerMetaDescriptor desc1 = builder.BuildDescriptor(new Controller1());
                ControllerMetaDescriptor desc2 = builder.BuildDescriptor(new Controller2());

                Assert.AreEqual(0, desc1.ActionProviders.Count);
                Assert.AreEqual(1, desc1.Filters.Count);
                Assert.IsNotNull(desc1.Layout);
                Assert.IsNotNull(desc1.Rescues);

                Assert.AreEqual(0, desc2.ActionProviders.Count);
                Assert.AreEqual(1, desc2.Filters.Count);
                Assert.IsNotNull(desc2.Layout);
                Assert.IsNotNull(desc2.Rescues);

                ActionMetaDescriptor ac1 = desc1.GetAction(typeof(Controller1).GetMethod("Index"));
                Assert.IsNotNull(ac1.SkipRescue);
                Assert.AreEqual(1, ac1.SkipFilters.Count);

                ActionMetaDescriptor ac2 = desc2.GetAction(typeof(Controller2).GetMethod("Index", new Type[] { typeof(int) }));
                Assert.IsNotNull(ac2.SkipRescue);
                Assert.AreEqual(1, ac2.SkipFilters.Count);

                ActionMetaDescriptor ac3 = desc2.GetAction(typeof(Controller2).GetMethod("Index", new Type[] { typeof(String) }));
                Assert.IsNotNull(ac3.SkipRescue);
                Assert.AreEqual(0, ac3.SkipFilters.Count);
            }
        }
コード例 #6
0
        /// <summary>
        /// Collects the action level attributes.
        /// </summary>
        /// <param name="descriptor">The descriptor.</param>
        private void CollectActionLevelAttributes(ControllerMetaDescriptor descriptor)
        {
            foreach (var action in descriptor.Actions.Values)
            {
                if (action is IList)
                {
                    foreach (MethodInfo overloadedAction in (action as IList))
                    {
                        CollectActionAttributes(overloadedAction, descriptor);
                    }

                    continue;
                }

                var methodInfo = action as MethodInfo;

                if (methodInfo != null)
                {
                    CollectActionAttributes(methodInfo, descriptor);
                }
                else
                {
                    var asyncActionPair = (AsyncActionPair)action;
                    CollectActionAttributes(asyncActionPair.BeginActionInfo, descriptor);
                    CollectActionAttributes(asyncActionPair.EndActionInfo, descriptor);
                }
            }
        }
コード例 #7
0
		/// <summary>
		/// Initializes a new instance of the <see cref="ControllerContext"/> class.
		/// </summary>
		/// <param name="name">The controller name.</param>
		/// <param name="areaName">The area name.</param>
		/// <param name="action">The action name.</param>
		/// <param name="metaDescriptor">The meta descriptor.</param>
		public ControllerContext(string name, string areaName, string action, ControllerMetaDescriptor metaDescriptor)
		{
			this.name = name;
			this.areaName = areaName;
			this.action = action;
			this.metaDescriptor = metaDescriptor;
		}
コード例 #8
0
 /// <summary>
 /// Creates the handler.
 /// </summary>
 /// <param name="controllerDesc">The controller descriptor.</param>
 /// <param name="engineContext">The engine context.</param>
 /// <param name="controller">The controller.</param>
 /// <param name="controllerContext">The controller context.</param>
 /// <returns>
 /// A new <see cref="T:System.Web.IHttpHandler"></see> object that processes the request.
 /// </returns>
 protected virtual IHttpHandler CreateHandler(ControllerMetaDescriptor controllerDesc, IEngineContext engineContext,
                                              IController controller, IControllerContext controllerContext)
 {
     if (IgnoresSession(controllerDesc.ControllerDescriptor))
     {
         return(new SessionlessMonoRailHttpHandler(engineContext, controller, controllerContext));
     }
     return(new MonoRailHttpHandler(engineContext, controller, controllerContext));
 }
コード例 #9
0
        /// <summary>
        /// Collects the default action.
        /// </summary>
        /// <param name="descriptor">The descriptor.</param>
        /// <param name="controllerType">Type of the controller.</param>
        private void CollectDefaultAction(ControllerMetaDescriptor descriptor, Type controllerType)
        {
            var attributes = controllerType.GetCustomAttributes(typeof(DefaultActionAttribute), true);

            if (attributes.Length != 0)
            {
                descriptor.DefaultAction = (DefaultActionAttribute)attributes[0];
            }
        }
コード例 #10
0
 /// <summary>
 /// Collects the class level attributes.
 /// </summary>
 /// <param name="controllerType">Type of the controller.</param>
 /// <param name="descriptor">The descriptor.</param>
 private void CollectClassLevelAttributes(Type controllerType, ControllerMetaDescriptor descriptor)
 {
     CollectHelpers(descriptor, controllerType);
     CollectResources(descriptor, controllerType);
     CollectFilters(descriptor, controllerType);
     CollectLayout(descriptor, controllerType);
     CollectRescues(descriptor, controllerType);
     CollectDefaultAction(descriptor, controllerType);
     CollectScaffolding(descriptor, controllerType);
     CollectDynamicActionProviders(descriptor, controllerType);
     CollectCacheConfigure(descriptor, controllerType);
 }
コード例 #11
0
        /// <summary>
        /// Collects the scaffolding.
        /// </summary>
        /// <param name="descriptor">The descriptor.</param>
        /// <param name="controllerType">Type of the controller.</param>
        private void CollectScaffolding(ControllerMetaDescriptor descriptor, Type controllerType)
        {
            var attributes = controllerType.GetCustomAttributes(typeof(ScaffoldingAttribute), false);

            if (attributes.Length != 0)
            {
                foreach (ScaffoldingAttribute scaffolding in attributes)
                {
                    descriptor.Scaffoldings.Add(scaffolding);
                }
            }
        }
コード例 #12
0
        public void CanSelectMethodAndCreatesAnActionMethodExecutorForIt()
        {
            var controllerMeta = new ControllerMetaDescriptor();
            var controller     = new BaseClassController();
            var context        = new ControllerContext("baseclass", "", "action1", controllerMeta);

            controllerMeta.Actions["action1"] = typeof(BaseClassController).GetMethod("Action1");

            var action = selector.Select(engine, controller, context, ActionType.Sync);

            Assert.IsNotNull(action);
            Assert.IsInstanceOf(typeof(ActionMethodExecutor), action);
        }
コード例 #13
0
        public void CanSelectDynActionAndCreatesADynamicActionExecutor()
        {
            var controllerMeta = new ControllerMetaDescriptor();
            var controller     = new BaseClassController();
            var context        = new ControllerContext("baseclass", "", "action2", controllerMeta);

            context.DynamicActions.Add("action2", new DummyDynamicAction());

            var action = selector.Select(engine, controller, context, ActionType.Sync);

            Assert.IsNotNull(action);
            Assert.IsInstanceOf(typeof(DynamicActionExecutor), action);
        }
コード例 #14
0
        /// <summary>
        /// Collects the actions.
        /// </summary>
        /// <param name="controllerType">Type of the controller.</param>
        /// <param name="desc">The desc.</param>
        private void CollectActions(Type controllerType, ControllerMetaDescriptor desc)
        {
            // HACK: GetRealControllerType is a workaround for DYNPROXY-14 bug
            // see: http://support.castleproject.org/browse/DYNPROXY-14
            controllerType = GetRealControllerType(controllerType);

            var methods = controllerType.GetMethods(BindingFlags.Public | BindingFlags.Instance);

            foreach (var method in methods)
            {
                var declaringType = method.DeclaringType;

                if (method.IsSpecialName)
                {
                    continue;
                }

                if (declaringType == typeof(Object) ||
                    declaringType == typeof(IController) || declaringType == typeof(Controller))
                // || declaringType == typeof(SmartDispatcherController))
                {
                    continue;
                }

                if (desc.Actions.Contains(method.Name))
                {
                    var list = desc.Actions[method.Name] as ArrayList;

                    if (list == null)
                    {
                        list = new ArrayList {
                            desc.Actions[method.Name]
                        };

                        desc.Actions[method.Name] = list;
                    }

                    list.Add(method);
                }
                else
                {
                    desc.Actions[method.Name] = method;
                }
            }

            MergeAsyncMethodPairsToSingleAction(desc);
        }
コード例 #15
0
        /// <summary>
        /// Collects the action attributes.
        /// </summary>
        /// <param name="method">The method.</param>
        /// <param name="descriptor">The descriptor.</param>
        private void CollectActionAttributes(MethodInfo method, ControllerMetaDescriptor descriptor)
        {
            if (logger.IsDebugEnabled)
            {
                logger.DebugFormat("Collection attributes for action {0}", method.Name);
            }

            var actionDescriptor = descriptor.GetAction(method);

            if (actionDescriptor == null)
            {
                actionDescriptor = CreateActionDescriptor();

                descriptor.AddAction(method, actionDescriptor);
            }

            CollectResources(actionDescriptor, method);
            CollectSkipFilter(actionDescriptor, method);
            CollectRescues(actionDescriptor, method);
            CollectAccessibleThrough(actionDescriptor, method);
            CollectSkipRescue(actionDescriptor, method);
            CollectLayout(actionDescriptor, method);
            CollectCacheConfigure(actionDescriptor, method);
            CollectTransformFilter(actionDescriptor, method);
            CollectReturnTypeBinder(actionDescriptor, method);
            CollectActionLevelFiltersIntoActionDescriptor(method, actionDescriptor);
            if (method.IsDefined(typeof(AjaxActionAttribute), true))
            {
                descriptor.AjaxActions.Add(method);
            }

            if (method.IsDefined(typeof(DefaultActionAttribute), true))
            {
                if (descriptor.DefaultAction != null)
                {
                    throw new MonoRailException(
                              "Cannot resolve a default action for {0}, DefaultActionAttribute was declared more than once.",
                              method.DeclaringType.FullName);
                }
                descriptor.DefaultAction = new DefaultActionAttribute(method.Name);
            }

            if (AfterActionProcess != null)
            {
                AfterActionProcess(actionDescriptor);
            }
        }
コード例 #16
0
        /// <summary>
        /// The following lines were added to handle _default processing
        /// if present look for and load _default action method
        /// <seealso cref="DefaultActionAttribute"/>
        /// </summary>
        private IExecutableAction ResolveDefaultMethod(ControllerMetaDescriptor controllerDesc, IController controller,
                                                       IControllerContext context, ActionType actionType)
        {
            if (controllerDesc.DefaultAction != null)
            {
                var method = SelectActionMethod(
                    controller, context,
                    controllerDesc.DefaultAction.DefaultAction, actionType);

                if (method != null)
                {
                    var actionDesc = controllerDesc.GetAction(method);

                    return(new ActionMethodExecutor(method, actionDesc ?? new ActionMetaDescriptor()));
                }
            }

            return(null);
        }
コード例 #17
0
        public void Request_CreatesSessionlessHandler_Async()
        {
            var writer = new StringWriter();

            var res = new HttpResponse(writer);
            var req = new HttpRequest(Path.Combine(
                                          AppDomain.CurrentDomain.BaseDirectory, "Handlers/Files/simplerequest.txt"),
                                      "http://localhost:1333/home/something", "");
            var routeMatch = new RouteMatch();
            var httpCtx    = new HttpContext(req, res);

            httpCtx.Items[RouteMatch.RouteMatchKey] = routeMatch;

            using (mockRepository.Record())
            {
                var controllerDesc = new ControllerMetaDescriptor
                {
                    ControllerDescriptor = new ControllerDescriptor(typeof(Controller), "home", "", true)
                };

                Expect.Call(controllerFactoryMock.CreateController("", "home")).IgnoreArguments().Return(controllerMock);
                Expect.Call(controllerDescriptorProviderMock.BuildDescriptor(controllerMock)).Return(controllerDesc);
                var controllerContext = new ControllerContext
                {
                    Action = "something",
                    ControllerDescriptor = new ControllerMetaDescriptor()
                };
                controllerContext.ControllerDescriptor.Actions["something"] = new AsyncActionPair(null, null, null);
                Expect.Call(controllerContextFactoryMock.Create("", "home", "something", controllerDesc, routeMatch)).
                Return(controllerContext);
            }

            using (mockRepository.Playback())
            {
                var handler = handlerFactory.GetHandler(httpCtx, "GET", "", "");

                Assert.IsNotNull(handler);
                Assert.IsInstanceOf(typeof(AsyncSessionlessMonoRailHttpHandler), handler);
            }
        }
コード例 #18
0
		/// <summary>
		/// Pendent
		/// </summary>
		/// <param name="area">The area.</param>
		/// <param name="controller">The controller.</param>
		/// <param name="action">The action.</param>
		/// <param name="metaDescriptor">The meta descriptor.</param>
		/// <param name="match">The routing match.</param>
		/// <returns></returns>
		public IControllerContext Create(string area, string controller, string action,
										 ControllerMetaDescriptor metaDescriptor, RouteMatch match)
		{
			ControllerContext context = new ControllerContext(controller, area, action, metaDescriptor);
			context.RouteMatch = match;
			context.ViewFolder = ResolveViewFolder(context, area, controller, action);
			context.SelectedViewName = ResolveDefaultViewSelection(context, area, controller, action);

			foreach(KeyValuePair<string, string> pair in match.Parameters)
			{
				if (pair.Value == null || pair.Key == "controller" || pair.Key == "action" || pair.Key == "area")
				{
					// We skip those only to avoid compatibility issues as 
					// customactionparameters have higher precedence on parameters matching
					continue;
				}

				context.CustomActionParameters[pair.Key] = pair.Value;
			}

			return context;
		}
コード例 #19
0
        /// <summary>
        /// Builds the <see cref="ControllerMetaDescriptor"/>.
        /// </summary>
        /// <param name="controller">Controller.</param>
        /// <returns></returns>
        public ControllerMetaDescriptor BuildDescriptor(Controller controller)
        {
            Type controllerType = controller.GetType();

            ControllerMetaDescriptor desc = null;

            locker.AcquireReaderLock(-1);

            try
            {
                desc = (ControllerMetaDescriptor)
                       descriptorRepository[controllerType];

                if (desc != null)
                {
                    return(desc);
                }

                LockCookie lc = locker.UpgradeToWriterLock(-1);

                try
                {
                    desc = BuildDescriptor(controllerType);

                    descriptorRepository[controllerType] = desc;
                }
                finally
                {
                    locker.DowngradeFromWriterLock(ref lc);
                }
            }
            finally
            {
                locker.ReleaseReaderLock();
            }

            return(desc);
        }
コード例 #20
0
        private ControllerMetaDescriptor BuildDescriptor(Type controllerType)
        {
            ControllerMetaDescriptor descriptor = new ControllerMetaDescriptor(controllerType);

            CollectClassLevelAttributes(controllerType, descriptor);

            foreach (object action in descriptor.Actions.Values)
            {
                if (action is IList)
                {
                    foreach (MethodInfo overloadedAction in (action as IList))
                    {
                        CollectActionAttributes(overloadedAction, descriptor);
                    }

                    continue;
                }

                CollectActionAttributes(action as MethodInfo, descriptor);
            }

            return(descriptor);
        }
コード例 #21
0
        private void CollectActionAttributes(MethodInfo method, ControllerMetaDescriptor descriptor)
        {
            object[] attributes = method.GetCustomAttributes(typeof(ResourceAttribute), true);

            foreach (ResourceAttribute resource in attributes)
            {
                descriptor.GetAction(method).Resources.Add(resource);
            }

            attributes = method.GetCustomAttributes(typeof(SkipFilterAttribute), true);

            foreach (SkipFilterAttribute resource in attributes)
            {
                descriptor.GetAction(method).SkipFilters.Add(resource);
            }

            attributes = method.GetCustomAttributes(typeof(RescueAttribute), true);

            if (attributes.Length != 0)
            {
                descriptor.GetAction(method).Rescues = attributes;
            }

            attributes = method.GetCustomAttributes(typeof(SkipRescueAttribute), true);

            if (attributes.Length != 0)
            {
                descriptor.GetAction(method).SkipRescue = (SkipRescueAttribute)attributes[0];
            }

            attributes = method.GetCustomAttributes(typeof(LayoutAttribute), true);

            if (attributes.Length != 0)
            {
                descriptor.GetAction(method).Layout = (LayoutAttribute)attributes[0];
            }
        }
コード例 #22
0
 /// <summary>
 /// Collects the helpers.
 /// </summary>
 /// <param name="descriptor">The descriptor.</param>
 /// <param name="controllerType">Type of the controller.</param>
 private void CollectHelpers(ControllerMetaDescriptor descriptor, Type controllerType)
 {
     descriptor.Helpers = helperDescriptorProvider.CollectHelpers(controllerType);
 }
コード例 #23
0
		/// <summary>
		/// Collects the filters.
		/// </summary>
		/// <param name="descriptor">The descriptor.</param>
		/// <param name="controllerType">Type of the controller.</param>
		private void CollectFilters(ControllerMetaDescriptor descriptor, Type controllerType)
		{
			descriptor.Filters = filterDescriptorProvider.CollectFilters(controllerType);

			Array.Sort(descriptor.Filters, FilterDescriptorComparer.Instance);
		}
コード例 #24
0
		/// <summary>
		/// Collects the helpers.
		/// </summary>
		/// <param name="descriptor">The descriptor.</param>
		/// <param name="controllerType">Type of the controller.</param>
		private void CollectHelpers(ControllerMetaDescriptor descriptor, Type controllerType)
		{
			descriptor.Helpers = helperDescriptorProvider.CollectHelpers(controllerType);
		}
コード例 #25
0
		/// <summary>
		/// Collects the dynamic action providers.
		/// </summary>
		/// <param name="descriptor">The descriptor.</param>
		/// <param name="controllerType">Type of the controller.</param>
		private void CollectDynamicActionProviders(ControllerMetaDescriptor descriptor, Type controllerType)
		{
			descriptor.DynamicActionProviders = dynamicActionProviderDescriptorProvider.CollectProviders(controllerType);
		}
コード例 #26
0
		/// <summary>
		/// Collects the scaffolding.
		/// </summary>
		/// <param name="descriptor">The descriptor.</param>
		/// <param name="controllerType">Type of the controller.</param>
		private void CollectScaffolding(ControllerMetaDescriptor descriptor, Type controllerType)
		{
			var attributes = controllerType.GetCustomAttributes(typeof(ScaffoldingAttribute), false);

			if (attributes.Length != 0)
			{
				foreach(ScaffoldingAttribute scaffolding in attributes)
				{
					descriptor.Scaffoldings.Add(scaffolding);
				}
			}
		}
コード例 #27
0
		/// <summary>
		/// Collects the default action.
		/// </summary>
		/// <param name="descriptor">The descriptor.</param>
		/// <param name="controllerType">Type of the controller.</param>
		private void CollectDefaultAction(ControllerMetaDescriptor descriptor, Type controllerType)
		{
			var attributes = controllerType.GetCustomAttributes(typeof(DefaultActionAttribute), true);

			if (attributes.Length != 0)
			{
				descriptor.DefaultAction = (DefaultActionAttribute) attributes[0];
			}
		}
コード例 #28
0
		/// <summary>
		/// Collects the class level attributes.
		/// </summary>
		/// <param name="controllerType">Type of the controller.</param>
		/// <param name="descriptor">The descriptor.</param>
		private void CollectClassLevelAttributes(Type controllerType, ControllerMetaDescriptor descriptor)
		{
			CollectHelpers(descriptor, controllerType);
			CollectResources(descriptor, controllerType);
			CollectFilters(descriptor, controllerType);
			CollectLayout(descriptor, controllerType);
			CollectRescues(descriptor, controllerType);
			CollectDefaultAction(descriptor, controllerType);
			CollectScaffolding(descriptor, controllerType);
			CollectDynamicActionProviders(descriptor, controllerType);
			CollectCacheConfigure(descriptor, controllerType);
		}
コード例 #29
0
        private void MergeAsyncMethodPairsToSingleAction(ControllerMetaDescriptor desc)
        {
            foreach (string name in new ArrayList(desc.Actions.Keys))
            {
                // skip methods that are not named "BeginXyz"
                if (!name.StartsWith("Begin", StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }

                var actionName = name.Substring("Begin".Length);

                var list = desc.Actions[name] as ArrayList;

                if (list != null)
                {
                    foreach (MethodInfo info in list)
                    {
                        if (info.ReturnType == typeof(IAsyncResult))
                        {
                            throw new MonoRailException("Action '" + actionName + "' on controller '" + desc.ControllerDescriptor.Name +
                                                        "' is an async action, but there are method overloads '" + name +
                                                        "(...)', which is not allowed on async actions.");
                        }
                    }
                    continue;
                }

                if (desc.Actions.Contains(actionName))
                {
                    throw new MonoRailException("Found both async method '" + name + "' and sync method '" + actionName +
                                                "' on controller '" + desc.ControllerDescriptor.Name +
                                                "'. MonoRail doesn't support mixing sync and async methods for the same action");
                }

                var beginActionInfo = (MethodInfo)desc.Actions[name];
                // we allow BeginXyz method as sync methods, as long as they do not return
                // IAsyncResult
                if (beginActionInfo.ReturnType != typeof(IAsyncResult))
                {
                    continue;
                }

                var endActionName = "End" + actionName;
                if (desc.Actions.Contains(endActionName) == false)
                {
                    throw new MonoRailException("Found beginning of async pair '" + name + "' but not the end '" + endActionName +
                                                "' on controller '" + desc.ControllerDescriptor.Name + "', did you forget to define " +
                                                endActionName + "(IAsyncResult ar) ?");
                }

                if (desc.Actions[endActionName] is IList)
                {
                    throw new MonoRailException("Found more than a single " + endActionName +
                                                " method, for async action '" + actionName + "' on controller '" +
                                                desc.ControllerDescriptor.Name + "', only a single " +
                                                endActionName + " may be defined as part of an async action");
                }

                var endActionInfo = (MethodInfo)desc.Actions[endActionName];

                desc.Actions.Remove(name);
                desc.Actions.Remove(endActionName);
                desc.Actions[actionName] = new AsyncActionPair(actionName, beginActionInfo, endActionInfo);
            }
        }
コード例 #30
0
        public virtual IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
        {
            IController controller;

            PerformOneTimeInitializationIfNecessary(context);
            EnsureServices();

            HttpRequest request    = context.Request;
            RouteMatch  routeMatch = (( RouteMatch )context.Items[RouteMatch.RouteMatchKey]) ?? new RouteMatch();

            UrlInfo urlInfo = UrlTokenizer.TokenizeUrl(
                request.FilePath,
                request.PathInfo,
                request.Url,
                request.IsLocal,
                request.ApplicationPath);

            if (urlInfo.Area.Equals("MonoRail", StringComparison.CurrentCultureIgnoreCase) &&
                urlInfo.Controller.Equals("Files", StringComparison.CurrentCultureIgnoreCase))
            {
                return(new ResourceFileHandler(urlInfo, new DefaultStaticResourceRegistry()));
            }

            if (urlInfo.Area.Equals("MonoRail", StringComparison.CurrentCultureIgnoreCase) &&
                urlInfo.Controller.Equals("Resources", StringComparison.CurrentCultureIgnoreCase))
            {
                return(new ResourceFileHandlerEx(urlInfo, new DefaultStaticResourceRegistryEx()));
            }

            IEngineContext serviceInstance = _EngineContextFactory.Create(
                _MonoRailContainer,
                urlInfo,
                context,
                routeMatch);

            serviceInstance.AddService(typeof(IEngineContext), serviceInstance);

            try
            {
                controller = _ControllerFactory.CreateController(urlInfo.Area, urlInfo.Controller);
            }
            catch (ControllerNotFoundException)
            {
                return(new MonoRailHttpHandlerFactory.NotFoundHandler(
                           urlInfo.Area,
                           urlInfo.Controller,
                           serviceInstance));
            }

            ControllerMetaDescriptor metaDescriptor = _MonoRailContainer.ControllerDescriptorProvider.BuildDescriptor(controller);

            IControllerContext context3 = _ControllerContextFactory.Create(
                urlInfo.Area,
                urlInfo.Controller,
                urlInfo.Action,
                metaDescriptor,
                routeMatch);

            serviceInstance.CurrentController          = controller;
            serviceInstance.CurrentControllerContext   = context3;
            context.Items[CurrentEngineContextKey]     = serviceInstance;
            context.Items[CurrentControllerKey]        = controller;
            context.Items[CurrentControllerContextKey] = context3;

            if (IgnoresSession(metaDescriptor.ControllerDescriptor))
            {
                return(new SessionlessMonoRailHttpHandler(serviceInstance, controller, context3));
            }

            return(new MonoRailHttpHandler(serviceInstance, controller, context3));
        }
コード例 #31
0
		/// <summary>
		/// Initializes a new instance of the <see cref="ControllerContext"/> class.
		/// </summary>
		/// <param name="name">The controller name.</param>
		/// <param name="action">The action name.</param>
		/// <param name="metaDescriptor">The meta descriptor.</param>
		public ControllerContext(string name, string action, ControllerMetaDescriptor metaDescriptor) :
			this(name, string.Empty, action, metaDescriptor)
		{
		}
コード例 #32
0
        private void CollectClassLevelAttributes(Type controllerType, ControllerMetaDescriptor descriptor)
        {
            object[] attributes = controllerType.GetCustomAttributes(typeof(DefaultActionAttribute), true);

            if (attributes.Length != 0)
            {
                descriptor.DefaultAction = (DefaultActionAttribute)attributes[0];
            }

            attributes = controllerType.GetCustomAttributes(typeof(HelperAttribute), true);

            if (attributes.Length != 0)
            {
                foreach (HelperAttribute helper in attributes)
                {
                    descriptor.Helpers.Add(helper);
                }
            }

            attributes = controllerType.GetCustomAttributes(typeof(ResourceAttribute), true);

            if (attributes.Length != 0)
            {
                foreach (ResourceAttribute resource in attributes)
                {
                    descriptor.Resources.Add(resource);
                }
            }

            attributes = controllerType.GetCustomAttributes(typeof(FilterAttribute), true);

            if (attributes.Length != 0)
            {
                foreach (FilterAttribute filter in attributes)
                {
                    descriptor.Filters.Add(filter);
                }
            }

            attributes = controllerType.GetCustomAttributes(typeof(LayoutAttribute), true);

            if (attributes.Length != 0)
            {
                descriptor.Layout = (LayoutAttribute)attributes[0];
            }

            attributes = controllerType.GetCustomAttributes(typeof(RescueAttribute), true);

            if (attributes.Length != 0)
            {
                descriptor.Rescues = attributes;
            }

            attributes = controllerType.GetCustomAttributes(typeof(ScaffoldingAttribute), false);

            if (attributes.Length != 0)
            {
                foreach (ScaffoldingAttribute scaffolding in attributes)
                {
                    descriptor.Scaffoldings.Add(scaffolding);
                }
            }

            attributes = controllerType.GetCustomAttributes(typeof(DynamicActionProviderAttribute), true);

            if (attributes.Length != 0)
            {
                foreach (DynamicActionProviderAttribute actionProvider in attributes)
                {
                    descriptor.ActionProviders.Add(actionProvider);
                }
            }
        }
コード例 #33
0
 /// <summary>
 /// Collects the dynamic action providers.
 /// </summary>
 /// <param name="descriptor">The descriptor.</param>
 /// <param name="controllerType">Type of the controller.</param>
 private void CollectDynamicActionProviders(ControllerMetaDescriptor descriptor, Type controllerType)
 {
     descriptor.DynamicActionProviders = dynamicActionProviderDescriptorProvider.CollectProviders(controllerType);
 }
コード例 #34
0
        /// <summary>
        /// Collects the filters.
        /// </summary>
        /// <param name="descriptor">The descriptor.</param>
        /// <param name="controllerType">Type of the controller.</param>
        private void CollectFilters(ControllerMetaDescriptor descriptor, Type controllerType)
        {
            descriptor.Filters = filterDescriptorProvider.CollectFilters(controllerType);

            Array.Sort(descriptor.Filters, FilterDescriptorComparer.Instance);
        }
コード例 #35
0
		/// <summary>
		/// Pendent
		/// </summary>
		/// <param name="area"></param>
		/// <param name="controller"></param>
		/// <param name="action"></param>
		/// <param name="metaDescriptor"></param>
		/// <returns></returns>
		public IControllerContext Create(string area, string controller, string action,
		                                 ControllerMetaDescriptor metaDescriptor)
		{
			return Create(area, controller, action, metaDescriptor, new RouteMatch());
		}
コード例 #36
0
		private void MergeAsyncMethodPairsToSingleAction(ControllerMetaDescriptor desc)
		{
			foreach(string name in new ArrayList(desc.Actions.Keys))
			{
				// skip methods that are not named "BeginXyz"
				if (!name.StartsWith("Begin", StringComparison.InvariantCultureIgnoreCase))
				{
					continue;
				}

				var actionName = name.Substring("Begin".Length);

				var list = desc.Actions[name] as ArrayList;

				if (list != null)
				{
					foreach(MethodInfo info in list)
					{
						if (info.ReturnType == typeof(IAsyncResult))
						{
							throw new MonoRailException("Action '" + actionName + "' on controller '" + desc.ControllerDescriptor.Name +
							                            "' is an async action, but there are method overloads '" + name +
							                            "(...)', which is not allowed on async actions.");
						}
					}
					continue;
				}

				if (desc.Actions.Contains(actionName))
				{
					throw new MonoRailException("Found both async method '" + name + "' and sync method '" + actionName +
					                            "' on controller '" + desc.ControllerDescriptor.Name +
					                            "'. MonoRail doesn't support mixing sync and async methods for the same action");
				}
				
				var beginActionInfo = (MethodInfo) desc.Actions[name];
				// we allow BeginXyz method as sync methods, as long as they do not return
				// IAsyncResult
				if(beginActionInfo.ReturnType != typeof(IAsyncResult))
					continue;
				
				var endActionName = "End" + actionName;
				if (desc.Actions.Contains(endActionName) == false)
				{
					throw new MonoRailException("Found beginning of async pair '" + name + "' but not the end '" + endActionName +
					                            "' on controller '" + desc.ControllerDescriptor.Name + "', did you forget to define " +
					                            endActionName + "(IAsyncResult ar) ?");
				}

				if (desc.Actions[endActionName] is IList)
				{
					throw new MonoRailException("Found more than a single " + endActionName +
					                            " method, for async action '" + actionName + "' on controller '" +
					                            desc.ControllerDescriptor.Name + "', only a single " +
					                            endActionName + " may be defined as part of an async action");
				}

				var endActionInfo = (MethodInfo) desc.Actions[endActionName];

				desc.Actions.Remove(name);
				desc.Actions.Remove(endActionName);
				desc.Actions[actionName] = new AsyncActionPair(actionName, beginActionInfo, endActionInfo);
			}
		}
コード例 #37
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ControllerContext"/> class.
 /// </summary>
 /// <param name="name">The controller name.</param>
 /// <param name="action">The action name.</param>
 /// <param name="metaDescriptor">The meta descriptor.</param>
 public ControllerContext(string name, string action, ControllerMetaDescriptor metaDescriptor) :
     this(name, string.Empty, action, metaDescriptor)
 {
 }
コード例 #38
0
		/// <summary>
		/// Collects the action level attributes.
		/// </summary>
		/// <param name="descriptor">The descriptor.</param>
		private void CollectActionLevelAttributes(ControllerMetaDescriptor descriptor)
		{
			foreach(var action in descriptor.Actions.Values)
			{
				if (action is IList)
				{
					foreach(MethodInfo overloadedAction in (action as IList))
					{
						CollectActionAttributes(overloadedAction, descriptor);
					}

					continue;
				}

				var methodInfo = action as MethodInfo;

				if (methodInfo != null)
				{
					CollectActionAttributes(methodInfo, descriptor);
				}
				else
				{
					var asyncActionPair = (AsyncActionPair) action;
					CollectActionAttributes(asyncActionPair.BeginActionInfo, descriptor);
					CollectActionAttributes(asyncActionPair.EndActionInfo, descriptor);
				}
			}
		}
コード例 #39
0
		/// <summary>
		/// The following lines were added to handle _default processing
		/// if present look for and load _default action method
		/// <seealso cref="DefaultActionAttribute"/>
		/// </summary>
		private IExecutableAction ResolveDefaultMethod(ControllerMetaDescriptor controllerDesc, IController controller,
		                                               IControllerContext context, ActionType actionType)
		{
			if (controllerDesc.DefaultAction != null)
			{
				MethodInfo method = SelectActionMethod(
					controller, context,
					controllerDesc.DefaultAction.DefaultAction, actionType);

				if (method != null)
				{
					ActionMetaDescriptor actionDesc = controllerDesc.GetAction(method);

					return new ActionMethodExecutor(method, actionDesc ?? new ActionMetaDescriptor());
				}
			}

			return null;
		}
コード例 #40
0
		/// <summary>
		/// Collects the action attributes.
		/// </summary>
		/// <param name="method">The method.</param>
		/// <param name="descriptor">The descriptor.</param>
		private void CollectActionAttributes(MethodInfo method, ControllerMetaDescriptor descriptor)
		{
			if (logger.IsDebugEnabled)
			{
				logger.DebugFormat("Collection attributes for action {0}", method.Name);
			}

			var actionDescriptor = descriptor.GetAction(method);

			if (actionDescriptor == null)
			{
				actionDescriptor = CreateActionDescriptor();

				descriptor.AddAction(method, actionDescriptor);
			}

			CollectResources(actionDescriptor, method);
			CollectSkipFilter(actionDescriptor, method);
			CollectRescues(actionDescriptor, method);
			CollectAccessibleThrough(actionDescriptor, method);
			CollectSkipRescue(actionDescriptor, method);
			CollectLayout(actionDescriptor, method);
			CollectCacheConfigure(actionDescriptor, method);
			CollectTransformFilter(actionDescriptor, method);
			CollectReturnTypeBinder(actionDescriptor, method);
			CollectActionLevelFiltersIntoActionDescriptor(method, actionDescriptor);
			if (method.IsDefined(typeof(AjaxActionAttribute), true))
			{
				descriptor.AjaxActions.Add(method);
			}

			if (method.IsDefined(typeof(DefaultActionAttribute), true))
			{
				if (descriptor.DefaultAction != null)
				{
					throw new MonoRailException(
						"Cannot resolve a default action for {0}, DefaultActionAttribute was declared more than once.",
						method.DeclaringType.FullName);
				}
				descriptor.DefaultAction = new DefaultActionAttribute(method.Name);
			}

			if (AfterActionProcess != null)
			{
				AfterActionProcess(actionDescriptor);
			}
		}
コード例 #41
0
		/// <summary>
		/// Collects the actions.
		/// </summary>
		/// <param name="controllerType">Type of the controller.</param>
		/// <param name="desc">The desc.</param>
		private void CollectActions(Type controllerType, ControllerMetaDescriptor desc)
		{
			// HACK: GetRealControllerType is a workaround for DYNPROXY-14 bug
			// see: http://support.castleproject.org/browse/DYNPROXY-14
			controllerType = GetRealControllerType(controllerType);

			var methods = controllerType.GetMethods(BindingFlags.Public | BindingFlags.Instance);

			foreach(var method in methods)
			{
				var declaringType = method.DeclaringType;

				if (method.IsSpecialName)
				{
					continue;
				}

				if (declaringType == typeof(Object) ||
				    declaringType == typeof(IController) || declaringType == typeof(Controller))
					// || declaringType == typeof(SmartDispatcherController))
				{
					continue;
				}

				if (desc.Actions.Contains(method.Name))
				{
					var list = desc.Actions[method.Name] as ArrayList;

					if (list == null)
					{
						list = new ArrayList { desc.Actions[method.Name] };

						desc.Actions[method.Name] = list;
					}

					list.Add(method);
				}
				else
				{
					desc.Actions[method.Name] = method;
				}
			}

			MergeAsyncMethodPairsToSingleAction(desc);
		}
コード例 #42
0
 /// <summary>
 /// Pendent
 /// </summary>
 /// <param name="area"></param>
 /// <param name="controller"></param>
 /// <param name="action"></param>
 /// <param name="metaDescriptor"></param>
 /// <returns></returns>
 public IControllerContext Create(string area, string controller, string action,
                                  ControllerMetaDescriptor metaDescriptor)
 {
     return(Create(area, controller, action, metaDescriptor, new RouteMatch()));
 }