using System.Threading.Tasks;
using Tiobon.Core.Common;
using Tiobon.Core.Common.LogHelper;
using Tiobon.Core.Hubs;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.SignalR;
namespace Tiobon.Core.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);
}
}
}