Updated to latest moonlight and mooncore version. Done refactoring to async scheme and other changes. Recreated database migrations and cleaned models

This commit is contained in:
2025-09-22 12:13:57 +02:00
parent 91fb15a03e
commit 85392208c4
150 changed files with 2722 additions and 2726 deletions

View File

@@ -1,5 +1,3 @@
using MoonCore.Helpers;
namespace MoonlightServers.Daemon.Configuration;
public class AppConfiguration

View File

@@ -23,8 +23,6 @@ public static class ServerConfigurationExtensions
Variables = response.Variables,
OnlineDetection = response.OnlineDetection,
DockerImage = response.DockerImage,
UseVirtualDisk = response.UseVirtualDisk,
Bandwidth = response.Bandwidth,
Cpu = response.Cpu,
Disk = response.Disk,
Memory = response.Memory,

View File

@@ -57,18 +57,18 @@ public class HostSystemHelper
#region CPU Usage
public async Task<CpuUsageDetails> GetCpuUsage()
public async Task<CpuUsageDetails> GetCpuUsageAsync()
{
var result = new CpuUsageDetails();
var perCoreUsages = new List<double>();
// Initial read
var (cpuLastStats, cpuLastSums) = await ReadAllCpuStats();
var (cpuLastStats, cpuLastSums) = await ReadAllCpuStatsAsync();
await Task.Delay(1000);
// Second read
var (cpuNowStats, cpuNowSums) = await ReadAllCpuStats();
var (cpuNowStats, cpuNowSums) = await ReadAllCpuStatsAsync();
for (var i = 0; i < cpuNowStats.Length; i++)
{
@@ -94,7 +94,7 @@ public class HostSystemHelper
return result;
}
private async Task<(long[][] cpuStatsList, long[] cpuSums)> ReadAllCpuStats()
private async Task<(long[][] cpuStatsList, long[] cpuSums)> ReadAllCpuStatsAsync()
{
var lines = await File.ReadAllLinesAsync("/proc/stat");
@@ -128,12 +128,12 @@ public class HostSystemHelper
#region Memory
public async Task ClearCachedMemory()
public async Task ClearCachedMemoryAsync()
{
await File.WriteAllTextAsync("/proc/sys/vm/drop_caches", "3");
}
public async Task<MemoryUsageDetails> GetMemoryUsage()
public async Task<MemoryUsageDetails> GetMemoryUsageAsync()
{
var details = new MemoryUsageDetails();
@@ -194,7 +194,7 @@ public class HostSystemHelper
#region Disks
public async Task<DiskUsageDetails[]> GetDiskUsages()
public async Task<DiskUsageDetails[]> GetDiskUsagesAsync()
{
var details = new List<DiskUsageDetails>();

View File

@@ -3,7 +3,6 @@ using ICSharpCode.SharpZipLib.GZip;
using ICSharpCode.SharpZipLib.Tar;
using ICSharpCode.SharpZipLib.Zip;
using Mono.Unix.Native;
using MoonCore.Unix.Exceptions;
using MoonCore.Unix.SecureFs;
using MoonlightServers.DaemonShared.DaemonSide.Http.Responses.Servers;
using MoonlightServers.DaemonShared.Enums;
@@ -19,7 +18,7 @@ public class ServerFileSystem
FileSystem = fileSystem;
}
public Task<ServerFileSystemResponse[]> List(string inputPath)
public Task<ServerFileSystemResponse[]> ListAsync(string inputPath)
{
var path = Normalize(inputPath);
var entries = FileSystem.ReadDir(path);
@@ -45,7 +44,7 @@ public class ServerFileSystem
return Task.FromResult(result);
}
public Task Move(string inputOldPath, string inputNewPath)
public Task MoveAsync(string inputOldPath, string inputNewPath)
{
var oldPath = Normalize(inputOldPath);
var newPath = Normalize(inputNewPath);
@@ -55,7 +54,7 @@ public class ServerFileSystem
return Task.CompletedTask;
}
public Task Delete(string inputPath)
public Task DeleteAsync(string inputPath)
{
var path = Normalize(inputPath);
@@ -64,7 +63,7 @@ public class ServerFileSystem
return Task.CompletedTask;
}
public Task Mkdir(string inputPath)
public Task MkdirAsync(string inputPath)
{
var path = Normalize(inputPath);
@@ -73,7 +72,7 @@ public class ServerFileSystem
return Task.CompletedTask;
}
public Task Touch(string inputPath)
public Task TouchAsync(string inputPath)
{
var path = Normalize(inputPath);
@@ -91,7 +90,7 @@ public class ServerFileSystem
return Task.CompletedTask;
}
public Task CreateChunk(string inputPath, long totalSize, long positionToSkip, Stream chunkStream)
public Task CreateChunkAsync(string inputPath, long totalSize, long positionToSkip, Stream chunkStream)
{
var path = Normalize(inputPath);
@@ -114,7 +113,7 @@ public class ServerFileSystem
return Task.CompletedTask;
}
public Task Create(string inputPath, Stream dataStream)
public Task CreateAsync(string inputPath, Stream dataStream)
{
var path = Normalize(inputPath);
@@ -134,7 +133,7 @@ public class ServerFileSystem
return Task.CompletedTask;
}
public Task Read(string inputPath, Func<Stream, Task> onHandle)
public Task ReadAsync(string inputPath, Func<Stream, Task> onHandle)
{
var path = Normalize(inputPath);
@@ -149,7 +148,7 @@ public class ServerFileSystem
#region Compression
public Task Compress(string[] itemsInput, string destinationInput, CompressType type)
public Task CompressAsync(string[] itemsInput, string destinationInput, CompressType type)
{
var destination = Normalize(destinationInput);
var items = itemsInput.Select(Normalize);
@@ -191,7 +190,7 @@ public class ServerFileSystem
return Task.CompletedTask;
}
public Task Decompress(string pathInput, string destinationInput, CompressType type)
public Task DecompressAsync(string pathInput, string destinationInput, CompressType type)
{
var path = Normalize(pathInput);
var destination = Normalize(destinationInput);

View File

@@ -17,7 +17,7 @@ public class UnsafeDockerClient
Configuration = configuration;
}
public Task<HttpClient> CreateHttpClient()
public Task<HttpClient> CreateHttpClientAsync()
{
var client = new HttpClient(new SocketsHttpHandler()
{
@@ -35,9 +35,9 @@ public class UnsafeDockerClient
return Task.FromResult(client);
}
public async Task<DataUsageResponse> GetDataUsage()
public async Task<DataUsageResponse> GetDataUsageAsync()
{
using var client = await CreateHttpClient();
using var client = await CreateHttpClientAsync();
var responseJson = await client.GetStringAsync("http://some.random.domain/v1.47/system/df");
var response = JsonSerializer.Deserialize<DataUsageResponse>(responseJson)!;

View File

@@ -16,7 +16,7 @@ public class PowerController : Controller
}
[HttpPost("start")]
public async Task<ActionResult> Start([FromRoute] int id)
public async Task<ActionResult> StartAsync([FromRoute] int id)
{
var server = ServerService.GetById(id);
@@ -31,7 +31,7 @@ public class PowerController : Controller
}
[HttpPost("stop")]
public async Task<ActionResult> Stop([FromRoute] int id)
public async Task<ActionResult> StopAsync([FromRoute] int id)
{
var server = ServerService.GetById(id);
@@ -46,7 +46,7 @@ public class PowerController : Controller
}
[HttpPost("kill")]
public async Task<ActionResult> Kill([FromRoute] int id)
public async Task<ActionResult> KillAsync([FromRoute] int id)
{
var server = ServerService.GetById(id);
@@ -61,7 +61,7 @@ public class PowerController : Controller
}
[HttpPost("install")]
public async Task<ActionResult> Install([FromRoute] int id)
public async Task<ActionResult> InstallAsync([FromRoute] int id)
{
var server = ServerService.GetById(id);

View File

@@ -3,7 +3,6 @@ using MoonlightServers.Daemon.Mappers;
using MoonlightServers.Daemon.Services;
using MoonlightServers.DaemonShared.DaemonSide.Http.Responses.Servers;
using MoonlightServers.DaemonShared.Enums;
using MoonlightServers.DaemonShared.PanelSide.Http.Responses;
namespace MoonlightServers.Daemon.Http.Controllers.Servers;
@@ -21,14 +20,14 @@ public class ServersController : Controller
}
[HttpPost("sync")]
public async Task<ActionResult> Sync([FromRoute] int id)
public async Task<ActionResult> SyncAsync([FromRoute] int id)
{
await ServerService.InitializeById(id);
await ServerService.InitializeByIdAsync(id);
return NoContent();
}
[HttpGet("status")]
public async Task<ActionResult<ServerStatusResponse>> Status([FromRoute] int id)
public async Task<ActionResult<ServerStatusResponse>> StatusAsync([FromRoute] int id)
{
var server = ServerService.GetById(id);
@@ -42,7 +41,7 @@ public class ServersController : Controller
}
[HttpGet("logs")]
public async Task<ActionResult<ServerLogsResponse>> Logs([FromRoute] int id)
public async Task<ActionResult<ServerLogsResponse>> LogsAsync([FromRoute] int id)
{
var server = ServerService.GetById(id);
@@ -58,7 +57,7 @@ public class ServersController : Controller
}
[HttpGet("stats")]
public async Task<ServerStatsResponse> GetStats([FromRoute] int id)
public async Task<ServerStatsResponse> GetStatsAsync([FromRoute] int id)
{
return new ServerStatsResponse()
{

View File

@@ -18,17 +18,17 @@ public class StatisticsController : Controller
}
[HttpGet]
public async Task<StatisticsResponse> Get()
public async Task<StatisticsResponse> GetAsync()
{
var response = new StatisticsResponse();
var cpuUsage = await HostSystemHelper.GetCpuUsage();
var cpuUsage = await HostSystemHelper.GetCpuUsageAsync();
response.Cpu.Model = cpuUsage.Model;
response.Cpu.Usage = cpuUsage.OverallUsage;
response.Cpu.UsagePerCore = cpuUsage.PerCoreUsage;
var memoryUsage = await HostSystemHelper.GetMemoryUsage();
var memoryUsage = await HostSystemHelper.GetMemoryUsageAsync();
response.Memory.Available = memoryUsage.Available;
response.Memory.Cached = memoryUsage.Cached;
@@ -37,7 +37,7 @@ public class StatisticsController : Controller
response.Memory.SwapTotal = memoryUsage.SwapTotal;
response.Memory.SwapFree = memoryUsage.SwapFree;
var diskDetails = await HostSystemHelper.GetDiskUsages();
var diskDetails = await HostSystemHelper.GetDiskUsagesAsync();
response.Disks = diskDetails.Select(x => new StatisticsResponse.DiskData()
{

View File

@@ -20,13 +20,13 @@ public class StatisticsDockerController : Controller
}
[HttpGet]
public async Task<StatisticsDockerResponse> Get()
public async Task<StatisticsDockerResponse> GetAsync()
{
var usage = await DockerInfoService.GetDataUsage();
var usage = await DockerInfoService.GetDataUsageAsync();
return new StatisticsDockerResponse
{
Version = await DockerInfoService.GetDockerVersion(),
Version = await DockerInfoService.GetDockerVersionAsync(),
ContainersReclaimable = usage.Containers.Reclaimable,
ContainersUsed = usage.Containers.Used,
BuildCacheReclaimable = usage.BuildCache.Reclaimable,

View File

@@ -18,7 +18,7 @@ public class SystemStatusController : Controller
RemoteService = remoteService;
}
public async Task<SystemStatusResponse> Get()
public async Task<SystemStatusResponse> GetAsync()
{
SystemStatusResponse response;
@@ -27,7 +27,7 @@ public class SystemStatusController : Controller
try
{
await RemoteService.GetStatus();
await RemoteService.GetStatusAsync();
sw.Stop();

View File

@@ -30,8 +30,6 @@ public class ServerConfigurationMapper
Variables = response.Variables,
OnlineDetection = response.OnlineDetection,
DockerImage = response.DockerImage,
UseVirtualDisk = response.UseVirtualDisk,
Bandwidth = response.Bandwidth,
Cpu = response.Cpu,
Disk = response.Disk,
Memory = response.Memory,

View File

@@ -8,8 +8,6 @@ public class ServerConfiguration
public int Cpu { get; set; }
public int Memory { get; set; }
public int Disk { get; set; }
public int Bandwidth { get; set; }
public bool UseVirtualDisk { get; set; }
// Start, Stop & Status
public string StartupCommand { get; set; }

View File

@@ -14,7 +14,7 @@ public class ServerConsole
MaxMessagesInCache = maxMessagesInCache;
}
public async Task WriteToOutput(string content)
public async Task WriteToOutputAsync(string content)
{
lock (MessageCache)
{
@@ -32,7 +32,7 @@ public class ServerConsole
}
}
public async Task WriteToInput(string content)
public async Task WriteToInputAsync(string content)
{
if (OnInput != null)
await OnInput.Invoke(content);

View File

@@ -8,9 +8,10 @@
<ItemGroup>
<PackageReference Include="Docker.DotNet" Version="3.125.15" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.9" />
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.2.0" />
<PackageReference Include="MoonCore" Version="1.9.7" />
<PackageReference Include="MoonCore.Extended" Version="1.3.7" />
<PackageReference Include="MoonCore" Version="2.0.1" />
<PackageReference Include="MoonCore.Extended" Version="1.4.0" />
<PackageReference Include="MoonCore.Unix" Version="1.0.8" />
<PackageReference Include="SharpZipLib" Version="1.4.2" />
<PackageReference Include="Stateless" Version="5.19.0" />

View File

@@ -2,4 +2,4 @@ using MoonlightServers.Daemon;
var startup = new Startup();
await startup.Run(args);
await startup.RunAsync(args);

View File

@@ -57,17 +57,17 @@ public class DockerConsole : IConsole
{
var containerName = string.Format(DockerConstants.RuntimeNameTemplate, Context.Configuration.Id);
await AttachToContainer(containerName);
await AttachToContainerAsync(containerName);
}
public async Task AttachInstallationAsync()
{
var containerName = string.Format(DockerConstants.InstallationNameTemplate, Context.Configuration.Id);
await AttachToContainer(containerName);
await AttachToContainerAsync(containerName);
}
private async Task AttachToContainer(string containerName)
private async Task AttachToContainerAsync(string containerName)
{
var cts = new CancellationTokenSource();
@@ -171,17 +171,17 @@ public class DockerConsole : IConsole
{
var containerName = string.Format(DockerConstants.RuntimeNameTemplate, Context.Configuration.Id);
await FetchFromContainer(containerName);
await FetchFromContainerAsync(containerName);
}
public async Task FetchInstallationAsync()
{
var containerName = string.Format(DockerConstants.InstallationNameTemplate, Context.Configuration.Id);
await FetchFromContainer(containerName);
await FetchFromContainerAsync(containerName);
}
private async Task FetchFromContainer(string containerName)
private async Task FetchFromContainerAsync(string containerName)
{
var logStream = await DockerClient.Containers.GetContainerLogsAsync(containerName, true, new()
{

View File

@@ -104,7 +104,7 @@ public class DockerInstallation : IInstallation
// Docker image
await Reporter.StatusAsync("Downloading docker image");
await ImageService.Download(data.DockerImage, async status => { await Reporter.StatusAsync(status); });
await ImageService.DownloadAsync(data.DockerImage, async status => { await Reporter.StatusAsync(status); });
await Reporter.StatusAsync("Downloaded docker image");
@@ -159,7 +159,7 @@ public class DockerInstallation : IInstallation
}
}
public async Task<IAsyncDisposable> SubscribeExited(Func<int, ValueTask> callback)
public async Task<IAsyncDisposable> SubscribeExitedAsync(Func<int, ValueTask> callback)
=> await ExitEventSource.SubscribeAsync(callback);
public async Task RestoreAsync()

View File

@@ -96,7 +96,7 @@ public class DockerRuntime : IRuntime
// Docker image
await Reporter.StatusAsync("Downloading docker image");
await ImageService.Download(
await ImageService.DownloadAsync(
Context.Configuration.DockerImage,
async status => { await Reporter.StatusAsync(status); }
);
@@ -152,7 +152,7 @@ public class DockerRuntime : IRuntime
}
}
public async Task<IAsyncDisposable> SubscribeExited(Func<int, ValueTask> callback)
public async Task<IAsyncDisposable> SubscribeExitedAsync(Func<int, ValueTask> callback)
=> await ExitEventSource.SubscribeAsync(callback);
public async Task RestoreAsync()

View File

@@ -80,7 +80,7 @@ public class InstallationHandler : IServerStateHandler
await Server.Installation.CreateAsync(runtimePath, installationPath, installData);
if (ExitSubscription == null)
ExitSubscription = await Server.Installation.SubscribeExited(OnInstallationExited);
ExitSubscription = await Server.Installation.SubscribeExitedAsync(OnInstallationExited);
// 6. Attach console

View File

@@ -58,7 +58,7 @@ public class StartupHandler : IServerStateHandler
await Server.Runtime.CreateAsync(hostPath);
if (ExitSubscription == null)
ExitSubscription = await Server.Runtime.SubscribeExited(OnRuntimeExited);
ExitSubscription = await Server.Runtime.SubscribeExitedAsync(OnRuntimeExited);
// 6. Attach console

View File

@@ -42,7 +42,7 @@ public interface IInstallation : IServerComponent
/// </summary>
/// <param name="callback">Callback to invoke whenever the installation exists</param>
/// <returns>Subscription disposable to unsubscribe from the event</returns>
public Task<IAsyncDisposable> SubscribeExited(Func<int, ValueTask> callback);
public Task<IAsyncDisposable> SubscribeExitedAsync(Func<int, ValueTask> callback);
/// <summary>
/// Connects an existing installation to this abstraction in order to restore it.

View File

@@ -44,7 +44,7 @@ public interface IRuntime : IServerComponent
/// </summary>
/// <param name="callback">Callback gets invoked whenever the runtime exites</param>
/// <returns>Subscription disposable to unsubscribe from the event</returns>
public Task<IAsyncDisposable> SubscribeExited(Func<int, ValueTask> callback);
public Task<IAsyncDisposable> SubscribeExitedAsync(Func<int, ValueTask> callback);
/// <summary>
/// Connects an existing runtime to this abstraction in order to restore it.

View File

@@ -1,5 +1,4 @@
using MoonlightServers.Daemon.Models.Cache;
using MoonlightServers.Daemon.ServerSystem.Interfaces;
namespace MoonlightServers.Daemon.ServerSystem.Models;

View File

@@ -1,4 +1,3 @@
using System.Collections;
using MoonlightServers.Daemon.ServerSystem.Enums;
using MoonlightServers.Daemon.ServerSystem.Interfaces;
using MoonlightServers.Daemon.ServerSystem.Models;

View File

@@ -1,11 +1,6 @@
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using Docker.DotNet;
using Docker.DotNet.Models;
using MoonCore.Events;
using MoonCore.Observability;
using MoonlightServers.Daemon.Helpers;
namespace MoonlightServers.Daemon.Services;

View File

@@ -25,7 +25,7 @@ public class DockerImageService
Logger = logger;
}
public async Task Download(string name, Action<string>? onProgressUpdated = null)
public async Task DownloadAsync(string name, Action<string>? onProgressUpdated = null)
{
// If there is already a download for this image occuring, we want to wait for this to complete instead
// of calling docker to download it again

View File

@@ -17,16 +17,16 @@ public class DockerInfoService
UnsafeDockerClient = unsafeDockerClient;
}
public async Task<string> GetDockerVersion()
public async Task<string> GetDockerVersionAsync()
{
var version = await DockerClient.System.GetVersionAsync();
return $"{version.Version} commit {version.GitCommit} ({version.APIVersion})";
}
public async Task<UsageDataReport> GetDataUsage()
public async Task<UsageDataReport> GetDataUsageAsync()
{
var response = await UnsafeDockerClient.GetDataUsage();
var response = await UnsafeDockerClient.GetDataUsageAsync();
var report = new UsageDataReport()
{

View File

@@ -1,6 +1,3 @@
using System.IdentityModel.Tokens.Jwt;
using System.Text;
using Microsoft.IdentityModel.Tokens;
using MoonCore.Attributes;
using MoonCore.Helpers;
using MoonCore.Models;
@@ -19,26 +16,26 @@ public class RemoteService
ApiClient = CreateHttpClient(configuration);
}
public async Task GetStatus()
public async Task GetStatusAsync()
{
await ApiClient.Get("api/remote/servers/node/trip");
}
public async Task<PagedData<ServerDataResponse>> GetServers(int page, int perPage)
public async Task<CountedData<ServerDataResponse>> GetServersAsync(int startIndex, int count)
{
return await ApiClient.GetJson<PagedData<ServerDataResponse>>(
$"api/remote/servers?page={page}&pageSize={perPage}"
return await ApiClient.GetJson<CountedData<ServerDataResponse>>(
$"api/remote/servers?startIndex={startIndex}&count={count}"
);
}
public async Task<ServerDataResponse> GetServer(int serverId)
public async Task<ServerDataResponse> GetServerAsync(int serverId)
{
return await ApiClient.GetJson<ServerDataResponse>(
$"api/remote/servers/{serverId}"
);
}
public async Task<ServerInstallDataResponse> GetServerInstallation(int serverId)
public async Task<ServerInstallDataResponse> GetServerInstallationAsync(int serverId)
{
return await ApiClient.GetJson<ServerInstallDataResponse>(
$"api/remote/servers/{serverId}/install"

View File

@@ -1,5 +1,4 @@
using System.Collections.Concurrent;
using MoonCore.Helpers;
using MoonCore.Models;
using MoonlightServers.Daemon.Mappers;
using MoonlightServers.Daemon.Models.Cache;
@@ -32,7 +31,7 @@ public class ServerService : IHostedLifecycleService
public Server? GetById(int id)
=> Servers.GetValueOrDefault(id);
public async Task Initialize(ServerConfiguration configuration)
public async Task InitializeAsync(ServerConfiguration configuration)
{
var existingServer = Servers.GetValueOrDefault(configuration.Id);
@@ -50,20 +49,20 @@ public class ServerService : IHostedLifecycleService
}
}
public async Task InitializeById(int id)
public async Task InitializeByIdAsync(int id)
{
var serverData = await RemoteService.GetServer(id);
var serverData = await RemoteService.GetServerAsync(id);
var config = ConfigurationMapper.FromServerDataResponse(serverData);
await Initialize(config);
await InitializeAsync(config);
}
private async Task InitializeAll()
private async Task InitializeAllAsync()
{
Logger.LogDebug("Initialing servers from panel");
var servers = await PagedData<ServerDataResponse>.All(async (page, pageSize) =>
await RemoteService.GetServers(page, pageSize)
var servers = await CountedData<ServerDataResponse>.LoadAllAsync(async (startIndex, count) =>
await RemoteService.GetServersAsync(startIndex, count)
);
foreach (var serverData in servers)
@@ -72,7 +71,7 @@ public class ServerService : IHostedLifecycleService
{
var config = ConfigurationMapper.FromServerDataResponse(serverData);
await Initialize(config);
await InitializeAsync(config);
}
catch (Exception e)
{
@@ -91,7 +90,7 @@ public class ServerService : IHostedLifecycleService
public async Task StartedAsync(CancellationToken cancellationToken)
{
await InitializeAll();
await InitializeAllAsync();
}
public Task StartingAsync(CancellationToken cancellationToken)

View File

@@ -14,11 +14,7 @@ using MoonlightServers.Daemon.Http.Hubs;
using MoonlightServers.Daemon.Mappers;
using MoonlightServers.Daemon.Models.Cache;
using MoonlightServers.Daemon.ServerSystem;
using MoonlightServers.Daemon.ServerSystem.Docker;
using MoonlightServers.Daemon.ServerSystem.Enums;
using MoonlightServers.Daemon.ServerSystem.FileSystems;
using MoonlightServers.Daemon.ServerSystem.Handlers;
using MoonlightServers.Daemon.ServerSystem.Implementations;
using MoonlightServers.Daemon.ServerSystem.Models;
using MoonlightServers.Daemon.Services;
@@ -40,35 +36,35 @@ public class Startup
private WebApplication WebApplication;
private WebApplicationBuilder WebApplicationBuilder;
public async Task Run(string[] args)
public async Task RunAsync(string[] args)
{
Args = args;
await SetupStorage();
await SetupAppConfiguration();
await SetupLogging();
await SetupStorageAsync();
await SetupAppConfigurationAsync();
await SetupLoggingAsync();
await CreateWebApplicationBuilder();
await CreateWebApplicationBuilderAsync();
await ConfigureKestrel();
await RegisterAppConfiguration();
await RegisterLogging();
await RegisterBase();
await RegisterAuth();
await RegisterDocker();
await RegisterServers();
await RegisterSignalR();
await RegisterCors();
await ConfigureKestrelAsync();
await RegisterAppConfigurationAsync();
await RegisterLoggingAsync();
await RegisterBaseAsync();
await RegisterAuthAsync();
await RegisterDockerAsync();
await RegisterServersAsync();
await RegisterSignalRAsync();
await RegisterCorsAsync();
await BuildWebApplication();
await BuildWebApplicationAsync();
await UseBase();
await UseCors();
await UseAuth();
await UseBaseMiddleware();
await UseBaseAsync();
await UseCorsAsync();
await UseAuthAsync();
await UseBaseMiddlewareAsync();
await MapBase();
await MapHubs();
await MapBaseAsync();
await MapHubsAsync();
Task.Run(async () =>
{
@@ -93,8 +89,6 @@ public class Startup
"java -Xms128M -Xmx{{SERVER_MEMORY}}M -Dterminal.jline=false -Dterminal.ansi=true -jar {{SERVER_JARFILE}}",
DockerImage = "ghcr.io/nexocrew-hq/moonlightdockerimages:java21",
StopCommand = "stop",
UseVirtualDisk = false,
Bandwidth = 0,
Variables = new Dictionary<string, string>()
{
{ "SERVER_JARFILE", "server.jar" },
@@ -139,7 +133,7 @@ public class Startup
await WebApplication.RunAsync();
}
private Task SetupStorage()
private Task SetupStorageAsync()
{
Directory.CreateDirectory("storage");
Directory.CreateDirectory(Path.Combine("storage", "logs"));
@@ -149,7 +143,7 @@ public class Startup
#region Base
private Task RegisterBase()
private Task RegisterBaseAsync()
{
WebApplicationBuilder.Services.AutoAddServices<Startup>();
WebApplicationBuilder.Services.AddControllers();
@@ -159,7 +153,7 @@ public class Startup
return Task.CompletedTask;
}
private Task ConfigureKestrel()
private Task ConfigureKestrelAsync()
{
WebApplicationBuilder.WebHost.ConfigureKestrel(options =>
{
@@ -170,7 +164,7 @@ public class Startup
return Task.CompletedTask;
}
private Task UseBase()
private Task UseBaseAsync()
{
WebApplication.UseRouting();
WebApplication.UseExceptionHandler();
@@ -178,12 +172,12 @@ public class Startup
return Task.CompletedTask;
}
private Task UseBaseMiddleware()
private Task UseBaseMiddlewareAsync()
{
return Task.CompletedTask;
}
private Task MapBase()
private Task MapBaseAsync()
{
WebApplication.MapControllers();
@@ -194,7 +188,7 @@ public class Startup
#region Docker
private Task RegisterDocker()
private Task RegisterDockerAsync()
{
var dockerClient = new DockerClientConfiguration(
new Uri(Configuration.Docker.Uri)
@@ -213,7 +207,7 @@ public class Startup
#region Configurations
private async Task SetupAppConfiguration()
private async Task SetupAppConfigurationAsync()
{
var configurationBuilder = new ConfigurationBuilder();
@@ -235,7 +229,7 @@ public class Startup
Configuration = configurationRoot.Get<AppConfiguration>()!;
}
private Task RegisterAppConfiguration()
private Task RegisterAppConfigurationAsync()
{
WebApplicationBuilder.Services.AddSingleton(Configuration);
@@ -246,13 +240,13 @@ public class Startup
#region Web Application
private Task CreateWebApplicationBuilder()
private Task CreateWebApplicationBuilderAsync()
{
WebApplicationBuilder = WebApplication.CreateBuilder(Args);
return Task.CompletedTask;
}
private Task BuildWebApplication()
private Task BuildWebApplicationAsync()
{
WebApplication = WebApplicationBuilder.Build();
return Task.CompletedTask;
@@ -262,7 +256,7 @@ public class Startup
#region Logging
private Task SetupLogging()
private Task SetupLoggingAsync()
{
LoggerFactory = new LoggerFactory();
LoggerFactory.AddAnsiConsole();
@@ -272,7 +266,7 @@ public class Startup
return Task.CompletedTask;
}
private async Task RegisterLogging()
private async Task RegisterLoggingAsync()
{
// Configure application logging
WebApplicationBuilder.Logging.ClearProviders();
@@ -323,7 +317,7 @@ public class Startup
#region Servers
private Task RegisterServers()
private Task RegisterServersAsync()
{
WebApplicationBuilder.Services.AddScoped<ServerContext>();
WebApplicationBuilder.Services.AddSingleton<ServerFactory>();
@@ -335,7 +329,7 @@ public class Startup
return Task.CompletedTask;
}
private Task UseServers()
private Task UseServersAsync()
{
return Task.CompletedTask;
}
@@ -344,13 +338,13 @@ public class Startup
#region Hubs
private Task RegisterSignalR()
private Task RegisterSignalRAsync()
{
WebApplicationBuilder.Services.AddSignalR();
return Task.CompletedTask;
}
private Task MapHubs()
private Task MapHubsAsync()
{
WebApplication.MapHub<ServerWebSocketHub>("api/servers/ws", options =>
{
@@ -365,7 +359,7 @@ public class Startup
#region Cors
private Task RegisterCors()
private Task RegisterCorsAsync()
{
//TODO: IMPORTANT: CHANGE !!!
WebApplicationBuilder.Services.AddCors(x =>
@@ -380,7 +374,7 @@ public class Startup
return Task.CompletedTask;
}
private Task UseCors()
private Task UseCorsAsync()
{
WebApplication.UseCors();
return Task.CompletedTask;
@@ -390,7 +384,7 @@ public class Startup
#region Authentication
private Task RegisterAuth()
private Task RegisterAuthAsync()
{
WebApplicationBuilder.Services
.AddAuthentication("token")
@@ -461,7 +455,7 @@ public class Startup
return Task.CompletedTask;
}
private Task UseAuth()
private Task UseAuthAsync()
{
WebApplication.UseAuthentication();
WebApplication.UseAuthorization();