Refactored DashboardChangeNotifier and IDashboardChangeNotifier to use async notification with improved error handling and logging. Updated SqlDashboardStorage to call the new async notification method after dashboard changes, ensuring non-blocking and reliable client updates.
29 lines
760 B
C#
29 lines
760 B
C#
using DbFirst.API.Hubs;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
|
|
namespace DbFirst.API.Dashboards;
|
|
|
|
public class DashboardChangeNotifier : IDashboardChangeNotifier
|
|
{
|
|
private readonly IHubContext<DashboardsHub> _hubContext;
|
|
private readonly ILogger<DashboardChangeNotifier> _logger;
|
|
|
|
public DashboardChangeNotifier(IHubContext<DashboardsHub> hubContext, ILogger<DashboardChangeNotifier> logger)
|
|
{
|
|
_hubContext = hubContext;
|
|
_logger = logger;
|
|
}
|
|
|
|
public async Task NotifyChangedAsync()
|
|
{
|
|
try
|
|
{
|
|
await _hubContext.Clients.All.SendAsync("DashboardsChanged");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Failed to notify dashboard clients.");
|
|
}
|
|
}
|
|
}
|