Class GenericFileProducer<TOptions>
Template-method base class for all file-based producers (local file, SFTP, FTP).
Owns the complete write flow: resolve body → resolve path → handle existing file →
write via temp → atomic rename → cleanup on failure.
Subclasses provide protocol-specific hooks (connection, chmod, jail check).
public abstract class GenericFileProducer<TOptions> : IProducer, IProcessor where TOptions : GenericFileEndpointOptions
Inheritance
Implements
Properties
FileNameProducedHeader
Header name for the produced file path (e.g. "redbFile.NameProduced").
protected abstract string FileNameProducedHeader { get; }
Methods
AfterWriteAsync(IExchange, string, CancellationToken)
Called after a successful write. Override for chmod, keepLastModified, content-type inference.
protected virtual Task AfterWriteAsync(IExchange exchange, string targetPath, CancellationToken ct)
AppendToFile(string, object?, CancellationToken)
Appends the body to the given path.
protected Task AppendToFile(string path, object? body, CancellationToken ct)
BeforeWriteAsync(string, CancellationToken)
Called before writing. Override to connect to remote server, auto-create directory with chmod, etc.
protected virtual Task BeforeWriteAsync(string targetDir, CancellationToken ct)
MoveExistingFile(string, CancellationToken)
Moves an existing file at the target path to a backup name.
protected virtual Task MoveExistingFile(string path, CancellationToken ct)
OnWriteCompletedAsync(IExchange, string, CancellationToken)
Called after write or early return (Ignore, Append). Override to disconnect if configured.
protected virtual Task OnWriteCompletedAsync(IExchange exchange, string targetPath, CancellationToken ct)
Process(IExchange, CancellationToken)
Processes the exchange asynchronously.
public Task Process(IExchange exchange, CancellationToken ct = default)
ResolveBody(IExchange)
Extracts the body from the exchange (Out preferred, falls back to In).
protected object? ResolveBody(IExchange exchange)
ResolveEncoding()
Resolves encoding from the Charset option with UTF-8 fallback.
protected Encoding ResolveEncoding()
ResolveTargetPath(IExchange)
Resolves the target file path from the FileName option or exchange headers.
protected virtual string ResolveTargetPath(IExchange exchange)
ResolveTempPath(string)
Computes the temp file path if TempPrefix or TempFileName is configured. The file keys in TempFileName
protected string ResolveTempPath(string targetPath)
Start(CancellationToken)
Starts the producer.
public virtual Task Start(CancellationToken ct = default)
ValidatePath(string)
Validates the target path before writing. Override for jail-directory checks.
protected virtual void ValidatePath(string targetPath)
WriteBody(string, object?, CancellationToken)
Writes the body to the given path.
protected Task WriteBody(string path, object? body, CancellationToken ct)
Constructors
GenericFileProducer(IEndpoint, TOptions, IFileOperations)
Creates a generic file producer.