示例#1
0
        private void CreateContext(IHttpContext httpContext, string portalPath, string virtualPath, bool isPortalRoute)
        {
            foreach (VirtualResourcesElement resource in config.VirtualResources)
            {
                SetVirtualResourceData(resource.Name, new VirtualResourceData(resource.Namespace, resource.Assembly));
            }

            PortalRequest  request  = CreateRequest(httpContext, portalPath, virtualPath, isPortalRoute);
            PortalResponse response = new PortalResponse(this);

            Request  = request;
            Response = response;

            AddConfigOptions(this, request);

            if (isPortalRoute)
            {
                int firstSlashIndex = portalPath.IndexOf('/', 1);
                int length          = firstSlashIndex >= 0 ? firstSlashIndex : portalPath.Length;
                request.TenantName = TenantCache.GetTenantName(httpContext.Request.Url.Host);
                if (!Compare.IsNullOrEmpty(request.TenantName))
                {
                    request.VirtualPath = "/Tenants/" + request.TenantName + request.VirtualPath;
                }

                Section = TenantCache.GetSectionOrDefault(request.TenantName, portalPath.Length == 1 ? null : portalPath.Substring(1, length - 1));
                AddRouteContext(request, response, Section);
                AddControllerResult(this, request, Section);
            }

            PortalTrace.Write("PortalRequestModule", "CreateContext", "PortalContext created.");
            PortalTrace.Write("PortalRequestModule", "CreateContext", "Setup={0}, AllowPhysicalPages={1}, jQuery Version={2}", config.Setup, config.Routes.AllowPhysicalPages, config.JQuery.Version);
        }
示例#2
0
        private static void AddRouteData(PortalRequest request, PortalResponse response, Route route)
        {
            if (route == null)
            {
                return;
            }

            request.MergeTokens(route.GetTokens(request.Path));
            NameValueCollection queryString = request.QueryString;

            if (queryString.Count > 0)
            {
                RouteTokens queryTokens = new RouteTokens();
                foreach (string s in queryString)
                {
                    queryTokens.Add(s, queryString[s]);
                }
                request.MergeTokens(queryTokens);
            }

            request.ControllerName = route.ControllerName ?? request.GetTokenValue(ControllerNameToken);

            foreach (TileDefinition tile in route.Tiles)
            {
                response.Tiles.Add(tile);
            }

            if (!Compare.IsNullOrEmpty(route.PageTitle))
            {
                request.Title = FormattableObject.ToString(request.Tokens.ToDictonary(), route.PageTitle, null);
            }
        }
示例#3
0
        private static void AddConfigOptions(PortalContext context, PortalRequest request)
        {
            context.SetupMode  = context.config.Setup;
            context.JQuery     = new ScriptSetting(context.config.JQuery.Version);
            context.Modernizer = new ScriptSetting(context.config.Modernizer.Version);

            request.AllowPhysicalPages = context.config.Routes.AllowPhysicalPages;
        }
示例#4
0
        private PortalRequest CreateRequest(IHttpContext httpContext, string portalPath, string virtualPath, bool isPortalRoute)
        {
            PortalRequest request = new PortalRequest
            {
                Path               = portalPath,
                VirtualPath        = virtualPath,
                IsPortalRoute      = isPortalRoute,
                AllowPhysicalPages = config.Routes.AllowPhysicalPages,
                IsXmlHttpRequest   = Headers.GetRequestedWith(httpContext) == HeaderValue.XmlHttpRequest
            };

            return(request);
        }
示例#5
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);
        }
示例#6
0
        private static void AddRouteContext(PortalRequest request, PortalResponse response, SectionData section)
        {
            PortalTrace.Write("PortalRequestModule", "InitializeRouteContext", "Begin InitializeRouteContext.");

            if (section == null)
            {
                throw new InvalidOperationException("No section found.");
            }

            List <Route> routes = section.GetMatchedRoutes(request.Path);

            if (routes.Count > 0)
            {
                AddRouteData(request, response, routes[0]);
            }

            PortalTrace.Write("PortalRequestModule", "InitializeRouteContext", "End InitializeRouteContext.");
        }