AI-Studio/app/MindWork AI Studio/Tools/Databases/DatabaseClient.cs
Thorsten Sommer 891b90819b
Some checks failed
Build and Release / Read metadata (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage deb updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage deb updater) (push) Has been cancelled
Build and Release / Prepare & create release (push) Has been cancelled
Build and Release / Publish release (push) Has been cancelled
Localized database information (#658)
2026-02-08 17:46:38 +01:00

52 lines
1.5 KiB
C#

namespace AIStudio.Tools.Databases;
public abstract class DatabaseClient(string name, string path)
{
public string Name => name;
private string Path => path;
private ILogger<DatabaseClient>? logger;
public abstract IAsyncEnumerable<(string Label, string Value)> GetDisplayInfo();
protected string GetStorageSize()
{
if (string.IsNullOrWhiteSpace(this.Path))
{
this.logger!.LogError($"Error: Database path '{this.Path}' cannot be null or empty.");
return "0 B";
}
if (!Directory.Exists(this.Path))
{
this.logger!.LogError($"Error: Database path '{this.Path}' does not exist.");
return "0 B";
}
var files = Directory.EnumerateFiles(this.Path, "*", SearchOption.AllDirectories)
.Where(file => !System.IO.Path.GetDirectoryName(file)!.Contains("cert", StringComparison.OrdinalIgnoreCase));
var size = files.Sum(file => new FileInfo(file).Length);
return FormatBytes(size);
}
private static string FormatBytes(long size)
{
string[] suffixes = { "B", "KB", "MB", "GB", "TB", "PB" };
int suffixIndex = 0;
while (size >= 1024 && suffixIndex < suffixes.Length - 1)
{
size /= 1024;
suffixIndex++;
}
return $"{size:0##} {suffixes[suffixIndex]}";
}
public void SetLogger(ILogger<DatabaseClient> logService)
{
this.logger = logService;
}
public abstract void Dispose();
}