Add contextual fiducial point downloads
This commit is contained in:
1 parent
85e1c93d8a
commit
ce355f820c
5 files changed
+262
-28
No files matched your search
@@ -65,7 +65,25 @@ public sealed partial class FiducialPointService
|
||||
new Dictionary<string, string> { ["foglio"] = normalizedSheet },
|
||||
cancellationToken);
|
||||
|
||||
return DownloadLinkRegex().Matches(html)
|
||||
return ParseFiducialLinks(html);
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<FiducialPointEntry>> GetFiducialsAsync(
|
||||
string municipalityCode,
|
||||
string sheet,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var code = NormalizeCode(municipalityCode);
|
||||
var normalizedSheet = NormalizeSheet(sheet);
|
||||
var html = await GetHtmlAsync(
|
||||
$"risultato.php?co={Uri.EscapeDataString(code)}&foglio={Uri.EscapeDataString(normalizedSheet)}",
|
||||
cancellationToken);
|
||||
|
||||
return ParseFiducialLinks(html);
|
||||
}
|
||||
|
||||
private static IReadOnlyList<FiducialPointEntry> ParseFiducialLinks(string html) =>
|
||||
DownloadLinkRegex().Matches(html)
|
||||
.Select(match =>
|
||||
{
|
||||
var relativeUrl = WebUtility.HtmlDecode(match.Groups["url"].Value);
|
||||
@@ -77,7 +95,6 @@ public sealed partial class FiducialPointService
|
||||
.DistinctBy(item => item.Identifier, StringComparer.OrdinalIgnoreCase)
|
||||
.OrderBy(item => item.Identifier, StringComparer.OrdinalIgnoreCase)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<MappedFiducialPoint>> GetMappedFiducialsAsync(
|
||||
string municipalityCode,
|
||||
@@ -85,7 +102,7 @@ public sealed partial class FiducialPointService
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var municipality = NormalizeCode(municipalityCode);
|
||||
if (!int.TryParse(new string(sheet.Where(char.IsDigit).ToArray()), out var sheetNumber))
|
||||
if (!int.TryParse(NormalizeSheet(sheet), out var sheetNumber))
|
||||
{
|
||||
throw new ArgumentException("Numero di foglio non valido.", nameof(sheet));
|
||||
}
|
||||
@@ -178,6 +195,19 @@ public sealed partial class FiducialPointService
|
||||
? property.ToString().Trim()
|
||||
: string.Empty;
|
||||
|
||||
private static string NormalizeSheet(string sheet)
|
||||
{
|
||||
var digits = new string((sheet ?? string.Empty).Where(char.IsDigit).ToArray());
|
||||
if (string.IsNullOrWhiteSpace(digits))
|
||||
{
|
||||
throw new ArgumentException("Numero di foglio non valido.", nameof(sheet));
|
||||
}
|
||||
|
||||
return int.TryParse(digits, out var number)
|
||||
? number.ToString(System.Globalization.CultureInfo.InvariantCulture)
|
||||
: digits;
|
||||
}
|
||||
|
||||
private async Task<string> GetHtmlAsync(string relativeUrl, CancellationToken cancellationToken)
|
||||
{
|
||||
using var response = await _httpClient.GetAsync(ServiceBaseUrl + relativeUrl, cancellationToken);
|
||||
|
||||
Reference in new issue
Block a user