mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-04-22 11:36:38 +00:00
zip file for tiles
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.IO.Compression;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -307,13 +308,21 @@ public class RouteProcessingService : BackgroundService
|
||||
await StitchRouteTilesAsync(allTiles.Values.ToList(), stitchedImagePath, route.ZoomLevel, geofencePolygonBounds, routePoints, cancellationToken);
|
||||
}
|
||||
|
||||
string? tilesZipPath = null;
|
||||
if (route.CreateTilesZip)
|
||||
{
|
||||
tilesZipPath = Path.Combine(readyDir, $"route_{routeId}_tiles.zip");
|
||||
await CreateTilesZipAsync(tilesZipPath, allTiles.Values, cancellationToken);
|
||||
}
|
||||
|
||||
var summaryPath = Path.Combine(readyDir, $"route_{routeId}_summary.txt");
|
||||
await GenerateRouteSummaryAsync(summaryPath, route, allTiles.Count, totalTilesFromRegions, duplicateTiles, cancellationToken);
|
||||
await GenerateRouteSummaryAsync(summaryPath, route, allTiles.Count, totalTilesFromRegions, duplicateTiles, tilesZipPath, cancellationToken);
|
||||
|
||||
route.MapsReady = true;
|
||||
route.CsvFilePath = csvPath;
|
||||
route.SummaryFilePath = summaryPath;
|
||||
route.StitchedImagePath = stitchedImagePath;
|
||||
route.TilesZipPath = tilesZipPath;
|
||||
route.UpdatedAt = DateTime.UtcNow;
|
||||
|
||||
await _routeRepository.UpdateRouteAsync(route);
|
||||
@@ -400,6 +409,7 @@ public class RouteProcessingService : BackgroundService
|
||||
int uniqueTiles,
|
||||
int totalTilesFromRegions,
|
||||
int duplicateTiles,
|
||||
string? tilesZipPath,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var summary = new System.Text.StringBuilder();
|
||||
@@ -428,6 +438,10 @@ public class RouteProcessingService : BackgroundService
|
||||
{
|
||||
summary.AppendLine($"- Stitched Map: route_{route.Id}_stitched.jpg");
|
||||
}
|
||||
if (tilesZipPath != null)
|
||||
{
|
||||
summary.AppendLine($"- Tiles ZIP: route_{route.Id}_tiles.zip");
|
||||
}
|
||||
summary.AppendLine();
|
||||
summary.AppendLine($"Completed: {DateTime.UtcNow:yyyy-MM-dd HH:mm:ss} UTC");
|
||||
|
||||
@@ -670,6 +684,52 @@ public class RouteProcessingService : BackgroundService
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Task CreateTilesZipAsync(
|
||||
string zipFilePath,
|
||||
IEnumerable<TileInfo> tiles,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
if (File.Exists(zipFilePath))
|
||||
{
|
||||
File.Delete(zipFilePath);
|
||||
}
|
||||
|
||||
using var zipArchive = ZipFile.Open(zipFilePath, ZipArchiveMode.Create);
|
||||
int addedFiles = 0;
|
||||
int missingFiles = 0;
|
||||
|
||||
foreach (var tile in tiles)
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
break;
|
||||
|
||||
if (File.Exists(tile.FilePath))
|
||||
{
|
||||
try
|
||||
{
|
||||
var fileName = Path.GetFileName(tile.FilePath);
|
||||
zipArchive.CreateEntryFromFile(tile.FilePath, fileName, CompressionLevel.Optimal);
|
||||
addedFiles++;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Failed to add tile to zip: {FilePath}", tile.FilePath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Tile file not found for zip: {FilePath}", tile.FilePath);
|
||||
missingFiles++;
|
||||
}
|
||||
}
|
||||
|
||||
_logger.LogInformation("Tiles zip created: {ZipPath} with {AddedFiles} tiles ({MissingFiles} missing)",
|
||||
zipFilePath, addedFiles, missingFiles);
|
||||
}, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
public class TileInfo
|
||||
|
||||
@@ -117,6 +117,7 @@ public class RouteService : IRouteService
|
||||
TotalDistanceMeters = totalDistance,
|
||||
TotalPoints = allPoints.Count,
|
||||
RequestMaps = request.RequestMaps,
|
||||
CreateTilesZip = request.CreateTilesZip,
|
||||
MapsReady = false,
|
||||
CreatedAt = now,
|
||||
UpdatedAt = now
|
||||
@@ -203,6 +204,7 @@ public class RouteService : IRouteService
|
||||
CsvFilePath = routeEntity.CsvFilePath,
|
||||
SummaryFilePath = routeEntity.SummaryFilePath,
|
||||
StitchedImagePath = routeEntity.StitchedImagePath,
|
||||
TilesZipPath = routeEntity.TilesZipPath,
|
||||
CreatedAt = routeEntity.CreatedAt,
|
||||
UpdatedAt = routeEntity.UpdatedAt
|
||||
};
|
||||
@@ -241,6 +243,7 @@ public class RouteService : IRouteService
|
||||
CsvFilePath = route.CsvFilePath,
|
||||
SummaryFilePath = route.SummaryFilePath,
|
||||
StitchedImagePath = route.StitchedImagePath,
|
||||
TilesZipPath = route.TilesZipPath,
|
||||
CreatedAt = route.CreatedAt,
|
||||
UpdatedAt = route.UpdatedAt
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user