Interface IFileRepoTransaction
Represents a transaction for an IFileRepo, which adds and deletes main files and is committed or rolled back as a whole.
Inherited Members
Namespace: FulcrumFS
Assembly: FulcrumFS.dll
Syntax
public interface IFileRepoTransaction : IAsyncDisposable
Remarks
When the files belong to rows in a database, commit the database transaction first and this transaction second. Implementations must keep that ordering safe: a file added by a transaction that did not finish committing stays readable until a cleanup pass resolves it through the callback passed to CleanAsync(TimeSpan, Func<FileId, Task<IndeterminateResolution>>?, CancellationToken), and so does a file whose deletion did not finish committing.
A transaction ends with CommitAsync(CancellationToken) or RollbackAsync(CancellationToken). Disposing it without either does not roll it back. A transaction is disposed that way when something failed before its commit, and it cannot know whether that was before or after the application's database committed: a database commit that has taken effect on the server still throws if, for example, the connection is lost before the answer arrives. Implementations must therefore leave the files the transaction added and the files it deleted in the state that a process which ended at that point leaves them in: readable, reported as indeterminate by EnumerateFilesAsync(CancellationToken), and resolved by a cleanup pass through the resolution callback, which keeps the files the database references and deletes the others. A pass without a callback leaves them as they are. An application that knows that its database did not commit calls RollbackAsync(CancellationToken) before the transaction is disposed, which discards them at once. Disposing a transaction that has been committed or rolled back, or that added and deleted nothing, does nothing, and disposal does not throw.
Properties
| Name | Description |
|---|---|
| Repository | Gets the repository the transaction belongs to. |
Methods
| Name | Description |
|---|---|
| AddAsync(FileStream, bool, IFileProcessingPipelineSelector, CancellationToken) | Adds a new file to the repository from the specified file stream, taking the extension from the stream's file name, and processes it through the specified pipeline. |
| AddAsync(Stream, string, bool, IFileProcessingPipelineSelector, CancellationToken) | Adds a new file to the repository from the specified stream and extension, and processes it through the specified pipeline. |
| CommitAsync(CancellationToken) | Commits the transaction, making the files it added and deleted permanent in the repository. |
| DeleteAsync(FileId, CancellationToken) | Deletes an existing file, or a file added by this transaction, by its file ID. |
| RollbackAsync(CancellationToken) | Rolls back the transaction, discarding the files it added and abandoning the deletions it made. |
| TryDeleteAsync(FileId, CancellationToken) | Deletes an existing file, or a file added by this transaction, by its file ID if it exists, and reports whether it did. |