![]() |
VOOZH | about |
dotnet add package Oakrey.Applications.Files --version 6.0.0
NuGet\Install-Package Oakrey.Applications.Files -Version 6.0.0
<PackageReference Include="Oakrey.Applications.Files" Version="6.0.0" />
<PackageVersion Include="Oakrey.Applications.Files" Version="6.0.0" />Directory.Packages.props
<PackageReference Include="Oakrey.Applications.Files" />Project file
paket add Oakrey.Applications.Files --version 6.0.0
#r "nuget: Oakrey.Applications.Files, 6.0.0"
#:package Oakrey.Applications.Files@6.0.0
#addin nuget:?package=Oakrey.Applications.Files&version=6.0.0Install as a Cake Addin
#tool nuget:?package=Oakrey.Applications.Files&version=6.0.0Install as a Cake Tool
A .NET 10 class library that provides file and directory management through a single injectable service interface. It supports synchronous and asynchronous operations, thread-safe file access via SemaphoreSlim, age-based cleanup, and full OpenTelemetry tracing and structured logging on every operation.
CancellationToken supportFileStreamTimeSpan, with optional extension filterSemaphoreSlimOakrey.LogclassDiagram
class IFileService {
+CreateFolder(folderName)
+CreateSaveStream(fileName) FileStream
+DeleteFile(fileName)
+DeleteFileOlderThan(path, timeSpan, extension, ct) Task
+GetFilesPaths(folder, extension) string[]
+LoadFile(fileName) string
+LoadFileAsync(fileName, ct) Task~string~
+LoadFileStream(fileName) FileStream
+SaveFile(fileName, value)
}
class FileService {
-ILogger logger
-ITracing tracer
-SemaphoreSlim semaphoreSlim
+FileService()
}
IFileService <|.. FileService
Oakrey.Log 2.0.0 or higherOakrey.Telemetry 2.0.1 or higherNuGet Package Manager
Oakrey.Applications.Files and click Install..NET CLI
dotnet add package Oakrey.Applications.Files
Package Manager Console
Install-Package Oakrey.Applications.Files
FileService has no required configuration. Register it with the DI container of your choice:
// Microsoft.Extensions.DependencyInjection
services.AddSingleton<IFileService, FileService>();
Oakrey.Log and Oakrey.Telemetry must be configured separately according to their own documentation before FileService is resolved.
public class ReportExporter(IFileService fileService)
{
// Save a text report, directories are created automatically
public async Task SaveReportAsync(string path, string content, CancellationToken ct)
{
fileService.SaveFile(path, content);
}
// Load a text report asynchronously
public async Task<string> LoadReportAsync(string path, CancellationToken ct)
{
return await fileService.LoadFileAsync(path, ct);
}
// Write binary output via stream
public FileStream OpenWriteStream(string path)
{
return fileService.CreateSaveStream(path);
}
// Remove log files older than 30 days
public Task CleanupLogsAsync(string logDirectory, CancellationToken ct)
{
return fileService.DeleteFileOlderThan(logDirectory, TimeSpan.FromDays(30), "log", ct);
}
// List all CSV files in a directory tree
public string[] GetCsvFiles(string root)
{
return fileService.GetFilesPaths(root, "csv");
}
}
SaveFile and LoadFileAsync share a single SemaphoreSlim(1,1) instance to prevent concurrent read/write collisions on the same FileService instance. Register the service as a singleton to benefit from this guarantee.DeleteFileOlderThan uses file.LastWriteTime for age comparison and respects CancellationToken between file deletions.try/catch, logs the error via Oakrey.Log, and re-throws so callers receive the original exception with full context.Activity via Oakrey.Telemetry.Tracing; configure an exporter in the host to capture traces.This project is licensed under the MIT License. See the LICENSE file for details.
Author: Oakrey
Repository: https://dev.azure.com/oakrey/OpenPackages/_git/ApplicationServices
Project URL: http://www.oakrey.cz/opkg_applications
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 1 NuGet packages that depend on Oakrey.Applications.Files:
| Package | Downloads |
|---|---|
|
Oakrey.Applications.Base
A foundational .NET library for building modular WPF applications. Provides application lifecycle management, MVVM ViewModel resolution, structured logging, telemetry, and sequential or parallel service preloading with full unhandled-exception coverage. |
This package is not used by any popular GitHub repositories.