From ccec79cca7d355493b6054fbc62f8a02d866d27c Mon Sep 17 00:00:00 2001 From: Moritz <101179677+Moritz-Deiaco@users.noreply.github.com> Date: Sun, 19 May 2024 00:04:27 +0200 Subject: [PATCH] Added node online check on Server create --- .../Features/Servers/Services/ServerService.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Moonlight/Features/Servers/Services/ServerService.cs b/Moonlight/Features/Servers/Services/ServerService.cs index 135f110..6dc8dab 100644 --- a/Moonlight/Features/Servers/Services/ServerService.cs +++ b/Moonlight/Features/Servers/Services/ServerService.cs @@ -2,6 +2,7 @@ using Microsoft.EntityFrameworkCore; using MoonCore.Abstractions; using MoonCore.Attributes; using MoonCore.Exceptions; +using MoonCore.Helpers; using MoonCore.Services; using Moonlight.Core.Configuration; using Moonlight.Core.Database.Entities; @@ -22,6 +23,8 @@ public class ServerService public ServerConsoleService Console => ServiceProvider.GetRequiredService(); public ServerBackupService Backup => ServiceProvider.GetRequiredService(); public ServerScheduleService Schedule => ServiceProvider.GetRequiredService(); + + public NodeService NodeService => ServiceProvider.GetRequiredService(); private readonly IServiceProvider ServiceProvider; @@ -74,6 +77,19 @@ public class ServerService // Load node var node = nodeRepo.Get().First(x => x.Id == form.Node.Id); + // Check if node is available + try + { + await NodeService.GetStatus(node); + } + catch (Exception e) + { + Logger.Warn($"Could not establish to the node with the id {node.Id}"); + Logger.Warn(e); + + throw new DisplayException($"Could not establish connection to the node: {e.Message}"); + } + // Load user var user = userRepo.Get().First(x => x.Id == form.Owner.Id);