@inject ServerService ServerService @inject ServerProcessService ServerProcessService @inject IMessageService MessageService @inject INotificationService NotificationService @implements IAsyncDisposable @switch (Status) { case ServerProcessStatus.Running: break; case ServerProcessStatus.Starting: break; case ServerProcessStatus.Error: break; case ServerProcessStatus.Stopped: break; case ServerProcessStatus.Stopping: break; default: break; } @if (Status != ServerProcessStatus.Running) { } else { } @code { [Parameter] public Guid ServerId { get; set; } Server Server; Timer Timer; ServerProcessStatus Status = ServerProcessStatus.Retrieving; protected override async Task OnInitializedAsync() { Server = await ServerService.Get(ServerId); ServerProcessService.OnStatusUpdate += OnStatusUpdate; } protected override void OnAfterRender(bool firstRender) { if (firstRender) { Timer = new Timer(async (object? stateInfo) => { Status = ServerProcessService.GetStatus(Server); await InvokeAsync(StateHasChanged); }, new AutoResetEvent(false), 1000, 1000); } } private void OnStatusUpdate(object sender, ServerStatusUpdateEventArgs args) { if (args?.Server?.Id == ServerId) { Status = args.Status; if (Status == ServerProcessStatus.Error) { NotificationService.Error(new NotificationConfig { Message = $"Error starting server {args.Server.Name}", Description = args.Exception.Message, }); } } } private async Task Start() { await ServerProcessService.StartServerAsync(Server.Id); } private void Stop() { ServerProcessService.StopServer(Server.Id); } public async ValueTask DisposeAsync() { if (Timer != null) await Timer.DisposeAsync(); } }