Browse Source

change notification data

pull/64/head
cKey 5 years ago
parent
commit
d517df75de
  1. 11
      aspnet-core/LINGYUN.MicroService.sln
  2. 10
      aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Notifications/LINGYUN/Abp/ExceptionHandling/Notifications/AbpNotificationsExceptionSubscriber.cs
  3. 6
      aspnet-core/modules/common/LINGYUN.Abp.Notifications.SignalR/LINGYUN/Abp/Notifications/SignalR/OnlineClientHubBase.cs
  4. 17
      aspnet-core/modules/common/LINGYUN.Abp.Notifications.SignalR/LINGYUN/Abp/Notifications/SignalR/SignalRNotificationPublishProvider.cs
  5. 50
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationData.cs
  6. 5
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationDefinition.cs
  7. 10
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationType.cs
  8. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/EventBus/Local/UserCreateSendWelcomeEventHandler.cs
  9. 15
      aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs
  10. 2
      aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/EventBus/Distributed/TenantCreateEventHandler.cs

11
aspnet-core/LINGYUN.MicroService.sln

@ -209,9 +209,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.IdentityServer.
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.IdentityServer.EntityFrameworkCore", "modules\identityServer\LINGYUN.Abp.IdentityServer.EntityFrameworkCore\LINGYUN.Abp.IdentityServer.EntityFrameworkCore.csproj", "{5D0ED1FC-3A7C-4531-9512-832E73AD9555}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.IdentityServer.EntityFrameworkCore", "modules\identityServer\LINGYUN.Abp.IdentityServer.EntityFrameworkCore\LINGYUN.Abp.IdentityServer.EntityFrameworkCore.csproj", "{5D0ED1FC-3A7C-4531-9512-832E73AD9555}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Identity.Domain", "modules\identity\LINGYUN.Abp.Identity.Domain\LINGYUN.Abp.Identity.Domain.csproj", "{2BF7FB73-0C62-4ECF-99F0-0583855D2777}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Identity.Domain", "modules\identity\LINGYUN.Abp.Identity.Domain\LINGYUN.Abp.Identity.Domain.csproj", "{2BF7FB73-0C62-4ECF-99F0-0583855D2777}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Identity.EntityFrameworkCore", "modules\identity\LINGYUN.Abp.Identity.EntityFrameworkCore\LINGYUN.Abp.Identity.EntityFrameworkCore.csproj", "{6FE7E243-2D99-4567-8786-6C9283D608EF}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Identity.EntityFrameworkCore", "modules\identity\LINGYUN.Abp.Identity.EntityFrameworkCore\LINGYUN.Abp.Identity.EntityFrameworkCore.csproj", "{6FE7E243-2D99-4567-8786-6C9283D608EF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Notifications.AspNetCore.Mvc", "modules\common\LINGYUN.Abp.Notifications.AspNetCore.Mvc\LINGYUN.Abp.Notifications.AspNetCore.Mvc.csproj", "{1A9C06D0-1A12-48C6-B3F6-F2DBC66AA355}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -567,6 +569,10 @@ Global
{6FE7E243-2D99-4567-8786-6C9283D608EF}.Debug|Any CPU.Build.0 = Debug|Any CPU {6FE7E243-2D99-4567-8786-6C9283D608EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6FE7E243-2D99-4567-8786-6C9283D608EF}.Release|Any CPU.ActiveCfg = Release|Any CPU {6FE7E243-2D99-4567-8786-6C9283D608EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6FE7E243-2D99-4567-8786-6C9283D608EF}.Release|Any CPU.Build.0 = Release|Any CPU {6FE7E243-2D99-4567-8786-6C9283D608EF}.Release|Any CPU.Build.0 = Release|Any CPU
{1A9C06D0-1A12-48C6-B3F6-F2DBC66AA355}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1A9C06D0-1A12-48C6-B3F6-F2DBC66AA355}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1A9C06D0-1A12-48C6-B3F6-F2DBC66AA355}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1A9C06D0-1A12-48C6-B3F6-F2DBC66AA355}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -674,6 +680,7 @@ Global
{5D0ED1FC-3A7C-4531-9512-832E73AD9555} = {0439B173-F41E-4CE0-A44A-CCB70328F272} {5D0ED1FC-3A7C-4531-9512-832E73AD9555} = {0439B173-F41E-4CE0-A44A-CCB70328F272}
{2BF7FB73-0C62-4ECF-99F0-0583855D2777} = {52B5D4F7-237B-4E0A-A167-68442164F70A} {2BF7FB73-0C62-4ECF-99F0-0583855D2777} = {52B5D4F7-237B-4E0A-A167-68442164F70A}
{6FE7E243-2D99-4567-8786-6C9283D608EF} = {52B5D4F7-237B-4E0A-A167-68442164F70A} {6FE7E243-2D99-4567-8786-6C9283D608EF} = {52B5D4F7-237B-4E0A-A167-68442164F70A}
{1A9C06D0-1A12-48C6-B3F6-F2DBC66AA355} = {8AC72641-30D3-4ACF-89FA-808FADC55C2E}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C95FDF91-16F2-4A8B-A4BE-0E62D1B66718} SolutionGuid = {C95FDF91-16F2-4A8B-A4BE-0E62D1B66718}

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

