forked from ddrilling/AsbCloudServer
1. Обновил классы модели и dto уведомления. 2. Удалил лишние сервисы. 3. Накатил новую миграцию. 4. Поправил репозиторий. 5. Поправил сервис уведомлений.
50 lines
1.1 KiB
C#
50 lines
1.1 KiB
C#
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using AsbCloudApp.Requests;
|
|
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, NotificationRequest request)
|
|
{
|
|
try
|
|
{
|
|
string connectionId = Context.ConnectionId;
|
|
|
|
connectionManager.AddConnection(idUser, connectionId);
|
|
|
|
await notificationService.ResendNotificationAsync(idUser,
|
|
request,
|
|
CancellationToken.None);
|
|
|
|
await base.OnConnectedAsync();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
}
|
|
}
|
|
|
|
public Task OnDisconnected(int idUser)
|
|
{
|
|
connectionManager.RemoveConnection(idUser);
|
|
|
|
return base.OnDisconnectedAsync(null);
|
|
}
|
|
} |