mirror of
https://github.com/Cleanuparr/Cleanuparr.git
synced 2026-06-12 15:56:29 -04:00
removed old hubs
This commit is contained in:
@@ -74,12 +74,6 @@ public static class ApiDI
|
||||
|
||||
// Map SignalR hubs
|
||||
app.MapHub<HealthStatusHub>("/api/hubs/health");
|
||||
|
||||
// Legacy hubs (for backward compatibility)
|
||||
app.MapHub<LogHub>("/api/hubs/logs");
|
||||
app.MapHub<EventHub>("/api/hubs/events");
|
||||
|
||||
// New unified hub
|
||||
app.MapHub<AppHub>("/api/hubs/app");
|
||||
|
||||
return app;
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
using Data;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Infrastructure.Events;
|
||||
|
||||
/// <summary>
|
||||
/// SignalR hub for real-time event delivery
|
||||
/// </summary>
|
||||
public class EventHub : Hub
|
||||
{
|
||||
private readonly DataContext _context;
|
||||
private readonly ILogger<EventHub> _logger;
|
||||
|
||||
public EventHub(DataContext context, ILogger<EventHub> logger)
|
||||
{
|
||||
_context = context;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Client requests recent events (for initial load)
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Client connection established
|
||||
/// </summary>
|
||||
public override async Task OnConnectedAsync()
|
||||
{
|
||||
await base.OnConnectedAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Client disconnected
|
||||
/// </summary>
|
||||
public override async Task OnDisconnectedAsync(Exception? exception)
|
||||
{
|
||||
await base.OnDisconnectedAsync(exception);
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@ namespace Infrastructure.Events;
|
||||
public class EventPublisher
|
||||
{
|
||||
private readonly DataContext _context;
|
||||
private readonly IHubContext<EventHub> _eventHubContext;
|
||||
private readonly IHubContext<AppHub> _appHubContext;
|
||||
private readonly ILogger<EventPublisher> _logger;
|
||||
private readonly INotificationPublisher _notificationPublisher;
|
||||
@@ -26,14 +25,12 @@ public class EventPublisher
|
||||
|
||||
public EventPublisher(
|
||||
DataContext context,
|
||||
IHubContext<EventHub> eventHubContext,
|
||||
IHubContext<AppHub> appHubContext,
|
||||
ILogger<EventPublisher> 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)
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace Infrastructure.Logging;
|
||||
|
||||
/// <summary>
|
||||
/// SignalR hub for streaming log messages to connected clients
|
||||
/// </summary>
|
||||
public class LogHub : Hub
|
||||
{
|
||||
private readonly SignalRLogSink _logSink;
|
||||
|
||||
public LogHub(SignalRLogSink logSink)
|
||||
{
|
||||
_logSink = logSink;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows a client to request all recent logs from the buffer
|
||||
/// </summary>
|
||||
public async Task RequestRecentLogs()
|
||||
{
|
||||
foreach (var logEvent in _logSink.GetRecentLogs())
|
||||
{
|
||||
await Clients.Caller.SendAsync("ReceiveLog", logEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,13 +17,11 @@ public class SignalRLogSink : ILogEventSink
|
||||
private readonly ILogger<SignalRLogSink> _logger;
|
||||
private readonly ConcurrentQueue<object> _logBuffer;
|
||||
private readonly int _bufferSize;
|
||||
private readonly IHubContext<LogHub> _logHubContext;
|
||||
private readonly IHubContext<AppHub> _appHubContext;
|
||||
private readonly MessageTemplateTextFormatter _formatter = new("{Message:l}", CultureInfo.InvariantCulture);
|
||||
|
||||
public SignalRLogSink(ILogger<SignalRLogSink> logger, IHubContext<LogHub> logHubContext, IHubContext<AppHub> appHubContext)
|
||||
public SignalRLogSink(ILogger<SignalRLogSink> logger, IHubContext<AppHub> 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)
|
||||
|
||||
@@ -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<AppEvent> {
|
||||
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([]);
|
||||
}
|
||||
}
|
||||
@@ -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<LogEntry> {
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user