代码拉取完成,页面将自动刷新
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading.Tasks;
using Benchmarks.Configuration;
using Benchmarks.Data;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace Benchmarks.Middleware
{
public class MultipleUpdatesEfMiddleware
{
private static readonly PathString _path = new PathString(Scenarios.GetPath(s => s.DbMultiUpdateEf));
private static readonly JsonSerializerSettings _jsonSettings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
private readonly RequestDelegate _next;
public MultipleUpdatesEfMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext httpContext)
{
if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal))
{
var count = MiddlewareHelpers.GetMultipleQueriesQueryCount(httpContext);
var db = httpContext.RequestServices.GetService<EfDb>();
var rows = await db.LoadMultipleUpdatesRows(count);
var result = JsonConvert.SerializeObject(rows, _jsonSettings);
httpContext.Response.StatusCode = StatusCodes.Status200OK;
httpContext.Response.ContentType = "application/json";
httpContext.Response.ContentLength = result.Length;
await httpContext.Response.WriteAsync(result);
return;
}
await _next(httpContext);
}
}
public static class MultipleUpdatesEfMiddlewareExtensions
{
public static IApplicationBuilder UseMultipleUpdatesEf(this IApplicationBuilder builder)
{
return builder.UseMiddleware<MultipleUpdatesEfMiddleware>();
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。