Oakrey.Applications.Files
8.0.0
dotnet add package Oakrey.Applications.Files --version 8.0.0
NuGet\Install-Package Oakrey.Applications.Files -Version 8.0.0
<PackageReference Include="Oakrey.Applications.Files" Version="8.0.0" />
<PackageVersion Include="Oakrey.Applications.Files" Version="8.0.0" />
<PackageReference Include="Oakrey.Applications.Files" />
paket add Oakrey.Applications.Files --version 8.0.0
#r "nuget: Oakrey.Applications.Files, 8.0.0"
#:package Oakrey.Applications.Files@8.0.0
#addin nuget:?package=Oakrey.Applications.Files&version=8.0.0
#tool nuget:?package=Oakrey.Applications.Files&version=8.0.0
Oakrey.Applications.Files
A .NET 11 class library that provides file and directory management through a single injectable service interface. It supports synchronous and asynchronous reads, age-based cleanup, OpenTelemetry tracing, and exception-aware logging.
Main features
- Read file content as a string, synchronously or asynchronously with
CancellationTokensupport - Read and write files via
FileStream - Save text content to a file with automatic intermediate directory creation
- Create directories on demand
- Delete a single file by path
- Delete files in a directory that are older than a given
TimeSpan, with optional extension filter - Enumerate all file paths in a directory tree by extension
- Recursive enumeration skips reparse points to avoid leaving the requested directory tree through links
- Every operation emits an OpenTelemetry activity span and log entries via
Oakrey.Log
Architecture
classDiagram
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
+FileService()
}
IFileService <|.. FileService
Requirements
- .NET 11 or higher
Oakrey.Log.Abstractions3.0.0 or higherOakrey.Telemetry2.0.1 or higher
Installation
NuGet Package Manager
- In Visual Studio open Tools > NuGet Package Manager > Manage NuGet Packages for Solution.
- Search for
Oakrey.Applications.Filesand click Install.
.NET CLI
dotnet add package Oakrey.Applications.Files
Package Manager Console
Install-Package Oakrey.Applications.Files
Configuration
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.
Example usage
public class ReportExporter(IFileService fileService)
{
// Save a text report, directories are created automatically
public void SaveReport(string path, string content)
{
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");
}
}
Development notes
SaveFileis synchronous, matching theIFileServicecontract, so write failures are propagated directly to the caller.DeleteFileOlderThancomparesLastWriteTimeUtcwith the completeTimeSpanand respectsCancellationTokenbetween file deletions.- Recursive enumeration skips reparse points and sorts results using ordinal case-insensitive ordering.
- Failures are logged with their exception objects. Log messages use only the terminal file or directory name to reduce disclosure of sensitive path information.
- All operations start an OpenTelemetry
ActivityviaOakrey.Telemetry.Tracing; configure an exporter in the host to capture traces.
License
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: https://www.oakrey.cz/opkg_applications
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Oakrey.Applications.Files.Abstractions (>= 8.0.0)
- Oakrey.Log.Abstractions (>= 4.0.0)
- Oakrey.Telemetry (>= 3.0.0)
NuGet packages (2)
Showing the top 2 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. |
|
|
Oakrey.Applications.SecureSettings
Readable JSON secured settings service for critical values stored in SecuredSettings.json, with HMAC integrity protection, Windows-user authorization, audit history, and an explicit ISecuredSettingsService API that can run beside regular Settings.json settings. |
GitHub repositories
This package is not used by any popular GitHub repositories.