![]() | FileManager Class |
Namespace: Novacta.Transactions.IO
The FileManager type exposes the following members.
Name | Description | |
---|---|---|
![]() | FileManager |
Initializes a new instance of the FileManager class.
|
Name | Description | |
---|---|---|
![]() | ManagedFileStream |
Provides the stream for the managed file.
|
Name | Description | |
---|---|---|
![]() | Commit |
Notifies an enlisted object that a transaction is being committed.
|
![]() | Dispose |
Performs application-defined tasks associated with freeing,
releasing, or resetting unmanaged resources.
|
![]() | Dispose(Boolean) |
Releases unmanaged and - optionally - managed resources.
|
![]() | EnlistVolatile |
Enlists this instance as a volatile resource
manager using the specified enlistment
options.
|
![]() | Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as the default hash function. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | InDoubt |
Notifies an enlisted object that the status of a transaction is
in doubt.
|
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | OnCommit |
Called when the transaction is successfully committed.
|
![]() | OnInDoubt |
Called when the transaction is in doubt.
|
![]() | OnPrepareFileStream |
Prepares the stream for managing the file.
|
![]() | OnRollback |
Called when the transaction is rolled back.
|
![]() | Prepare |
Notifies an enlisted object that a transaction is being prepared
for commitment.
|
![]() | Rollback |
Notifies an enlisted object that a transaction is being rolled
back (aborted).
|
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
Given that FileManager is an abstract class, you do not instantiate it in your code. Define a class which derives from FileManager to add new files or modify existing ones inside a given transaction. You can also use one of its specialized subclasses, such as CreateFileManager, EditFileManager, DeleteFileManager, and CopyFileManager, to create, update, delete, and copy files, respectively.
In order for a file manager to participate in a transaction, it must be explicitly enlisted in the current transaction using the EnlistVolatile(EnlistmentOptions) method. In this way, the manager can be notified at the different phases of the transaction as follows.
When the transaction is being prepared for commitment, the manager is notified by calling its method Prepare(PreparingEnlistment), which will create a FileStream for the managed file by calling OnPrepareFileStream(String). The returned stream can be accessed through property ManagedFileStream.
When the transaction is being rolled back (aborted), an enlisted file manager is notified by calling its method Rollback(Enlistment), which will in turn call method OnRollback to do the work necessary to finish the aborted transaction.
When the transaction is being committed, an enlisted object is notified by calling its method Commit(Enlistment). A FileManager instance will in turn call method OnCommit to do the work necessary to finish the committed transaction.
Notes to Inheritors
A class derived from FileManager must implement a constructor passing information to FileManager(String) about the path of the managed file. In addition, the following abstract methods need to be implemented.
Method | Description |
---|---|
OnPrepareFileStream(String) | Called by Prepare(PreparingEnlistment) when a transaction is being prepared for commitment. It is executed inside a try/catch block: throw an exception if conditions hold under which the transaction need to be rolled back. Otherwise, return a stream for the managed file. |
OnRollback | Called by Rollback(Enlistment) when a transaction is being rolled back. Must be implemented to state how the manager should react to a rolled back transaction. |
OnCommit | Called by Commit(Enlistment) when a transaction is being committed. Must be implemented to state how the manager should operate in case of a successfully committed transaction. |
An enlisted FileManager instance can also eventually be notified that the status of a transaction is in doubt. In such case, the virtual method OnInDoubt is called by InDoubt(Enlistment). By default, OnInDoubt does nothing. You should override it to perform whatever recovery or containment operation it understands on the affected file.