DD.WellWorkover.Cloud/AsbCloudWebApi/SignalR/NotificationHub.cs
Степанов Дмитрий Александрович 29a534258e Отправка уведомлений
1. Сделал отправку уведомлений через SignalR.
2. Сделал рефакторинг для хабов.
2023-07-10 16:59:11 +05:00

39 lines
1.2 KiB
C#

using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Services;
using AsbCloudWebApi.Options.Notifications;
using AsbCloudWebApi.SignalR.ConnectionManager;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Options;
namespace AsbCloudWebApi.SignalR;
[Authorize]
public class NotificationHub : BaseHub
{
private readonly IConnectionManager connectionManager;
private readonly INotificationService notificationService;
private readonly NotificationsOptionsSignalR notificationsOptionsSignalR;
public NotificationHub(IConnectionManager connectionManager,
INotificationService notificationService,
IOptions<NotificationsOptionsSignalR> notificationsOptionsSignalR)
{
this.connectionManager = connectionManager;
this.notificationService = notificationService;
this.notificationsOptionsSignalR = notificationsOptionsSignalR.Value;
}
public async Task OnConnected(int idUser)
{
string connectionId = Context.ConnectionId;
connectionManager.AddConnection(idUser.ToString(), connectionId);
await notificationService.ResendNotificationAsync(idUser,
notificationsOptionsSignalR.IdTransport,
CancellationToken.None);
await base.OnConnectedAsync();
}
}