Browse Source

添加异常推送邮件模板

pull/11/head
cKey 6 years ago
parent
commit
c1347304d0
  1. 22
      aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN.Abp.ExceptionHandling.Emailing.csproj
  2. 46
      aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN/Abp/ExceptionHandling/AbpEmailExceptionHandlingOptions.cs
  3. 10
      aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN/Abp/ExceptionHandling/AbpEmailingExceptionHandlingModule.cs
  4. 37
      aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN/Abp/ExceptionHandling/AbpEmailingExceptionSubscriber.cs
  5. 72
      aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN/Abp/ExceptionHandling/Emailing/AbpEmailExceptionHandlingOptions.cs
  6. 29
      aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN/Abp/ExceptionHandling/Emailing/AbpEmailingExceptionHandlingModule.cs
  7. 68
      aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN/Abp/ExceptionHandling/Emailing/AbpEmailingExceptionSubscriber.cs
  8. 9
      aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN/Abp/ExceptionHandling/Emailing/Localization/ExceptionHandlingResource.cs
  9. 7
      aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN/Abp/ExceptionHandling/Emailing/Localization/Resources/en.json
  10. 7
      aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN/Abp/ExceptionHandling/Emailing/Localization/Resources/zh-Hans.json
  11. 20
      aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN/Abp/ExceptionHandling/Emailing/Templates/ExceptionHandlingTemplateDefinitionProvider.cs
  12. 7
      aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN/Abp/ExceptionHandling/Emailing/Templates/ExceptionHandlingTemplates.cs
  13. 48
      aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN/Abp/ExceptionHandling/Emailing/Templates/SendEmail/en.tpl
  14. 48
      aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN/Abp/ExceptionHandling/Emailing/Templates/SendEmail/zh-Hans.tpl
  15. 9
      aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Notifications/LINGYUN/Abp/ExceptionHandling/AbpNotificationsExceptionHandlingModule.cs
  16. 2
      aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Notifications/LINGYUN/Abp/ExceptionHandling/Notifications/AbpExceptionHandlingNotificationDefinitionProvider.cs
  17. 2
      aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Notifications/LINGYUN/Abp/ExceptionHandling/Notifications/AbpExceptionHandlingNotificationNames.cs
  18. 12
      aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Notifications/LINGYUN/Abp/ExceptionHandling/Notifications/AbpNotificationsExceptionHandlingModule.cs
  19. 2
      aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Notifications/LINGYUN/Abp/ExceptionHandling/Notifications/AbpNotificationsExceptionSubscriber.cs
  20. 10
      aspnet-core/services/account/AuthServer.Host/AuthIdentityServerModule.cs
  21. 10
      aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/ApiGatewayHttpApiHostModule.cs
  22. 14
      aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiHostModule.cs
  23. 1
      aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj
  24. 31
      aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/PlatformHttpApiHostModule.cs
  25. 18
      aspnet-core/tests/LINGYUN.Abp.ExceptionHandling.Emailing.Tests/LINGYUN.Abp.ExceptionHandling.Emailing.Tests.csproj
  26. 44
      aspnet-core/tests/LINGYUN.Abp.ExceptionHandling.Emailing.Tests/LINGYUN/Abp/ExceptionHandling/Emailing/AbpEmailingExceptionSubscriber_Test.cs
  27. 8
      aspnet-core/tests/LINGYUN.Abp.ExceptionHandling.Emailing.Tests/LINGYUN/Abp/ExceptionHandling/Emailing/AbpExceptionHandlingEmailingTestBase.cs
  28. 59
      aspnet-core/tests/LINGYUN.Abp.ExceptionHandling.Emailing.Tests/LINGYUN/Abp/ExceptionHandling/Emailing/AbpExceptionHandlingEmailingTestModule.cs
  29. 19
      aspnet-core/tests/LINGYUN.Abp.ExceptionHandling.Emailing.Tests/LINGYUN/Abp/ExceptionHandling/Emailing/TestSendEmailException.cs

22
aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN.Abp.ExceptionHandling.Emailing.csproj

