public string Resolve(ApiInterface source, object destination, string destMember, ResolutionContext context) { if (!source.IsUseEnvelop) { try { var result = JToken.Parse(source.ResponseResult); return(JsonConvert.SerializeObject(result, Formatting.Indented)); } catch (System.Exception) { return("Json内容格式不正确, 通过编辑修复之后再查看"); } } var envelop = new EnvelopMessage <object>() { Code = 200, Tid = GuidGenerator.GenerateDigitalUUID(), FriendlyMessage = "返回成功", ErrorMessage = string.Empty }; try { envelop.Data = JToken.Parse(source.ResponseResult); } catch (System.Exception) { envelop.Data = "Json内容格式不正确, 通过编辑修复之后再查看"; } return(JsonConvert.SerializeObject(envelop, Formatting.Indented)); }
public async Task Invoke(HttpContext context, IRequestSession requestSession) { if (!context.Request.IsApiRequest()) { await Next(context); return; } //if (context.Request.Headers.ContainsKey(EnvelopDefaults.IgnoreEnvelopKey)) //{ // context.Items.Add(EnvelopDefaults.IgnoreEnvelopKey, context.Request.Headers[EnvelopDefaults.IgnoreEnvelopKey].ToString() ?? false.ToString()); //} //标记当前请求是API请求 context.Items[ContextItemsNames.IsApiRequest] = true; _logger.LogInformation($"API开始处理"); //处理TID _logger.LogDebug($"处理TID"); var tid = requestSession.Tid; if (tid.IsNullOrWhitespace()) { tid = GuidGenerator.GenerateDigitalUUID(); context.Items[ContextItemsNames.Tid] = tid; } await Next(context); }
public async Task Invoke(HttpContext context) { if (!context.Request.Path.HasValue || !context.Request.Path.Value.Contains("/api/", StringComparison.OrdinalIgnoreCase)) { await Next(context); return; } var requestPath = context.Request.Path.Value; var pathArray = requestPath.Trim('/').Split('/'); var category = pathArray[0]; var apiSection = pathArray[1]; var realApiPath = requestPath.Substring(category.Length + 1); if (!apiSection.Equals("api", StringComparison.OrdinalIgnoreCase)) { await Next(context); return; } var apiInterfaceRepository = context.RequestServices.GetService <MockServerNoSqlRepository <ApiInterface> >(); var entity = await apiInterfaceRepository.SearchOneAsync(Builders <ApiInterface> .Filter.Where(x => x.Category == category && x.RequestPath == realApiPath)); if (entity != null) { if (entity.IsUseEnvelop) { var envelop = new EnvelopMessage <object>() { Code = 200, Tid = GuidGenerator.GenerateDigitalUUID(), FriendlyMessage = "返回成功", ErrorMessage = string.Empty }; envelop.Data = JToken.Parse(entity.ResponseResult); await HandleStatus(context, envelop); } else { var data = JToken.Parse(entity.ResponseResult); await HandleStatus(context, data); } } else { await InterfaceNotFound(context); } }
public string Resolve(object source, object destination, string sourceMember, string destMember, ResolutionContext context) { var envelop = new EnvelopMessage <object>() { Code = 200, Tid = GuidGenerator.GenerateDigitalUUID(), FriendlyMessage = "返回成功", ErrorMessage = string.Empty }; try { envelop.Data = JToken.Parse(sourceMember); } catch (System.Exception) { envelop.Data = "Json内容格式不正确, 通过编辑修复之后再查看"; } return(JsonConvert.SerializeObject(envelop, Formatting.Indented)); }