@ -24,7 +24,15 @@ namespace LINGYUN.Abp.ExceptionHandling.Notifications
var notificationDispatcher = context.ServiceProvider.GetRequiredService<INotificationDispatcher>(); var notificationDispatcher = context.ServiceProvider.GetRequiredService<INotificationDispatcher>();
var notificationName = NotificationNameNormalizer var notificationName = NotificationNameNormalizer
.NormalizerName(AbpExceptionHandlingNotificationNames.NotificationName); .NormalizerName(AbpExceptionHandlingNotificationNames.NotificationName);
var notificationData = new NotificationData(); NotificationData notificationData;
if (CurrentTenant.IsAvailable)
{
notificationData = NotificationData.CreateTenantNotificationData(CurrentTenant.Id.Value);
}
else
{
notificationData = NotificationData.CreateNotificationData();
}
// 写入通知数据 // 写入通知数据
//TODO:集成TextTemplate完成格式化的推送 //TODO:集成TextTemplate完成格式化的推送
notificationData.WriteStandardData( notificationData.WriteStandardData(

6
aspnet-core/modules/common/LINGYUN.Abp.Notifications.SignalR/LINGYUN/Abp/Notifications/SignalR/OnlineClientHubBase.cs

@ -1,6 +1,5 @@
using LINGYUN.Abp.RealTime.Client; using LINGYUN.Abp.RealTime.Client;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -26,6 +25,11 @@ namespace LINGYUN.Abp.Notifications.SignalR
IOnlineClient onlineClient = CreateClientForCurrentConnection(); IOnlineClient onlineClient = CreateClientForCurrentConnection();
Logger.LogDebug("A client is connected: " + onlineClient.ToString()); Logger.LogDebug("A client is connected: " + onlineClient.ToString());
OnlineClientManager.Add(onlineClient); OnlineClientManager.Add(onlineClient);
if (onlineClient.TenantId.HasValue)
{
// 以租户为分组,将用户加入租户通讯组
await Groups.AddToGroupAsync(onlineClient.ConnectionId, onlineClient.TenantId.Value.ToString());
}
} }
public override async Task OnDisconnectedAsync(Exception exception) public override async Task OnDisconnectedAsync(Exception exception)

17
aspnet-core/modules/common/LINGYUN.Abp.Notifications.SignalR/LINGYUN/Abp/Notifications/SignalR/SignalRNotificationPublishProvider.cs

@ -29,6 +29,22 @@ namespace LINGYUN.Abp.Notifications.SignalR
} }
public override async Task PublishAsync(NotificationInfo notification, IEnumerable<UserIdentifier> identifiers) public override async Task PublishAsync(NotificationInfo notification, IEnumerable<UserIdentifier> identifiers)
{
if (notification.Data.HasTenantNotification(out Guid tenantId))
{
// 返回标准数据给前端
notification.Data = NotificationData.ToStandardData(notification.Data);
var singalRGroup = _hubContext.Clients.Group(tenantId.ToString());
if (singalRGroup == null)
{
Logger.LogDebug("Can not get group " + tenantId + " from SignalR hub!");
return;
}
// 租户通知群发
Logger.LogDebug($"Found a singalr group, begin senging notifications");
await singalRGroup.SendAsync("getNotification", notification);
}
else
{ {
// 返回标准数据给前端 // 返回标准数据给前端
notification.Data = NotificationData.ToStandardData(notification.Data); notification.Data = NotificationData.ToStandardData(notification.Data);
@ -60,4 +76,5 @@ namespace LINGYUN.Abp.Notifications.SignalR
} }
} }
} }
}
} }

