From 022693e50f947defaceb8a1b1b311ed44bd80e97 Mon Sep 17 00:00:00 2001 From: Daniel Balk <67603460+Daniel-Balk@users.noreply.github.com> Date: Fri, 5 May 2023 17:46:44 +0200 Subject: [PATCH] dotnet runtime settings --- Moonlight/App/Helpers/ParseHelper.cs | 11 +++ .../ServerControl/ServerSettings.razor | 6 ++ .../Settings/DotnetFileSetting.razor | 85 ++++++++++++++++++ .../Settings/DotnetVersionSetting.razor | 89 +++++++++++++++++++ 4 files changed, 191 insertions(+) create mode 100644 Moonlight/Shared/Components/ServerControl/Settings/DotnetFileSetting.razor create mode 100644 Moonlight/Shared/Components/ServerControl/Settings/DotnetVersionSetting.razor diff --git a/Moonlight/App/Helpers/ParseHelper.cs b/Moonlight/App/Helpers/ParseHelper.cs index b3074c1..b068e7b 100644 --- a/Moonlight/App/Helpers/ParseHelper.cs +++ b/Moonlight/App/Helpers/ParseHelper.cs @@ -37,6 +37,17 @@ public static class ParseHelper return res; } + + public static string ToDotnetVersionName(string raw) + { + var dockerImageTag = raw.Split(":").Last(); + + var name = dockerImageTag.Replace("_", ".") + .Replace("dotnetcore", ".NET Core ") + .Replace("dotnet", ".NET "); + + return name; + } public static string GetHighestVersion(string[] versions) { diff --git a/Moonlight/Shared/Components/ServerControl/ServerSettings.razor b/Moonlight/Shared/Components/ServerControl/ServerSettings.razor index e76bdef..3afd4ea 100644 --- a/Moonlight/Shared/Components/ServerControl/ServerSettings.razor +++ b/Moonlight/Shared/Components/ServerControl/ServerSettings.razor @@ -58,12 +58,18 @@ if(Tags.Contains("javaversion")) Settings.Add("Java version", typeof(JavaRuntimeVersionSetting)); + if(Tags.Contains("dotnetversion")) + Settings.Add("Dotnet version", typeof(DotnetVersionSetting)); + if(Tags.Contains("pythonfile")) Settings.Add("Python file", typeof(PythonFileSetting)); if(Tags.Contains("javafile")) Settings.Add("Jar file", typeof(JavaFileSetting)); + if(Tags.Contains("dotnetfile")) + Settings.Add("Dll file", typeof(DotnetFileSetting)); + Settings.Add("Rename", typeof(ServerRenameSetting)); Settings.Add("Reset", typeof(ServerResetSetting)); diff --git a/Moonlight/Shared/Components/ServerControl/Settings/DotnetFileSetting.razor b/Moonlight/Shared/Components/ServerControl/Settings/DotnetFileSetting.razor new file mode 100644 index 0000000..0cd31a6 --- /dev/null +++ b/Moonlight/Shared/Components/ServerControl/Settings/DotnetFileSetting.razor @@ -0,0 +1,85 @@ +@using Task = System.Threading.Tasks.Task +@using Moonlight.App.Repositories.Servers +@using Moonlight.Shared.Components.FileManagerPartials +@using Moonlight.App.Database.Entities +@using Moonlight.App.Helpers +@using Moonlight.App.Helpers.Files +@using Moonlight.App.Services + +@inject ServerRepository ServerRepository +@inject ServerService ServerService +@inject SmartTranslateService SmartTranslateService + +
+
+ + + + + + + +
+ + + +
+
+
+
+ + + + +@code +{ + [CascadingParameter] + public Server CurrentServer { get; set; } + + private string PathAndFile; + private FileAccess Access; + + private FileSelectModal FileSelectModal; + private LazyLoader LazyLoader; + + protected override async Task OnInitializedAsync() + { + Access = await ServerService.CreateFileAccess(CurrentServer, null!); + } + + private async Task Load(LazyLoader lazyLoader) + { + var v = CurrentServer.Variables.FirstOrDefault(x => x.Key == "MAIN_DLL"); + + PathAndFile = v != null ? v.Value : ""; + + await InvokeAsync(StateHasChanged); + } + + private async Task Show() + { + await FileSelectModal.Show(); + } + + private async Task OnSubmit(string path) + { + var v = CurrentServer.Variables.FirstOrDefault(x => x.Key == "MAIN_DLL"); + + if (v != null) + { + v.Value = path.TrimStart("/"[0]); + + ServerRepository.Update(CurrentServer); + } + + await LazyLoader.Reload(); + } +} \ No newline at end of file diff --git a/Moonlight/Shared/Components/ServerControl/Settings/DotnetVersionSetting.razor b/Moonlight/Shared/Components/ServerControl/Settings/DotnetVersionSetting.razor new file mode 100644 index 0000000..0698628 --- /dev/null +++ b/Moonlight/Shared/Components/ServerControl/Settings/DotnetVersionSetting.razor @@ -0,0 +1,89 @@ +@using Moonlight.App.Services +@using Moonlight.App.Helpers +@using Moonlight.App.Repositories +@using Moonlight.App.Repositories.Servers +@using Microsoft.EntityFrameworkCore +@using Moonlight.App.Database.Entities + +@inject ServerRepository ServerRepository +@inject ImageRepository ImageRepository +@inject SmartTranslateService TranslationService + +
+
+ + + + + + + +
+ + + + +
+ +
+
+
+ +@code +{ + [CascadingParameter] + public Server CurrentServer { get; set; } + + private LazyLoader LazyLoader; + private List DockerImages; + private DockerImage SelectedImage; + + private int ImageIndex + { + get => SelectedImage.Id; + set { SelectedImage = DockerImages.First(x => x.Id == value); } + } + + private Task Load(LazyLoader lazyLoader) + { + var image = ImageRepository + .Get() + .Include(x => x.DockerImages) + .First(x => x.Id == CurrentServer.Image.Id); + + DockerImages = image.DockerImages; + + SelectedImage = DockerImages[CurrentServer.DockerImageIndex]; + + return Task.CompletedTask; + } + + private async Task Save() + { + CurrentServer.DockerImageIndex = DockerImages.IndexOf(SelectedImage); + + ServerRepository.Update(CurrentServer); + + await LazyLoader.Reload(); + } +} \ No newline at end of file