@ -5,4 +5,26 @@
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<None Remove="LINGYUN\Abp\ExceptionHandling\Emailing\Localization\Resources\en.json" />
<None Remove="LINGYUN\Abp\ExceptionHandling\Emailing\Localization\Resources\zh-Hans.json" />
<None Remove="LINGYUN\Abp\ExceptionHandling\Emailing\Templates\SendEmail\en.tpl" />
<None Remove="LINGYUN\Abp\ExceptionHandling\Emailing\Templates\SendEmail\zh-Hans.tpl" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="LINGYUN\Abp\ExceptionHandling\Emailing\Localization\Resources\en.json" />
<EmbeddedResource Include="LINGYUN\Abp\ExceptionHandling\Emailing\Localization\Resources\zh-Hans.json" />
<EmbeddedResource Include="LINGYUN\Abp\ExceptionHandling\Emailing\Templates\SendEmail\en.tpl" />
<EmbeddedResource Include="LINGYUN\Abp\ExceptionHandling\Emailing\Templates\SendEmail\zh-Hans.tpl" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.Emailing" Version="2.9.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LINGYUN.Abp.ExceptionHandling\LINGYUN.Abp.ExceptionHandling.csproj" />
</ItemGroup>
</Project>

46
aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN/Abp/ExceptionHandling/AbpEmailExceptionHandlingOptions.cs

@ -1,46 +0,0 @@
using System;
using System.Collections.Generic;
namespace LINGYUN.Abp.ExceptionHandling
{
public class AbpEmailExceptionHandlingOptions
{
/// <summary>
/// 默认异常收件人
/// </summary>
public string DefaultReceiveEmail { get; set; }
/// <summary>
/// 异常类型指定收件人处理映射列表
/// </summary>
public IDictionary<Exception, string> Handlers { get; set; }
public AbpEmailExceptionHandlingOptions()
{
Handlers = new Dictionary<Exception, string>();
}
/// <summary>
/// 把需要接受异常通知的用户加进处理列表
/// </summary>
/// <param name="ex">处理的异常类型</param>
/// <param name="receivedEmails">接收邮件的用户类别,群发用,符号分隔</param>
public void HandReceivedException(Exception ex, string receivedEmails)
{
if (Handlers.ContainsKey(ex))
{
Handlers[ex] += receivedEmails;
}
else
{
Handlers.Add(ex, receivedEmails);
}
}
public string GetReceivedEmailOrDefault(Exception ex)
{
if (Handlers.TryGetValue(ex, out string receivedUsers))
{
return receivedUsers;
}
return DefaultReceiveEmail;
}
}
}

10
aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN/Abp/ExceptionHandling/AbpEmailingExceptionHandlingModule.cs

@ -1,10 +0,0 @@
using Volo.Abp.Modularity;
namespace LINGYUN.Abp.ExceptionHandling.Emailing
{
[DependsOn(typeof(AbpExceptionHandlingModule))]
public class AbpEmailingExceptionHandlingModule : AbpModule
{
}
}

37
aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN/Abp/ExceptionHandling/AbpEmailingExceptionSubscriber.cs

@ -1,37 +0,0 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System;
using System.Threading.Tasks;
using Volo.Abp.Emailing;
namespace LINGYUN.Abp.ExceptionHandling
{
public class AbpEmailingExceptionSubscriber : AbpExceptionSubscriberBase
{
protected IEmailSender EmailSender { get; }
protected AbpEmailExceptionHandlingOptions EmailOptions { get; }
public AbpEmailingExceptionSubscriber(
IEmailSender emailSender,
IServiceScopeFactory serviceScopeFactory,
IOptions<AbpExceptionHandlingOptions> options,
IOptions<AbpEmailExceptionHandlingOptions> emailOptions)
: base(serviceScopeFactory, options)
{
EmailSender = emailSender;
EmailOptions = emailOptions.Value;
}
protected override async Task SendErrorNotifierAsync(ExceptionSendNotifierContext context)
{
var receivedUsers = EmailOptions.GetReceivedEmailOrDefault(context.Exception);
if (!receivedUsers.IsNullOrWhiteSpace())
{
// TODO: 使用 Template 格式化推送
await EmailSender.SendAsync(receivedUsers,
context.Exception.GetType().FullName,
context.Exception.Message);
}
}
}
}

72
aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN/Abp/ExceptionHandling/Emailing/AbpEmailExceptionHandlingOptions.cs

