You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2 KiB
C#

using EntrustSettle.Common;
using EntrustSettle.Hubs;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.SignalR;
using System.Threading.Tasks;
namespace EntrustSettle.Extensions.Middlewares
{
/// <summary>
/// 中间件
/// SignalR发送数据
/// </summary>
public class SignalRSendMiddleware
{
/// <summary>
///
/// </summary>
private readonly RequestDelegate _next;
private readonly IHubContext<ChatHub> _hubContext;
/// <summary>
///
/// </summary>
/// <param name="next"></param>
/// <param name="hubContext"></param>
public SignalRSendMiddleware(RequestDelegate next, IHubContext<ChatHub> hubContext)
{
_next = next;
_hubContext = hubContext;
}
public async Task InvokeAsync(HttpContext context)
{
if (AppSettings.app("Middleware", "SignalR", "Enabled").ObjToBool())
{
//TODO 主动发送错误消息
9 months ago
await _hubContext.Clients.All.SendAsync("ReceiveUpdate", "LogLock.GetLogData()");
}
await _next(context);
}
}
}