EQXMedia.TxFileSystem
is a transactional file system wrapper using the .NET file system abstraction from System.IO.Abstractions
.
This file system wrapper supports transactional operations on:
- Files,
- Directories,
- File streams.
This library has been designed and implemented by Jarno Kamminga for EQX Media B.V., and published as an OpenSource project on GitHub.
The project has a website of its own which can be found at https://txfilesystem.io/.
The documentation of the library can be found at https://txfilesystem.io/docs/.
A NuGet package is created of every EQXMedia.TxFileSystem
release and can be installed to your .NET project using the NuGet Package Manager or dotnet
command.
More information about the NuGet package can be found at NuGet.org:
https://www.nuget.org/packages/EQXMedia.TxFileSystem/
PS> Install-Package EQXMedia.TxFileSystem -Version 2.0.2
$ dotnet add package EQXMedia.TxFileSystem --version 2.0.2
<PackageReference Include="EQXMedia.TxFileSystem" Version="2.0.2" />
/**
*
* Because an error occurs inside the transaction scope, the creation of the file will not take place
* (or better said be rolled back):
*
* txFileSystem.File.Exists(@"C:\Users\JohnDoe\Documents\example.txt");
*
* Would simply return 'false' after execution of the below code.
*
**/
using System;
using System.IO.Abstractions;
using System.Transactions;
using EQXMedia.TxFileSystem;
using var transactionScope = TransactionScope();
var txFileSystem = new TxFileSystem(new FileSystem());
txFileSystem.File.Create(@"C:\Users\JohnDoe\Documents\example.txt");
throw new Exception("Error occurs after creating the file. Resulting in the creation to be rolled back.");
transactionScope.Complete();