Re-implemented server state machine. Cleaned up code
TODO: Handle trigger errors
This commit is contained in:
52
MoonlightServers.Daemon/Abstractions/Server.cs
Normal file
52
MoonlightServers.Daemon/Abstractions/Server.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using Docker.DotNet.Models;
|
||||
using MoonlightServers.Daemon.Enums;
|
||||
using MoonlightServers.Daemon.Models;
|
||||
using MoonlightServers.Daemon.Models.Cache;
|
||||
using Stateless;
|
||||
|
||||
namespace MoonlightServers.Daemon.Abstractions;
|
||||
|
||||
public partial class Server
|
||||
{
|
||||
// Exposed configuration/state values
|
||||
public int Id => Configuration.Id;
|
||||
public ServerState State => StateMachine.State;
|
||||
|
||||
// Exposed container names and ids
|
||||
public string RuntimeContainerName { get; private set; }
|
||||
public string? RuntimeContainerId { get; private set; }
|
||||
|
||||
public string InstallationContainerName { get; private set; }
|
||||
public string? InstallationContainerId { get; private set; }
|
||||
|
||||
// Events
|
||||
public event Func<ServerState, Task> OnStateChanged;
|
||||
public event Func<string, Task> OnConsoleOutput;
|
||||
|
||||
// Private stuff
|
||||
|
||||
private readonly ILogger Logger;
|
||||
private readonly IServiceProvider ServiceProvider;
|
||||
private readonly ServerConsole Console;
|
||||
|
||||
private StateMachine<ServerState, ServerTrigger> StateMachine;
|
||||
private ServerConfiguration Configuration;
|
||||
private CancellationTokenSource Cancellation;
|
||||
|
||||
public Server(
|
||||
ILogger logger,
|
||||
IServiceProvider serviceProvider,
|
||||
ServerConfiguration configuration
|
||||
)
|
||||
{
|
||||
Logger = logger;
|
||||
ServiceProvider = serviceProvider;
|
||||
Configuration = configuration;
|
||||
|
||||
Console = new();
|
||||
Cancellation = new();
|
||||
|
||||
RuntimeContainerName = $"moonlight-runtime-{Configuration.Id}";
|
||||
InstallationContainerName = $"moonlight-install-{Configuration.Id}";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user