Signalr ASP.NET样板文件的信号器集成

Signalr ASP.NET样板文件的信号器集成,signalr,aspnetboilerplate,Signalr,Aspnetboilerplate,我正在做一个ASP.NET样板项目。我想将信号器适当地集成到这个项目中 有文档,但我想知道从后端向前端发送通知时信号器的流程。欢迎提供任何示例代码或建议。ASP.NET样板文件是开源的,因此您可以在上查看代码 从:Abp.AspNetCore.signal包实现IRealTimeNotifier 下面的代码适用于ASP.NET Core和jQuery版本,但其他版本的流程相同 在后端,NotificationDistributer注入和IRealTimeNotifier: 等待RealTimeN

我正在做一个ASP.NET样板项目。我想将信号器适当地集成到这个项目中


有文档,但我想知道从后端向前端发送通知时信号器的流程。欢迎提供任何示例代码或建议。

ASP.NET样板文件是开源的,因此您可以在上查看代码

从:Abp.AspNetCore.signal包实现IRealTimeNotifier

下面的代码适用于ASP.NET Core和jQuery版本,但其他版本的流程相同

  • 在后端,
    NotificationDistributer
    注入和
    IRealTimeNotifier

    等待RealTimeNotifier.SendNotificationsAsync(userNotifications.ToArray());
    
  • signalRelateMeNotifier
    SendNotificationsAsync
    ,它获取每个用户的在线客户端,并调用客户端方法,将
    userNotification
    作为参数:

    var onlineClients=\u onlineClientManager.GetAllByUserId(userNotification);
    foreach(在线客户端中的var onlineClient)
    {
    var signalRClient=\u hubContext.Clients.Client(onlineClient.ConnectionId);
    InvokeAsync(“getNotification”,userNotification);
    }
    
  • 用于
    getNotification
    的信号器客户端将触发
    'abp.notifications.received'
    ,并将
    通知
    作为参数:

    connection.on('getNotification',函数(通知){
    abp.event.trigger('abp.notifications.received',通知);
    });
    
  • 具有通知处理程序的main.js

    abp.event.on('abp.notifications.received',函数(userNotification){
    abp.notifications.showUiNotifyForUserNotification(userNotification);
    }
    
  • showUiNotifyForUserNotification
    前端的通知:

    abp.notifications.showUiNotifyForUserNotification=函数(userNotification,选项){
    var message=abp.notifications.getFormattedMessageFromUserNotification(userNotification);
    var uiNotifyFunc=abp.notifications.getUiNotifyFuncBySeverity(userNotification.notification.severity);
    uiNotifyFunc(消息,未定义,选项);
    }
    

  • ASP.NET样板文件是开源的,因此您可以在上查看代码

    从:Abp.AspNetCore.signal包实现IRealTimeNotifier

    下面的代码适用于ASP.NET Core和jQuery版本,但其他版本的流程相同

  • 在后端,
    NotificationDistributer
    注入和
    IRealTimeNotifier

    等待RealTimeNotifier.SendNotificationsAsync(userNotifications.ToArray());
    
  • signalRelateMeNotifier
    SendNotificationsAsync
    ,它获取每个用户的在线客户端,并调用客户端方法,将
    userNotification
    作为参数:

    var onlineClients=\u onlineClientManager.GetAllByUserId(userNotification);
    foreach(在线客户端中的var onlineClient)
    {
    var signalRClient=\u hubContext.Clients.Client(onlineClient.ConnectionId);
    InvokeAsync(“getNotification”,userNotification);
    }
    
  • 用于
    getNotification
    的信号器客户端将触发
    'abp.notifications.received'
    ,并将
    通知
    作为参数:

    connection.on('getNotification',函数(通知){
    abp.event.trigger('abp.notifications.received',通知);
    });
    
  • 具有通知处理程序的main.js

    abp.event.on('abp.notifications.received',函数(userNotification){
    abp.notifications.showUiNotifyForUserNotification(userNotification);
    }
    
  • showUiNotifyForUserNotification
    前端的通知:

    abp.notifications.showUiNotifyForUserNotification=函数(userNotification,选项){
    var message=abp.notifications.getFormattedMessageFromUserNotification(userNotification);
    var uiNotifyFunc=abp.notifications.getUiNotifyFuncBySeverity(userNotification.notification.severity);
    uiNotifyFunc(消息,未定义,选项);
    }
    

  • 感谢aaron提供的详细解决方案。这应该行得通。感谢aaron提供的详细解决方案。这应该行得通。