using EntrustSettle.Common; using EntrustSettle.Hubs; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.SignalR; using System.Threading.Tasks; namespace EntrustSettle.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", "Enabled").ObjToBool()) { //TODO 主动发送错误消息 await _hubContext.Clients.All.SendAsync("ReceiveUpdate", "LogLock.GetLogData()"); } await _next(context); } } }