From 681403ec6e1a1c5208454a777909624f98f36cfd Mon Sep 17 00:00:00 2001 From: Marcel Baumgartner Date: Tue, 30 Jan 2024 22:42:07 +0100 Subject: [PATCH] Fixed some bugs and added a error handler for the service creation --- .../Features/Servers/Actions/ServerActions.cs | 2 ++ Moonlight/Features/Servers/Entities/Server.cs | 2 +- .../Features/Servers/Services/ServerService.cs | 2 +- .../Services/ServiceAdminService.cs | 14 +++++++++++--- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Moonlight/Features/Servers/Actions/ServerActions.cs b/Moonlight/Features/Servers/Actions/ServerActions.cs index 1edec7b0..ccf62891 100644 --- a/Moonlight/Features/Servers/Actions/ServerActions.cs +++ b/Moonlight/Features/Servers/Actions/ServerActions.cs @@ -102,6 +102,8 @@ public class ServerActions : ServiceActions }); } + serverRepo.Add(server); + await serverService.Sync(server); await serverService.SendPowerAction(server, PowerAction.Install); } diff --git a/Moonlight/Features/Servers/Entities/Server.cs b/Moonlight/Features/Servers/Entities/Server.cs index b546e130..c96454e3 100644 --- a/Moonlight/Features/Servers/Entities/Server.cs +++ b/Moonlight/Features/Servers/Entities/Server.cs @@ -14,7 +14,7 @@ public class Server public ServerImage Image { get; set; } public int DockerImageIndex { get; set; } public string? OverrideStartupCommand { get; set; } - public List Variables { get; set; } + public List Variables { get; set; } = new(); public ServerNode Node { get; set; } public ServerAllocation MainAllocation { get; set; } diff --git a/Moonlight/Features/Servers/Services/ServerService.cs b/Moonlight/Features/Servers/Services/ServerService.cs index 54238055..d355ed44 100644 --- a/Moonlight/Features/Servers/Services/ServerService.cs +++ b/Moonlight/Features/Servers/Services/ServerService.cs @@ -48,7 +48,7 @@ public class ServerService .First(x => x.Id == server.Id); var protocol = serverWithNode.Node.UseSsl ? "https" : "http"; - var remoteUrl = $"{protocol}://{serverWithNode.Node.Fqdn}/"; + var remoteUrl = $"{protocol}://{serverWithNode.Node.Fqdn}:{serverWithNode.Node.HttpPort}/"; return new HttpApiClient(remoteUrl, serverWithNode.Node.Token); } diff --git a/Moonlight/Features/ServiceManagement/Services/ServiceAdminService.cs b/Moonlight/Features/ServiceManagement/Services/ServiceAdminService.cs index b50781f8..2e9398d2 100644 --- a/Moonlight/Features/ServiceManagement/Services/ServiceAdminService.cs +++ b/Moonlight/Features/ServiceManagement/Services/ServiceAdminService.cs @@ -47,9 +47,17 @@ public class ServiceAdminService // Add new service in database var finishedService = serviceRepo.Add(service); - // Call the action for the logic behind the service type - await impl.Actions.Create(scope.ServiceProvider, finishedService); - + try + { + // Call the action for the logic behind the service type + await impl.Actions.Create(scope.ServiceProvider, finishedService); + } + catch (Exception) // Handle any implementation errors and let the creation fail + { + serviceRepo.Delete(finishedService); + throw; + } + return finishedService; }