/// <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)); FastWebSocketCommon.SetRemoteException(this.Server.JsonSerializer, exceptionContext); this.ExecExceptionFilters(actionfilters, exceptionContext); if (exceptionContext.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.api); if (action == null) { var exception = new ApiNotExistException(requestContext.Packet.api); var exceptionContext = new ExceptionContext(requestContext, exception); FastWebSocketCommon.SetRemoteException(this.JsonSerializer, exceptionContext); this.ExecGlobalExceptionFilters(exceptionContext); } return(action); }
/// <summary> /// 获取ApiService实例 /// </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); FastWebSocketCommon.SetRemoteException(this.JsonSerializer, exceptionContext); this.ExecExceptionFilters(exceptionContext); if (exceptionContext.ExceptionHandled == false) { throw exception; } return(null); }
/// <summary> /// 获取ApiService实例 /// </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); FastWebSocketCommon.SetRemoteException(this.JsonSerializer, exceptionContext); this.ExecGlobalExceptionFilters(exceptionContext); } return(fastApiService); }