我尝试在 ASP.NET Boilerplate 中显示实时通知,但未发送。
public override async Task<MessagesDto> Create(MessagesCreateDto input)
{
var MessagesCore = ObjectMapper.Map<MessagesCore>(input);
MessagesCore.UserId = Convert.ToInt32(AbpSession.UserId);
MessagesCore.CreationId = Convert.ToInt32(AbpSession.UserId);
MessagesCore.FromUserId = Convert.ToInt32(AbpSession.UserId);
MessagesCore.CreationTime = DateTime.Now;
MessagesCore.LastModificationId = Convert.ToInt32(AbpSession.UserId);
MessagesCore.LastModificationTime = DateTime.Now;
_stateRepository.Insert(MessagesCore);
CurrentUnitOfWork.SaveChanges();
UserIdentifier identifier = new UserIdentifier(1,input.ToUserId);
await _notificationSubscriptionManager.SubscribeAsync(new UserIdentifier(1, input.ToUserId), "NewMessage");
await _notificationPublisher.PublishAsync("NewMessage", new SentMessageNotificationData("Test", "New Message"), userIds: new[] { identifier });
return MapToEntityDto(MessagesCore);
}
SentMessage
通知数据类:
[Serializable]
public class SentMessageNotificationData : NotificationData
{
public string SenderUserName { get; set; }
public string FriendshipMessage { get; set; }
public SentMessageNotificationData(string senderUserName, string friendshipMessage)
{
SenderUserName = senderUserName;
FriendshipMessage = friendshipMessage;
}
}
数据存储在通知表中,但客户端不显示通知消息。
app.component.ts中的SignalR代码:
ngOnInit(): void {
if (this.appSession.application.features['SignalR']) {
SignalRHelper.initSignalR();
}
abp.event.on('abp.notifications.received', userNotification => {
abp.notifications.showUiNotifyForUserNotification(userNotification);
if (userNotification.notification.data.type === 'Abp.Notifications.LocalizableMessageNotificationData') {
var localizedText = abp.localization.localize(
userNotification.notification.data.message.name,
userNotification.notification.data.message.sourceName
);
$.each(userNotification.notification.data.properties, function (key, value) {
localizedText = localizedText.replace('{' + key + '}', value);
});
alert('New localized notification: ' + localizedText);
} else if (userNotification.notification.data.type === 'Abp.Notifications.MessageNotificationData') {
alert('New simple notification: ' + userNotification.notification.data.message);
}
//Desktop notification
Push.create("AbpZeroTemplate", {
body: userNotification.notification.data.message,
icon: abp.appPath + 'assets/app-logo-small.png',
timeout: 6000,
onClick: function () {
window.focus();
this.close();
}
});
});
}
最佳答案
i am on netcoreapp2.0
- SignalR 仍处于 .NET Core 的
1.0.0-alpha2-final
版本。 2.x
仅在 2018 年第一季度/第二季度稳定。
更新 1
Abp.AspNetCore.SignalR NuGet 包已发布。
阅读 SignalR AspNetCore Integration 的文档.
您可以try并进行必要的changes到您的文件。 或者只是等待它被释放。
更新2
您现在可以download具有 AspNetCore.SignalR 预览的模板的 v3.4.1
。
关于angular - 实时通知未发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47795281/