@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
namespace LINGYUN.Abp.ExceptionHandling.Emailing
{
public class AbpEmailExceptionHandlingOptions
{
/// <summary>
/// 发送堆栈信息
/// </summary>
public bool SendStackTrace { get; set; } = false;
/// <summary>
/// 默认邮件标题
/// </summary>
public string DefaultTitle { get; set; }
/// <summary>
/// 默认邮件内容头
/// </summary>
public string DefaultContentHeader { get; set; }
/// <summary>
/// 默认邮件内容底
/// </summary>
public string DefaultContentFooter { get; set; }
/// <summary>
/// 默认异常收件人
/// </summary>
public string DefaultReceiveEmail { get; set; }
/// <summary>
/// 异常类型指定收件人处理映射列表
/// </summary>
public IDictionary<Type, string> Handlers { get; set; }
public AbpEmailExceptionHandlingOptions()
{
Handlers = new Dictionary<Type, string>();
}
/// <summary>
/// 把需要接受异常通知的用户加进处理列表
/// </summary>
/// <typeparam name="TException">处理的异常类型</typeparam>
/// <param name="receivedEmails">接收邮件的用户类别,群发用,符号分隔</param>
public void HandReceivedException<TException>(string receivedEmails) where TException : Exception
{
HandReceivedException(typeof(TException), receivedEmails);
}
/// <summary>
/// 把需要接受异常通知的用户加进处理列表
/// </summary>
/// <param name="ex">处理的异常类型</param>
/// <param name="receivedEmails">接收邮件的用户类别,群发用,符号分隔</param>
public void HandReceivedException(Type exceptionType, string receivedEmails)
{
if (Handlers.ContainsKey(exceptionType))
{
Handlers[exceptionType] += receivedEmails;
}
else
{
Handlers.Add(exceptionType, receivedEmails);
}
}
public string GetReceivedEmailOrDefault(Type exceptionType)
{
if (Handlers.TryGetValue(exceptionType, out string receivedUsers))
{
return receivedUsers;
}
return DefaultReceiveEmail;
}
}
}

29
aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN/Abp/ExceptionHandling/Emailing/AbpEmailingExceptionHandlingModule.cs

@ -0,0 +1,29 @@
using LINGYUN.Abp.ExceptionHandling.Emailing.Localization;
using Volo.Abp.Emailing;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Volo.Abp.VirtualFileSystem;
namespace LINGYUN.Abp.ExceptionHandling.Emailing
{
[DependsOn(
typeof(AbpExceptionHandlingModule),
typeof(AbpEmailingModule))]
public class AbpEmailingExceptionHandlingModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpVirtualFileSystemOptions>(options =>
{
options.FileSets.AddEmbedded<AbpEmailingExceptionHandlingModule>();
});
Configure<AbpLocalizationOptions>(options =>
{
options.Resources
.Add<ExceptionHandlingResource>("en")
.AddVirtualJson("/LINGYUN/Abp/ExceptionHandling/Emailing/Localization/Resources");
});
}
}
}

68
aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN/Abp/ExceptionHandling/Emailing/AbpEmailingExceptionSubscriber.cs

@ -0,0 +1,68 @@
using LINGYUN.Abp.ExceptionHandling.Emailing.Localization;
using LINGYUN.Abp.ExceptionHandling.Emailing.Templates;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Options;
using System;
using System.Threading.Tasks;
using Volo.Abp.Emailing;
using Volo.Abp.TextTemplating;
namespace LINGYUN.Abp.ExceptionHandling.Emailing
{
public class AbpEmailingExceptionSubscriber : AbpExceptionSubscriberBase
{
protected IEmailSender EmailSender { get; }
protected IStringLocalizer StringLocalizer { get; }
protected ITemplateRenderer TemplateRenderer { get; }
protected AbpEmailExceptionHandlingOptions EmailOptions { get; }
public AbpEmailingExceptionSubscriber(
IEmailSender emailSender,
ITemplateRenderer templateRenderer,
IServiceScopeFactory serviceScopeFactory,
IOptions<AbpExceptionHandlingOptions> options,
IOptions<AbpEmailExceptionHandlingOptions> emailOptions,
IStringLocalizer<ExceptionHandlingResource> stringLocalizer)
: base(serviceScopeFactory, options)
{
EmailSender = emailSender;
EmailOptions = emailOptions.Value;
StringLocalizer = stringLocalizer;
TemplateRenderer = templateRenderer;
}
protected override async Task SendErrorNotifierAsync(ExceptionSendNotifierContext context)
{
// 需不需要用 SettingProvider 来获取?
var receivedUsers = EmailOptions.GetReceivedEmailOrDefault(context.Exception.GetType());
if (!receivedUsers.IsNullOrWhiteSpace())
{
var emailTitle = EmailOptions.DefaultTitle ?? L("SendEmailTitle");
var templateContent = await TemplateRenderer
.RenderAsync(ExceptionHandlingTemplates.SendEmail,
new
{
title = emailTitle,
header = EmailOptions.DefaultContentHeader ?? L("SendEmailHeader"),
type = context.Exception.GetType().FullName,
message = context.Exception.Message,
loglevel = context.LogLevel.ToString(),
triggertime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"),
sendstacktrace = EmailOptions.SendStackTrace,
stacktrace = context.Exception.ToString(),
footer = EmailOptions.DefaultContentFooter ?? "Copyright to LINGYUN © 2020"
});
await EmailSender.SendAsync(receivedUsers,
emailTitle,
templateContent);
}
}
protected string L(string name, params object[] args)
{
return StringLocalizer[name, args].Value;
}
}
}

