Document things Management Transactional example of File Manager

Source: Internet
Author: User
Tags file copy xsl xsl file
recommend a file things management transactional File Manager

Project Description

Transactional file Manager is a. NET API, supports including file system operations such as File copy, move, delete, a Ppend, etc. in a transaction. It's an implementation of System.Transaction.IEnlistmentNotification (works with System.Transactions.TransactionScope ).

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

Wrap a file copy and a database insert in the same transactiontxfilemanager filemgr = new Txfilemanager (); using (Transa Ctionscope scope1 = new TransactionScope ()) {//Copy a filefilemgr.copy (Srcfilename, destfilename);//Insert a database rec Orddbmgr.executenonquery (Insertsql); Scope1.complete ();}

Current Features

    • Support for the following file operations in transactions:

      • Appendalltext

      • Copy

      • CreateDirectory

      • DeleteDirectory

      • DeleteFile

      • Move

      • Snapshot

      • WriteAllText

      • WriteAllBytes

This library supports any file system and are not a wrapper over transactional NTFS (see ALPHAFS).

Examples

Completely Unrealistic example showing how various file operations, including operations did//by library/3rd Party C Ode, can participate in transactions. Ifilemanager FileManager = new Txfilemanager (), using (TransactionScope scope1 = new TransactionScope ()) {FILEMANAGER.WR    Itealltext (Infilename, XML);    Snapshot allows any file operation to BES part of our transaction.    All we need to know are the file name.    The statement below tells the Txfilemanager to remember the state of this file.  So even though XslCompiledTransform have no knowledge of our Txfilemanager, the file it creates (Outfilename)//would    Still is restored to the the event of a rollback.    Filemanager.snapshot (Outfilename);    XslCompiledTransform xsl = new XslCompiledTransform (true); Xsl.    Load (URI); Xsl.    Transform (Infilename, outfilename); Write to Database 1.   This database op would get committed/rolled back along with the file operations we is doing in this transaction. Mydb1.executenonquery (SQL1); Write to Database 2.    The transaction is promoted to a distributed transaction.    Mydb2.executenonquery (SQL2);    Let's delete some files for (string filename in Filestodelete) {filemanager.delete (fileName); }//Just for kicks, let ' s start a new nested transaction. Since We specify requiresnew here, this nested transaction//'ll be committed/rolled back separately from the main TR    Ansaction. Note that we can still use the same FileManager instance.    It knows how to sort things out correctly. using (TransactionScope scope2 = new TransactionScope (transactionscopeoptions.requiresnew)) {Filemanager.movefi    Le (Anotherfile, anotherfiledest); }//move some files for (string filename in Filestomove) {filemanager.move (FileName, getnewfilename (file    Name));    }//Finally, let's create a few temporary files ...//disk space has been used for something. The nice thing about FileManager.gettempfilename is and//the temp file would be a cleaned up automatically for your when the TransactionScope com    Pletes.    No more worries about temp files, that get left behind.    for (int i=0; i<10; i++) {Filemanager.writealltext (Filemanager.gettempfilename (), "Testing 1 2");    } scope1.complete (); In the event a exception occurs, everything done here would be rolled back including the output XSL file.}

This is an open source project. The original project site is the transaction File Manager.

Copyright (c) 2008-2013 Chinh do

Any person who obtains a copy of the software and associated documentation ("SOFTWARE") hereby grants free permission to process the software without limitation, including, but not limited to, the right to use, reproduce, modify, merge, publish, distribute, sublicense and/or sell copies of the software, and allow the person providing the software to comply with the following conditions:

The above copyright notice and this License statement shall be included in all copies or major portions of the software.

The software is provided "as is" without warranty of any kind, either express or implied, including, but not limited to, the warranties of merchantability, fitness for a particular purpose and non-infringement. In no event shall the author or the copyright owner be liable for any claim, damage or other liability, whether or not due to any contract, tort or other aspect of the software relating to the use of the software or the software or other transactions.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.