DD.WellWorkover.Cloud/AsbCloudWebApi/SignalR/NotificationHub.cs
Степанов Дмитрий Александрович 83ee280fbb Рефакторинг
1. Поменял время жизни для отправителей уведомлений.
2. Добавил метод в контроллере для получения уведомления по Id.
3. Поправил хаб уведомлений
4. Небольшие фиксы в репозитории и сервисах
2023-07-12 13:31:55 +05:00

50 lines
1.1 KiB
C#

using System;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data;
using AsbCloudApp.Services.Notifications;
using AsbCloudWebApi.SignalR.ConnectionManager;
using Microsoft.AspNetCore.Authorization;
namespace AsbCloudWebApi.SignalR;
[Authorize]
public class NotificationHub : BaseHub
{
private readonly IConnectionManager connectionManager;
private readonly INotificationService notificationService;
public NotificationHub(IConnectionManager connectionManager,
INotificationService notificationService)
{
this.connectionManager = connectionManager;
this.notificationService = notificationService;
}
public async Task OnConnected(int idUser)
{
try
{
string connectionId = Context.ConnectionId;
connectionManager.AddConnection(idUser, connectionId);
await notificationService.ResendNotificationAsync(idUser,
NotificationTransport.SignalR,
CancellationToken.None);
await base.OnConnectedAsync();
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
public Task OnDisconnected(int idUser)
{
connectionManager.RemoveConnection(idUser);
return base.OnDisconnectedAsync(null);
}
}