/// <summary> /// 代理执行方法 /// </summary> /// <param name="action"></param> /// <param name="obj"></param> /// <param name="nameValues"></param> /// <returns></returns> static ActionResult MethodInvoke(MethodInfo action, object obj, NameValueCollection nameValues) { ActionResult result = null; try { object data; var @params = action.GetParameters(); if (@params != null && @params.Any()) { var list = ParamsHelper.FillPamars(@params, nameValues); data = action.Invoke(obj, list.ToArray()); } else { data = action.Invoke(obj, null); } if (data.GetType().Name == "AsyncStateMachineBox`1") { var tdata = data as Task <ActionResult>; result = tdata.Result; } else { result = (ActionResult)data; } } catch (Exception ex) { result = new ContentResult($"→_→,出错了:{obj}/{action.Name},出现异常:{ex.Message}", System.Net.HttpStatusCode.InternalServerError); } return(result); }
/// <summary> /// 处理业务逻辑 /// </summary> /// <param name="userToken"></param> public override void HttpHandle(IUserToken userToken) { IHttpResult result = null; try { this.InitSession(userToken); switch (this.Request.Method) { case ConstHelper.GET: case ConstHelper.POST: case ConstHelper.PUT: case ConstHelper.DELETE: if (this.Request.Query.Count > 0) { foreach (var item in this.Request.Query) { this.Request.Parmas[item.Key] = item.Value; } } if (this.Request.Forms.Count > 0) { foreach (var item in this.Request.Forms) { this.Request.Parmas[item.Key] = item.Value; } } if (OnRequestDelegate != null) { OnRequestDelegate.Invoke(this); } else { result = GetActionResult(); } break; case ConstHelper.OPTIONS: result = new EmptyResult(); break; default: result = new ContentResult("不支持的请求方式", System.Net.HttpStatusCode.HttpVersionNotSupported); break; } } catch (Exception ex) { result = OnException.Invoke(this, ex); if (result == null) { result = new ContentResult("请求发生异常:" + ex.Message, System.Net.HttpStatusCode.InternalServerError); } } if (result != null) { if (!(result is IBigDataResult || result is IEventStream)) { Response.SetCached(result, this.Session.CacheCalcString); Response.End(); } } }