From f6bcd29ea00f3c26010f03e4a3ad289092fa7358 Mon Sep 17 00:00:00 2001 From: Flaminel Date: Wed, 28 May 2025 19:30:57 +0300 Subject: [PATCH] removed old hubs --- code/Executable/DependencyInjection/ApiDI.cs | 6 -- code/Infrastructure/Events/EventHub.cs | 57 ------------ code/Infrastructure/Events/EventPublisher.cs | 8 +- code/Infrastructure/Logging/LogHub.cs | 27 ------ code/Infrastructure/Logging/SignalRLogSink.cs | 9 +- .../app/core/services/event-hub.service.ts | 87 ------------------- .../src/app/core/services/log-hub.service.ts | 58 ------------- 7 files changed, 3 insertions(+), 249 deletions(-) delete mode 100644 code/Infrastructure/Events/EventHub.cs delete mode 100644 code/Infrastructure/Logging/LogHub.cs delete mode 100644 code/UI/src/app/core/services/event-hub.service.ts delete mode 100644 code/UI/src/app/core/services/log-hub.service.ts diff --git a/code/Executable/DependencyInjection/ApiDI.cs b/code/Executable/DependencyInjection/ApiDI.cs index e3df4dd9..0a008696 100644 --- a/code/Executable/DependencyInjection/ApiDI.cs +++ b/code/Executable/DependencyInjection/ApiDI.cs @@ -74,12 +74,6 @@ public static class ApiDI // Map SignalR hubs app.MapHub("/api/hubs/health"); - - // Legacy hubs (for backward compatibility) - app.MapHub("/api/hubs/logs"); - app.MapHub("/api/hubs/events"); - - // New unified hub app.MapHub("/api/hubs/app"); return app; diff --git a/code/Infrastructure/Events/EventHub.cs b/code/Infrastructure/Events/EventHub.cs deleted file mode 100644 index 752edb31..00000000 --- a/code/Infrastructure/Events/EventHub.cs +++ /dev/null @@ -1,57 +0,0 @@ -using Data; -using Microsoft.AspNetCore.SignalR; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Logging; - -namespace Infrastructure.Events; - -/// -/// SignalR hub for real-time event delivery -/// -public class EventHub : Hub -{ - private readonly DataContext _context; - private readonly ILogger _logger; - - public EventHub(DataContext context, ILogger logger) - { - _context = context; - _logger = logger; - } - - /// - /// Client requests recent events (for initial load) - /// - public async Task GetRecentEvents(int count = 50) - { - try - { - var events = await _context.Events - .OrderByDescending(e => e.Timestamp) - .Take(Math.Min(count, 100)) // Cap at 100 - .ToListAsync(); - - await Clients.Caller.SendAsync("RecentEventsReceived", events); - } - catch (Exception ex) - { - _logger.LogError(ex, "Failed to send recent events to client {connectionId}", Context.ConnectionId); - } - } - - /// - /// Client connection established - /// - public override async Task OnConnectedAsync() - { - await base.OnConnectedAsync(); - } - - /// - /// Client disconnected - /// - public override async Task OnDisconnectedAsync(Exception? exception) - { - await base.OnDisconnectedAsync(exception); - } -} \ No newline at end of file diff --git a/code/Infrastructure/Events/EventPublisher.cs b/code/Infrastructure/Events/EventPublisher.cs index 221985b6..f58f228d 100644 --- a/code/Infrastructure/Events/EventPublisher.cs +++ b/code/Infrastructure/Events/EventPublisher.cs @@ -18,7 +18,6 @@ namespace Infrastructure.Events; public class EventPublisher { private readonly DataContext _context; - private readonly IHubContext _eventHubContext; private readonly IHubContext _appHubContext; private readonly ILogger _logger; private readonly INotificationPublisher _notificationPublisher; @@ -26,14 +25,12 @@ public class EventPublisher public EventPublisher( DataContext context, - IHubContext eventHubContext, IHubContext appHubContext, ILogger logger, INotificationPublisher notificationPublisher, IDryRunInterceptor dryRunInterceptor) { _context = context; - _eventHubContext = eventHubContext; _appHubContext = appHubContext; _logger = logger; _notificationPublisher = notificationPublisher; @@ -160,10 +157,7 @@ public class EventPublisher { try { - // Send to all connected clients via the legacy EventHub - await _eventHubContext.Clients.All.SendAsync("EventReceived", appEventEntity); - - // Send to all connected clients via the new unified AppHub + // Send to all connected clients via the unified AppHub await _appHubContext.Clients.All.SendAsync("EventReceived", appEventEntity); } catch (Exception ex) diff --git a/code/Infrastructure/Logging/LogHub.cs b/code/Infrastructure/Logging/LogHub.cs deleted file mode 100644 index c0aba30f..00000000 --- a/code/Infrastructure/Logging/LogHub.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Microsoft.AspNetCore.SignalR; - -namespace Infrastructure.Logging; - -/// -/// SignalR hub for streaming log messages to connected clients -/// -public class LogHub : Hub -{ - private readonly SignalRLogSink _logSink; - - public LogHub(SignalRLogSink logSink) - { - _logSink = logSink; - } - - /// - /// Allows a client to request all recent logs from the buffer - /// - public async Task RequestRecentLogs() - { - foreach (var logEvent in _logSink.GetRecentLogs()) - { - await Clients.Caller.SendAsync("ReceiveLog", logEvent); - } - } -} diff --git a/code/Infrastructure/Logging/SignalRLogSink.cs b/code/Infrastructure/Logging/SignalRLogSink.cs index 2a0bd7e1..b728670b 100644 --- a/code/Infrastructure/Logging/SignalRLogSink.cs +++ b/code/Infrastructure/Logging/SignalRLogSink.cs @@ -17,13 +17,11 @@ public class SignalRLogSink : ILogEventSink private readonly ILogger _logger; private readonly ConcurrentQueue _logBuffer; private readonly int _bufferSize; - private readonly IHubContext _logHubContext; private readonly IHubContext _appHubContext; private readonly MessageTemplateTextFormatter _formatter = new("{Message:l}", CultureInfo.InvariantCulture); - public SignalRLogSink(ILogger logger, IHubContext logHubContext, IHubContext appHubContext) + public SignalRLogSink(ILogger logger, IHubContext appHubContext) { - _logHubContext = logHubContext; _appHubContext = appHubContext; _logger = logger; _bufferSize = 100; @@ -53,10 +51,7 @@ public class SignalRLogSink : ILogEventSink // Add to buffer for new clients AddToBuffer(logData); - // Send to connected clients (legacy hub) - _ = _logHubContext.Clients.All.SendAsync("ReceiveLog", logData); - - // Send to connected clients (new unified hub) + // Send to connected clients via the unified hub _ = _appHubContext.Clients.All.SendAsync("LogReceived", logData); } catch (Exception ex) diff --git a/code/UI/src/app/core/services/event-hub.service.ts b/code/UI/src/app/core/services/event-hub.service.ts deleted file mode 100644 index ca2a9e2f..00000000 --- a/code/UI/src/app/core/services/event-hub.service.ts +++ /dev/null @@ -1,87 +0,0 @@ -import { Injectable } from '@angular/core'; -import { BaseSignalRService } from './base-signalr.service'; -import { AppEvent } from '../models/event.models'; -import { SignalRHubConfig } from '../models/signalr.models'; -import { environment } from '../../../environments/environment'; -import * as signalR from '@microsoft/signalr'; - -/** - * Service for connecting to the events SignalR hub - */ -@Injectable({ - providedIn: 'root' -}) -export class EventHubService extends BaseSignalRService { - constructor() { - // Configuration for the events hub - const config: SignalRHubConfig = { - hubUrl: `${environment.apiUrl}/api/hubs/events`, - maxReconnectAttempts: 0, // Infinite reconnection attempts for self-hosted - reconnectDelayMs: 2000, - bufferSize: 1000, // Keep more events in buffer - healthCheckIntervalMs: 30000 // Check connection every 30 seconds - }; - - super(config, 'EventReceived'); - } - - /** - * Override to handle both EventReceived and RecentEventsReceived events - */ - protected override registerSignalREvents(): void { - // Call base implementation for standard connection events - super.registerSignalREvents(); - - // Handle recent events response (bulk load) - this.hubConnection.on('RecentEventsReceived', (events: AppEvent[]) => { - this.messageSubject.next(events); - console.log(`Received ${events.length} recent events`); - }); - } - - /** - * Request recent events from the server - */ - public requestRecentEvents(count: number = 100): void { - if (this.hubConnection && - this.hubConnection.state === signalR.HubConnectionState.Connected) { - this.hubConnection.invoke('GetRecentEvents', count) - .catch(err => console.error('Error while requesting recent events:', err)); - } - } - - /** - * Override to request recent events when connection is established - */ - protected override onConnectionEstablished(): void { - this.requestRecentEvents(); - } - - /** - * Get the buffered events - */ - public getBufferedEvents(): AppEvent[] { - return this.getBufferedMessages(); - } - - /** - * Get events as an observable - */ - public getEvents() { - return this.getMessages(); - } - - /** - * Get new events as an observable - */ - public getNewEvents() { - return this.getMessages(); - } - - /** - * Clear current events - */ - public clearEvents(): void { - this.messageSubject.next([]); - } -} \ No newline at end of file diff --git a/code/UI/src/app/core/services/log-hub.service.ts b/code/UI/src/app/core/services/log-hub.service.ts deleted file mode 100644 index 7b8634a6..00000000 --- a/code/UI/src/app/core/services/log-hub.service.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { Injectable, inject } from '@angular/core'; -import { BaseSignalRService } from './base-signalr.service'; -import { LogEntry, SignalRHubConfig } from '../models/signalr.models'; -import { environment } from '../../../environments/environment'; -import * as signalR from '@microsoft/signalr'; - -/** - * Service for connecting to the logs SignalR hub - */ -@Injectable({ - providedIn: 'root' -}) -export class LogHubService extends BaseSignalRService { - constructor() { - // Default configuration for the logs hub - const config: SignalRHubConfig = { - hubUrl: `${environment.apiUrl}/api/hubs/logs`, - maxReconnectAttempts: 0, // Infinite reconnection attempts - reconnectDelayMs: 2000, - bufferSize: 100, - healthCheckIntervalMs: 30000 // Check connection every 30 seconds - }; - - super(config, 'ReceiveLog'); - } - - /** - * Request recent logs from the server - */ - public requestRecentLogs(): void { - if (this.hubConnection && - this.hubConnection.state === signalR.HubConnectionState.Connected) { - this.hubConnection.invoke('RequestRecentLogs') - .catch(err => console.error('Error while requesting recent logs:', err)); - } - } - - /** - * Override to request recent logs when connection is established - */ - protected override onConnectionEstablished(): void { - this.requestRecentLogs(); - } - - /** - * Get the buffered logs - */ - public getBufferedLogs(): LogEntry[] { - return this.getBufferedMessages(); - } - - /** - * Get logs as an observable - */ - public getLogs() { - return this.getMessages(); - } -}