Display status of the server process
This commit is contained in:
parent
4b48b4c45c
commit
c6997ccecc
3 changed files with 74 additions and 5 deletions
|
@ -20,16 +20,48 @@
|
||||||
<PropertyColumn Property="g => g.UpdatedBy" Sortable>
|
<PropertyColumn Property="g => g.UpdatedBy" Sortable>
|
||||||
@context.UpdatedBy?.UserName
|
@context.UpdatedBy?.UserName
|
||||||
</PropertyColumn>
|
</PropertyColumn>
|
||||||
|
<Column TData="string" Title="Status">
|
||||||
|
|
||||||
|
@switch (Status.GetValueOrDefault(context.Id))
|
||||||
|
{
|
||||||
|
case ServerProcessStatus.Running:
|
||||||
|
<Badge Status="success" Text="Running" />
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ServerProcessStatus.Starting:
|
||||||
|
<Badge Status="processing" Text="Starting" />
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ServerProcessStatus.Error:
|
||||||
|
<Badge Status="error" Text="Error" />
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ServerProcessStatus.Stopped:
|
||||||
|
default:
|
||||||
|
<Badge Status="default" Text="Stopped" />
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
</Column>
|
||||||
<ActionColumn Title="">
|
<ActionColumn Title="">
|
||||||
<Space Direction="DirectionVHType.Horizontal">
|
<Space Direction="DirectionVHType.Horizontal">
|
||||||
<SpaceItem>
|
<SpaceItem>
|
||||||
<Button OnClick="() => Edit(context)">Edit</Button>
|
<Button OnClick="() => Edit(context)">Edit</Button>
|
||||||
<Button OnClick="() => Logs(context)">Logs</Button>
|
<Button OnClick="() => Logs(context)">Logs</Button>
|
||||||
<Button OnClick="() => Start(context)">Start</Button>
|
|
||||||
<Button OnClick="() => Stop(context)">Stop</Button>
|
@if (Status.GetValueOrDefault(context.Id) != ServerProcessStatus.Running)
|
||||||
|
{
|
||||||
|
<Button Type="@ButtonType.Primary" OnClick="() => Start(context)">Start</Button>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (Status.GetValueOrDefault(context.Id) == ServerProcessStatus.Running)
|
||||||
|
{
|
||||||
|
<Popconfirm OnConfirm="() => Stop(context)" Title="Are you sure you want to kill this server process?">
|
||||||
|
<Button Danger Type="@ButtonType.Primary" OnClick="() => Stop(context)">Stop</Button>
|
||||||
|
</Popconfirm>
|
||||||
|
}
|
||||||
</SpaceItem>
|
</SpaceItem>
|
||||||
<SpaceItem>
|
<SpaceItem>
|
||||||
<Popconfirm OnConfirm="() => Delete(context)" Title="Are you sure you want to delete this game?">
|
<Popconfirm OnConfirm="() => Delete(context)" Title="Are you sure you want to delete this server?">
|
||||||
<Button Icon="@IconType.Outline.Close" Type="@ButtonType.Text" Danger />
|
<Button Icon="@IconType.Outline.Close" Type="@ButtonType.Text" Danger />
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
</SpaceItem>
|
</SpaceItem>
|
||||||
|
@ -41,6 +73,8 @@
|
||||||
IEnumerable<Server> Servers { get; set; } = new List<Server>();
|
IEnumerable<Server> Servers { get; set; } = new List<Server>();
|
||||||
|
|
||||||
bool Loading = true;
|
bool Loading = true;
|
||||||
|
Dictionary<Guid, ServerProcessStatus> Status = new Dictionary<Guid, ServerProcessStatus>();
|
||||||
|
Timer Timer;
|
||||||
|
|
||||||
protected override void OnAfterRender(bool firstRender)
|
protected override void OnAfterRender(bool firstRender)
|
||||||
{
|
{
|
||||||
|
@ -50,6 +84,16 @@
|
||||||
|
|
||||||
Loading = false;
|
Loading = false;
|
||||||
|
|
||||||
|
Timer = new Timer(async (object? stateInfo) =>
|
||||||
|
{
|
||||||
|
foreach (var server in Servers)
|
||||||
|
{
|
||||||
|
Status[server.Id] = ServerProcessService.GetStatus(server);
|
||||||
|
}
|
||||||
|
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
}, new AutoResetEvent(false), 1000, 1000);
|
||||||
|
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,8 +40,6 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
await HubConnection.StartAsync();
|
await HubConnection.StartAsync();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||||
|
|
|
@ -4,6 +4,14 @@ using System.Diagnostics;
|
||||||
|
|
||||||
namespace LANCommander.Services
|
namespace LANCommander.Services
|
||||||
{
|
{
|
||||||
|
public enum ServerProcessStatus
|
||||||
|
{
|
||||||
|
Stopped,
|
||||||
|
Starting,
|
||||||
|
Running,
|
||||||
|
Error
|
||||||
|
}
|
||||||
|
|
||||||
public class ServerProcessService
|
public class ServerProcessService
|
||||||
{
|
{
|
||||||
private readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
private readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||||
|
@ -53,5 +61,24 @@ namespace LANCommander.Services
|
||||||
process.Kill();
|
process.Kill();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ServerProcessStatus GetStatus(Server server)
|
||||||
|
{
|
||||||
|
Process process = null;
|
||||||
|
|
||||||
|
if (Processes.ContainsKey(server.Id))
|
||||||
|
process = Processes[server.Id];
|
||||||
|
|
||||||
|
if (process == null || process.HasExited)
|
||||||
|
return ServerProcessStatus.Stopped;
|
||||||
|
|
||||||
|
if (!process.HasExited)
|
||||||
|
return ServerProcessStatus.Running;
|
||||||
|
|
||||||
|
if (process.ExitCode != 0)
|
||||||
|
return ServerProcessStatus.Error;
|
||||||
|
|
||||||
|
return ServerProcessStatus.Stopped;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue