Class FixedWidthTransformer<TSource, TDestination>
- Namespace
- Wolfgang.Etl.FixedWidth
- Assembly
- Wolfgang.Etl.FixedWidth.dll
Transforms a stream of TSource records into
TDestination records in a single streaming pass (#14) —
the middle stage of an extract → transform → load pipeline. Compose it between
a FixedWidthExtractor<TRecord> reading one fixed-width layout and
a FixedWidthLoader<TRecord> writing another to reformat a file
(reorder, add/remove, or reformat fields).
public sealed class FixedWidthTransformer<TSource, TDestination> : TransformerBase<TSource, TDestination, FixedWidthReport>, ITransformWithProgressAndCancellationAsync<TSource, TDestination, FixedWidthReport>, ITransformWithCancellationAsync<TSource, TDestination>, ITransformWithProgressAsync<TSource, TDestination, FixedWidthReport>, ITransformAsync<TSource, TDestination>, IReportsItemErrors, IAsyncDisposable, IDisposable where TSource : notnull where TDestination : notnull
Type Parameters
TSourceThe source record type.
TDestinationThe destination record type.
- Inheritance
-
TransformerBase<TSource, TDestination, FixedWidthReport>FixedWidthTransformer<TSource, TDestination>
- Implements
-
ITransformWithProgressAndCancellationAsync<TSource, TDestination, FixedWidthReport>ITransformWithCancellationAsync<TSource, TDestination>ITransformWithProgressAsync<TSource, TDestination, FixedWidthReport>ITransformAsync<TSource, TDestination>IReportsItemErrors
- Inherited Members
-
TransformerBase<TSource, TDestination, FixedWidthReport>.DisposeAsync()TransformerBase<TSource, TDestination, FixedWidthReport>.Dispose()TransformerBase<TSource, TDestination, FixedWidthReport>.ReportingIntervalTransformerBase<TSource, TDestination, FixedWidthReport>.CurrentItemCountTransformerBase<TSource, TDestination, FixedWidthReport>.CurrentSkippedItemCountTransformerBase<TSource, TDestination, FixedWidthReport>.CurrentErrorItemCountTransformerBase<TSource, TDestination, FixedWidthReport>.MaximumItemCountTransformerBase<TSource, TDestination, FixedWidthReport>.SkipItemCountTransformerBase<TSource, TDestination, FixedWidthReport>.WorkerResilienceTransformerBase<TSource, TDestination, FixedWidthReport>.ErrorPolicy
Examples
using var extractor = new FixedWidthExtractor<LegacyRecord>(sourceReader);
using var transformer = new FixedWidthTransformer<LegacyRecord, ModernRecord>(
legacy => new ModernRecord { Id = legacy.OldId, Name = legacy.FullName });
using var loader = new FixedWidthLoader<ModernRecord>(destinationWriter);
var modern = transformer.TransformAsync(extractor.ExtractAsync(token), token);
await loader.LoadAsync(modern, token);
Constructors
FixedWidthTransformer(Func<TSource, TDestination>, ILogger<FixedWidthTransformer<TSource, TDestination>>?)
Creates a transformer that projects each source record with transform.
The projection handles every reformatting case — reordered, added, removed, or
format-converted fields.
public FixedWidthTransformer(Func<TSource, TDestination> transform, ILogger<FixedWidthTransformer<TSource, TDestination>>? logger = null)
Parameters
transformFunc<TSource, TDestination>The per-record projection.
loggerILogger<FixedWidthTransformer<TSource, TDestination>>An optional ILogger<TCategoryName> for diagnostic output. When null — or omitted — Instance is used and logging is disabled.
Exceptions
- ArgumentNullException
transformis null.
FixedWidthTransformer(Func<TSource, TDestination>, FixedWidthTransformerOptions?, ILogger<FixedWidthTransformer<TSource, TDestination>>?)
Initializes a new FixedWidthTransformer<TSource, TDestination> with the base-stage
configuration taken from options (ADR-0009).
public FixedWidthTransformer(Func<TSource, TDestination> transform, FixedWidthTransformerOptions? options, ILogger<FixedWidthTransformer<TSource, TDestination>>? logger = null)
Parameters
transformFunc<TSource, TDestination>The per-record transformation.
optionsFixedWidthTransformerOptionsThe stage configuration (
ReportingInterval,MaximumItemCount,SkipItemCount,ErrorPolicy); null keeps the defaults.loggerILogger<FixedWidthTransformer<TSource, TDestination>>The logger; null logs nothing.
Exceptions
- ArgumentNullException
transformis null.
Methods
ByMatchingProperties()
Creates a transformer that copies every source property to the destination
property of the same name and an assignable type. TDestination
must have a public parameterless constructor. Use the projection constructor for
anything beyond a straight same-name copy (reordering, format conversion, combining
fields).
public static FixedWidthTransformer<TSource, TDestination> ByMatchingProperties()
Returns
- FixedWidthTransformer<TSource, TDestination>
CreateProgressReport()
Creates a progress report object of type TProgress.
protected override FixedWidthReport CreateProgressReport()
Returns
- FixedWidthReport
TProgress - A new instance of the progress report object.
CreateProgressTimer(IProgress<FixedWidthReport>)
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<FixedWidthReport> progress)
Parameters
progressIProgress<FixedWidthReport>The progress sink that will receive callbacks.
Returns
- IProgressTimer
A started Wolfgang.Etl.Abstractions.IProgressTimer instance.
TransformWorkerAsync(IAsyncEnumerable<TSource>, CancellationToken)
The worker method that performs the actual transformation.
protected override IAsyncEnumerable<TDestination> TransformWorkerAsync(IAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
Parameters
sourceIAsyncEnumerable<TSource>cancellationTokenCancellationToken
Returns
- IAsyncEnumerable<TDestination>
IAsyncEnumerable<TDestination> - The result may be an empty sequence if no data is available or if the transformation fails.