50
aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationData.cs

@ -5,6 +5,10 @@ namespace LINGYUN.Abp.Notifications
{ {
public class NotificationData public class NotificationData
{ {
public const string NotificationKey = "N:G";
public const string UserIdNotificationKey = "N:UI";
public const string UserNameNotificationKey = "N:UN";
public const string TenantNotificationKey = "N:T";
public virtual string Type => GetType().FullName; public virtual string Type => GetType().FullName;
public object this[string key] public object this[string key]
@ -45,6 +49,29 @@ namespace LINGYUN.Abp.Notifications
{ {
_properties = new Dictionary<string, object>(); _properties = new Dictionary<string, object>();
} }
public static NotificationData CreateNotificationData()
{
var data = new NotificationData();
data.TrySetData(NotificationKey, "AbpNotification");
return data;
}
public static NotificationData CreateUserNotificationData(Guid userId, string userName)
{
var data = new NotificationData();
data.TrySetData(UserIdNotificationKey, userId);
data.TrySetData(UserNameNotificationKey, userName);
return data;
}
public static NotificationData CreateTenantNotificationData(Guid tenantId)
{
var data = new NotificationData();
data.TrySetData(TenantNotificationKey, tenantId);
return data;
}
/// <summary> /// <summary>
/// 写入标准数据 /// 写入标准数据
/// </summary> /// </summary>
@ -123,5 +150,28 @@ namespace LINGYUN.Abp.Notifications
Properties[key] = value; Properties[key] = value;
} }
} }
public bool HasUserNotification(out Guid userId, out string userName)
{
if (Properties.TryGetValue(UserIdNotificationKey, out object userKey))
{
userId = (Guid)userKey;
var name = TryGetData(UserNameNotificationKey);
userName = name != null ? name.ToString() : "";
return true;
}
userName = "";
return false;
}
public bool HasTenantNotification(out Guid tenantId)
{
if (Properties.TryGetValue(TenantNotificationKey, out object tenantKey))
{
tenantId = (Guid)tenantKey;
return true;
}
return false;
}
} }
} }

5
aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationDefinition.cs

@ -9,6 +9,11 @@ using Volo.Abp.Localization;
* ,,,Catalog * ,,,Catalog
* Prefix * Prefix
* *
* TODO: 2020-08-26 ?
* 宿,
* NotificationData[FormUser]
* NotificationData[FormTenant]
* NotificationData[FormGlobal]
*/ */
namespace LINGYUN.Abp.Notifications namespace LINGYUN.Abp.Notifications

10
aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationType.cs

@ -6,12 +6,16 @@
public enum NotificationType public enum NotificationType
{ {
/// <summary> /// <summary>
/// 应用 /// 应用(对应租户)
/// </summary> /// </summary>
Application = 0, Application = 0,
/// <summary> /// <summary>
/// 系统 /// 系统(对应宿主)
/// </summary> /// </summary>
System = 10 System = 10,
/// <summary>
/// 用户(对应用户)
/// </summary>
User = 20
} }
} }

2
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/EventBus/Local/UserCreateSendWelcomeEventHandler.cs

