예제 #1
0
        /// <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;
        }
예제 #2
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;
 }
예제 #3
0
        /// <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);
        }
예제 #4
0
 /// <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);
     }
 }
예제 #5
0
        /// <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);
                }
            });
        }
예제 #6
0
 /// <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;
 }
예제 #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;
 }