using System.Threading.Tasks; using zzz.Common; using zzz.Common.LogHelper; using zzz.Hubs; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.SignalR; namespace zzz.Extensions.Middlewares { /// /// 中间件 /// SignalR发送数据 /// public class SignalRSendMiddleware { /// /// /// private readonly RequestDelegate _next; private readonly IHubContext _hubContext; /// /// /// /// /// public SignalRSendMiddleware(RequestDelegate next, IHubContext hubContext) { _next = next; _hubContext = hubContext; } public async Task InvokeAsync(HttpContext context) { if (Appsettings.app("Middleware", "SignalR").ObjToBool()) { await _hubContext.Clients.All.SendAsync("ReceiveUpdate", LogLock.GetLogData()); } await _next(context); } } }