Giter Site home page Giter Site logo

david0718 / txfilemanager Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chinhdo/txfilemanager

0.0 1.0 0.0 737 KB

.NET Transactional File Manager is a .NET Standard library that allows you to enlist file operations (file/folder copies, writes, deletes, appends, etc.) in distributed transactions.

License: MIT License

C# 100.00%

txfilemanager's Introduction

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.

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 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.

Version 1.4 (released 3/2020)

  • 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.

txfilemanager's People

Contributors

chinhdo avatar gvas avatar remye06 avatar developermj avatar mugsy0815 avatar zungmou avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.