Add real-time dashboard updates with SignalR
Integrate SignalR to provide real-time dashboard update notifications. - Added DashboardsHub and DashboardChangeNotifier on the backend. - Modified SqlDashboardStorage to trigger notifications on changes. - Registered SignalR services and mapped the hub endpoint. - Updated Blazor clients to connect to the hub and refresh dashboards on change. - Added SignalR client packages and necessary DI/configuration.
This commit is contained in:
19
DbFirst.API/Dashboards/DashboardChangeNotifier.cs
Normal file
19
DbFirst.API/Dashboards/DashboardChangeNotifier.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using DbFirst.API.Hubs;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace DbFirst.API.Dashboards;
|
||||
|
||||
public class DashboardChangeNotifier : IDashboardChangeNotifier
|
||||
{
|
||||
private readonly IHubContext<DashboardsHub> _hubContext;
|
||||
|
||||
public DashboardChangeNotifier(IHubContext<DashboardsHub> hubContext)
|
||||
{
|
||||
_hubContext = hubContext;
|
||||
}
|
||||
|
||||
public void NotifyChanged()
|
||||
{
|
||||
_ = _hubContext.Clients.All.SendAsync("DashboardsChanged");
|
||||
}
|
||||
}
|
||||
6
DbFirst.API/Dashboards/IDashboardChangeNotifier.cs
Normal file
6
DbFirst.API/Dashboards/IDashboardChangeNotifier.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace DbFirst.API.Dashboards;
|
||||
|
||||
public interface IDashboardChangeNotifier
|
||||
{
|
||||
void NotifyChanged();
|
||||
}
|
||||
@@ -11,12 +11,14 @@ public sealed class SqlDashboardStorage : IEditableDashboardStorage
|
||||
private readonly string _connectionString;
|
||||
private readonly string _tableName;
|
||||
private readonly Func<string?>? _userProvider;
|
||||
private readonly IDashboardChangeNotifier? _notifier;
|
||||
|
||||
public SqlDashboardStorage(string connectionString, string tableName = "TBDD_SMF_CONFIG", Func<string?>? userProvider = null)
|
||||
public SqlDashboardStorage(string connectionString, string tableName = "TBDD_SMF_CONFIG", Func<string?>? userProvider = null, IDashboardChangeNotifier? notifier = null)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_tableName = tableName;
|
||||
_userProvider = userProvider;
|
||||
_notifier = notifier;
|
||||
}
|
||||
|
||||
public IEnumerable<DashboardInfo> GetAvailableDashboardsInfo()
|
||||
@@ -98,6 +100,7 @@ public sealed class SqlDashboardStorage : IEditableDashboardStorage
|
||||
|
||||
connection.Open();
|
||||
command.ExecuteNonQuery();
|
||||
_notifier?.NotifyChanged();
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -118,6 +121,8 @@ public sealed class SqlDashboardStorage : IEditableDashboardStorage
|
||||
{
|
||||
throw new ArgumentException($"Dashboard '{dashboardId}' not found.");
|
||||
}
|
||||
|
||||
_notifier?.NotifyChanged();
|
||||
}
|
||||
|
||||
public void DeleteDashboard(string dashboardId)
|
||||
@@ -128,5 +133,6 @@ public sealed class SqlDashboardStorage : IEditableDashboardStorage
|
||||
|
||||
connection.Open();
|
||||
command.ExecuteNonQuery();
|
||||
_notifier?.NotifyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user