Method IFileRepoTransaction.AddAsync
IFileRepoTransaction.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.
Declaration
TaskWithProgress<IRepoFileGroup> IFileRepoTransaction.AddAsync(FileStream stream, bool leaveOpen, IFileProcessingPipelineSelector pipeline, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| FileStream | stream | The source file stream. |
| bool | leaveOpen | Indicates whether to leave the stream open after the operation completes. |
| IFileProcessingPipelineSelector | pipeline | The processing pipeline, or the selector that chooses one by extension. |
| CancellationToken | cancellationToken | A cancellation token that cancels the operation. |
Returns
| Type | Description |
|---|---|
| TaskWithProgress<IRepoFileGroup> | The resulting file group, including the main file and any variants declared by the pipeline. |
Implements
Remarks
IFileRepoTransaction.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.
Declaration
TaskWithProgress<IRepoFileGroup> IFileRepoTransaction.AddAsync(Stream stream, string extension, bool leaveOpen, IFileProcessingPipelineSelector pipeline, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The source stream. |
| string | extension | The source file extension including the leading period, or an empty string if it has none. |
| bool | leaveOpen | Indicates whether to leave the stream open after the operation completes. |
| IFileProcessingPipelineSelector | pipeline | The processing pipeline, or the selector that chooses one by extension. |
| CancellationToken | cancellationToken | A cancellation token that cancels the operation. |
Returns
| Type | Description |
|---|---|
| TaskWithProgress<IRepoFileGroup> | The resulting file group, including the main file and any variants declared by the pipeline. |
Implements
Remarks
The repository generates the new file's ID. The file is durable once the add returns: an implementation must not lose it after that, because the application may commit a database row that references it next. If the transaction is rolled back instead of committed, the file is deleted.
The files of the returned group know their sizes without storage access or a network round trip (see GetLengthAsync(CancellationToken)).
The pipeline runs before the file is stored. Progress of each processor can be observed by enumerating the returned task before awaiting it (see TaskWithProgress<T>).
Exceptions
| Type | Condition |
|---|---|
| FileProcessingException | A processor in the pipeline rejected or failed to process the source. |
| FileSourceUnchangedException | The pipeline made no changes to the source and its ThrowWhenMainSourceUnchanged option is set. |
| ObjectDisposedException | The transaction has been disposed. |