2023-07-12 13:31:55 +05:00
|
|
|
using System;
|
2023-07-10 16:59:11 +05:00
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2023-07-13 14:44:40 +05:00
|
|
|
using AsbCloudApp.Requests;
|
2023-07-11 19:07:57 +05:00
|
|
|
using AsbCloudApp.Services.Notifications;
|
2023-07-10 16:59:11 +05:00
|
|
|
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,
|
2023-07-11 19:07:57 +05:00
|
|
|
INotificationService notificationService)
|
2023-07-10 16:59:11 +05:00
|
|
|
{
|
|
|
|
this.connectionManager = connectionManager;
|
|
|
|
this.notificationService = notificationService;
|
|
|
|
}
|
|
|
|
|
2023-07-13 14:44:40 +05:00
|
|
|
public async Task OnConnected(int idUser, NotificationRequest request)
|
2023-07-10 16:59:11 +05:00
|
|
|
{
|
2023-07-12 13:31:55 +05:00
|
|
|
try
|
|
|
|
{
|
|
|
|
string connectionId = Context.ConnectionId;
|
2023-07-10 16:59:11 +05:00
|
|
|
|
2023-07-12 13:31:55 +05:00
|
|
|
connectionManager.AddConnection(idUser, connectionId);
|
2023-07-10 16:59:11 +05:00
|
|
|
|
2023-07-12 13:31:55 +05:00
|
|
|
await notificationService.ResendNotificationAsync(idUser,
|
2023-07-13 14:44:40 +05:00
|
|
|
request,
|
2023-07-12 13:31:55 +05:00
|
|
|
CancellationToken.None);
|
2023-07-10 16:59:11 +05:00
|
|
|
|
2023-07-12 13:31:55 +05:00
|
|
|
await base.OnConnectedAsync();
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Console.WriteLine(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Task OnDisconnected(int idUser)
|
|
|
|
{
|
|
|
|
connectionManager.RemoveConnection(idUser);
|
|
|
|
|
|
|
|
return base.OnDisconnectedAsync(null);
|
2023-07-10 16:59:11 +05:00
|
|
|
}
|
|
|
|
}
|