using Bootstrap.DataAccess;
using Longbow.Web.SignalR;
using Microsoft.AspNetCore.SignalR;
using System;
using System.Data.Common;
using System.Threading;
using Task = System.Threading.Tasks.Task;
namespace Bootstrap.Admin
{
///
/// SignalR 操作扩展类
///
public static class SignalRExtensions
{
///
/// 推送异常信息到客户端方法扩展
///
///
///
///
///
public static async Task SendMessageBody(this IHubContext context, Exception ex, CancellationToken token = default)
{
var category = "App";
if (ex.GetType().IsSubclassOf(typeof(DbException))) category = "DB";
await context.SendMessageBody(new MessageBody() { Category = category, Message = ex.Message }, token);
}
///
/// 推送 MessageBody 到客户端方法扩展
///
///
///
///
///
public static Task SendMessageBody(this IHubContext context, MessageBody messageBody, CancellationToken token = default) => context.Clients.All.SendAsync("rev", messageBody, token);
///
/// 推送任务消息到客户端扩展
///
///
///
///
public static Task SendTaskLog(this IHubContext context, string args) => context.Clients.All.SendAsync("rev", args);
}
}