public static IHttpHandler CreateHandler(InvokeInfo vkInfo) { // MyMMC对异步的支持,只限于返回值类型是 Task 或者 Task<T> // 所以这里只判断是不是Task类型的返回值,如果是,则表示是一个异步Action if( vkInfo.Action.MethodInfo.IsTaskMethod() ) return TaskAsyncActionHandler.CreateHandler(vkInfo); else return ActionHandler.CreateHandler(vkInfo); }
public static IHttpHandler CreateHandler(InvokeInfo vkInfo) { SessionMode mode = vkInfo.GetSessionMode(); if( mode == SessionMode.NotSupport ) return new TaskAsyncActionHandler { InvokeInfo = vkInfo }; else if( mode == SessionMode.ReadOnly ) return new TaskAsyncReadOnlySessionActionHandler { InvokeInfo = vkInfo }; else return new TaskAsyncRequiresSessionActionHandler { InvokeInfo = vkInfo }; }
/// <summary> /// 根据一个页面请求路径,返回内部表示的调用信息。 /// </summary> /// <param name="url"></param> /// <returns></returns> public InvokeInfo GetActionInvokeInfo(string url) { if (string.IsNullOrEmpty(url)) { throw new ArgumentNullException("url"); } MatchActionDescription md = null; ActionDescription action = null; // 先直接用URL从字典中查找匹配项。 if (s_metadata.PageActionDict.TryGetValue(url, out action) == false) { // 如果不能直接匹配URL,就用正则表达式再逐个匹配。 md = GetActionByRegex(url); if (md == null) { if (this.DiagnoseResult != null) { // 填充诊断结果 SetPageUrlDiagnoseResult(url); } return(null); } else { action = md.ActionDescription; } } InvokeInfo vkInfo = new InvokeInfo(); vkInfo.Controller = action.PageController; vkInfo.Action = action; if (md != null) { vkInfo.RegexMatch = md.Match; } if (vkInfo.Action.MethodInfo.IsStatic == false) { //vkInfo.Instance = Activator.CreateInstance(vkInfo.Controller.ControllerType); vkInfo.Instance = vkInfo.Controller.ControllerType.New(); } return(vkInfo); }
/// <summary> /// 根据一个Action的调用信息(类名与方法名),返回内部表示的调用信息。 /// </summary> /// <param name="info"></param> /// <returns></returns> public InvokeInfo GetActionInvokeInfo(UrlActionInfo info) { if (info == null) { throw new ArgumentNullException("info"); } HttpRequest request = _context.Request; if (info.Action == null) { info.Action = info.MethodName; } if (info.Controller == null) { info.Namesapce = GetNamespaceMap(info.Namesapce); info.Controller = s_recognizer.GetServiceFullName(info); } InvokeInfo vkInfo = new InvokeInfo(); vkInfo.Controller = info.ControllerDescription ?? GetServiceController(info.Controller); if (vkInfo.Controller == null) { return(null); } vkInfo.Action = info.ActionDescription ?? GetServiceAction(vkInfo.Controller.ControllerType, info.Action); if (vkInfo.Action == null) { return(null); } if (vkInfo.Action.MethodInfo.IsStatic == false) { vkInfo.Instance = vkInfo.Controller.ControllerType.New(); } vkInfo.UrlActionInfo = info; return(vkInfo); }
internal void ProcessRequest(HttpContext context, ActionHandler handler) { if( context == null ) throw new ArgumentNullException("context"); if( handler == null ) throw new ArgumentNullException("handler"); this.HttpContext = context; this.Handler = handler; this.InvokeInfo = handler.InvokeInfo; // 设置 BaseController 的相关属性 SetController(); // 进入请求处理阶段 BeginRequest(); // 安全检查 SecurityCheck(); // 授权检查 AuthorizeRequest(); // 执行 Action object actionResult = ExecuteAction(); // 设置输出缓存 SetOutputCache(); // 处理方法的返回结果 OutputResult(actionResult); }
internal async Task ProcessRequestAsync(HttpContext context, TaskAsyncActionHandler handler) { if( context == null ) throw new ArgumentNullException("context"); if( handler == null ) throw new ArgumentNullException("handler"); this.HttpContext = context; this.Handler = handler; this.InvokeInfo = handler.InvokeInfo; // 设置 BaseController 的相关属性 SetController(); // 在异步执行前,先保存当前同步上下文的实例,供异步完成后执行切换调用。 SynchronizationContext syncContxt = SynchronizationContext.Current; // 进入请求处理阶段 BeginRequest(); // 安全检查 SecurityCheck(); // 授权检查 AuthorizeRequest(); //this.HttpContext.WriteHeader("ProcessRequestAsync-before-await"); // 执行 Action object actionResult = await ExecuteActionAsync(); //this.HttpContext.WriteHeader("ProcessRequestAsync-after-await"); // 切换到原先的上下文环境,执行余下操作 syncContxt.Send(x => { //System.Runtime.Remoting.Messaging.CallContext.HostContext = (HttpContext)x; // 设置输出缓存 SetOutputCache(); // 处理方法的返回结果 //this.HttpContext.WriteHeader("call OutputResult()"); OutputResult(actionResult); }, this.HttpContext); }