Class DocumentReaderWriterBase<TNativeType>
Abstract base class for implementations of IReadsAndWritesDocument. This class takes care of some boilerplate logic related to the validation of parameters and raising an exception if the operation is to be cancelled.
Inheritance
Implements
Inherited Members
Namespace: ZptSharp.Dom
Assembly: ZptSharp.Abstractions.dll
Syntax
public abstract class DocumentReaderWriterBase<TNativeType> : IReadsAndWritesDocument where TNativeType : class
Type Parameters
Name | Description |
---|---|
TNativeType |
Properties
| Improve this Doc View SourceResolvableType
Gets the type of the current instance, for the purpose of future dependency resolution.
Declaration
public abstract Type ResolvableType { get; }
Property Value
Type | Description |
---|---|
System.Type |
Remarks
Gets the type of the current instance, for the purpose of dependency resolution. This is not/should not be quite the same as System.Object.GetType(), because a derived implementation might not always be resolved as its precise type, it might be resolved as a less-derived base type.
Methods
| Improve this Doc View SourceCanReadWriteForFilename(String)
Gets whether or not the current instance may be used to read & write documents which have the specified filename.
Declaration
public abstract bool CanReadWriteForFilename(string filenameOrPath)
Parameters
Type | Name | Description |
---|---|---|
System.String | filenameOrPath | The filename of a ZPT document. |
Returns
Type | Description |
---|---|
System.Boolean |
|
GetDocumentAsync(Stream, RenderingConfig, IDocumentSourceInfo, CancellationToken)
Gets a document instance from the specified input stream. Implementors of this base class should implement logic in GetDocumentProtectedAsync(Stream, RenderingConfig, IDocumentSourceInfo, CancellationToken).
Declaration
public Task<IDocument> GetDocumentAsync(Stream stream, RenderingConfig config, IDocumentSourceInfo sourceInfo = null, CancellationToken token = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | stream | A stream containing the source of the document. |
RenderingConfig | config | Rendering configuration. |
IDocumentSourceInfo | sourceInfo | Information which identifies the source of the document. |
System.Threading.CancellationToken | token | An object used to cancel the operation if required. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<IDocument> | A task which provides the document which has been read. |
GetDocumentProtectedAsync(Stream, RenderingConfig, IDocumentSourceInfo, CancellationToken)
Implement this method in a derived class to perform custom logic related to reading a document from a stream.
Derived types should assume that the stream
& config
parameters have
been null-checked. Also, they should assume that the token
parameter does not request cancellation.
Declaration
protected abstract Task<IDocument> GetDocumentProtectedAsync(Stream stream, RenderingConfig config, IDocumentSourceInfo sourceInfo, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | stream | A stream containing the source of the document. |
RenderingConfig | config | Rendering configuration. |
IDocumentSourceInfo | sourceInfo | Information which identifies the source of the document. |
System.Threading.CancellationToken | token | An object used to cancel the operation if required. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<IDocument> | A task which provides the document which has been read. |
WriteDocumentAsync(IDocument, RenderingConfig, CancellationToken)
Writes the specified document to a specified output stream. Implementors of this base class should implement logic in WriteDocumentProtectedAsync(TNativeType, RenderingConfig, CancellationToken).
Declaration
public Task<Stream> WriteDocumentAsync(IDocument document, RenderingConfig config, CancellationToken token = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
IDocument | document | The document to write. |
RenderingConfig | config | Rendering configuration. |
System.Threading.CancellationToken | token | An object used to cancel the operation if required. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.IO.Stream> | A task which provides the output stream. |
WriteDocumentProtectedAsync(TNativeType, RenderingConfig, CancellationToken)
Implement this method in a derived class to perform custom logic related to writing a document to a stream.
Derived types should assume that the document
& config
parameters
have been null-checked. The document will also already be converted to TNativeType
.
Finally, the token
parameter will have already been checked that it does not request cancellation.
Declaration
protected abstract Task<Stream> WriteDocumentProtectedAsync(TNativeType document, RenderingConfig config, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
TNativeType | document | The document to write. |
RenderingConfig | config | Rendering configuration. |
System.Threading.CancellationToken | token | An object used to cancel the operation if required. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.IO.Stream> | A task which provides the output stream. |