9
aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN/Abp/ExceptionHandling/Emailing/Localization/ExceptionHandlingResource.cs

@ -0,0 +1,9 @@
using Volo.Abp.Localization;
namespace LINGYUN.Abp.ExceptionHandling.Emailing.Localization
{
[LocalizationResourceName("AbpExceptionHandlingEmailing")]
public class ExceptionHandlingResource
{
}
}

7
aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN/Abp/ExceptionHandling/Emailing/Localization/Resources/en.json

@ -0,0 +1,7 @@
{
"culture": "en",
"texts": {
"SendEmailTitle": "Application exception push",
"SendEmailHeader": "Application exception"
}
}

7
aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN/Abp/ExceptionHandling/Emailing/Localization/Resources/zh-Hans.json

@ -0,0 +1,7 @@
{
"culture": "zh-Hans",
"texts": {
"SendEmailTitle": "应用程序异常推送",
"SendEmailHeader": "应用程序异常"
}
}

20
aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN/Abp/ExceptionHandling/Emailing/Templates/ExceptionHandlingTemplateDefinitionProvider.cs

@ -0,0 +1,20 @@
using LINGYUN.Abp.ExceptionHandling.Emailing.Localization;
using Volo.Abp.Localization;
using Volo.Abp.TextTemplating;
namespace LINGYUN.Abp.ExceptionHandling.Emailing.Templates
{
public class ExceptionHandlingTemplateDefinitionProvider : TemplateDefinitionProvider
{
public override void Define(ITemplateDefinitionContext context)
{
context.Add(
new TemplateDefinition(
ExceptionHandlingTemplates.SendEmail,
displayName: LocalizableString.Create<ExceptionHandlingResource>("TextTemplate:ExceptionHandlingTemplates.SendEmail"),
defaultCultureName: "en"
).WithVirtualFilePath("/LINGYUN/Abp/ExceptionHandling/Emailing/Templates/SendEmail", false)
);
}
}
}

7
aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN/Abp/ExceptionHandling/Emailing/Templates/ExceptionHandlingTemplates.cs

@ -0,0 +1,7 @@
namespace LINGYUN.Abp.ExceptionHandling.Emailing.Templates
{
public class ExceptionHandlingTemplates
{
public const string SendEmail = "Abp.ExceptionHandling.SendEmail";
}
}

48
aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN/Abp/ExceptionHandling/Emailing/Templates/SendEmail/en.tpl

@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{ model.title }}</title>
</head>
<body leftmargin="8" marginwidth="0" topmargin="8" marginheight="4" offset="0">
<table width="95%" cellpadding="0" cellspacing="0" style="font-size: 11pt; font-family: Tahoma, Arial, Helvetica, sans-serif">
<tr>
<td>
<br /> <b><font color="#0B610B">{{ model.header }}</font></b>
<hr size="2" width="100%" align="center" />
</td>
</tr>
<tr>
<td>
<ul>
<li>Type &nbsp;:&nbsp;{{ model.type }}</li>
<li>Message &nbsp;:&nbsp;{{ model.message }}</li>
<li>Alarm level&nbsp;:&nbsp;{{ model.loglevel }}</li>
<li>TriggerTime&nbsp;:&nbsp;{{ model.triggertime }}</li>
</ul>
</td>
</tr>
{{ if model.sendstacktrace }}
<tr>
<td>
<b><font color="#0B610B">Stack trace</font></b>
<hr size="2" width="100%" align="center" />
</td>
</tr>
<tr>
<td>
<pre style="font-size: 11pt; font-family: Tahoma, Arial, Helvetica, sans-serif">{{ model.stacktrace }}</pre>
<br />
</td>
</tr>
{{ end }}
<tr>
<td>
<br />
<b style="float: right"><font color="#0B610B">{{ model.footer }}</font></b>
<hr size="2" width="100%" align="center" />
</td>
</tr>
</table>
</body>
</html>

48
aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Emailing/LINGYUN/Abp/ExceptionHandling/Emailing/Templates/SendEmail/zh-Hans.tpl

