Esempio n. 1
0
        private ViewTemplateDescription AnalyzeView(HttpContextBase httpContext, VirtualFile file, string controllerName, Type modelType)
        {
            if (modelType == null || !typeof(ContentItem).IsAssignableFrom(modelType) || modelType.IsAbstract)
                return null;

            var model = Activator.CreateInstance(modelType) as ContentItem;

            var rd = new RouteData();
            bool isPage = model.IsPage;
            rd.ApplyCurrentItem(controllerName, Path.GetFileNameWithoutExtension(file.Name), isPage ? model : new StubItem(), isPage ? null : model);

            var cctx = new ControllerContext(httpContext, rd, new StubController());

            var result = isPage
                ? viewEnginesProvider.Get().FindView(cctx, file.VirtualPath, null)
                : viewEnginesProvider.Get().FindPartialView(cctx, file.VirtualPath);

            if (result.View == null)
                return null;

            return RenderViewForRegistration(file, modelType, cctx, result);
        }
 private static HtmlHelper CreateHtmlHelper(ContentItem item, TextWriter writer)
 {
     var httpContext = new HttpContextWrapper(HttpContext.Current);
     var routeData = new RouteData();
     routeData.ApplyCurrentItem("webforms", "index", item.ClosestPage(), item);
     return new HtmlHelper(
         new ViewContext(
             new ControllerContext() { HttpContext = httpContext, RequestContext = new RequestContext(httpContext, routeData), RouteData = routeData },
             new WebFormView(HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath),
             new ViewDataDictionary(),
             new TempDataDictionary(),
             writer),
         new ViewPage(),
         RouteTable.Routes);
 }
Esempio n. 3
0
        private RouteData GetRouteDataForPath(HttpRequestBase request)
        {
            //On a multi-lingual site with separate domains per language,
            //the full url (with host) should be passed to UrlParser.ResolvePath():
            string host = (request.Url.IsDefaultPort) ? request.Url.Host : request.Url.Authority;
            string hostAndRawUrl = String.Format("{0}://{1}{2}", request.Url.Scheme, host, Url.ToAbsolute(request.AppRelativeCurrentExecutionFilePath));
            PathData td = engine.UrlParser.ResolvePath(hostAndRawUrl);

            var page = td.CurrentPage;

            var actionName = td.Action;
            if (string.IsNullOrEmpty(actionName))
                actionName = request.QueryString["action"] ?? "Index";

            if (!string.IsNullOrEmpty(request.QueryString[PathData.PageQueryKey]))
            {
                int pageId;
                if (int.TryParse(request.QueryString[PathData.PageQueryKey], out pageId))
                {
                    td.CurrentPage = page = engine.Persister.Get(pageId);
                }
            }

            ContentItem part = null;
            if (!string.IsNullOrEmpty(request.QueryString[PathData.PartQueryKey]))
            {
                // part in query string is used to render a part
                int partId;
                if (int.TryParse(request.QueryString[PathData.PartQueryKey], out partId))
                    td.CurrentItem = part = engine.Persister.Get(partId);
            }

            if (page == null && part == null)
                return null;
            else if (page == null)
                page = part.ClosestPage();

            var controllerName = controllerMapper.GetControllerName((part ?? page).GetContentType());

            if (controllerName == null)
                return null;

            if (actionName == null || !controllerMapper.ControllerHasAction(controllerName, actionName))
                return null;

            var data = new RouteData(this, routeHandler);

            foreach (var defaultPair in innerRoute.Defaults)
                data.Values[defaultPair.Key] = defaultPair.Value;
            foreach (var tokenPair in innerRoute.DataTokens)
                data.DataTokens[tokenPair.Key] = tokenPair.Value;

            data.ApplyCurrentItem(controllerName, actionName, page, part);
            data.DataTokens[ContentEngineKey] = engine;

            return data;
        }
            private RouteData CreateRouteData()
            {
                ContentItem page = item;
                var ic = Page as IItemContainer;
                if (ic != null)
                    page = ic.CurrentItem;

                var rd = new RouteData();
                rd.ApplyCurrentItem("webform", "Index", page, item);
                return rd;
            }
Esempio n. 5
0
            private RouteData GetRouteData(RequestContext requestContext, ContentItem item, string controllerName)
            {
                var data = new RouteData();
                data.Values[ContentRoute.ControllerKey] = controllerName;
                data.Values[ContentRoute.ActionKey] = "Index";
                data.Values[ContentRoute.ContentItemKey] = item.ID;

                // retrieve the virtual path so we can figure out if this item is routed through an area
                var vpd = routes.GetVirtualPath(requestContext, data.Values);
                if (vpd == null)
                    throw new InvalidOperationException("Unable to render " + item + " (" + data.Values.ToQueryString() + " did not match any route)");

                data.Values["area"] = vpd.DataTokens["area"];
                data.Route = vpd.Route;
                data.ApplyCurrentItem(item.ClosestPage(), item);
                return data;
            }