/// <summary> /// 处理Api行为执行过程中产生的异常 /// </summary> /// <param name="actionContext">上下文</param> /// <param name="actionfilters">过滤器</param> /// <param name="exception">异常项</param> private void ProcessExecutingException(ActionContext actionContext, IEnumerable <IFilter> actionfilters, Exception exception) { var exceptionContext = new ExceptionContext(actionContext, new ApiExecuteException(actionContext, exception)); FastTcpCommon.SetRemoteException(actionContext.Session, exceptionContext); this.ExecExceptionFilters(actionfilters, exceptionContext); if (exceptionContext.ExceptionHandled == false) { throw exception; } }
/// <summary> /// 处理Api行为执行过程中产生的异常 /// </summary> /// <param name="actionContext">上下文</param> /// <param name="exception">异常项</param> private void ProcessExecutingException(ActionContext actionContext, Exception exception) { var exceptionContext = new ExceptionContext(actionContext, new ApiExecuteException(actionContext, exception)); FastTcpCommon.SetRemoteException(this, exceptionContext); var exceptionHandled = false; this.OnException(actionContext.Packet, exception, out exceptionHandled); if (exceptionHandled == false) { throw exception; } }
/// <summary> /// 获取Api行为 /// </summary> /// <param name="requestContext">请求上下文</param> /// <returns></returns> private ApiAction GetApiAction(RequestContext requestContext) { var action = this.apiActionList.TryGet(requestContext.Packet.ApiName); if (action == null) { var exception = new ApiNotExistException(requestContext.Packet.ApiName); var exceptionContext = new ExceptionContext(requestContext, exception); FastTcpCommon.SetRemoteException(requestContext.Session, exceptionContext); this.ExecGlobalExceptionFilters(exceptionContext); } return(action); }
/// <summary> /// 获取FastApiService实例 /// </summary> /// <param name="actionContext">Api行为上下文</param> /// <returns></returns> private IFastApiService GetFastApiService(ActionContext actionContext) { // 获取服务实例 var fastApiService = (IFastApiService)DependencyResolver.Current.GetService(actionContext.Action.DeclaringService); if (fastApiService != null) { return(fastApiService); } var exception = new Exception(string.Format("无法获取类型{0}的实例", actionContext.Action.DeclaringService)); var exceptionContext = new ExceptionContext(actionContext, exception); FastTcpCommon.SetRemoteException(actionContext.Session, exceptionContext); this.ExecExceptionFilters(exceptionContext); if (exceptionContext.ExceptionHandled == false) { throw exception; } return(null); }
/// <summary> /// 获取Api行为 /// </summary> /// <param name="requestContext">请求上下文</param> /// <returns></returns> private ApiAction GetApiAction(RequestContext requestContext) { var action = this.apiActionList.TryGet(requestContext.Packet.ApiName); if (action != null) { return(action); } var exception = new ApiNotExistException(requestContext.Packet.ApiName); var exceptionContext = new ExceptionContext(requestContext, exception); FastTcpCommon.SetRemoteException(requestContext.Session, exceptionContext); this.ExecExceptionFilters(exceptionContext); if (exceptionContext.ExceptionHandled == false) { throw exception; } return(null); }
/// <summary> /// 获取FastApiService实例 /// </summary> /// <param name="actionContext">Api行为上下文</param> /// <returns></returns> private IFastApiService GetFastApiService(ActionContext actionContext) { IFastApiService fastApiService = null; Exception innerException = null; try { fastApiService = (IFastApiService)this.DependencyResolver.GetService(actionContext.Action.DeclaringService); } catch (Exception ex) { innerException = ex; } if (fastApiService == null) { var exception = new ResolveException(actionContext.Action.DeclaringService, innerException); var exceptionContext = new ExceptionContext(actionContext, exception); FastTcpCommon.SetRemoteException(actionContext.Session, exceptionContext); this.ExecGlobalExceptionFilters(exceptionContext); } return(fastApiService); }