Example #1
0
        /// <summary>
        /// 获取api的描述
        /// </summary>
        /// <param name="method">接口的方法</param>
        /// <param name="parameters">参数集合</param>
        /// <returns></returns>
        private ApiActionDescriptor GetApiActionDescriptor(MethodInfo method, object[] parameters)
        {
            var cache            = ApiDescriptorCache.GetApiActionDescriptor(method);
            var actionDescripter = cache.Clone() as ApiActionDescriptor;

            for (var i = 0; i < actionDescripter.Parameters.Length; i++)
            {
                actionDescripter.Parameters[i].Value = parameters[i];
            }
            return(actionDescripter);
        }
        /// <summary>
        /// 执行Http请求接口
        /// </summary>
        /// <param name="invocation">上下文</param>
        /// <returns></returns>
        private Task ExecuteHttpApi(IInvocation invocation)
        {
            var cache            = ApiDescriptorCache.GetApiActionDescriptor(invocation);
            var actionDescripter = cache.Clone() as ApiActionDescriptor;

            for (var i = 0; i < actionDescripter.Parameters.Length; i++)
            {
                actionDescripter.Parameters[i].Value = invocation.GetArgumentValue(i);
            }

            var actionContext = new ApiActionContext
            {
                ApiActionDescriptor = actionDescripter,
                HttpApiConfig       = this.httpApiConfig,
                RequestMessage      = new HttpRequestMessage {
                    RequestUri = this.httpApiConfig.HttpHost
                },
                ResponseMessage = null
            };

            return(actionDescripter.Execute(actionContext));
        }