TxFileManager 1.5.0.1

dotnet add package TxFileManager --version 1.5.0.1
NuGet\Install-Package TxFileManager -Version 1.5.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TxFileManager" Version="1.5.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TxFileManager --version 1.5.0.1
#r "nuget: TxFileManager, 1.5.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TxFileManager as a Cake Addin
#addin nuget:?package=TxFileManager&version=1.5.0.1

// Install TxFileManager as a Cake Tool
#tool nuget:?package=TxFileManager&version=1.5.0.1

Transactional File Manager is a .NET Standard 2.0 library that supports including file system operations such as file copy, move, delete, append, etc. in a transaction. It's an implementation of System.Transaction.IEnlistmentNotification.

This library allows you to wrap file system operations in transactions like this:

// Wrap a file copy and a database insert in the same transaction
IFileManager fm = new TxFileManager();
using (TransactionScope scope1 = new TransactionScope())
{
    // Copy a file
    fm.Copy(srcFileName, destFileName);

    // Insert a database record
    db.ExecuteNonQuery(insertSql);

    scope1.Complete();
} 

Current features

Support the following file operations in transactions:

  • AppendAllText: Appends the specified string the file, creating the file if it doesn't already exist.
  • Copy: Copy a file to another file.
  • Delete: Delete a file.
  • Move: Move a file.
  • CreateDirectory: Create a directory.
  • DeleteDirectory: Delete a directory.
  • MoveDirectory: Move a directory.
  • Snapshot: Take a snapshot of the specified file. The snapshot is used to rollback the file later if needed.
  • WriteAllBytes: Write the specified bytes to the file.
  • WriteAllText: Write the specified text content to the file.

If you have any suggestions for enhancements or bug reports please use the Issues list. Better yet, if possible join this project and contribute.

This library is available as a NuGet package. The current/latest release is 1.4.

This started out as a blog post. It was hosted on CodePlex and migrated to GitHub in 3/2020.

Additional contributors: @gvas, AirBreather.

Quick Start

  1. Add a reference to TxFileManager
dotnet add package TxFileManager
  1. Start writing code
IFileManager fm = new TxFileManager();
using (TransactionScope scope1 = new TransactionScope())
{
    // Copy a file
    fm.Copy(srcFileName, destFileName);

    scope1.Complete();
} 

Frequently Asked Questions

How do I run tests?

In a PowerShell/Command window:

dotnet test

In Visual Studio, open Test/Text Explorer and choose Run All Tests (or CTRL-R, A)

How do I reference this library?

The recommended method is to add a NuGet reference:

dotnet add package TxFileManager

Or Use Visual Studio's Manage NuGet Packages to add. Search for "TxFileManager".

Can I reuse instances of TxFileManager?

It's not expensive to create new instances of TxFileManager as needed. There's a bit of overhead (like creating instances of any small class) but not much.

On the other hand, it's totally safe to re-use the same instance for multiple transactions, even nested transactions.

Is TxFileManager Thread Safe?

Yes - it's been tested for that.

Which IsolationLevel's are supported?

Regardless of the specified IsolationLevel, the effective IsolationLevel is ReadUncommitted.

How does TxFileManager work?

See Chinh's blog post: Include File Operations in Your Transactions Today with IEnlistmentNotification

Where are temporary files/directories kept?

By default, the path returned by Path.GetTempPath() is used to keep temporary files/directories used by TxFileManager. However, you can override that and have TxFileManager use another temp path:

IFileManager fm = new TxFileManager(myTempPath);

How do I contribute to the project?

  • Fork the repo
  • Create a branch such as my-new-feature
  • Make your change/fix and associated unit tests and commit
  • Run the tests (dotnet test)
  • Open a Pull Request (PR) to the "master" branch

Notes: A release branch will be created out of the master branch when a release is made. The master branch will contain the latest features being added/tested for the next release.

Nuget Releases

Version 1.4 (released 3/2020)

  • Convert to xUnit tests
  • Add support for custom temp paths to address issues with file/dir operations accross filesystems
  • Fix for resource leak in TxFileManager._txEnlistment
  • Target .NET Standard 2.0
  • Additional testing for .NET Core on Ubuntu
  • Additional stress testing both on Windows and Ubuntu
  • Created Github workflow to automatically build/test on ubuntu
  • Added FxCop static analysis

Version 1.5.0.1 (released 7/21/2021)

Please suggest your features using the Issues list.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on TxFileManager:

Package Downloads
Micro.Net.Transport.FileSystem

File system-based (FileSystemWatcher) transport component to be used as a base for transports for Micro.NET

Bnsights.Providers.File.FileSystem

Bnsights.Providers.File.FileSystem contains a BaseFileProvider Implementation for FileSystem Bnsights Business Solutions Framework (BBSF) Package.

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on TxFileManager:

Repository Stars
tjackenpacken/taskbar-groups
Lightweight utility for organizing the taskbar through groups
Warewolf-ESB/Warewolf
Effortless Microservice Design and Integration. This repository includes the code-base for the Warewolf Studio and Server.
Version Downloads Last updated
1.5.0.1 50,174 7/22/2021
1.4.0 17,939 3/29/2020
1.3.0 236,740 8/24/2013
1.2.1 10,250 12/6/2011
1.1.0.25 2,448 5/4/2011

- Bug fix Async code (Issue #27)
- Added new operations: CopyDirectory, MoveDirectory
- Added Encoding support to WriteAllText, AppendAllText
- Nuget package icon
- Misc refactors/clean-up