@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="zh-Hans">
<head>
<meta charset="UTF-8">
<title>{{ model.title }}</title>
</head>
<body leftmargin="8" marginwidth="0" topmargin="8" marginheight="4" offset="0">
<table width="95%" cellpadding="0" cellspacing="0" style="font-size: 11pt; font-family: Tahoma, Arial, Helvetica, sans-serif">
<tr>
<td>
<br /> <b><font color="#0B610B">{{ model.header }}</font></b>
<hr size="2" width="100%" align="center" />
</td>
</tr>
<tr>
<td>
<ul>
<li>异常类型&nbsp;:&nbsp;{{ model.type }}</li>
<li>异常信息&nbsp;:&nbsp;{{ model.message }}</li>
<li>告警级别&nbsp;:&nbsp;{{ model.loglevel }}</li>
<li>触发时间&nbsp;:&nbsp;{{ model.triggertime }}</li>
</ul>
</td>
</tr>
{{ if model.sendstacktrace }}
<tr>
<td>
<b><font color="#0B610B">异常堆栈</font></b>
<hr size="2" width="100%" align="center" />
</td>
</tr>
<tr>
<td>
<pre style="font-size: 11pt; font-family: Tahoma, Arial, Helvetica, sans-serif">{{ model.stacktrace }}</pre>
<br />
</td>
</tr>
{{ end }}
<tr>
<td>
<br />
<b style="float: right"><font color="#0B610B">{{ model.footer }}</font></b>
<hr size="2" width="100%" align="center" />
</td>
</tr>
</table>
</body>
</html>

9
aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Notifications/LINGYUN/Abp/ExceptionHandling/AbpNotificationsExceptionHandlingModule.cs

@ -1,9 +0,0 @@
using Volo.Abp.Modularity;
namespace LINGYUN.Abp.ExceptionHandling
{
[DependsOn(typeof(AbpExceptionHandlingModule))]
public class AbpNotificationsExceptionHandlingModule : AbpModule
{
}
}

2
aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Notifications/LINGYUN/Abp/ExceptionHandling/AbpExceptionHandlingNotificationDefinitionProvider.cs → aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Notifications/LINGYUN/Abp/ExceptionHandling/Notifications/AbpExceptionHandlingNotificationDefinitionProvider.cs

