Started reimplementing server feature because we use a new project structure now. This is way cleaner than the last implementation

This commit is contained in:
Marcel Baumgartner
2024-01-26 20:09:53 +01:00
parent 19001e5836
commit 33c1ffa0ba
19 changed files with 569 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
using Moonlight.Features.Servers.Entities;
using Moonlight.Features.Servers.Models.Abstractions;
namespace Moonlight.Features.Servers.Extensions;
public static class ServerExtensions
{
public static ServerConfiguration ToServerConfiguration(this Server server)
{
var serverConfiguration = new ServerConfiguration();
// Set general information
serverConfiguration.Id = server.Id;
// Set variables
serverConfiguration.Variables = server.Variables
.ToDictionary(x => x.Key, x => x.Value);
// Set server image
serverConfiguration.Image = new()
{
OnlineDetection = server.Image.OnlineDetection,
ParseConfigurations = server.Image.ParseConfigurations,
StartupCommand = server.Image.StartupCommand,
StopCommand = server.Image.StopCommand
};
// Find docker image by index
ServerDockerImage dockerImage;
if (server.DockerImageIndex >= server.Image.DockerImages.Count || server.DockerImageIndex == -1)
dockerImage = server.Image.DockerImages.Last();
else
dockerImage = server.Image.DockerImages[server.DockerImageIndex];
serverConfiguration.Image.DockerImage = dockerImage.Name;
serverConfiguration.Image.PullDockerImage = dockerImage.AutoPull;
// Set server limits
serverConfiguration.Limits = new()
{
Cpu = server.Cpu,
Memory = server.Memory,
Disk = server.Disk
};
// Set allocations
serverConfiguration.Allocations = server.Allocations.Select(x => new ServerConfiguration.AllocationData()
{
IpAddress = x.IpAddress,
Port = x.Port
}).ToList();
// Set main allocation
serverConfiguration.MainAllocation = new()
{
IpAddress = server.MainAllocation.IpAddress,
Port = server.MainAllocation.Port
};
return serverConfiguration;
}
}