From 708ae080a3c4ef2504b95c580f2ceed342fd69cb Mon Sep 17 00:00:00 2001 From: Daniel Balk <67603460+Daniel-Balk@users.noreply.github.com> Date: Sun, 2 Apr 2023 23:17:09 +0200 Subject: [PATCH] cleanup ui (part 1) + stupidity fix --- Moonlight/App/Models/Misc/AuditLogType.cs | 5 +- Moonlight/App/Services/CleanupService.cs | 12 +- Moonlight/Program.cs | 1 + .../Shared/Views/Admin/Servers/Cleanup.razor | 185 ++++++++++++++++++ Moonlight/resources/lang/de_de.lang | 22 ++- 5 files changed, 215 insertions(+), 10 deletions(-) create mode 100644 Moonlight/Shared/Views/Admin/Servers/Cleanup.razor diff --git a/Moonlight/App/Models/Misc/AuditLogType.cs b/Moonlight/App/Models/Misc/AuditLogType.cs index d505deb9..13fafa1c 100644 --- a/Moonlight/App/Models/Misc/AuditLogType.cs +++ b/Moonlight/App/Models/Misc/AuditLogType.cs @@ -19,5 +19,8 @@ public enum AuditLogType AddDomainRecord, UpdateDomainRecord, DeleteDomainRecord, - PasswordReset + PasswordReset, + CleanupEnabled, + CleanupDisabled, + CleanupTriggered, } \ No newline at end of file diff --git a/Moonlight/App/Services/CleanupService.cs b/Moonlight/App/Services/CleanupService.cs index d4c6ff8c..ef500550 100644 --- a/Moonlight/App/Services/CleanupService.cs +++ b/Moonlight/App/Services/CleanupService.cs @@ -37,12 +37,8 @@ public class CleanupService { ServiceScopeFactory = serviceScopeFactory; ConfigService = configService; - - IConfiguration configuration = new ConfigurationBuilder() - .AddJsonFile("appsettings.json") - .Build(); - var config = configuration.GetSection("Cleanup"); + var config = configService.GetSection("Moonlight").GetSection("Cleanup"); RequiredCpu = config.GetValue("Cpu"); RequiredMemory = config.GetValue("Memory"); @@ -71,9 +67,9 @@ public class CleanupService try { - await Task.Delay((int)TimeSpan.FromMinutes(WaitTime).TotalMilliseconds); + await Task.Delay((int) TimeSpan.FromMinutes(WaitTime).TotalMilliseconds); } - catch (Exception) + catch (Exception ex) { } } @@ -338,7 +334,7 @@ public class CleanupService watch.Stop(); - Status = $"Cleanup finifhed. Duration: {Math.Round(TimeSpan.FromMilliseconds(watch.ElapsedMilliseconds).TotalMinutes, 2)} Minuten"; + Status = $"Cleanup finished. Duration: {Math.Round(TimeSpan.FromMilliseconds(watch.ElapsedMilliseconds).TotalMinutes, 2)} Minutes"; PercentProgress = 100; OnUpdated?.Invoke(this, null); } diff --git a/Moonlight/Program.cs b/Moonlight/Program.cs index 8dc94299..f7fa1df6 100644 --- a/Moonlight/Program.cs +++ b/Moonlight/Program.cs @@ -65,6 +65,7 @@ namespace Moonlight builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); + builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); diff --git a/Moonlight/Shared/Views/Admin/Servers/Cleanup.razor b/Moonlight/Shared/Views/Admin/Servers/Cleanup.razor new file mode 100644 index 00000000..5215224c --- /dev/null +++ b/Moonlight/Shared/Views/Admin/Servers/Cleanup.razor @@ -0,0 +1,185 @@ +@page "/admin/servers/cleanup" + +@using Moonlight.App.Services +@using Logging.Net +@using Moonlight.App.Models.Misc +@using Moonlight.App.Services.LogServices + +@inject CleanupService CleanupService +@inject AuditLogService AuditLogService + +@implements IDisposable + +Cleanup + + +
+
+
+
+
+ +
+
+
+
+ @(CleanupService.ServersCleaned) +
+ Servers + stopped +
+
+
+
+
+
+
+
+
+ +
+
+
+
+ @(CleanupService.CleanupsPerformed) +
+ Cleanups + executed +
+
+
+
+
+
+
+
+
+ +
+
+
+
+ @(CleanupService.ServersRunning) +
+ Used clanup + Servers +
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+ @if (CleanupService.IsRunning) + { + + } + else + { + + } +
+
+ @if (CleanupService.Activated) + { + + } + else + { + + } +
+
+ @if (CleanupService.Activated) + { + + } + else + { + + } +
+
+
+
+
+
+
+
+ + + + +@code +{ + protected async override Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + CleanupService.OnUpdated += OnUpdated; + } + } + + private void OnUpdated(object? sender, EventArgs e) + { + Logger.Debug(CleanupService.PercentProgress); + + InvokeAsync(StateHasChanged); + } + + public void Dispose() + { + CleanupService.OnUpdated -= OnUpdated; + } + + private void Enable() + { + CleanupService.Activated = true; + AuditLogService.Log(AuditLogType.CleanupEnabled, "The automatic cleanup has been activated"); + InvokeAsync(StateHasChanged); + } + + private void Disabled() + { + CleanupService.Activated = false; + AuditLogService.Log(AuditLogType.CleanupDisabled, "The automatic cleanup has been disabled"); + InvokeAsync(StateHasChanged); + } + + private async void Trigger() + { + await CleanupService.TriggerPerform(); + await AuditLogService.Log(AuditLogType.CleanupTriggered, "The automatic cleanup has been manually triggered"); + await InvokeAsync(StateHasChanged); + } +} \ No newline at end of file diff --git a/Moonlight/resources/lang/de_de.lang b/Moonlight/resources/lang/de_de.lang index 8f280dab..7e426f46 100644 --- a/Moonlight/resources/lang/de_de.lang +++ b/Moonlight/resources/lang/de_de.lang @@ -406,4 +406,24 @@ The City field is required.;The City field is required. The State field is required.;The State field is required. The Country field is required.;The Country field is required. Street and house number requered;Street and house number requered -Max lenght reached;Max lenght reached \ No newline at end of file +Max lenght reached;Max lenght reached +stopped;stopped +Cleanups;Cleanups +executed;executed +Used clanup;Used clanup +Checking Nodes;Checking Nodes +Enable;Enable +Disabble;Disabble +Checking found servers;Checking found servers +Scanning servers;Scanning servers +Scanning code containers;Scanning code containers +Cleanup finifhed. Duration: 0.08 Minuten;Cleanup finifhed. Duration: 0.08 Minuten +Disable;Disable +Cleanup finished. Duration: 0.08 Minuten;Cleanup finished. Duration: 0.08 Minuten +Cleanup finished. Duration: 0.08 Minutes;Cleanup finished. Duration: 0.08 Minutes +Cleanup finished. Duration: 0.13 Minutes;Cleanup finished. Duration: 0.13 Minutes +Cleanup finished. Duration: 0.23 Minutes;Cleanup finished. Duration: 0.23 Minutes +Cleanup finished. Duration: 0.14 Minutes;Cleanup finished. Duration: 0.14 Minutes +Cleanup finished. Duration: 0.09 Minutes;Cleanup finished. Duration: 0.09 Minutes +Cleanup finished. Duration: 0.1 Minutes;Cleanup finished. Duration: 0.1 Minutes +Cleanup finished. Duration: 0.11 Minutes;Cleanup finished. Duration: 0.11 Minutes