/// <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);

                Common.SendRemoteException(requestContext.Session.UnWrap(), exceptionContext);
                this.ExecGlobalExceptionFilters(exceptionContext);
            }
            return action;
        }
 /// <summary>
 /// Api行为上下文
 /// </summary>
 /// <param name="context">请求上下文</param>
 /// <param name="action">Api行为</param>
 public ActionContext(RequestContext context, ApiAction action)
     : base(context.Session, context.Packet, context.AllSessions)
 {
     this.Action = action;
 }
        /// <summary>
        /// 处理正常的数据请求
        /// </summary>
        /// <param name="requestContext">请求上下文</param>       
        private void ProcessRequest(RequestContext requestContext)
        {
            if (requestContext.Packet.IsFromClient == false)
            {
                Common.SetApiActionTaskResult(requestContext, this.TaskSetActionTable, this.Serializer);
                return;
            }

            var action = this.GetApiAction(requestContext);
            if (action == null)
            {
                return;
            }

            var actionContext = new ActionContext(requestContext, action);
            var fastApiService = this.GetFastApiService(actionContext);
            if (fastApiService == null)
            {
                return;
            }

            // 执行Api行为           
            fastApiService.Execute(actionContext);
            this.DependencyResolver.TerminateService(fastApiService);
        }
 /// <summary>
 /// 接收到会话对象的数据包
 /// </summary>
 /// <param name="requestContext">请求上下文</param>
 private void OnRecvFastPacket(RequestContext requestContext)
 {
     if (requestContext.Packet.IsException == true)
     {
         Common.SetApiActionTaskException(this.TaskSetActionTable, requestContext);
     }
     else
     {
         this.ProcessRequest(requestContext);
     }
 }
        /// <summary>
        /// 收到fast请求
        /// </summary>
        /// <param name="context">上下文</param>
        /// <returns></returns>
        private Task OnFastRequest(IContenxt context)
        {
            var fastPacket = default(FastPacket);
            if (FastPacket.Parse(context.Buffer, out fastPacket) == false)
            {
                return this.Next.Invoke(context);
            }

            if (fastPacket == null)
            {
                return new Task(() => { });
            }

            if (context.Session.Protocol == null)
            {
                var wrapper = new FastSession(context.Session, this);
                context.Session.SetProtocolWrapper("fast", wrapper);
            }

            var fastSession = (FastSession)context.Session.Wrapper;
            var fastPackets = this.GenerateFastPackets(context, fastPacket);

            return new Task(() =>
            {
                foreach (var packet in fastPackets)
                {
                    var requestContext = new RequestContext(fastSession, packet, context.AllSessions);
                    this.OnRecvFastPacket(requestContext);
                }
            });
        }
 /// <summary>
 /// 异常上下文
 /// </summary>
 /// <param name="context">请求上下文</param>
 /// <param name="exception">异常</param>
 public ExceptionContext(RequestContext context, Exception exception)
     : base(context.Session, context.Packet, context.AllSessions)
 {
     this.Exception = exception;
 }
Beispiel #7
0
 /// <summary>
 /// Api行为上下文
 /// </summary>
 /// <param name="context">请求上下文</param>
 /// <param name="action">Api行为</param>
 public ActionContext(RequestContext context, ApiAction action)
     : base(context.Session, context.Packet, context.AllSessions)
 {
     this.Action = action;
 }