示例#1
0
        private static void RegisterControllerEx(Type controllerType, TenantData tenantData, string name)
        {
            Match match = Expressions.ControllerPathRegex.Match(controllerType.FullName);

            if (!match.Success)
            {
                return;
            }

            SectionData section = tenantData.Sections.Values.FirstOrDefault(sec => controllerType.Namespace == sec.Namespace + ".Controllers");

            if (section == null)
            {
                return;
            }

            string controllerName = name ?? controllerType.Name;

            if (controllerName.EndsWith("controller", StringComparison.OrdinalIgnoreCase))
            {
                controllerName = controllerName.Substring(0, controllerName.Length - 10);
            }

            ControllerMetaWrapper wrapper = new ControllerMetaWrapper(controllerType, controllerName);

            string pathPrefix = HttpContext.Current.Request.ApplicationPath + (tenantData.Name != null ? "Tenants/" + tenantData.Name + "/" : null) + (section.Name == null || section.Name == DefaultSection.DefaultName ? null : section.Name); // + (match.Groups["PATH"].Value.Replace(".", "/")));
            bool   needsSlash = !pathPrefix.EndsWith("/");

            wrapper.BaseViewVirtualPaths.Add(pathPrefix + (needsSlash ? "/" : null) + "Views/" + controllerName + "/");
            wrapper.BaseViewVirtualPaths.Add(pathPrefix + (needsSlash ? "/" : null) + "Views/Shared/");

            section.AddControllerMeta(wrapper, controllerName);
        }
示例#2
0
        internal void AddControllerMeta(ControllerMetaWrapper controller, string name)
        {
            if (Controllers.ContainsKey(name))
            {
                Debugger.Break();
//                throw new ArgumentException("A controller named '" + name + "' has already been registered with the '" + name + "' section.");
                return;
            }

            Controllers.Add(name, controller);
        }
示例#3
0
        private static void AddControllerResult(PortalContext context, PortalRequest request, SectionData section)
        {
            ControllerMetaWrapper controller = section.GetControllerMeta(request.ControllerName);
            string actionName = controller.Name == "Home" ? request.GetTokenValue(ControllerNameToken) : request.GetTokenValue(ControllerActionToken);

            if (actionName == null || actionName == controller.Name)
            {
                actionName = "Index";
            }

            request.ControllerName = controller.Name;
            request.ActionName     = actionName;
            request.Result         = controller.Execute(context);
        }