Class XmlMultiStreamLoader<TRecord>
Loads items of type TRecord into multiple streams,
writing one XML document per stream.
public sealed class XmlMultiStreamLoader<TRecord> : LoaderBase<TRecord, XmlReport>, ILoadWithProgressAndCancellationAsync<TRecord, XmlReport>, ILoadWithProgressAsync<TRecord, XmlReport>, ILoadWithCancellationAsync<TRecord>, ILoadAsync<TRecord>, IReportsItemErrors, IAsyncDisposable, IDisposable, ISupportDryRun where TRecord : notnull, new()
Type Parameters
TRecordThe type of items to load. Must be
notnulland have a parameterless constructor.
- Inheritance
-
LoaderBase<TRecord, XmlReport>XmlMultiStreamLoader<TRecord>
- Implements
-
ILoadWithProgressAndCancellationAsync<TRecord, XmlReport>ILoadWithProgressAsync<TRecord, XmlReport>ILoadWithCancellationAsync<TRecord>ILoadAsync<TRecord>IReportsItemErrorsISupportDryRun
- Inherited Members
-
LoaderBase<TRecord, XmlReport>.DisposeAsync()LoaderBase<TRecord, XmlReport>.Dispose()LoaderBase<TRecord, XmlReport>.ReportingIntervalLoaderBase<TRecord, XmlReport>.CurrentItemCountLoaderBase<TRecord, XmlReport>.CurrentSkippedItemCountLoaderBase<TRecord, XmlReport>.CurrentErrorItemCountLoaderBase<TRecord, XmlReport>.MaximumItemCountLoaderBase<TRecord, XmlReport>.SkipItemCountLoaderBase<TRecord, XmlReport>.WorkerResilienceLoaderBase<TRecord, XmlReport>.ErrorPolicy
Examples
var loader = new XmlMultiStreamLoader<Person>
(
person => File.Create($"output/{person.Id}.xml")
);
await loader.LoadAsync(items, cancellationToken);
Remarks
For each item in the input sequence, calls a factory function to obtain a Stream, serializes the item as a single XML document, and disposes the stream. The factory receives the item being written, allowing stream creation based on item properties (e.g., generating file names from record fields).
Constructors
XmlMultiStreamLoader(Func<TRecord, IBufferWriter<byte>>)
Initializes a new instance of the XmlMultiStreamLoader<TRecord> class whose factory returns an IBufferWriter<T> of bytes per item instead of a Stream (#8) — serialized bytes flow straight into each buffer writer.
[RequiresUnreferencedCode("XmlMultiStreamLoader serializes TRecord via System.Xml.Serialization.XmlSerializer, which uses runtime reflection/Reflection.Emit the trimmer cannot follow. The library is not trim/NativeAOT safe.")]
public XmlMultiStreamLoader(Func<TRecord, IBufferWriter<byte>> bufferWriterFactory)
Parameters
bufferWriterFactoryFunc<TRecord, IBufferWriter<byte>>A factory that receives the item to be written and returns an IBufferWriter<T> of bytes to write it to.
Exceptions
- ArgumentNullException
Thrown when
bufferWriterFactoryisnull.
XmlMultiStreamLoader(Func<TRecord, IBufferWriter<byte>>, ILogger<XmlMultiStreamLoader<TRecord>>)
Initializes a new instance of the XmlMultiStreamLoader<TRecord> class with an IBufferWriter<T>-of-bytes factory (#8) and a logger.
[RequiresUnreferencedCode("XmlMultiStreamLoader serializes TRecord via System.Xml.Serialization.XmlSerializer, which uses runtime reflection/Reflection.Emit the trimmer cannot follow. The library is not trim/NativeAOT safe.")]
public XmlMultiStreamLoader(Func<TRecord, IBufferWriter<byte>> bufferWriterFactory, ILogger<XmlMultiStreamLoader<TRecord>> logger)
Parameters
bufferWriterFactoryFunc<TRecord, IBufferWriter<byte>>A factory that receives the item to be written and returns an IBufferWriter<T> of bytes to write it to.
loggerILogger<XmlMultiStreamLoader<TRecord>>The logger instance for diagnostic output.
Exceptions
- ArgumentNullException
Thrown when
bufferWriterFactoryorloggerisnull.
XmlMultiStreamLoader(Func<TRecord, IBufferWriter<byte>>, XmlWriterSettings, ILogger<XmlMultiStreamLoader<TRecord>>)
Initializes a new instance of the XmlMultiStreamLoader<TRecord> class with an IBufferWriter<T>-of-bytes factory (#8) and custom writer settings.
[RequiresUnreferencedCode("XmlMultiStreamLoader serializes TRecord via System.Xml.Serialization.XmlSerializer, which uses runtime reflection/Reflection.Emit the trimmer cannot follow. The library is not trim/NativeAOT safe.")]
public XmlMultiStreamLoader(Func<TRecord, IBufferWriter<byte>> bufferWriterFactory, XmlWriterSettings writerSettings, ILogger<XmlMultiStreamLoader<TRecord>> logger)
Parameters
bufferWriterFactoryFunc<TRecord, IBufferWriter<byte>>A factory that receives the item to be written and returns an IBufferWriter<T> of bytes to write it to.
writerSettingsXmlWriterSettingsThe XML writer settings to use for serialization.
loggerILogger<XmlMultiStreamLoader<TRecord>>The logger instance for diagnostic output.
Exceptions
- ArgumentNullException
Thrown when
bufferWriterFactory,writerSettings, orloggerisnull.
XmlMultiStreamLoader(Func<TRecord, Stream>)
Initializes a new instance of the XmlMultiStreamLoader<TRecord> class.
[RequiresUnreferencedCode("XmlMultiStreamLoader serializes TRecord via System.Xml.Serialization.XmlSerializer, which uses runtime reflection/Reflection.Emit the trimmer cannot follow. The library is not trim/NativeAOT safe.")]
public XmlMultiStreamLoader(Func<TRecord, Stream> streamFactory)
Parameters
streamFactoryFunc<TRecord, Stream>A factory function that receives the item to be written and returns a Stream to write it to. The loader will dispose the stream after writing.
Exceptions
- ArgumentNullException
Thrown when
streamFactoryisnull.
XmlMultiStreamLoader(Func<TRecord, Stream>, ILogger<XmlMultiStreamLoader<TRecord>>)
Initializes a new instance of the XmlMultiStreamLoader<TRecord> class with a logger.
[RequiresUnreferencedCode("XmlMultiStreamLoader serializes TRecord via System.Xml.Serialization.XmlSerializer, which uses runtime reflection/Reflection.Emit the trimmer cannot follow. The library is not trim/NativeAOT safe.")]
public XmlMultiStreamLoader(Func<TRecord, Stream> streamFactory, ILogger<XmlMultiStreamLoader<TRecord>> logger)
Parameters
streamFactoryFunc<TRecord, Stream>A factory function that receives the item to be written and returns a Stream to write it to. The loader will dispose the stream after writing.
loggerILogger<XmlMultiStreamLoader<TRecord>>The logger instance for diagnostic output.
Exceptions
- ArgumentNullException
Thrown when
streamFactoryorloggerisnull.
XmlMultiStreamLoader(Func<TRecord, Stream>, XmlWriterSettings, ILogger<XmlMultiStreamLoader<TRecord>>)
Initializes a new instance of the XmlMultiStreamLoader<TRecord> class with custom writer settings.
[RequiresUnreferencedCode("XmlMultiStreamLoader serializes TRecord via System.Xml.Serialization.XmlSerializer, which uses runtime reflection/Reflection.Emit the trimmer cannot follow. The library is not trim/NativeAOT safe.")]
public XmlMultiStreamLoader(Func<TRecord, Stream> streamFactory, XmlWriterSettings writerSettings, ILogger<XmlMultiStreamLoader<TRecord>> logger)
Parameters
streamFactoryFunc<TRecord, Stream>A factory function that receives the item to be written and returns a Stream to write it to. The loader will dispose the stream after writing.
writerSettingsXmlWriterSettingsThe XML writer settings to use for serialization.
loggerILogger<XmlMultiStreamLoader<TRecord>>The logger instance for diagnostic output.
Exceptions
- ArgumentNullException
Thrown when
streamFactory,writerSettings, orloggerisnull.
Properties
IsDryRun
Gets or sets a value indicating whether the loader runs in dry-run mode (#176). When true, the load enumerates the source, honours Wolfgang.Etl.Abstractions.LoaderBase<TDestination, TProgress>.SkipItemCount / Wolfgang.Etl.Abstractions.LoaderBase<TDestination, TProgress>.MaximumItemCount, advances the progress counters, and logs as usual, but never invokes the destination-stream factory and writes nothing. Defaults to false.
public bool IsDryRun { get; set; }
Property Value
Methods
CreateProgressReport()
Creates a progress report of type TProgress. This gives the derived class the opportunity to implement a custom progress report that is specific to the loading process.
protected override XmlReport CreateProgressReport()
Returns
- XmlReport
Progress of type TProgress
CreateProgressTimer(IProgress<XmlReport>)
Creates the Wolfgang.Etl.Abstractions.IProgressTimer used to drive progress callbacks. Override this method in a derived class to inject a custom timer (for example, a custom implementation that allows manual control in unit tests).
protected override IProgressTimer CreateProgressTimer(IProgress<XmlReport> progress)
Parameters
Returns
- IProgressTimer
A started Wolfgang.Etl.Abstractions.IProgressTimer instance.
LoadWorkerAsync(IAsyncEnumerable<TRecord>, CancellationToken)
This method is the core implementation of the loading logic and should be overridden by derived classes.
protected override Task LoadWorkerAsync(IAsyncEnumerable<TRecord> items, CancellationToken token)
Parameters
itemsIAsyncEnumerable<TRecord>The items to be loaded to the destination.
tokenCancellationTokenA CancellationToken to observe while waiting for the task to complete.
Returns
- Task
A task representing the asynchronous operation.
Remarks
Items may be an empty sequence if no data is available or if the loading fails.
Exceptions
- ArgumentNullException
Argument items is null