39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
using Manager.App.Extensions;
|
|
using Manager.App.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace Manager.App.Components.Pages;
|
|
|
|
public partial class Services : ComponentBase
|
|
{
|
|
private string _searchText = "";
|
|
private List<ExtendedBackgroundService> _backgroundServices = [];
|
|
private readonly CancellationTokenSource _cts = new();
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
_backgroundServices = ServiceRegistry.GetServices();
|
|
}
|
|
|
|
private Func<ExtendedBackgroundService, bool> QuickFilter
|
|
=> x => string.IsNullOrWhiteSpace(_searchText) || $"{x.Name} {x.Description} {x.State} {x.ExecuteInterval}".Contains(_searchText);
|
|
|
|
private IAsyncEnumerable<ServiceEvent> GetEventAsyncEnumerable()
|
|
{
|
|
var asyncEnumerators = _backgroundServices.Select(x => x.ProgressEvents.GetStreamAsync());
|
|
return AsyncEnumerableExtensions.Merge(asyncEnumerators, CancellationToken.None);
|
|
}
|
|
|
|
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();
|
|
_cts.Dispose();
|
|
}
|
|
} |