Пример #1
0
        public string GetModulePositionIdForUrl(ModulePosition modulePosition, RouteValueDictionary routeValues, out Page page)
        {
            page = this.PageRequestContext.Page;
            string modulePositionId = modulePosition.PagePositionId;

            if (!string.IsNullOrEmpty(modulePosition.Entry.LinkToEntryName))
            {
                foreach (var item in Sites.Services.ServiceFactory.PageManager.All(this.PageRequestContext.Site, null))
                {
                    foreach (var position in item.PagePositions.OfType<ModulePosition>())
                    {
                        if (position.Entry != null && !string.IsNullOrEmpty(position.Entry.Name)
                            && position.Entry.Name.EqualsOrNullEmpty(modulePosition.Entry.LinkToEntryName, StringComparison.OrdinalIgnoreCase))
                        {
                            page = item;
                            modulePositionId = position.PagePositionId;
                        }
                    }
                }
            }
            else
            {
                modulePositionId = GetModulePositionIdForUrl(modulePosition.ModuleName, modulePosition.PagePositionId, routeValues);
            }

            return modulePositionId;
        }
Пример #2
0
        public static ModuleContext Create(string moduleName, Site site, ModulePosition position)
        {
            var context = new ModuleContext(moduleName, site, position);

            if (!System.IO.Directory.Exists(context.ModulePath.PhysicalPath))
            {
                throw new Exception(string.Format("The module does not exist.Module name:{0}", moduleName));
            }
            return context;
        }
Пример #3
0
 public ModuleContext(string moduleName, Site site, ModulePosition position)
     : this(moduleName, site)
 {
     this.FrontEndContext = new FrontEndContext(moduleName, this.GetModuleSettings(), position);
 }
Пример #4
0
 public ModuleActionInvokedContext(ModulePosition modulePosition, ControllerContext controllerContext, ActionResult actionResult)
 {
     this.ControllerContext = controllerContext;
     this.ModulePosition = modulePosition;
     this.ActionResult = actionResult;
 }
Пример #5
0
 public FrontEndContext(string moduleName, ModuleSettings moduleSettings, ModulePosition modulePosition)
 {
     this._moduleName = moduleName;
     this._moduleSettings = moduleSettings;
     this._modulePosition = modulePosition;
 }
Пример #6
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;
                }
            }
        }