using Dpz.Core.EnumLibrary;
using Dpz.Core.Service.V4.Services;
using Microsoft.AspNetCore.SignalR;
namespace Dpz.Core.Web.Library.Hub;
public class ApplicationNotificationHub(
IArticleService articleService,
IConfiguration configuration,
ILogger<ApplicationNotificationHub> logger)
: Microsoft.AspNetCore.SignalR.Hub
{
public async Task ReceiveInstruction(ApplicationNotification appNotification)
{
logger.LogInformation("receive application notification,notification information:{@Information}",
appNotification);
var key = configuration["SystemNotificationKey"];
if(string.IsNullOrEmpty(key) || key != appNotification.Key)
return;
switch (appNotification.Type)
{
case NotificationType.Message:
var level = (int)appNotification.MessageLevel;
await Clients.All.SendAsync("systemMessage",level,appNotification.Message);
break;
case NotificationType.ClearArticleCache:
logger.LogInformation("已收到清除文章缓存通知");
await articleService.ClearCacheAsync();
await Clients.All.SendAsync("systemMessage",0,"文章缓存清除缓存完毕");
break;
case NotificationType.None:
default:
logger.LogWarning("Instruction type unknown");
break;
}
}
}