// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
namespace Admin.NET.Core;
///
/// 事件订阅
///
public class AppEventSubscriber : IEventSubscriber, ISingleton, IDisposable
{
private readonly IServiceScope _serviceScope;
public AppEventSubscriber(IServiceScopeFactory scopeFactory)
{
_serviceScope = scopeFactory.CreateScope();
}
///
/// 增加异常日志
///
///
///
[EventSubscribe("Add:ExLog")]
public async Task CreateExLog(EventHandlerExecutingContext context)
{
var rep = _serviceScope.ServiceProvider.GetRequiredService>();
await rep.InsertAsync((SysLogEx)context.Source.Payload);
}
///
/// 发送异常邮件
///
///
///
[EventSubscribe("Send:ErrorMail")]
public async Task SendOrderErrorMail(EventHandlerExecutingContext context)
{
//var mailTempPath = Path.Combine(App.WebHostEnvironment.WebRootPath, "Temp\\ErrorMail.tp");
//var mailTemp = File.ReadAllText(mailTempPath);
//var mail = await _serviceScope.ServiceProvider.GetRequiredService().RunCompileFromCachedAsync(mailTemp, );
var title = "Admin.NET 系统异常";
await _serviceScope.ServiceProvider.GetRequiredService().SendEmail(JSON.Serialize(context.Source.Payload), title);
}
///
/// 释放服务作用域
///
public void Dispose()
{
_serviceScope.Dispose();
}
}