/// <summary> /// 创建 PartialRenderAdapter 实例 /// </summary> /// <param name="view">需要渲染部分视图的宿主视图</param> public PartialRenderAdapter(ViewContext viewContext, JumonyUrlHelper urlHelper, IViewHandler viewHandler) { if (viewContext == null) { throw new ArgumentNullException("viewContext"); } if (urlHelper == null) { throw new ArgumentNullException("urlHelper"); } if (viewHandler == null) { throw new ArgumentNullException("viewHandler"); } ViewContext = viewContext; ViewHandler = viewHandler; Url = urlHelper; var wrapper = viewHandler as IHandlerWrapper; if (wrapper != null) { _partialExecutors = GetPartialExecutors(wrapper.Handler.GetType()); } else { _partialExecutors = GetPartialExecutors(viewHandler.GetType()); } }
/// <summary> /// 创建 PartialRenderAdapter 实例 /// </summary> /// <param name="view">需要渲染部分视图的宿主视图</param> public PartialRenderAdapter( ViewContext viewContext, JumonyUrlHelper urlHelper, IViewHandler viewHandler ) { if ( viewContext == null ) throw new ArgumentNullException( "viewContext" ); if ( urlHelper == null ) throw new ArgumentNullException( "urlHelper" ); if ( viewHandler == null ) throw new ArgumentNullException( "viewHandler" ); ViewContext = viewContext; ViewHandler = viewHandler; Url = urlHelper; var wrapper = viewHandler as IHandlerWrapper; if ( wrapper != null ) _partialExecutors = GetPartialExecutors( wrapper.Handler.GetType() ); else _partialExecutors = GetPartialExecutors( viewHandler.GetType() ); }
/*Executor commander !*/ public ResponseMethodDTO Execute(string methodName, object[] parameters, bool redirect, IViewHandler viewHandler, bool block) { /*Existen cosas que siempre deben de buscarse*/ MethodInfo methodToExecute = this.GetMethodToExecute (methodName, parameters); ComponentMethodAttribute componentMethodAttribute = this.GetComponentAttributes (methodToExecute); /*Primero discernimos si es bloqueante o no lo es*/ if (block) { //Operaciones que son bloqueantes if (redirect) { MethodInfo methodToResponse ; Type viewType; if (viewHandler == null) { //FIX: Aún se podria mejorar esta invocación. viewType = this.GetViewType (componentMethodAttribute); methodToResponse = this.GetMethodToResponse (viewType, componentMethodAttribute); return ExecuteRedirectNewView (methodToExecute, parameters, viewType, methodToResponse); } else { //Redirigimos a la que nos pide viewType = viewHandler.GetType (); methodToResponse = this.GetMethodToResponse (viewType, componentMethodAttribute); return ExecuteRedirectView (methodToExecute, parameters, viewHandler, methodToResponse); } } else { //No necesitamos información sobre la vista, ni el response. //No se va a ejecutar. return ExecuteNoRedirect (methodToExecute, parameters); } } else { ComponentActionDispatcher componentActionDispatcher; //Operaciones bloqueantes, envolver en un hilo if (redirect) { MethodInfo methodToResponse; Type viewType; if (viewHandler == null) { //Exception handling ¿¿ viewType = this.GetViewType (componentMethodAttribute); methodToResponse = this.GetMethodToResponse (viewType, componentMethodAttribute); componentActionDispatcher = new ComponentActionDispatcher (this, methodToExecute, parameters, viewType, methodToResponse); try { componentActionDispatcher.Do (); } catch (TargetInvocationException exception) { this.MapException (exception); } return componentActionDispatcher.ResponseMethodDTO; } else { viewType = viewHandler.GetType (); methodToResponse = this.GetMethodToResponse (viewType, componentMethodAttribute); componentActionDispatcher = new ComponentActionDispatcher (this, methodToExecute, parameters, viewHandler, methodToResponse); try { componentActionDispatcher.Do (); } catch (TargetInvocationException exception) { this.MapException (exception); } return componentActionDispatcher.ResponseMethodDTO; } } else { componentActionDispatcher = new ComponentActionDispatcher (this, methodToExecute, parameters); try { componentActionDispatcher.Do (); } catch (TargetInvocationException exception) { this.MapException (exception); } return componentActionDispatcher.ResponseMethodDTO; } } //return null; }
/*Executor commander !*/ public ResponseMethodDTO Execute(string methodName, object[] parameters, bool redirect, IViewHandler viewHandler, bool block) { /*Existen cosas que siempre deben de buscarse*/ MethodInfo methodToExecute = this.GetMethodToExecute(methodName, parameters); ComponentMethodAttribute componentMethodAttribute = this.GetComponentAttributes(methodToExecute); /*Primero discernimos si es bloqueante o no lo es*/ if (block) { //Operaciones que son bloqueantes if (redirect) { MethodInfo methodToResponse; Type viewType; if (viewHandler == null) { //FIX: Aún se podria mejorar esta invocación. viewType = this.GetViewType(componentMethodAttribute); methodToResponse = this.GetMethodToResponse(viewType, componentMethodAttribute); return(ExecuteRedirectNewView(methodToExecute, parameters, viewType, methodToResponse)); } else { //Redirigimos a la que nos pide viewType = viewHandler.GetType(); methodToResponse = this.GetMethodToResponse(viewType, componentMethodAttribute); return(ExecuteRedirectView(methodToExecute, parameters, viewHandler, methodToResponse)); } } else { //No necesitamos información sobre la vista, ni el response. //No se va a ejecutar. return(ExecuteNoRedirect(methodToExecute, parameters)); } } else { ComponentActionDispatcher componentActionDispatcher; //Operaciones bloqueantes, envolver en un hilo if (redirect) { MethodInfo methodToResponse; Type viewType; if (viewHandler == null) { //Exception handling ¿¿ viewType = this.GetViewType(componentMethodAttribute); methodToResponse = this.GetMethodToResponse(viewType, componentMethodAttribute); componentActionDispatcher = new ComponentActionDispatcher(this, methodToExecute, parameters, viewType, methodToResponse); try { componentActionDispatcher.Do(); } catch (TargetInvocationException exception) { this.MapException(exception); } return(componentActionDispatcher.ResponseMethodDTO); } else { viewType = viewHandler.GetType(); methodToResponse = this.GetMethodToResponse(viewType, componentMethodAttribute); componentActionDispatcher = new ComponentActionDispatcher(this, methodToExecute, parameters, viewHandler, methodToResponse); try { componentActionDispatcher.Do(); } catch (TargetInvocationException exception) { this.MapException(exception); } return(componentActionDispatcher.ResponseMethodDTO); } } else { componentActionDispatcher = new ComponentActionDispatcher(this, methodToExecute, parameters); try { componentActionDispatcher.Do(); } catch (TargetInvocationException exception) { this.MapException(exception); } return(componentActionDispatcher.ResponseMethodDTO); } } //return null; }