@page "/Services" @using LibSystemdCli.Models @using System.Text.RegularExpressions @using SystemdCtl.Client.Abstractions @* @attribute [StreamRendering] *@ @rendermode InteractiveWebAssembly @inject NavigationManager NavigationManager Services

Services

@foreach (var i in UnitTypes) { } @if (filteredItems is not { Count: > 0 }) {

Loading...

} else { @foreach (var unit in filteredItems) { @foreach (var frag in unit.FragmentPaths) { } }
Service Description Status
@unit.Unit @unit.Description @unit.Active Manage
@frag
} @code { private static Regex[] AlwaysHidden = new Regex[] { //services new Regex(@"^systemd-fsck@.*\.service$"), new Regex(@"^modprobe@.*\.service$"), new Regex(@"^xen.*\.service$"), new Regex(@"^virt.*\.service$"), new Regex(@"^libvirt.*\.service$"), new Regex(@"^systemd-.*\.service$"), //sockets new Regex(@"^virt.*\.socket$"), new Regex(@"^systemd.*\.socket$"), new Regex(@"^libvirt.*\.socket$"), //device new(@"^dev-disk-by.*\.device$"), new(@"^sys-device.*\.device$"), new(@".*-by\\x2d.*\.device$"), //mount new(@"^run-credentials.*\.mount"), //target new(@"^blockdev@dev-disk-by.*\.target$") }; private static bool IsClient => !Environment.CommandLine.Contains("/"); private List? items = new(); private List? filteredItems = new(); private List UnitTypes = new(); private string _typeFilter = ""; private bool _showSystem; public string TypeFilter { get => _typeFilter; set { _typeFilter = value; FilterItems(); } } public bool ShowSystem { get => _showSystem; set { _showSystem = value; FilterItems(); } } protected override async Task OnInitializedAsync() { // await Task.Delay(500); // items = await SystemdExecutor.GetUnits(); Console.WriteLine("OnInitializedAsync"); await ReloadItems(); } private async Task ReloadItems() { if (!IsClient) return; items.Clear(); var Http = new StreamingHttpClient() { BaseAddress = new Uri(NavigationManager.BaseUri) }; var _items = Http.GetAsyncEnumerableFromJsonAsync("/api/listUnits"); await foreach (var item in _items) { items.Add(item); if (items.Count % 10 == 0) await FilterItems(); } await FilterItems(); } private async Task FilterItems() { var filter = items.Where(x => true);//!AlwaysHidden.Any(y => y.IsMatch(x.Unit))); if (!_showSystem) filter = filter.Where(x => !x.IsSystem); UnitTypes = filter.Select(x => x.UnitType).Distinct().ToList(); filter = filter.Where(x => x.Unit.EndsWith(TypeFilter)).ToList(); filteredItems = filter.ToList(); StateHasChanged(); } private string Capitalize(string input) { return input switch { null => throw new ArgumentNullException(nameof(input)), "" => throw new ArgumentException($"{nameof(input)} cannot be empty", nameof(input)), _ => input.First().ToString().ToUpper() + input[1..] }; } }