LANCommander/LANCommander.Server/UI/Components/ServerProcessMonitor.razor

36 lines
No EOL
1.1 KiB
Text

@using LANCommander.Server.Services.Enums
@inject ServerProcessService ServerProcessService
@inject NotificationService NotificationService
<CascadingValue Value="CurrentServerStatus">
@ChildContent
</CascadingValue>
@code {
[Parameter] public RenderFragment ChildContent { get; set; }
Dictionary<Guid, ServerProcessStatus> CurrentServerStatus = new();
protected override async Task OnInitializedAsync()
{
ServerProcessService.OnStatusUpdate += ServerProcessServiceOnOnStatusUpdate;
}
private void ServerProcessServiceOnOnStatusUpdate(object? sender, ServerStatusUpdateEventArgs e)
{
if (!CurrentServerStatus.ContainsKey(e.Server.Id))
CurrentServerStatus[e.Server.Id] = e.Status;
else if (CurrentServerStatus[e.Server.Id] != e.Status)
CurrentServerStatus[e.Server.Id] = e.Status;
if (e.Status == ServerProcessStatus.Error)
{
NotificationService.Error(new NotificationConfig
{
Message = $"Error starting server {e.Server.Name}",
Description = e.Exception.Message,
});
}
}
}