angular - 实时通知未发送

标签 angular .net-core signalr aspnetboilerplate asp.net-core-signalr

我尝试在 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/

相关文章:

Angular 2 辅助路线首次有效,但在后续点击中无效

c# - 获取临时键 x 和 y 坐标

.net - 尝试将 AutoMapper 添加到 .NetCore1.1 - 无法识别 services.AddAutoMapper()

c# - 将 Signal R 整合到现有的 Web 应用程序中

javascript - Angular,如何在多个页面而不是在一个大列表中显示 *ngFor

javascript - 如何在渲染后动态取消选中和选中 Nebular 复选框

java - 是否有类似于 “dotnet add package xxx” 的 maven 命令?

c# - 不使用 FCM 为 Xamarin.Android 创建推送通知

c# - 为什么 SignalR 会多次更改函数?

Angular ngFor 在更新数组时不更新 DOM