protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) { var positionType = controllerContext.HttpContext.Request["PositionType"]; object model = null; switch (positionType) { case "View": model = new ViewPosition(); break; case "Module": model = new ModulePosition(); break; case "Content": model = new HtmlPosition(); break; default: break; } bindingContext.ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(() => model, model.GetType()); return model; }
public virtual ActionResult ViewEntry(string viewName) { viewName = Server.UrlDecode(viewName); var viewPosition = new ViewPosition() { LayoutPositionId = Kooboo.UniqueIdGenerator.GetInstance().GetBase32UniqueId(5), ViewName = viewName, PagePositionId = Kooboo.UniqueIdGenerator.GetInstance().GetBase32UniqueId(5) }; //pageUrl: product/detail/product1 var rawPage = new Page(Site, "____VisitViewPage_____") { IsDummy = false }; rawPage.PagePositions.Add(viewPosition); var requestUrl = ""; var pageRequestContext = new PageRequestContext(this.ControllerContext, FrontHttpRequest.RawSite, FrontHttpRequest.Site, rawPage, rawPage, FrontHttpRequest.RequestChannel, requestUrl); Page_Context.Current.InitContext(pageRequestContext, ControllerContext); var actionResult = Page_Context.Current.ExecutePlugins(); if (actionResult != null) { return actionResult; } Page_Context.Current.ExecuteDataRules(); var viewMock = new ViewMock() { ViewData = new ViewDataDictionary(ViewData) }; ViewContext viewContext = new ViewContext(this.ControllerContext, viewMock, ViewData, this.TempData, Response.Output); HtmlHelper html = new HtmlHelper(viewContext, viewMock); return Content(html.FrontHtml().RenderView(viewPosition).ToString()); }
protected internal virtual IHtmlString RenderView(ViewPosition viewPosition) { Func<IHtmlString> renderView = () => this.RenderView(viewPosition.ViewName, PageContext.GetPositionViewData(viewPosition.PagePositionId), viewPosition.ToParameterDictionary(), false); if (viewPosition.EnabledCache) { var cacheKey = string.Format("View OutputCache - Full page name:{0};Raw request url:{1};PagePositionId:{2};ViewName:{3};LayoutPositionId:{4}" , PageContext.PageRequestContext.Page.FullName, PageContext.ControllerContext.HttpContext.Request.RawUrl, viewPosition.PagePositionId, viewPosition.ViewName, viewPosition.LayoutPositionId); var cacheItemPolicy = viewPosition.OutputCache.ToCachePolicy(); return this.PageContext.PageRequestContext.Site.ObjectCache().GetCache<IHtmlString>(cacheKey, renderView, cacheItemPolicy); } else { return renderView(); } }
public PageDesignViewContent(ViewPosition pos) : base(pos) { this.Parameter.Add("ViewName", PageDesignContent.Code(pos.ViewName)); if (pos.OutputCache != null) { var outputCacheJson = new { Duration = pos.OutputCache.Duration, ExpirationPolicy = pos.OutputCache.ExpirationPolicy.ToString() }; var serializer = new JavaScriptSerializer(); var outputCacheJsonString = serializer.Serialize(outputCacheJson); this.Parameter.Add("OutputCache", PageDesignContent.Code(outputCacheJsonString)); } if (pos.Parameters != null && pos.Parameters.Count > 0) { var parameters = new List<object>(); pos.Parameters.ForEach((p) => { var value = string.Empty; if (p.Value != null) { value = p.Value.ToString(); if (p.DataType == DataType.DateTime) { var date = ((DateTime)p.Value); value = date.ToLocalTime().ToShortDateString(); } } parameters.Add(new { Name = p.Name, DataType = p.DataType.ToString(), Value = value }); }); var serializer = new JavaScriptSerializer(); var parametersJson = serializer.Serialize(parameters); this.Parameter.Add("Parameters", PageDesignContent.Code(parametersJson)); } }
private static string GetOutputCacheKey(HttpContextBase httpContext, Page page, ViewPosition viewPosition) { var cacheKey = string.Format("View OutputCache - Full page name:{0};Raw request url:{1};PagePositionId:{2};ViewName:{3};LayoutPositionId:{4}" , page.FullName, httpContext.Request.RawUrl, viewPosition.PagePositionId, viewPosition.ViewName, viewPosition.LayoutPositionId); return cacheKey; }
protected virtual IHtmlString RenderView(ViewPosition viewPosition) { string cacheKey = null; var site = PageContext.PageRequestContext.Site; if (viewPosition.EnabledCache) { cacheKey = GetOutputCacheKey(PageContext.ControllerContext.HttpContext, PageContext.PageRequestContext.Page, viewPosition); var outputCache = PageContext.PageRequestContext.Site.ObjectCache().Get(cacheKey); if (outputCache != null) { return new HtmlString(outputCache.ToString()); } } var htmlString = RenderView(viewPosition.ViewName, Page_Context.Current.GetPositionViewData(viewPosition.PagePositionId), viewPosition.ToParameterDictionary(), false); if (!string.IsNullOrEmpty(cacheKey)) { PageContext.PageRequestContext.Site.ObjectCache().Add(cacheKey, htmlString, viewPosition.OutputCache.ToCachePolicy()); } return htmlString; }