未发送实时通知 [英] Realtime notification not sent

查看:28
本文介绍了未发送实时通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 ASP.NET Boilerplate 中显示实时通知,但没有发送.

public override async Task创建(MessagesCreateDto 输入){var MessagesCore = ObjectMapper.Map(输入);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);等待 _notificationSubscriptionManager.SubscribeAsync(new UserIdentifier(1, input.ToUserId), "NewMessage");await _notificationPublisher.PublishAsync("NewMessage", new SentMessageNotificationData("Test", "New Message"), userIds: new[] { identifier });返回 MapToEntityDto(MessagesCore);}

SentMessage 通知数据类:

[Serializable]公共类 SentMessageNotificationData : NotificationData{公共字符串 SenderUserName { get;放;}公共字符串 FriendshipMessage { 获取;放;}public SentMessageNotificationData(string senderUserName, stringfriendshipMessage){发件人用户名 = 发件人用户名;FriendshipMessage = FriendshipMessage;}}

数据存储在通知表中,但客户端没有显示通知消息.

app.component.ts 中的 SignalR 代码:

ngOnInit(): void {如果(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('新的本地化通知:' + localizedText);} else if (userNotification.notification.data.type === 'Abp.Notifications.MessageNotificationData') {alert('新的简单通知:' + userNotification.notification.data.message);}//桌面通知Push.create("AbpZeroTemplate", {正文:userNotification.notification.data.message,图标:abp.appPath + 'assets/app-logo-small.png',超时:6000,onClick: 函数 () {window.focus();this.close();}});});}

解决方案

我在 netcoreapp2.0 上

  • SignalR 仍在用于 .NET Core 的 1.0.0-alpha2-final 上.
  • 2.x 仅在 2018 年第一季度/第二季度稳定.

更新 1

Abp.AspNetCore.SignalR NuGet 包已发布.>

阅读有关 SignalR AspNetCore 集成的文档.

您可以尝试 并进行必要的更改到您的文件.或者只是等待它发布.

更新 2

您现在可以下载 v3.4.1 带有 AspNetCore 的模板.SignalR 预览.

I am trying to display realtime notification in ASP.NET Boilerplate, but it is not sent.

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 notification data class:

[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;
    }
}

Data is stored in notification table, but no notification message is displaying in client side.

SignalR code in app.component.ts:

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 is still on 1.0.0-alpha2-final for .NET Core.
  • 2.x will only be stable in Q1/Q2 2018.

Update 1

Abp.AspNetCore.SignalR NuGet package has been published.

Read the documentation for SignalR AspNetCore Integration.

You can try it and make the necessary changes to your files. Or just wait for it to be released.

Update 2

You can now download v3.4.1 of the template with the AspNetCore.SignalR preview.

这篇关于未发送实时通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