Path: redb-route/redb.Route.File/FileComponent.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.File/FileComponent.cs
----
using redb.Route.Abstractions;
using redb.Route.Core;
using redb.Route.GenericFile;
namespace redb.Route.File;
///
/// File component. Scheme: "file".
/// Provides file system polling (consumer) and atomic file writing (producer).
/// URI: file:///C:/input?include=*.csv&delay=5000&noop=true
/// URI: file:///C:/output?fileName=${header.orderId}.json&fileExist=Override
///
public class FileComponent : ComponentBase
{
///
public override string Scheme => "file";
/// Structured XML form: <file directory="out/orders"/>.
public override string? StructuredPathSynonym => "directory";
///
public override IEndpoint CreateEndpoint(EndpointUri uri)
{
ArgumentNullException.ThrowIfNull(uri);
var options = new FileEndpointOptions();
options.BindFromUri(uri.RawParameters);
options.ResolveFilter(Context);
options.Validate();
return new FileEndpoint(uri, this, options);
}
}
///
/// File endpoint. Creates either a consumer (for polling) or a producer (for writing).
/// The path part of the URI is the base directory.
///
public class FileEndpoint : EndpointBase
{
/// Creates a file endpoint.
public FileEndpoint(EndpointUri uri, FileComponent component, FileEndpointOptions options)
: base(uri, component, options)
{
}
/// The base directory path derived from the endpoint URI.
public string DirectoryPath => NormalizeDirectoryPath(Uri.Path);
/// Gets the endpoint options for external access.
internal FileEndpointOptions EndpointOptions => Options;
///
public override IProducer CreateProducer()
{
return new FileProducer(this, Options);
}
///
public override IConsumer CreateConsumer(IProcessor processor)
{
ArgumentNullException.ThrowIfNull(processor);
return new FileConsumer(this, processor, Options);
}
private static string NormalizeDirectoryPath(string path)
{
// Handle URI-style paths: remove leading slash for Windows absolute paths
// e.g. "/C:/input" -> "C:/input", "/home/user/input" stays as-is on Linux
if (path.Length >= 3 && path[0] == '/' && char.IsLetter(path[1]) && path[2] == ':')
{
path = path[1..]; // Remove leading '/'
}
return Path.GetFullPath(path);
}
}