public HtmlHandlerWrapper( IHtmlHandler handler ) { if ( handler == null ) throw new ArgumentNullException( "handler" ); _handler = handler; }
/// <summary> /// 派生类重写此方法接管 HTTP 请求处理流程 /// </summary> /// <param name="context">当前 HTML 请求上下文</param> /// <param name="handler">用于处理 HTML 文档的处理程序</param> /// <returns>处理后的结果</returns> protected virtual ICachedResponse ProcessRequest(HtmlRequestContext context, IHtmlHandler handler) { var filters = GetFilters(context.VirtualPath); OnProcessing(context, filters); Trace("Begin process document."); handler.ProcessScope(context); Trace("End process document."); OnProcessed(context, filters); OnRendering(context, filters); Trace("Begin render document."); string content; using (StringWriter writer = new StringWriter()) { context.Scope.RenderChilds(writer, GetAdapters(handler)); content = writer.ToString(); } Trace("End render document."); OnRendered(context, filters); return(CreateResponse(content)); }
/// <summary> /// 创建 RequestMapping 对象 /// </summary> /// <param name="mapper">产生此结果的映射器</param> /// <param name="virtualPath">HTML 模版路径</param> /// <param name="handler">HTML 文档处理程序</param> public RequestMapping( IRequestMapper mapper, string virtualPath, IHtmlHandler handler ) { if ( !VirtualPathUtility.IsAppRelative( virtualPath ) ) throw new ArgumentException( "模版文件路径只能使用应用程序根相对路径,即以~/开头的路径,调用VirtualPathUtility.ToAppRelative方法或使用HttpRequest.AppRelativeCurrentExecutionFilePath属性获取", "templatePath" ); VirtualPath = virtualPath; Handler = handler; }
public HttpHandler(IHtmlHandler handler) { if (handler == null) { throw new ArgumentNullException("handler"); } _handler = handler; }
/// <summary> /// 创建 RequestMapping 对象 /// </summary> /// /// <param name="templatePath">HTML 模版路径</param> /// <param name="handler">HTML 文档处理程序</param> public RequestMapping(IRequestMapper mapper, string templatePath, IHtmlHandler handler) { if (!VirtualPathUtility.IsAppRelative(templatePath)) { throw new ArgumentException("模版文件路径只能使用应用程序根相对路径,即以~/开头的路径,调用VirtualPathUtility.ToAppRelative方法或使用HttpRequest.AppRelativeCurrentExecutionFilePath属性获取", "templatePath"); } TemplatePath = templatePath; Handler = handler; }
/// <summary> /// 获取 HTML 处理程序 /// </summary> /// <param name="virtualPath">要处理的 HTML 文档的虚拟路径</param> /// <returns>HTML 处理程序</returns> protected virtual IHtmlHandler GetHandler(string virtualPath) { IHtmlHandler handler = null; if (RequestContext != null) { handler = RequestContext.RouteData.DataTokens[JumonyRequestRoute.HtmlHandlerToken] as IHtmlHandler; RequestContext.RouteData.DataTokens.Remove(JumonyRequestRoute.HtmlHandlerToken); } return(handler ?? HtmlHandlerProvider.GetHandler(virtualPath)); }
/// <summary> /// 派生类调用创建 RequestMapping 对象 /// </summary> /// <param name="mapper">请求映射器</param> /// <param name="handler">HTML 文档处理程序</param> protected RequestMapping(IRequestMapper mapper, IHtmlHandler handler) { Mapper = mapper; Handler = handler; }
/// <summary> /// 为现有的 IHtmlHandler 对象创建 ViewHandler 包装 /// </summary> /// <param name="handler">现有的 IHtmlHandler 对象</param> public HtmlViewHandlerWrapper(IHtmlHandler handler) { _handler = handler; }
/// <summary> /// 为现有的 IHtmlHandler 对象创建 ViewHandler 包装 /// </summary> /// <param name="handler">现有的 IHtmlHandler 对象</param> public HtmlViewHandlerWrapper( IHtmlHandler handler ) { _handler = handler; }
/// <summary> /// 渲染部分视图 /// </summary> /// <param name="context">当前 HTTP 请求上下文</param> /// <param name="virtualPath">当前要处理的部分视图的虚拟路径</param> /// <param name="handler">当前部分视图的 HTML 处理程序</param> /// <returns>渲染结果</returns> public string RenderPartial(HttpContextBase context, string virtualPath, IHtmlHandler handler) { _context = context; return(ProcessRequest(new HtmlRequestContext(context, virtualPath, CreateScope(virtualPath)), handler).CastTo <PartialResponse>().Content); }
/// <summary> /// 渲染部分视图 /// </summary> /// <param name="context">当前 HTTP 请求上下文</param> /// <param name="virtualPath">当前要处理的部分视图的虚拟路径</param> /// <param name="handler">当前部分视图的 HTML 处理程序</param> /// <returns>渲染结果</returns> public string RenderPartial( HttpContextBase context, string virtualPath, IHtmlHandler handler ) { _context = context; return ProcessRequest( new HtmlRequestContext( context, virtualPath, CreateScope( virtualPath ) ), handler ).CastTo<PartialResponse>().Content; }
/// <summary> /// 派生类重写此方法接管 HTTP 请求处理流程 /// </summary> /// <param name="context">当前 HTML 请求上下文</param> /// <param name="handler">用于处理 HTML 文档的处理程序</param> /// <returns>处理后的结果</returns> protected virtual ICachedResponse ProcessRequest( HtmlRequestContext context, IHtmlHandler handler ) { var filters = GetFilters( context.VirtualPath ); OnProcessing( context, filters ); Trace( "Begin process document." ); handler.ProcessScope( context ); Trace( "End process document." ); OnProcessed( context, filters ); OnRendering( context, filters ); Trace( "Begin render document." ); string content; using ( StringWriter writer = new StringWriter() ) { context.Scope.RenderChilds( writer, GetAdapters( handler ) ); content = writer.ToString(); } Trace( "End render document." ); OnRendered( context, filters ); return CreateResponse( content ); }