[CHANGE] ApplicationContext removed and related classes. Added Drive info to library info page.

This commit is contained in:
max
2025-10-19 22:47:48 +02:00
parent 2f19d60be0
commit e4596df392
8 changed files with 35 additions and 62 deletions

View File

@@ -8,7 +8,7 @@
<MudStack Spacing="2"> <MudStack Spacing="2">
<MudTable @ref="@_table" ServerData="ServerReload"> <MudTable @ref="@_table" ServerData="ServerReload">
<ToolBarContent> <ToolBarContent>
<MudText Typo="Typo.h6">Channels stored in the library</MudText> <MudText Typo="Typo.h6">Channels</MudText>
<MudSpacer /> <MudSpacer />
<MudTextField T="string" ValueChanged="@(s=>OnSearch(s))" Placeholder="Search" Adornment="Adornment.Start" DebounceInterval="300" <MudTextField T="string" ValueChanged="@(s=>OnSearch(s))" Placeholder="Search" Adornment="Adornment.Start" DebounceInterval="300"
AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium" Class="mt-0"></MudTextField> AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium" Class="mt-0"></MudTextField>

View File

@@ -26,6 +26,18 @@
<td>Library size:</td> <td>Library size:</td>
<td>@($"{Suffix.BytesToSizeSuffix(_libraryInformation.TotalSizeBytes)} ({_libraryInformation.TotalSizeBytes} bytes)")</td> <td>@($"{Suffix.BytesToSizeSuffix(_libraryInformation.TotalSizeBytes)} ({_libraryInformation.TotalSizeBytes} bytes)")</td>
</tr> </tr>
<tr>
<td>Drive total size:</td>
<td>@($"{Suffix.BytesToSizeSuffix(_libraryInformation.DriveTotalSpaceBytes)} ({_libraryInformation.DriveTotalSpaceBytes} bytes)")</td>
</tr>
<tr>
<td>Drive used space:</td>
<td>@($"{Suffix.BytesToSizeSuffix(_libraryInformation.DriveUsedSpaceBytes)} ({_libraryInformation.DriveUsedSpaceBytes} bytes)")</td>
</tr>
<tr>
<td>Drive free space available:</td>
<td>@($"{Suffix.BytesToSizeSuffix(_libraryInformation.DriveFreeSpaceBytes)} ({_libraryInformation.DriveFreeSpaceBytes} bytes)")</td>
</tr>
<tr> <tr>
<td>Total media:</td> <td>Total media:</td>

View File

@@ -8,4 +8,7 @@ public record LibraryInformation
public long TotalMedia { get; set; } public long TotalMedia { get; set; }
public long TotalChannels { get; set; } public long TotalChannels { get; set; }
public long TotalSizeBytes { get; set; } public long TotalSizeBytes { get; set; }
public long DriveTotalSpaceBytes { get; set; }
public long DriveFreeSpaceBytes { get; set; }
public long DriveUsedSpaceBytes { get; set; }
} }

View File

@@ -223,6 +223,7 @@ public class LibraryService : ILibraryService
try try
{ {
await using var context = await _dbContextFactory.CreateDbContextAsync(cancellationToken); await using var context = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
var libraryDriveInfo = GetLibraryDriveInfo(_libraryDirectory);
var libInfo = new LibraryInformation var libInfo = new LibraryInformation
{ {
LibraryPath = _libraryDirectory.FullName, LibraryPath = _libraryDirectory.FullName,
@@ -230,7 +231,10 @@ public class LibraryService : ILibraryService
LastModifiedUtc = _libraryDirectory.LastWriteTimeUtc, LastModifiedUtc = _libraryDirectory.LastWriteTimeUtc,
TotalChannels = await context.Channels.CountAsync(cancellationToken: cancellationToken), TotalChannels = await context.Channels.CountAsync(cancellationToken: cancellationToken),
TotalMedia = await context.Media.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; 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) private ResultError HandleException(Exception exception)
{ {
if (exception is OperationCanceledException) if (exception is OperationCanceledException)

View File

@@ -1,16 +0,0 @@
namespace Manager.App.Services.System;
public class SettingsService(ILogger<SettingsService> 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)
{
}
}

View File

@@ -1,24 +0,0 @@
using Microsoft.EntityFrameworkCore;
namespace Manager.Data.Contexts;
public sealed class ApplicationContext : DbContext
{
public ApplicationContext(DbContextOptions<ApplicationContext> 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);
}
}

View File

@@ -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; }
}

View File

@@ -1,10 +0,0 @@
namespace Manager.Data.Entities.ApplicationContext;
public enum WorkStatus
{
Pending = 0,
InProgress = 1,
Paused = 2,
Completed = 3,
Faulted = 4,
}