@ -1,6 +1,6 @@
using LINGYUN.Abp.Notifications;
namespace LINGYUN.Abp.ExceptionHandling
namespace LINGYUN.Abp.ExceptionHandling.Notifications
{
public class AbpExceptionHandlingNotificationDefinitionProvider : NotificationDefinitionProvider
{

2
aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Notifications/LINGYUN/Abp/ExceptionHandling/AbpExceptionHandlingNotificationNames.cs → aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Notifications/LINGYUN/Abp/ExceptionHandling/Notifications/AbpExceptionHandlingNotificationNames.cs

@ -1,4 +1,4 @@
namespace LINGYUN.Abp.ExceptionHandling
namespace LINGYUN.Abp.ExceptionHandling.Notifications
{
public class AbpExceptionHandlingNotificationNames
{

12
aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Notifications/LINGYUN/Abp/ExceptionHandling/Notifications/AbpNotificationsExceptionHandlingModule.cs

@ -0,0 +1,12 @@
using LINGYUN.Abp.Notifications;
using Volo.Abp.Modularity;
namespace LINGYUN.Abp.ExceptionHandling.Notifications
{
[DependsOn(
typeof(AbpExceptionHandlingModule),
typeof(AbpNotificationModule))]
public class AbpNotificationsExceptionHandlingModule : AbpModule
{
}
}

2
aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Notifications/LINGYUN/Abp/ExceptionHandling/AbpNotificationsExceptionSubscriber.cs → aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Notifications/LINGYUN/Abp/ExceptionHandling/Notifications/AbpNotificationsExceptionSubscriber.cs

@ -5,7 +5,7 @@ using System;
using System.Threading.Tasks;
using Volo.Abp.MultiTenancy;
namespace LINGYUN.Abp.ExceptionHandling
namespace LINGYUN.Abp.ExceptionHandling.Notifications
{
public class AbpNotificationsExceptionSubscriber : AbpExceptionSubscriberBase
{

10
aspnet-core/services/account/AuthServer.Host/AuthIdentityServerModule.cs

@ -14,6 +14,7 @@ using Microsoft.Extensions.Options;
using StackExchange.Redis;
using System;
using System.Linq;
using System.Text;
using Volo.Abp;
using Volo.Abp.AspNetCore.MultiTenancy;
using Volo.Abp.Auditing;
@ -29,6 +30,7 @@ using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Volo.Abp.MultiTenancy;
using Volo.Abp.PermissionManagement.EntityFrameworkCore;
using Volo.Abp.Security.Encryption;
using Volo.Abp.SettingManagement.EntityFrameworkCore;
using Volo.Abp.TenantManagement.EntityFrameworkCore;
using Volo.Abp.Threading;
@ -80,6 +82,14 @@ namespace AuthServer.Host
options.UseMySQL();
});
// 加解密
Configure<AbpStringEncryptionOptions>(options =>
{
options.DefaultPassPhrase = "s46c5q55nxpeS8Ra";
options.InitVectorBytes = Encoding.ASCII.GetBytes("s83ng0abvd02js84");
options.DefaultSalt = Encoding.ASCII.GetBytes("sf&5)s3#");
});
Configure<AbpDistributedCacheOptions>(options =>
{
// 滑动过期30天

10
aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/ApiGatewayHttpApiHostModule.cs

@ -14,6 +14,7 @@ using Microsoft.OpenApi.Models;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Text;
using Volo.Abp;
using Volo.Abp.Autofac;
using Volo.Abp.AutoMapper;
@ -24,6 +25,7 @@ using Volo.Abp.Modularity;
using Volo.Abp.MultiTenancy;
using Volo.Abp.PermissionManagement.EntityFrameworkCore;
using Volo.Abp.Security.Claims;
using Volo.Abp.Security.Encryption;
using Volo.Abp.SettingManagement.EntityFrameworkCore;
using Volo.Abp.TenantManagement.EntityFrameworkCore;
@ -67,6 +69,14 @@ namespace LINGYUN.ApiGateway
options.UseMySQL();
});
// 加解密
Configure<AbpStringEncryptionOptions>(options =>
{
options.DefaultPassPhrase = "s46c5q55nxpeS8Ra";
options.InitVectorBytes = Encoding.ASCII.GetBytes("s83ng0abvd02js84");
options.DefaultSalt = Encoding.ASCII.GetBytes("sf&5)s3#");
});
// 多租户
Configure<AbpMultiTenancyOptions>(options =>
{

14
aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiHostModule.cs

@ -4,9 +4,9 @@ using IdentityModel;
using LINGYUN.Abp.BackgroundJobs.Hangfire;
using LINGYUN.Abp.EventBus.CAP;
using LINGYUN.Abp.ExceptionHandling;
using LINGYUN.Abp.ExceptionHandling.Notifications;
using LINGYUN.Abp.Hangfire.Storage.MySql;
using LINGYUN.Abp.IM.SignalR;
using LINGYUN.Abp.MessageService.BackgroundJobs;
using LINGYUN.Abp.MessageService.EntityFrameworkCore;
using LINGYUN.Abp.MessageService.Localization;
using LINGYUN.Abp.MessageService.MultiTenancy;
@ -21,11 +21,11 @@ using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;
using StackExchange.Redis;
using System;
using System.Text;
using Volo.Abp;
using Volo.Abp.AspNetCore.Authentication.JwtBearer;
using Volo.Abp.AspNetCore.MultiTenancy;
using Volo.Abp.Autofac;
using Volo.Abp.BackgroundJobs;
using Volo.Abp.Caching;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Localization;
@ -33,9 +33,9 @@ using Volo.Abp.Modularity;
using Volo.Abp.MultiTenancy;
using Volo.Abp.PermissionManagement.EntityFrameworkCore;
using Volo.Abp.Security.Claims;
using Volo.Abp.Security.Encryption;
using Volo.Abp.SettingManagement.EntityFrameworkCore;
using Volo.Abp.TenantManagement.EntityFrameworkCore;
using Volo.Abp.Threading;
using Volo.Abp.VirtualFileSystem;
namespace LINGYUN.Abp.MessageService
@ -86,6 +86,14 @@ namespace LINGYUN.Abp.MessageService
options.UseMySQL();
});
// 加解密
Configure<AbpStringEncryptionOptions>(options =>
{
options.DefaultPassPhrase = "s46c5q55nxpeS8Ra";
options.InitVectorBytes = Encoding.ASCII.GetBytes("s83ng0abvd02js84");
options.DefaultSalt = Encoding.ASCII.GetBytes("sf&5)s3#");
});
Configure<AbpExceptionHandlingOptions>(options =>
{
// 加入需要处理的异常类型

1
aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj

@ -63,6 +63,7 @@
<ProjectReference Include="..\..\..\modules\account\LINGYUN.Abp.Account.HttpApi\LINGYUN.Abp.Account.HttpApi.csproj" />
<ProjectReference Include="..\..\..\modules\apigateway\LINGYUN.ApiGateway.Application.Contracts\LINGYUN.ApiGateway.Application.Contracts.csproj" />
<ProjectReference Include="..\..\..\modules\common\LINGYUN.Abp.EventBus.CAP\LINGYUN.Abp.EventBus.CAP.csproj" />
<ProjectReference Include="..\..\..\modules\common\LINGYUN.Abp.ExceptionHandling.Emailing\LINGYUN.Abp.ExceptionHandling.Emailing.csproj" />
<ProjectReference Include="..\..\..\modules\common\LINGYUN.Abp.Identity.OverrideOptions\LINGYUN.Abp.Identity.OverrideOptions.csproj" />
<ProjectReference Include="..\..\..\modules\common\LINGYUN.Abp.Location.Baidu\LINGYUN.Abp.Location.Baidu.csproj" />
<ProjectReference Include="..\..\..\modules\message\LINGYUN.Abp.MessageService.Application.Contracts\LINGYUN.Abp.MessageService.Application.Contracts.csproj" />

31
aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/PlatformHttpApiHostModule.cs

@ -1,6 +1,8 @@
using DotNetCore.CAP;
using IdentityModel;
using LINGYUN.Abp.EventBus.CAP;
using LINGYUN.Abp.ExceptionHandling;
using LINGYUN.Abp.ExceptionHandling.Emailing;
using LINGYUN.Abp.Identity;
using LINGYUN.Abp.IdentityServer;
using LINGYUN.Abp.Location.Baidu;
@ -21,6 +23,7 @@ using Microsoft.OpenApi.Models;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Text;
using Volo.Abp;
using Volo.Abp.Account;
using Volo.Abp.AspNetCore.Authentication.JwtBearer;
@ -42,6 +45,7 @@ using Volo.Abp.PermissionManagement.HttpApi;
using Volo.Abp.PermissionManagement.Identity;
using Volo.Abp.PermissionManagement.IdentityServer;
using Volo.Abp.Security.Claims;
using Volo.Abp.Security.Encryption;
using Volo.Abp.SettingManagement.EntityFrameworkCore;
using Volo.Abp.TenantManagement.EntityFrameworkCore;
using Volo.Abp.VirtualFileSystem;
@ -76,6 +80,7 @@ namespace LINGYUN.Platform
typeof(AbpSettingManagementEntityFrameworkCoreModule),
typeof(AbpPermissionManagementEntityFrameworkCoreModule),
typeof(AbpAspNetCoreAuthenticationJwtBearerModule),
typeof(AbpEmailingExceptionHandlingModule),
typeof(AbpCAPEventBusModule),
typeof(AbpAliyunSmsModule),
#if DEBUG
@ -117,6 +122,32 @@ namespace LINGYUN.Platform
options.UseMySQL();
});
// 加解密
Configure<AbpStringEncryptionOptions>(options =>
{
options.DefaultPassPhrase = "s46c5q55nxpeS8Ra";
options.InitVectorBytes = Encoding.ASCII.GetBytes("s83ng0abvd02js84");
options.DefaultSalt = Encoding.ASCII.GetBytes("sf&5)s3#");
});
// 自定义需要处理的异常
Configure<AbpExceptionHandlingOptions>(options =>
{
// 加入需要处理的异常类型
options.Handlers.Add<AbpException>();
});
// 自定义需要发送邮件通知的异常类型
Configure<AbpEmailExceptionHandlingOptions>(options =>
{
// 是否发送堆栈信息
options.SendStackTrace = true;
// 未指定异常接收者的默认接收邮件
options.DefaultReceiveEmail = "colin.in@foxmail.com";
// 指定某种异常发送到哪个邮件
options.HandReceivedException<AbpException>("colin.in@foxmail.com");
});
Configure<AbpDistributedCacheOptions>(options =>
{
// 滑动过期30天

18
aspnet-core/tests/LINGYUN.Abp.ExceptionHandling.Emailing.Tests/LINGYUN.Abp.ExceptionHandling.Emailing.Tests.csproj

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace />
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\modules\common\LINGYUN.Abp.ExceptionHandling.Emailing\LINGYUN.Abp.ExceptionHandling.Emailing.csproj" />
<ProjectReference Include="..\LINGYUN.Abp.TestBase\LINGYUN.Abp.TestsBase.csproj" />
</ItemGroup>
</Project>

44
aspnet-core/tests/LINGYUN.Abp.ExceptionHandling.Emailing.Tests/LINGYUN/Abp/ExceptionHandling/Emailing/AbpEmailingExceptionSubscriber_Test.cs

@ -0,0 +1,44 @@
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.ExceptionHandling;
using Volo.Abp.Localization;
using Xunit;
namespace LINGYUN.Abp.ExceptionHandling.Emailing
{
public class AbpEmailingExceptionSubscriber_Test : AbpExceptionHandlingEmailingTestBase
{
private readonly IExceptionNotifier _notifier;
public AbpEmailingExceptionSubscriber_Test()
{
_notifier = GetRequiredService<IExceptionNotifier>();
}
[Fact]
public async Task Send_Error_Notifier_Test()
{
try
{
int x = 10;
int y = 0;
int zeroDiv = x / y;
}
catch(Exception ex)
{
await _notifier.NotifyAsync(
new ExceptionNotificationContext(
new TestSendEmailException(
"Test exception notufy with en", ex), LogLevel.Warning));
using (CultureHelper.Use("zh-Hans"))
{
await _notifier.NotifyAsync(
new ExceptionNotificationContext(
new TestSendEmailException(
"测试中文异常模板推送", ex), LogLevel.Warning));
}
}
}
}
}

8
aspnet-core/tests/LINGYUN.Abp.ExceptionHandling.Emailing.Tests/LINGYUN/Abp/ExceptionHandling/Emailing/AbpExceptionHandlingEmailingTestBase.cs

@ -0,0 +1,8 @@
using LINGYUN.Abp.Tests;
namespace LINGYUN.Abp.ExceptionHandling.Emailing
{
public class AbpExceptionHandlingEmailingTestBase : AbpTestsBase<AbpExceptionHandlingEmailingTestModule>
{
}
}

59
aspnet-core/tests/LINGYUN.Abp.ExceptionHandling.Emailing.Tests/LINGYUN/Abp/ExceptionHandling/Emailing/AbpExceptionHandlingEmailingTestModule.cs

@ -0,0 +1,59 @@
using LINGYUN.Abp.Tests;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System.Text;
using Volo.Abp;
using Volo.Abp.Autofac;
using Volo.Abp.Modularity;
using Volo.Abp.Security.Encryption;
namespace LINGYUN.Abp.ExceptionHandling.Emailing
{
[DependsOn(
typeof(AbpEmailingExceptionHandlingModule),
typeof(AbpTestsBaseModule),
typeof(AbpAutofacModule)
)]
public class AbpExceptionHandlingEmailingTestModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
var configurationOptions = new AbpConfigurationBuilderOptions
{
BasePath = @"D:\Projects\Development\Abp\ExceptionHandling\Emailing",
EnvironmentName = "Development"
};
context.Services.ReplaceConfiguration(ConfigurationHelper.BuildConfiguration(configurationOptions));
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
// 加解密
Configure<AbpStringEncryptionOptions>(options =>
{
options.DefaultPassPhrase = "s46c5q55nxpeS8Ra";
options.InitVectorBytes = Encoding.ASCII.GetBytes("s83ng0abvd02js84");
options.DefaultSalt = Encoding.ASCII.GetBytes("sf&5)s3#");
});
// 自定义需要处理的异常
Configure<AbpExceptionHandlingOptions>(options =>
{
// 加入需要处理的异常类型
options.Handlers.Add<AbpException>();
});
// 自定义需要发送邮件通知的异常类型
Configure<AbpEmailExceptionHandlingOptions>(options =>
{
// 是否发送堆栈信息
options.SendStackTrace = true;
// 未指定异常接收者的默认接收邮件
options.DefaultReceiveEmail = "colin.in@foxmail.com";
// 指定某种异常发送到哪个邮件
options.HandReceivedException<AbpException>("colin.in@foxmail.com");
options.HandReceivedException<TestSendEmailException>("colin.in@foxmail.com");
});
}
}
}

19
aspnet-core/tests/LINGYUN.Abp.ExceptionHandling.Emailing.Tests/LINGYUN/Abp/ExceptionHandling/Emailing/TestSendEmailException.cs

@ -0,0 +1,19 @@
using System;
namespace LINGYUN.Abp.ExceptionHandling.Emailing
{
public class TestSendEmailException : Exception, IHasNotifierErrorMessage
{
public TestSendEmailException(string message)
: base(message)
{
}
public TestSendEmailException(string message, Exception innerException)
: base(message, innerException)
{
}
}
}
Loading…
Cancel
Save