From e4596df39292fc6242d80e5804bda666542bdc13 Mon Sep 17 00:00:00 2001 From: max Date: Sun, 19 Oct 2025 22:47:48 +0200 Subject: [PATCH] [CHANGE] ApplicationContext removed and related classes. Added Drive info to library info page. --- Manager.App/Components/Pages/Channels.razor | 2 +- Manager.App/Components/Pages/Library.razor | 12 ++++++++++ .../Models/Library/LibraryInformation.cs | 3 +++ Manager.App/Services/LibraryService.cs | 20 +++++++++++++++- .../Services/System/SettingsService.cs | 16 ------------- Manager.Data/Contexts/ApplicationContext.cs | 24 ------------------- .../ApplicationContext/WorkItemEntity.cs | 10 -------- .../Entities/ApplicationContext/WorkStatus.cs | 10 -------- 8 files changed, 35 insertions(+), 62 deletions(-) delete mode 100644 Manager.App/Services/System/SettingsService.cs delete mode 100644 Manager.Data/Contexts/ApplicationContext.cs delete mode 100644 Manager.Data/Entities/ApplicationContext/WorkItemEntity.cs delete mode 100644 Manager.Data/Entities/ApplicationContext/WorkStatus.cs diff --git a/Manager.App/Components/Pages/Channels.razor b/Manager.App/Components/Pages/Channels.razor index e60b2bf..3f05d56 100644 --- a/Manager.App/Components/Pages/Channels.razor +++ b/Manager.App/Components/Pages/Channels.razor @@ -8,7 +8,7 @@ - Channels stored in the library + Channels diff --git a/Manager.App/Components/Pages/Library.razor b/Manager.App/Components/Pages/Library.razor index 120d9cc..7d862ac 100644 --- a/Manager.App/Components/Pages/Library.razor +++ b/Manager.App/Components/Pages/Library.razor @@ -26,6 +26,18 @@ Library size: @($"{Suffix.BytesToSizeSuffix(_libraryInformation.TotalSizeBytes)} ({_libraryInformation.TotalSizeBytes} bytes)") + + Drive total size: + @($"{Suffix.BytesToSizeSuffix(_libraryInformation.DriveTotalSpaceBytes)} ({_libraryInformation.DriveTotalSpaceBytes} bytes)") + + + Drive used space: + @($"{Suffix.BytesToSizeSuffix(_libraryInformation.DriveUsedSpaceBytes)} ({_libraryInformation.DriveUsedSpaceBytes} bytes)") + + + Drive free space available: + @($"{Suffix.BytesToSizeSuffix(_libraryInformation.DriveFreeSpaceBytes)} ({_libraryInformation.DriveFreeSpaceBytes} bytes)") + Total media: diff --git a/Manager.App/Models/Library/LibraryInformation.cs b/Manager.App/Models/Library/LibraryInformation.cs index a153deb..e0d29e4 100644 --- a/Manager.App/Models/Library/LibraryInformation.cs +++ b/Manager.App/Models/Library/LibraryInformation.cs @@ -8,4 +8,7 @@ public record LibraryInformation public long TotalMedia { get; set; } public long TotalChannels { get; set; } public long TotalSizeBytes { get; set; } + public long DriveTotalSpaceBytes { get; set; } + public long DriveFreeSpaceBytes { get; set; } + public long DriveUsedSpaceBytes { get; set; } } \ No newline at end of file diff --git a/Manager.App/Services/LibraryService.cs b/Manager.App/Services/LibraryService.cs index 89408ac..30212b0 100644 --- a/Manager.App/Services/LibraryService.cs +++ b/Manager.App/Services/LibraryService.cs @@ -223,6 +223,7 @@ public class LibraryService : ILibraryService try { await using var context = await _dbContextFactory.CreateDbContextAsync(cancellationToken); + var libraryDriveInfo = GetLibraryDriveInfo(_libraryDirectory); var libInfo = new LibraryInformation { LibraryPath = _libraryDirectory.FullName, @@ -230,7 +231,10 @@ public class LibraryService : ILibraryService LastModifiedUtc = _libraryDirectory.LastWriteTimeUtc, TotalChannels = await context.Channels.CountAsync(cancellationToken: cancellationToken), TotalMedia = await context.Media.CountAsync(cancellationToken: cancellationToken), - TotalSizeBytes = GetDirectorySize(_libraryDirectory) + TotalSizeBytes = GetDirectorySize(_libraryDirectory), + DriveTotalSpaceBytes = libraryDriveInfo.totalSpace, + DriveFreeSpaceBytes = libraryDriveInfo.freeSpace, + DriveUsedSpaceBytes = libraryDriveInfo.usedSpace }; return libInfo; } @@ -352,6 +356,20 @@ public class LibraryService : ILibraryService } } + private (long totalSpace, long freeSpace, long usedSpace) GetLibraryDriveInfo(DirectoryInfo dir) + { + try + { + var drive = new DriveInfo(dir.FullName); + return (drive.TotalSize, drive.AvailableFreeSpace, drive.TotalSize - drive.AvailableFreeSpace); + } + catch (Exception e) + { + _logger.LogError(e, "Error while getting directory free space."); + throw; + } + } + private ResultError HandleException(Exception exception) { if (exception is OperationCanceledException) diff --git a/Manager.App/Services/System/SettingsService.cs b/Manager.App/Services/System/SettingsService.cs deleted file mode 100644 index 19b45d7..0000000 --- a/Manager.App/Services/System/SettingsService.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace Manager.App.Services.System; - -public class SettingsService(ILogger logger) : ExtendedBackgroundService(nameof(SettingsService), "Service for handling application settings.", logger, TimeSpan.FromMinutes(10)) -{ - protected override async Task InitializeAsync(CancellationToken stoppingToken) - { - AddActions([ - new ServiceAction("Save settings", "Save the application settings to the database", () => { }, () => true) - ]); - } - - protected override async Task ExecuteServiceAsync(CancellationToken stoppingToken) - { - - } -} \ No newline at end of file diff --git a/Manager.Data/Contexts/ApplicationContext.cs b/Manager.Data/Contexts/ApplicationContext.cs deleted file mode 100644 index ce2f7b3..0000000 --- a/Manager.Data/Contexts/ApplicationContext.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Microsoft.EntityFrameworkCore; - -namespace Manager.Data.Contexts; - -public sealed class ApplicationContext : DbContext -{ - public ApplicationContext(DbContextOptions options) : base(options) - { - ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; - ChangeTracker.LazyLoadingEnabled = false; - Database.EnsureCreated(); - } - - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - optionsBuilder.AddInterceptors(new DateInterceptor()); - } - - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - - base.OnModelCreating(modelBuilder); - } -} \ No newline at end of file diff --git a/Manager.Data/Entities/ApplicationContext/WorkItemEntity.cs b/Manager.Data/Entities/ApplicationContext/WorkItemEntity.cs deleted file mode 100644 index 67879e4..0000000 --- a/Manager.Data/Entities/ApplicationContext/WorkItemEntity.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Manager.Data.Entities.ApplicationContext; - -public class WorkItemEntity : DateTimeBase -{ - public required Guid Id { get; set; } - public required string Name { get; set; } - public required string Description { get; set; } - public WorkStatus Status { get; set; } = WorkStatus.Pending; - public required string ClientId { get; set; } -} \ No newline at end of file diff --git a/Manager.Data/Entities/ApplicationContext/WorkStatus.cs b/Manager.Data/Entities/ApplicationContext/WorkStatus.cs deleted file mode 100644 index be23d9a..0000000 --- a/Manager.Data/Entities/ApplicationContext/WorkStatus.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Manager.Data.Entities.ApplicationContext; - -public enum WorkStatus -{ - Pending = 0, - InProgress = 1, - Paused = 2, - Completed = 3, - Faulted = 4, -} \ No newline at end of file