Click or drag to resize

FileManager Class

Represents a file manager which can be enlisted in a transaction. This class is abstract.
Inheritance Hierarchy

Namespace:  Novacta.Transactions.IO
Assembly:  Novacta.Transactions.IO (in Novacta.Transactions.IO.dll) Version: 1.0.0
Syntax
public abstract class FileManager : IEnlistmentNotification, 
	IDisposable

The FileManager type exposes the following members.

Constructors
  NameDescription
Public methodFileManager
Initializes a new instance of the FileManager class.
Top
Properties
  NameDescription
Public propertyManagedFileStream
Provides the stream for the managed file.
Top
Methods
  NameDescription
Public methodCommit
Notifies an enlisted object that a transaction is being committed.
Public methodDispose
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Protected methodDispose(Boolean)
Releases unmanaged and - optionally - managed resources.
Public methodEnlistVolatile
Enlists this instance as a volatile resource manager using the specified enlistment options.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodInDoubt
Notifies an enlisted object that the status of a transaction is in doubt.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Protected methodOnCommit
Called when the transaction is successfully committed.
Protected methodOnInDoubt
Called when the transaction is in doubt.
Protected methodOnPrepareFileStream
Prepares the stream for managing the file.
Protected methodOnRollback
Called when the transaction is rolled back.
Public methodPrepare
Notifies an enlisted object that a transaction is being prepared for commitment.
Public methodRollback
Notifies an enlisted object that a transaction is being rolled back (aborted).
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Remarks

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.

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

See Also