dossier-dot-net 1.3.1

Transactional file management library for .NET.

Install-Package dossier-dot-net -Version 1.3.1
dotnet add package dossier-dot-net --version 1.3.1
<PackageReference Include="dossier-dot-net" Version="1.3.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add dossier-dot-net --version 1.3.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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();
    }
}

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();
    }
}

Release Notes

Add SourceLink support

  • .NETStandard 2.0

    • No dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.3.1 120 11/8/2018
1.3.0 263 8/25/2017
1.2.0 282 2/7/2017
1.1.0 321 6/27/2016
1.0.3 289 6/27/2016
1.0.2 403 6/25/2016
1.0.1 264 6/25/2016
1.0.0 301 6/25/2016