Ejemplo n.º 1
0
        private static void InitializeController(Controller moduleController, ModuleRequestContext moduleRequestContext)
        {
            moduleController.ControllerContext = new ControllerContext(moduleRequestContext, moduleController);

            var pageControllerContext = moduleRequestContext.PageControllerContext;

            var valueProvider = new ValueProviderCollection();
            valueProvider.Add(new ModuleFormValueProvider(moduleController.ControllerContext));
            valueProvider.Add(new ModuleQueryStringValueProvider(moduleController.ControllerContext));
            valueProvider.Add(new RouteDataValueProvider(moduleController.ControllerContext));
            if (View.Page_Context.Current.PageRequestContext != null)
            {
                valueProvider.Add(new NameValueCollectionValueProvider(View.Page_Context.Current.PageRequestContext.AllQueryString, System.Globalization.CultureInfo.InvariantCulture));
            }
            valueProvider.Add(pageControllerContext.Controller.ValueProvider);

            moduleController.ValueProvider = valueProvider;

            moduleController.TempDataProvider = new ModuleSessionStateTempDataProvider();

            moduleController.Url = new UrlHelper(moduleController.ControllerContext.RequestContext, moduleRequestContext.ModuleContext.FrontEndContext.RouteTable);
        }
Ejemplo n.º 2
0
        public static ModuleActionInvokedContext InvokeAction(ControllerContext controllerContext, Site site, string moduleUrl, ModulePosition modulePosition)
        {
            try
            {
                HttpContext context = HttpContext.Current;

                var positionId = modulePosition.PagePositionId;
                var moduleName = modulePosition.ModuleName;

                ModuleContext moduleContext = ModuleContext.Create(moduleName, site, modulePosition);
                ModuleContext.Current = moduleContext;

                if (string.IsNullOrEmpty(moduleUrl))
                {
                    var entry = modulePosition.Entry;
                    if (entry == null)
                    {
                        var moduleSetting = moduleContext.GetModuleSettings();
                        if (moduleSetting != null)
                        {
                            entry = moduleSetting.Entry;
                        }
                    }
                    if (entry != null)
                    {
                        moduleUrl = GetEntryUrl(context, moduleContext, entry);
                        if (!string.IsNullOrEmpty(moduleUrl) && !moduleUrl.StartsWith("~"))
                        {
                            moduleUrl = "~" + moduleUrl;
                        }
                    }
                }
                if (string.IsNullOrEmpty(moduleUrl))
                {
                    moduleUrl = "~/";
                }
                else if (moduleUrl[0] != '~')
                {
                    moduleUrl = "~/" + moduleUrl.TrimStart('/');
                }

                var httpContext = new ModuleHttpContext(context
                  , new ModuleHttpRequest(context.Request, moduleUrl, moduleContext, controllerContext), new ModuleHttpResponse(context.Response, moduleContext), moduleContext);

                var routeData = moduleContext.FrontEndContext.RouteTable.GetRouteData(httpContext);

                var requestContext = new ModuleRequestContext(httpContext, routeData, moduleContext) { PageControllerContext = controllerContext };

                string controllerName = requestContext.RouteData.GetRequiredString("controller");
                string actionName = requestContext.RouteData.GetRequiredString("action");
                var controller = (Controller)ControllerBuilder.Current.GetControllerFactory().CreateController(requestContext, controllerName);
                if (controller == null)
                {
                    throw new Exception(string.Format("The module '{0}' controller for path '{1}' does not found or does not implement IController.", moduleName, moduleUrl));
                }
                //if (!(controller is ModuleControllerBase))
                //{
                //    throw new Exception(string.Format("The controller type '{0}' must be inherited from ModuleControllerBase.", controller.GetType().FullName));
                //}
                //ModuleControllerBase moduleController = (ModuleControllerBase)controller;

                //ControllerContext moduleControllerContext = new ControllerContext(requestContext, moduleController);

                InitializeController(controller, requestContext);

                var result = actionInvoker.InvokeActionWithoutExecuteResult(modulePosition, controller.ControllerContext, actionName);
                if (result == null)
                {
                    HandleUnknownAction(controller, actionName);
                }
                return result;
            }
            catch
            {
                if (modulePosition.SkipError)
                {
                    return null;
                }
                else
                {
                    throw;
                }
            }
        }
Ejemplo n.º 3
0
        private static string GetEntryUrl(HttpContext context, ModuleContext moduleContext, Entry entry)
        {
            var httpContext = new GetEntryUrlContextWrapper(context, "~/");

            var routeData = moduleContext.FrontEndContext.RouteTable.GetRouteData(httpContext);

            var requestContext = new ModuleRequestContext(httpContext, routeData, moduleContext);

            UrlHelper url = new UrlHelper(requestContext, moduleContext.FrontEndContext.RouteTable);

            return url.Action(entry.Action, entry.Controller, entry.Values);
        }