30 lines
1.0 KiB
C#
30 lines
1.0 KiB
C#
using Marco.Pms.Services.Hubs;
|
|
using Marco.Pms.Services.Service.ServiceInterfaces;
|
|
using MarcoBMS.Services.Service;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
|
|
namespace Marco.Pms.Services.Service
|
|
{
|
|
public class SignalRService : ISignalRService
|
|
{
|
|
private readonly IHubContext<MarcoHub> _signalR;
|
|
private readonly ILoggingService _logger;
|
|
public SignalRService(IHubContext<MarcoHub> signalR, ILoggingService logger)
|
|
{
|
|
_signalR = signalR ?? throw new ArgumentNullException(nameof(signalR));
|
|
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
|
}
|
|
public async Task SendNotificationAsync(object notification)
|
|
{
|
|
try
|
|
{
|
|
await _signalR.Clients.All.SendAsync("NotificationEventHandler", notification);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Exception occured during sending notification through signalR");
|
|
}
|
|
}
|
|
}
|
|
}
|