@ -61,7 +61,7 @@ namespace LINGYUN.Abp.MessageService.EventBus
//await _notificationStore.InsertUserSubscriptionAsync(eventData.Entity.TenantId, //await _notificationStore.InsertUserSubscriptionAsync(eventData.Entity.TenantId,
// userIdentifer, UserNotificationNames.WelcomeToApplication); // userIdentifer, UserNotificationNames.WelcomeToApplication);
var userWelcomeNotifictionData = new NotificationData(); var userWelcomeNotifictionData = NotificationData.CreateUserNotificationData(eventData.Entity.Id, eventData.Entity.UserName);
userWelcomeNotifictionData.WriteStandardData( userWelcomeNotifictionData.WriteStandardData(
L("WelcomeToApplicationFormUser", eventData.Entity.Name ?? eventData.Entity.UserName), L("WelcomeToApplicationFormUser", eventData.Entity.Name ?? eventData.Entity.UserName),

15
aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs

@ -39,6 +39,10 @@ namespace LINGYUN.Abp.MessageService.EventBus.Distributed
/// </summary> /// </summary>
protected INotificationStore NotificationStore { get; } protected INotificationStore NotificationStore { get; }
/// <summary> /// <summary>
/// Reference to <see cref="INotificationSubscriptionManager"/>.
/// </summary>
protected INotificationSubscriptionManager NotificationSubscriptionManager { get; }
/// <summary>
/// Reference to <see cref="INotificationPublishProviderManager"/>. /// Reference to <see cref="INotificationPublishProviderManager"/>.
/// </summary> /// </summary>
protected INotificationPublishProviderManager NotificationPublishProviderManager { get; } protected INotificationPublishProviderManager NotificationPublishProviderManager { get; }
@ -50,11 +54,13 @@ namespace LINGYUN.Abp.MessageService.EventBus.Distributed
IBackgroundJobManager backgroundJobManager, IBackgroundJobManager backgroundJobManager,
IOptions<AbpNotificationOptions> options, IOptions<AbpNotificationOptions> options,
INotificationStore notificationStore, INotificationStore notificationStore,
INotificationSubscriptionManager notificationSubscriptionManager,
INotificationPublishProviderManager notificationPublishProviderManager) INotificationPublishProviderManager notificationPublishProviderManager)
{ {
BackgroundJobManager = backgroundJobManager; BackgroundJobManager = backgroundJobManager;
Options = options.Value; Options = options.Value;
NotificationStore = notificationStore; NotificationStore = notificationStore;
NotificationSubscriptionManager = notificationSubscriptionManager;
NotificationPublishProviderManager = notificationPublishProviderManager; NotificationPublishProviderManager = notificationPublishProviderManager;
Logger = NullLogger<NotificationEventHandler>.Instance; Logger = NullLogger<NotificationEventHandler>.Instance;
@ -85,9 +91,16 @@ namespace LINGYUN.Abp.MessageService.EventBus.Distributed
// 持久化通知 // 持久化通知
await NotificationStore.InsertNotificationAsync(notificationInfo); await NotificationStore.InsertNotificationAsync(notificationInfo);
// TODO: 某些情况下,不能直接在服务内订阅消息,目前只能通过将订阅内容放进消息内部,需要重构通知系统设计了
if (notificationInfo.Data.HasUserNotification(out Guid userId, out string userName))
{
await NotificationSubscriptionManager.SubscribeAsync(notificationInfo.TenantId,
new UserIdentifier(userId, userName), notificationInfo.Name);
}
Logger.LogDebug($"Gets a list of user subscriptions {notificationInfo.Name}"); Logger.LogDebug($"Gets a list of user subscriptions {notificationInfo.Name}");
// 获取用户订阅列表 // 获取用户订阅列表
var userSubscriptions = await NotificationStore.GetSubscriptionsAsync(notificationInfo.TenantId, notificationInfo.Name); var userSubscriptions = await NotificationSubscriptionManager.GetSubscriptionsAsync(notificationInfo.TenantId, notificationInfo.Name);
Logger.LogDebug($"Persistent user notifications {notificationInfo.Name}"); Logger.LogDebug($"Persistent user notifications {notificationInfo.Name}");
// 持久化用户通知 // 持久化用户通知

2
aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/EventBus/Distributed/TenantCreateEventHandler.cs

@ -55,7 +55,7 @@ namespace LINGYUN.Abp.MessageService.EventBus.Distributed
// 管理用户订阅租户创建通知 // 管理用户订阅租户创建通知
await NotificationSubscriptionManager.SubscribeAsync(eventData.Id, tenantAdminUserIdentifier, noticeNormalizerName.Name); await NotificationSubscriptionManager.SubscribeAsync(eventData.Id, tenantAdminUserIdentifier, noticeNormalizerName.Name);
var notificationData = new NotificationData(); var notificationData = NotificationData.CreateTenantNotificationData(eventData.Id);
notificationData.WriteStandardData( notificationData.WriteStandardData(
L("NewTenantRegisteredNotificationTitle"), L("NewTenantRegisteredNotificationTitle"),
L("NewTenantRegisteredNotificationMessage", eventData.Name), L("NewTenantRegisteredNotificationMessage", eventData.Name),

Loading…
Cancel
Save