Hi,
In the following method I didn't handle case of folder with extension of .gdb.
The needed checks:
I need the factory check.
Validate file exists is working => for folder
Validate file is not empty => for folder
And if all pass return
factory.TryCreate("Gdb", out converter)
How is can be done in best practice ?
I'm using .Net 10 on Windows ?
Thanks in advance,
/// <summary>
/// Attempts to create a converter for the specified GIS input file path with detailed diagnostic information.
/// </summary>
/// <param name="factory">The converter factory to use.</param>
/// <param name="gisInputFilePath">The path to the GIS input file.</param>
/// <param name="converter">When successful, contains the created converter; otherwise, <c>null</c>.</param>
/// <param name="detectedSourceFormat">Contains diagnostic information about the detection source format process (whether "GeoJson", "Shapefile", etc.).</param>
/// <param name="detectReason">Contains diagnostic information about the detection process.</param>
/// <returns><c>true</c> if converter creation succeeded; otherwise, <c>false</c>.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="factory"/> is null.</exception>
/// <remarks>
/// Detection priority:
/// 1. Archives: Fast-path extension checks → KMZ detection → JSON voting → requirement matching
/// 2. Single files: Explicit extension mapping → JSON format detection (with fallback) → generic extension mapping
///
/// All file reads are bounded and streaming. Archives are never extracted to disk.
/// </remarks>
public static bool TryCreateForInput(
this IConverterFactory factory,
string gisInputFilePath,
out IConverter? converter,
out string? detectedSourceFormat,
out string? detectReason)
{
converter = null;
detectReason = null;
detectedSourceFormat = null;
if (factory == null) throw new ArgumentNullException(nameof(factory));
// Validate input path is not null or empty
if (string.IsNullOrWhiteSpace(gisInputFilePath))
{
detectReason = "input path is null or whitespace";
Log.Error($"TryCreateForInput: {detectReason}");
return false;
}
// Validate file exists
if (!File.Exists(gisInputFilePath))
{
detectReason = $"file does not exist: {gisInputFilePath}";
Log.Error($"TryCreateForInput: {detectReason}");
return false;
}
// Validate file is not empty
FileInfo fileInfo;
try
{
fileInfo = new FileInfo(gisInputFilePath);
}
catch (Exception ex)
{
detectReason = $"failed to get file info: {ex.Message}";
Log.Error($"TryCreateForInput: {detectReason}", ex);
return false;
}
if (fileInfo.Length == 0)
{
detectReason = "file is empty (0 bytes)";
Log.Warn($"TryCreateForInput: {detectReason}");
return false;
}
try
{
return ConverterUtils.IsArchiveFile(gisInputFilePath)
? TryDetectArchiveFormat(factory, gisInputFilePath, out converter, out detectedSourceFormat, out detectReason)
: TryDetectSingleFileFormat(factory, gisInputFilePath, out converter, out detectedSourceFormat, out detectReason);
}
catch (Exception ex)
{
detectReason = $"unexpected error during format detection: {ex.GetType().Name} - {ex.Message}";
Log.Error(detectReason, ex);
return false;
}
}