Class GenericFileConsumer<TOptions>

Assembly: redb.Route.GenericFile.dll

Template-method base class for all file-based consumers (local file, SFTP, FTP).
Owns the complete poll loop: enumerate → filter → sort → limit → per-file processing
(min-age, done-file, idempotency, read-lock, pre-move, create exchange, post-process).
Subclasses provide protocol-specific hooks via virtual/abstract methods.

public abstract class GenericFileConsumer<TOptions> : DrainableConsumer, IConsumer where TOptions : GenericFileEndpointOptions

Inheritance

Object→DrainableConsumer→GenericFileConsumer<TOptions>

Implements

Inherited Members

Properties

BasePath

Base path for file operations (directory for local, remote path for SFTP/FTP).

protected abstract string BasePath { get; }

ConsumerEndpoint

The endpoint this consumer is attached to.

protected override IEndpoint ConsumerEndpoint { get; }

Operations

File operations (protocol-specific adapter).

protected IFileOperations Operations { get; }

Options

Endpoint options.

protected TOptions Options { get; }

ProcessedCount

Total number of files successfully processed.

public long ProcessedCount { get; }

Methods

AcquireReadLockAsync(GenericFileInfo, CancellationToken)

Acquires a read lock on the file before processing. Returns true if lock was acquired.

protected virtual Task<bool> AcquireReadLockAsync(GenericFileInfo file, CancellationToken ct)

AfterPollAsync(List<GenericFileInfo>, CancellationToken)

Called after each poll cycle with the list of files that were polled.

protected virtual Task AfterPollAsync(List<GenericFileInfo> files, CancellationToken ct)

ApplyFilters(IEnumerable<GenericFileInfo>)

Applies Include/Exclude glob filters and excludes internal temp files.

protected virtual IEnumerable<GenericFileInfo> ApplyFilters(IEnumerable<GenericFileInfo> files)

BeforePollAsync(CancellationToken)

Called before each poll cycle. Override to connect to remote server,

protected virtual Task BeforePollAsync(CancellationToken ct)

CheckMaxAge(GenericFileInfo)

Checks maximum file age. Returns true if the file should be processed.

protected virtual bool CheckMaxAge(GenericFileInfo file)

CreateExchangeAsync(GenericFileInfo, string, CancellationToken)

Creates an exchange with the file body and protocol-specific headers.

protected virtual Task<Exchange> CreateExchangeAsync(GenericFileInfo file, string workPath, CancellationToken ct)

OnNoFilesFoundAsync(CancellationToken)

Called when a poll cycle finds no files. Override to send heartbeat exchanges.

protected virtual Task OnNoFilesFoundAsync(CancellationToken ct)

OnPollError(Exception)

Called when PollDirectory catches a non-cancellation exception.

protected virtual void OnPollError(Exception ex)

OnProcessingFailedAsync(GenericFileInfo, string, CancellationToken)

Called when processing fails (exchange.Exception is set and not handled). Override in a connector to move the

protected virtual Task OnProcessingFailedAsync(GenericFileInfo file, string workPath, CancellationToken ct)

OnProcessingFailedAsync(string, string, string, CancellationToken)

The compatibility form of . A

protected virtual Task OnProcessingFailedAsync(string filePath, string fileName, string basePath, CancellationToken ct)

PostProcessAsync(GenericFileInfo, string, CancellationToken)

Applies the configured post-processing strategy (noop/delete/moveTo) to a processed file. The file keys in

protected virtual Task PostProcessAsync(GenericFileInfo file, string workPath, CancellationToken ct)

PostProcessAsync(string, string, string, CancellationToken)

The compatibility form of . A subclass

protected virtual Task PostProcessAsync(string filePath, string fileName, string basePath, CancellationToken ct)

PreMoveFileAsync(GenericFileInfo, CancellationToken)

Moves a file to the PreMove directory before processing.

protected virtual Task<string> PreMoveFileAsync(GenericFileInfo file, CancellationToken ct)

ReleaseReadLockAsync(GenericFileInfo, CancellationToken)

Releases the read lock after processing. Override in local file consumer.

protected virtual Task ReleaseReadLockAsync(GenericFileInfo file, CancellationToken ct)

ResolveDirectory(string, string)

Resolves a directory path: if absolute, returns as-is; if relative, combines with basePath.

protected string ResolveDirectory(string dir, string basePath)

ResolveEncoding()

Resolves encoding from the option with UTF-8 fallback.

protected Encoding ResolveEncoding()

ResolveWorkPath(GenericFileInfo)

Path the file occupies once the read lock is held. Called after

protected virtual string ResolveWorkPath(GenericFileInfo file)

RunAsync(CancellationToken, CancellationToken)

Main consumer loop. Receives pollCt (stop accepting new work)

protected override Task RunAsync(CancellationToken pollCt, CancellationToken processingCt)

SetExchangeHeaders(IMessage, GenericFileInfo, string)

Sets protocol-specific headers on the exchange message.

protected abstract void SetExchangeHeaders(IMessage message, GenericFileInfo file, string workPath)

Constructors