Transactional File Managerの例の詳細な説明
ファイル トランザクション管理の推奨 Transactional File Manager
プロジェクトの説明
Transactional File Manager は、ファイルのコピー、移動、削除、追加などのファイル システム操作をトランザクションに含めることをサポートする .NET API です。 System.Transaction.IEnlistmentNotification の実装 (System.Transactions.TransactionScope で動作します)。
このライブラリを使用すると、次のようなトランザクションでファイル システム操作をラップできます:
// Wrap a file copy and a database insert in the same transactionTxFileManager fileMgr = new TxFileManager();using (TransactionScope scope1 = new TransactionScope()) {// Copy a file fileMgr.Copy(srcFileName, destFileName);// Insert a database record dbMgr.ExecuteNonQuery(insertSql);scope1.Complete(); }
Current 機能
トランザクションで次のファイル操作をサポートします:
AppendAllText
Copy
CreateDirectory
DeleteDirectory
-
ファイルの削除
移動
スナップショット
WriteAllText
WriteAllBytes
このライブラリはあらゆるファイル システムをサポートしており、トランザクション NTFS のラッパーではありません (AlphaFS を参照)。
例
// Completely unrealistic example showing how various file operations, including operations done // by library/3rd party code, can participate in transactions.IFileManager fileManager = new TxFileManager();using (TransactionScope scope1 = new TransactionScope()) { fileManager.WriteAllText(inFileName, xml); // Snapshot allows any file operation to be part of our transaction. // All we need to know is the file name. //The statement below tells the TxFileManager to remember the state of this file. // So even though XslCompiledTransform has no knowledge of our TxFileManager, the file it creates (outFileName) // will still be restored to this state in 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 will get committed/rolled back along with the file operations we are doing in this transaction. myDb1.ExecuteNonQuery(sql1); // write to database 2. The transaction is promoted to a distributed transaction here. 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 // will be committed/rolled back separately from the main transaction. // 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.MoveFile(anotherFile, anotherFileDest); } // move some files for (string fileName in filesToMove) { fileManager.Move(fileName, GetNewFileName(fileName)); } // Finally, let's create a few temporary files... // disk space has to be used for something. // The nice thing about FileManager.GetTempFileName is that // The temp file will be cleaned up automatically for you when the TransactionScope completes. // 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 an exception occurs, everything done here will be rolled back including the output xsl file.}
これはオープン ソース プロジェクトです。元のプロジェクトの Web サイトは Transaction File Manager です。
Copyright (c) 2008-2013 Chinh Do
これにより、このソフトウェアおよび関連ドキュメント ファイル (以下「ソフトウェア」) のコピーを入手した人に、使用、複製を含む制限なくソフトウェアを扱うための無料ライセンスを付与します。 、ソフトウェアのコピーを変更、マージ、公開、配布、サブライセンスおよび/または販売する権利、および以下の条件に従ってソフトウェアを提供する者に与えられます:
上記の著作権表示とこのライセンス通知は、すべてのコピーに含まれるものとします。ソフトウェアまたは本体部分のこと。
このソフトウェアは、商品性、特定の目的への適合性、および非侵害の保証を含むがこれらに限定されない、明示的か黙示的かを問わず、いかなる種類の保証もなく「現状のまま」提供されます。いかなる場合においても、作者または著作権所有者は、契約行為、不法行為、またはその他の行為であるかどうかにかかわらず、ソフトウェアまたはソフトウェアの使用またはその他の取引に関連して、いかなる請求、損害賠償、またはその他の責任についても責任を負いません。
以上がTransactional File Managerの例の詳細な説明の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック









C# を使用した Active Directory のガイド。ここでは、Active Directory の概要と、C# での動作方法について、構文と例とともに説明します。

C# データ グリッド ビューのガイド。ここでは、SQL データベースまたは Excel ファイルからデータ グリッド ビューをロードおよびエクスポートする方法の例について説明します。

マルチスレッドと非同期の違いは、マルチスレッドが複数のスレッドを同時に実行し、現在のスレッドをブロックせずに非同期に操作を実行することです。マルチスレッドは計算集約型タスクに使用されますが、非同期はユーザーインタラクションに使用されます。マルチスレッドの利点は、コンピューティングのパフォーマンスを改善することですが、非同期の利点はUIスレッドをブロックしないことです。マルチスレッドまたは非同期を選択することは、タスクの性質に依存します。計算集約型タスクマルチスレッド、外部リソースと相互作用し、UIの応答性を非同期に使用する必要があるタスクを使用します。
