Skip to content

Commit b715002

Browse files
Wire up hubservice status reporting back to UI
1 parent 4e10eb3 commit b715002

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

src/Certify.Server/Certify.Server.Hub.Api/SignalR/UserInterfaceStatusHub.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ public class UserInterfaceStatusHubReporting : IStatusReporting
1212
{
1313
private IHubContext<UserInterfaceStatusHub> _hubContext;
1414

15+
/// <summary>
16+
/// Event raised when a progress update is available
17+
/// </summary>
18+
public event Action<RequestProgressState>? OnRequestProgressStateUpdated;
19+
20+
/// <summary>
21+
/// Event raised when a managed certificate has been updated
22+
/// </summary>
23+
public event Action<ManagedCertificate>? OnManagedCertificateUpdated;
24+
1525
/// <summary>
1626
/// constructor
1727
/// </summary>
@@ -29,6 +39,11 @@ public UserInterfaceStatusHubReporting(IHubContext<UserInterfaceStatusHub> hubCo
2939
public async Task ReportRequestProgress(RequestProgressState state)
3040
{
3141
Debug.WriteLine($"Sending progress update message to UI: {state.Message}");
42+
if (OnRequestProgressStateUpdated != null)
43+
{
44+
OnRequestProgressStateUpdated.Invoke(state);
45+
}
46+
3247
await _hubContext.Clients.All.SendAsync(StatusHubMessages.SendProgressStateMsg, state);
3348

3449
}
@@ -41,6 +56,12 @@ public async Task ReportRequestProgress(RequestProgressState state)
4156
public async Task ReportManagedCertificateUpdated(ManagedCertificate item)
4257
{
4358
Debug.WriteLine($"Sending updated managed cert message to UI: {item.Name}");
59+
60+
if (OnManagedCertificateUpdated != null)
61+
{
62+
OnManagedCertificateUpdated.Invoke(item);
63+
}
64+
4465
await _hubContext.Clients.All.SendAsync(StatusHubMessages.SendManagedCertificateUpdateMsg, item);
4566
}
4667
}

src/Certify.Server/Certify.Server.HubService/Program.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Certify.Client;
1+
using Certify.Client;
22
using Certify.Management;
33
using Certify.Models;
44
using Certify.Server.Hub.Api.Middleware;
@@ -132,10 +132,26 @@
132132
var statusReporting = new UserInterfaceStatusHubReporting(statusHubContext);
133133

134134
// wire up internal service to our hub
135+
var managementServerClient = app.Services.GetService<DirectManagementServerClient>();
135136

136137
var certifyManager = app.Services.GetRequiredService<ICertifyManager>();
137138
await certifyManager.Init();
138139

140+
// wire up status reporting, include management hub cached state ahndlers for request progress state updates and item updates
141+
certifyManager.SetStatusReporting(statusReporting);
142+
143+
statusReporting.OnRequestProgressStateUpdated += (RequestProgressState state) =>
144+
{
145+
146+
};
147+
148+
statusReporting.OnManagedCertificateUpdated += (ManagedCertificate item) =>
149+
{
150+
var mgmtHubState = app.Services.GetRequiredService<IInstanceManagementStateProvider>();
151+
mgmtHubState.UpdateCachedManagedInstanceItem(item.InstanceId, item);
152+
153+
};
154+
139155
var directServerClient = app.Services.GetRequiredService<IManagementServerClient>();
140156
certifyManager.SetDirectManagementClient(directServerClient);
141157

src/Certify.Server/Certify.Server.HubService/Services/DirectManagementServerClient.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,18 @@ void IManagementServerClient.SendInstanceInfo(Guid commandId, bool isCommandResp
4747
}
4848
void IManagementServerClient.SendNotificationToManagementHub(string msgCommandType, object updateMsg)
4949
{
50-
System.Diagnostics.Debug.WriteLine("SendInstanceInfo");
50+
var result = new InstanceCommandResult
51+
{
52+
CommandId = Guid.NewGuid(),
53+
InstanceId = _instanceInfo.InstanceId,
54+
CommandType = msgCommandType,
55+
Value = System.Text.Json.JsonSerializer.Serialize(updateMsg),
56+
ObjectValue = updateMsg,
57+
IsCommandResponse = false
58+
};
59+
60+
result.ObjectValue = updateMsg;
61+
_managementHub.ReceiveCommandResult(result);
5162

5263
}
5364
}

0 commit comments

Comments
 (0)