Path: redb-route/redb.Route.GenericFile/GenericFileEndpointOptions.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.GenericFile/GenericFileEndpointOptions.cs
----
using redb.Route.Core;
namespace redb.Route.GenericFile;
///
/// Base endpoint options shared by all file-based transports (local file, SFTP, FTP).
/// Provides consumer polling, post-processing, idempotency, done-file, and producer write options.
///
public abstract class GenericFileEndpointOptions : EndpointOptions
{
// ═══════════════════════════════════════════════════════════════════
// CONSUMER: Polling
// ═══════════════════════════════════════════════════════════════════
/// Polling delay in milliseconds between directory scans. (default: 500)
public int Delay { get; set; } = 500;
/// Initial delay before the first poll in milliseconds. (default: 0)
public int InitialDelay { get; set; }
/// Glob pattern to include files (e.g. "*.csv"). Multiple patterns: "*.csv,*.json". Empty = all files.
public string Include { get; set; } = "";
/// Glob pattern to exclude files (e.g. "*.tmp,.*"). Empty = exclude nothing.
public string Exclude { get; set; } = "";
///
/// Ant-style patterns over the path relative to the polled directory, several separated by
/// commas: TYPE_A/outbox/*.csv,TYPE_B/outbox/*.csv. Unlike , which
/// only ever sees a file name, this is how a recursive poll names the directories it wants.
/// Empty = every path. Requires to reach anything below the top level.
///
public string AntInclude { get; set; } = "";
///
/// Ant-style patterns over the relative path that drop a file: archive/**,**/*.tmp.
/// Applied after . Empty = drop nothing.
///
public string AntExclude { get; set; } = "";
///
/// Whether and respect case. (default: true,
/// as in Apache Camel — a remote path is case-sensitive even when the local file system is not)
///
public bool AntFilterCaseSensitive { get; set; } = true;
///
/// Condition deciding whether a subdirectory is walked into, evaluated against the directory's
/// own headers while the listing runs — a directory turned down here is never listed, which is
/// what makes a poll over a partner tree of two hundred directories affordable. Empty = walk
/// into every subdirectory. Only consulted when is on.
///
public string FilterDirectory { get; set; } = "";
///
/// Condition deciding whether a polled file is taken, evaluated against the file's headers
/// before anything reads or moves it (e.g. header.redbFile.Length > 1024).
/// Empty = take every file the other filters left.
///
public string FilterFile { get; set; } = "";
///
/// Name of an in the route registry (filter=#myFilter),
/// for a decision that needs code rather than a condition string. Resolved by the component.
///
[RegistryReference(typeof(IGenericFileFilter))]
public string Filter { get; set; } = "";
///
/// The filter bean itself, put here by the component once it resolved from
/// the registry. Set it directly when the route is built in code and has no registry entry.
///
public IGenericFileFilter? FilterInstance { get; set; }
/// Whether to recurse into subdirectories. (default: false)
public bool Recursive { get; set; }
/// Maximum recursion depth when Recursive=true. 0 = unlimited. (default: 0)
public int MaxDepth { get; set; }
/// Minimum recursion depth. Files at shallower levels are skipped. (default: 0)
public int MinDepth { get; set; }
/// Sort order for polled files. (default: None)
public GenericFileSortBy SortBy { get; set; } = GenericFileSortBy.None;
/// Maximum number of files to pick up per poll. 0 = unlimited. (default: 0)
public int MaxMessagesPerPoll { get; set; }
/// Minimum file age in milliseconds before the file is eligible for pickup. (default: 0)
public long MinAge { get; set; }
// ── Poll backoff (Apache Camel ScheduledPollConsumer parity) ──
///
/// How many subsequent polls to skip once a backoff threshold is reached. 0 = backoff disabled (default).
/// Requires at least one of / to be set.
///
public int BackoffMultiplier { get; set; }
///
/// Number of consecutive idle polls (a poll that created no exchange) that arms the backoff skip.
/// 0 = idle backoff disabled (default).
///
public int BackoffIdleThreshold { get; set; }
///
/// Number of consecutive failed polls (the poll itself threw — e.g. the server is down) that arms the
/// backoff skip. 0 = error backoff disabled (default).
///
public int BackoffErrorThreshold { get; set; }
///
/// Extension beyond Camel parity (default false): count a poll that created at least one exchange whose
/// route all failed (unhandled) as an Error for . Lets a route
/// back off polling when the downstream (e.g. the database) is down and every file fails, instead of
/// re-reading the same files every . A poll with any successful exchange counts as
/// success. Needs and to have effect.
///
public bool BackoffOnFailedExchanges { get; set; }
// ═══════════════════════════════════════════════════════════════════
// CONSUMER: Post-processing
// ═══════════════════════════════════════════════════════════════════
/// If true, the file is not moved or deleted after processing (read-only mode). (default: false)
public bool Noop { get; set; }
/// If true, delete the file after successful processing. (default: false)
public bool Delete { get; set; }
/// Directory to move files to after successful processing. Supports the file keys of (${file:name}, ${file:ext}).
public string MoveTo { get; set; } = "";
/// Strategy when the target file in MoveTo already exists. (default: Override)
public GenericFileExistStrategy MoveExisting { get; set; } = GenericFileExistStrategy.Override;
/// Directory to move files to BEFORE processing (pre-move for concurrency safety).
public string PreMove { get; set; } = "";
// ═══════════════════════════════════════════════════════════════════
// CONSUMER: Idempotency
// ═══════════════════════════════════════════════════════════════════
/// If true, skip files that have already been processed (tracked by idempotent key). (default: false)
public bool Idempotent { get; set; }
/// Expression for the idempotent key. Default uses path + last modified + size.
public string IdempotentKey { get; set; } = "";
// ═══════════════════════════════════════════════════════════════════
// CONSUMER: Done file
// ═══════════════════════════════════════════════════════════════════
///
/// Pattern for a "done" marker file. If set, the consumer waits for this marker before processing.
/// Example: "${file:name}.done" — processes "order.csv" only when "order.csv.done" exists.
///
public string DoneFileName { get; set; } = "";
// ═══════════════════════════════════════════════════════════════════
// CONSUMER: Body
// ═══════════════════════════════════════════════════════════════════
///
/// If true, the consumer sets the exchange body to a Stream instead of reading
/// the entire file into a byte array. The stream is closed by Exchange.DisposeAsync(). (default: false)
///
public bool StreamBody { get; set; }
// ═══════════════════════════════════════════════════════════════════
// PRODUCER: Write
// ═══════════════════════════════════════════════════════════════════
/// Dynamic file name for the producer. Supports ${header.xxx} expressions.
public DynamicValue? FileName { get; set; }
/// Strategy when the target file already exists. (default: Override)
public GenericFileExistStrategy FileExist { get; set; } = GenericFileExistStrategy.Override;
/// Prefix for the temp file during write (e.g. ".redb_"). Empty = write directly.
public string TempPrefix { get; set; } = "";
///
/// Full temp file name, in the target's directory. Overrides TempPrefix if set. The file keys read the target file
/// (${file:name}.part, ${file:name.noext}.tmp), matching ignoring case as in the consumer options.
///
public string TempFileName { get; set; } = "";
/// File encoding (default: "utf-8").
public string Charset { get; set; } = "utf-8";
/// If true, create the target directory if it doesn't exist. (default: true)
public bool AutoCreate { get; set; } = true;
/// If true, allow writing an empty file when body is null. (default: false)
public bool AllowNullBody { get; set; }
/// Characters to append after each Append write (e.g. "\n"). Empty = nothing.
public string AppendChars { get; set; } = "";
/// If true, delete the target file before writing when using Override strategy. (default: true)
public bool EagerDeleteTargetFile { get; set; } = true;
// ═══════════════════════════════════════════════════════════════════
// VALIDATION (base — subclasses should call base.ValidateCommon())
// ═══════════════════════════════════════════════════════════════════
///
/// Validates common file endpoint options. Subclasses should call this from their Validate() method.
///
protected void ValidateCommon()
{
if (Delay < 0)
throw new ArgumentOutOfRangeException(nameof(Delay), Delay, "Delay cannot be negative.");
if (InitialDelay < 0)
throw new ArgumentOutOfRangeException(nameof(InitialDelay), InitialDelay, "InitialDelay cannot be negative.");
if (MaxDepth < 0)
throw new ArgumentOutOfRangeException(nameof(MaxDepth), MaxDepth, "MaxDepth cannot be negative.");
if (MinDepth < 0)
throw new ArgumentOutOfRangeException(nameof(MinDepth), MinDepth, "MinDepth cannot be negative.");
if (MaxMessagesPerPoll < 0)
throw new ArgumentOutOfRangeException(nameof(MaxMessagesPerPoll), MaxMessagesPerPoll,
"MaxMessagesPerPoll cannot be negative.");
if (MinAge < 0)
throw new ArgumentOutOfRangeException(nameof(MinAge), MinAge, "MinAge cannot be negative.");
if (Noop && Delete)
throw new InvalidOperationException("Cannot set both Noop=true and Delete=true.");
if (Noop && !string.IsNullOrEmpty(MoveTo))
throw new InvalidOperationException("Cannot set both Noop=true and MoveTo.");
if (Delete && !string.IsNullOrEmpty(MoveTo))
throw new InvalidOperationException("Cannot set both Delete=true and MoveTo. Choose one post-processing strategy.");
// The file keys of the consumer options, checked here so a wrong key fails when the endpoint is created.
GenericFileUtils.ValidateFileKeys("moveTo", MoveTo);
GenericFileUtils.ValidateFileKeys("preMove", PreMove);
GenericFileUtils.ValidateFileKeys("doneFileName", DoneFileName);
GenericFileUtils.ValidateFileKeys("idempotentKey", IdempotentKey);
GenericFileUtils.ValidateFileKeys("tempFileName", TempFileName);
if (BackoffMultiplier < 0)
throw new ArgumentOutOfRangeException(nameof(BackoffMultiplier), BackoffMultiplier,
"BackoffMultiplier cannot be negative.");
if (BackoffIdleThreshold < 0)
throw new ArgumentOutOfRangeException(nameof(BackoffIdleThreshold), BackoffIdleThreshold,
"BackoffIdleThreshold cannot be negative.");
if (BackoffErrorThreshold < 0)
throw new ArgumentOutOfRangeException(nameof(BackoffErrorThreshold), BackoffErrorThreshold,
"BackoffErrorThreshold cannot be negative.");
// Camel refuses backoffMultiplier without a threshold; we also refuse a threshold without a
// multiplier, since that configuration is ambiguous (a threshold that can never skip anything).
var hasThreshold = BackoffIdleThreshold > 0 || BackoffErrorThreshold > 0;
if (BackoffMultiplier > 0 && !hasThreshold)
throw new InvalidOperationException(
"BackoffMultiplier requires at least one of BackoffIdleThreshold / BackoffErrorThreshold to be set.");
if (BackoffMultiplier == 0 && hasThreshold)
throw new InvalidOperationException(
"BackoffIdleThreshold / BackoffErrorThreshold require BackoffMultiplier to be set (> 0).");
}
}