操控平台后端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.8 KiB

5 months ago
// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
namespace Admin.NET.Core;
/// <summary>
/// 事件订阅
/// </summary>
public class AppEventSubscriber : IEventSubscriber, ISingleton, IDisposable
{
private readonly IServiceScope _serviceScope;
public AppEventSubscriber(IServiceScopeFactory scopeFactory)
{
_serviceScope = scopeFactory.CreateScope();
}
/// <summary>
/// 增加异常日志
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
[EventSubscribe("Add:ExLog")]
public async Task CreateExLog(EventHandlerExecutingContext context)
{
var rep = _serviceScope.ServiceProvider.GetRequiredService<SqlSugarRepository<SysLogEx>>();
await rep.InsertAsync((SysLogEx)context.Source.Payload);
}
/// <summary>
/// 发送异常邮件
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
[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<IViewEngine>().RunCompileFromCachedAsync(mailTemp, );
var title = "Admin.NET 系统异常";
await _serviceScope.ServiceProvider.GetRequiredService<SysEmailService>().SendEmail(JSON.Serialize(context.Source.Payload), title);
}
/// <summary>
/// 释放服务作用域
/// </summary>
public void Dispose()
{
_serviceScope.Dispose();
}
}