dossier-dot-net
1.3.1
dotnet add package dossier-dot-net --version 1.3.1
NuGet\Install-Package dossier-dot-net -Version 1.3.1
<PackageReference Include="dossier-dot-net" Version="1.3.1" />
paket add dossier-dot-net --version 1.3.1
#r "nuget: dossier-dot-net, 1.3.1"
// Install dossier-dot-net as a Cake Addin
#addin nuget:?package=dossier-dot-net&version=1.3.1
// Install dossier-dot-net as a Cake Tool
#tool nuget:?package=dossier-dot-net&version=1.3.1
Dossier.NET
A transactional file management library for the .NET Framework.
How it Works
All actions are added to a queue which can be rolled back should one or more of them fail. The bytes of any files copied, moved or deleted are held in memory until the transaction object is disposed.
using (var fsContext = new Dossier.FileSystemContext())
{
using (var trx = fsContext.BeginTransaction())
{
try
{
var myFile = fsContext.WriteFile(".\\hello-world.txt", "Hello World!");
fsContext.CopyFile(".\\hello-world.txt", ".\\my-file.txt");
fsContext.CreateDirectory(".\\MyDirectory"");
fsContext.MoveFile(".\\my-file.txt", ".\\MyDirectory\\my-file.txt");
fsContext.MoveDirectory(".\\MyDirectory", ".\\MySecondDirectory");
fsContext.DeleteFile(".\\MySecondDirectory\\my-file.txt");
var newFile = fsContext.WriteFile(".\\newfile.txt", "Another file!");
fsContext.MoveFile(".\\new-file.txt", ".\\moved-file.txt");
trx.Commit();
}
catch
{
// if any of the operations in the
// transaction queue throw an exception,
// roll it back
trx.Rollback();
}
}
}
You can also specify a temp directory to use instead of storing rollback data in memory. This is especially useful if you are working with a large amount of data. To use a temp directory, simply specify a path to the desired temporary storage location when creating a FileSystemContext.
using (var fsContext = new Dossier.FileSystemContext("\\data\\temp\\"))
{
// do stuff
}
Each transaction will create a temporary folder named with the unique identifier for the transaction. Every operation will then store it's rollback data in a file in the transaction folder with a unique identifier for the operation. The transaction folder is deleted when the transaction committed, rolled back, or disposed.
When using a temp directory for rollbacks, a transaction.txt
file is updated in the
folder for each transaction whenever an operation is executed. Upon creation of a new
FileSystemContext
, the temp directory is checked for any existing transactions,
which will be visible through the Transactions
collection of the FileSystemContext
.
This enables recovering partially completed transactions in the event of power loss or an unexpected application crash.
using Dossier;
using(var fsContext = new FileSystemContext("\\my-temp-directory"))
{
if (fsContext.Transactions.Any())
{
// clean up partially completed transactions
foreach (var trx in fsContext.Transactions)
{
trx.Rollback();
}
}
}
You may also call the UseTransaction()
method to resume using a previously
existing transaction.
using Dossier;
using (var fsContext = new FileSystem.Context("\\my-temp-directory"))
{
ITransaction trx;
if (fsContext.Transactions.Any())
{
trx = fsContext.Transactions.First();
fsContext.UseTransaction(trx);
}
else
{
trx = fsContext.BeginTransaction();
}
fsContext.MoveFile("\\file1.txt", "\\file2.txt");
try
{
trx.Commit();
}
catch (Exception)
{
trx.Rollback();
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|
Add SourceLink support