/// <summary>
        /// 设置结果
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override async Task SetResultAsync(ApiResponseContext context)
        {
            if (context.ResultStatus == ResultStatus.None)
            {
                var response = context.HttpContext.ResponseMessage;
                if (response == null)
                {
                    return;
                }

                if (response.IsSuccessStatusCode == false)
                {
                    var error = await context.JsonDeserializeAsync(typeof(InfuxdbError));

                    if (error is InfuxdbError infuxdbError)
                    {
                        throw new InfluxdbException(infuxdbError);
                    }
                }

                var encoding = response.Content.GetEncoding();
                using var stream = await response.Content.ReadAsStreamAsync();

                var csvReader = new CsvReader(stream, encoding);
                context.Result = await DataTableCollection.ParseAsync(csvReader);
            }
        }
 /// <summary>
 /// 设置强类型模型结果值
 /// </summary>
 /// <param name="context">上下文</param>
 /// <returns></returns>
 public override async Task SetResultAsync(ApiResponseContext context)
 {
     if (context.ApiAction.Return.DataType.IsRawType == false)
     {
         var resultType = context.ApiAction.Return.DataType.Type;
         context.Result = await context.JsonDeserializeAsync(resultType).ConfigureAwait(false);
     }
 }
Beispiel #3
0
        /// <summary>
        /// 检测结果的正确性
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override async Task SetResultAsync(ApiResponseContext context)
        {
            if (context.ResultStatus == ResultStatus.None)
            {
                var response = context.HttpContext.ResponseMessage;
                if (response != null && response.IsSuccessStatusCode == false)
                {
                    var error = await context.JsonDeserializeAsync(typeof(InfuxdbError));

                    if (error is InfuxdbError infuxdbError)
                    {
                        throw new InfluxdbException(infuxdbError);
                    }
                }
            }
        }
        /// <summary>
        /// 设置强类型模型结果值
        /// </summary>
        /// <param name="context">上下文</param>
        /// <returns></returns>
        public override async Task SetResultAsync(ApiResponseContext context)
        {
            if (context.ApiAction.Return.DataType.IsModelType == false)
            {
                return;
            }

            try
            {
                var resultType = context.ApiAction.Return.DataType.Type;
                context.Result = await context.JsonDeserializeAsync(resultType).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                context.Exception = ex;
            }
        }