[CHANGE] Reworked event console

This commit is contained in:
max
2025-09-10 18:19:36 +02:00
parent ef6ca0ee07
commit 9be6f5be89
16 changed files with 326 additions and 131 deletions

View File

@@ -1,4 +1,3 @@
using DotBased.Logging;
using Manager.App.Extensions;
using Manager.App.Services;
using Microsoft.AspNetCore.Components;
@@ -7,58 +6,31 @@ namespace Manager.App.Components.Pages;
public partial class Services : ComponentBase
{
private const int VisibleEventCapacity = 500;
private string _searchText = "";
private List<ExtendedBackgroundService> _backgroundServices = [];
private List<ServiceEvent> _serviceEvents = [];
private CancellationTokenSource _cts = new();
private readonly CancellationTokenSource _cts = new();
protected override void OnInitialized()
{
_backgroundServices = ServiceManager.GetServices();
_ = Task.Run(() => ReadEventStreamsAsync(_cts.Token));
_backgroundServices = ServiceRegistry.GetServices();
}
private Func<ExtendedBackgroundService, bool> QuickFilter
=> x => string.IsNullOrWhiteSpace(_searchText) || $"{x.Name} {x.Description} {x.State} {x.ExecuteInterval}".Contains(_searchText);
private async Task ReadEventStreamsAsync(CancellationToken token)
private IAsyncEnumerable<ServiceEvent> GetEventAsyncEnumerable()
{
if (_backgroundServices.Count == 0)
{
return;
}
var totalToGet = VisibleEventCapacity / _backgroundServices.Count;
_serviceEvents.AddRange(_backgroundServices.SelectMany(x => x.ProgressEvents.Items.TakeLast(totalToGet)));
var asyncEnumerators = _backgroundServices.Select(x => x.ProgressEvents.GetStreamAsync());
await foreach (var serviceEvent in AsyncEnumerableExtensions.Merge(asyncEnumerators, token))
{
if (!_serviceEvents.Contains(serviceEvent))
{
_serviceEvents.Add(serviceEvent);
}
if (_serviceEvents.Count > VisibleEventCapacity)
{
_serviceEvents.RemoveAt(0);
}
await InvokeAsync(StateHasChanged);
}
return AsyncEnumerableExtensions.Merge(asyncEnumerators, CancellationToken.None);
}
private string GetLogClass(ServiceEvent serviceEvent) =>
serviceEvent.Severity switch
{
LogSeverity.Info => "log-info",
LogSeverity.Warning => "log-warning",
LogSeverity.Error => "log-error",
_ => "log-info"
};
private List<ServiceEvent> GetInitialEvents()
{
var totalToGet = 1000 / _backgroundServices.Count;
var initial = _backgroundServices.SelectMany(x => x.ProgressEvents.Items.TakeLast(totalToGet));
return initial.ToList();
}
public void Dispose()
{
_cts.Cancel();