public virtual void RemoveSiteFromModule(string moduleName, string siteName) { var list = ModuleRelationData.GetSitesInModule(moduleName); list.RemoveAll(s => s.EqualsOrNullEmpty(siteName, StringComparison.OrdinalIgnoreCase)); ModuleRelationData.SaveSitesInModule(moduleName, list); try { var moduleAction = ResolveModuleAction(moduleName); if (moduleAction != null) { moduleAction.OnExcluded(ModuleContext.Create(moduleName, new Site(siteName))); } } catch (Exception e) { Kooboo.HealthMonitoring.Log.LogException(e); } }
public virtual void AddSiteToModule(string moduleName, string siteName) { var list = ModuleRelationData.GetSitesInModule(moduleName); if (!list.Contains(siteName, StringComparer.OrdinalIgnoreCase)) { list.Add(siteName); ModuleRelationData.SaveSitesInModule(moduleName, list); } try { var moduleAction = ResolveModuleAction(moduleName); if (moduleAction != null) { moduleAction.OnIncluded(ModuleContext.Create(moduleName, new Site(siteName))); } } catch (Exception e) { Kooboo.HealthMonitoring.Log.LogException(e); } }
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; } } }