Example #1
0
        /// <summary>准备上下文</summary>
        /// <param name="session"></param>
        /// <param name="action"></param>
        /// <param name="args"></param>
        /// <param name="api"></param>
        /// <returns></returns>
        protected virtual ControllerContext Prepare(IApiSession session, String action, Packet args, ApiAction api)
        {
            var enc = Host.Encoder;

            // 当前上下文
            var ctx = ControllerContext.Current;

            if (ctx == null)
            {
                ctx = new ControllerContext();
                ControllerContext.Current = ctx;
            }
            ctx.Action     = api;
            ctx.ActionName = action;
            ctx.Session    = session;
            ctx.Request    = args;

            // 如果服务只有一个二进制参数,则走快速通道
            if (!api.IsPacketParameter)
            {
                // 不允许参数字典为空
                var dic = args == null || args.Total == 0 ?
                          new NullableDictionary <String, Object>(StringComparer.OrdinalIgnoreCase) :
                          enc.DecodeParameters(action, args);
                ctx.Parameters = dic;

                // 准备好参数
                var ps = GetParams(api.Method, dic, enc);
                ctx.ActionParameters = ps;
            }

            return(ctx);
        }
Example #2
0
 /// <summary>创建控制器实例</summary>
 /// <param name="api"></param>
 /// <returns></returns>
 public virtual Object CreateController(ApiAction api) => _Host.CreateController(this, api);
Example #3
0
        /// <summary>创建控制器实例</summary>
        /// <param name="host"></param>
        /// <param name="session"></param>
        /// <param name="api"></param>
        /// <returns></returns>
        public static Object CreateController(this IApiHost host, IApiSession session, ApiAction api)
        {
            var controller = api.Controller;

            if (controller != null)
            {
                return(controller);
            }

            controller = api.Type.CreateInstance();

            return(controller);
        }