Skip to content

Commit

Permalink
Implement force tiling maps/sync query parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangiebel committed Feb 14, 2024
1 parent 57b00cb commit 9b2357b
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 10 deletions.
3 changes: 2 additions & 1 deletion SS14.MapServer/Controllers/ImageController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ public async Task<IActionResult> UploadImage(string path, IFormFile file)
if (image == null)
{
image = new ImageFile();
image.Path = path;
_context.Add(image);
}

// TODO: Delete previous image file if image already exists in database
image.Path = path;

await _fileUploadService.UploadImage(image, file, image.InternalPath);
Expand Down
5 changes: 3 additions & 2 deletions SS14.MapServer/Controllers/MapController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,13 @@ public async Task<IActionResult> DeleteMap(string id, string gitRef)

[HttpPost("sync")]
[Consumes("application/json")]
public async Task<IActionResult> SyncMaps(List<string>? mapFileNames, bool syncAll)
public async Task<IActionResult> SyncMaps(List<string>? mapFileNames, bool syncAll, bool forceTiled)
{
var data = new JobDataMap
{
{Jobs.SyncMaps.MapListKey, mapFileNames ?? new List<string>() },
{Jobs.SyncMaps.SyncAllKey, syncAll}
{Jobs.SyncMaps.SyncAllKey, syncAll},
{Jobs.SyncMaps.ForceTiledKey, forceTiled}
};

await _schedulingService.RunJob<Jobs.SyncMaps>(nameof(Jobs.SyncMaps), "Sync", data);
Expand Down
5 changes: 4 additions & 1 deletion SS14.MapServer/Jobs/SyncMaps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ public class SyncMaps : IJob
{
public const string MapListKey = "Maps";
public const string SyncAllKey = "SyncAll";
public const string ForceTiledKey = "ForceTiled";
public const string GitRefKey = "GitRef";

private readonly ProcessQueue _processQueue;

public List<string>? Maps { get; set; }
public string GitRef { get; set; } = "master";
public bool SyncAll { get; set; } = false;
public bool ForceTiled { get; set; } = false;

public SyncMaps(ProcessQueue processQueue)
{
Expand All @@ -34,7 +36,8 @@ public async Task Execute(IJobExecutionContext context)
GitRef,
Maps!,
LogCompletion,
SyncAll: SyncAll);
SyncAll: SyncAll,
ForceTiled: ForceTiled);

if (!await _processQueue.TryQueueProcessItem(processItem))
throw new JobExecutionException("Failed to start map sync process. Process queue is full.");
Expand Down
3 changes: 2 additions & 1 deletion SS14.MapServer/MapProcessing/ProcessItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ public record ProcessItem(
IList<string> Maps,
Action<IServiceProvider, MapProcessResult> OnCompletion,
string? RepositoryUrl = null,
bool SyncAll = false);
bool SyncAll = false,
bool ForceTiled = false);
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public MapReaderServiceService(IConfiguration configuration, FileUploadService f
configuration.Bind(BuildConfiguration.Name, _buildConfiguration);
}

public async Task<IList<Guid>> UpdateMapsFromFs(string path, string gitRef = "master", CancellationToken cancellationToken = default)
public async Task<IList<Guid>> UpdateMapsFromFs(string path, string gitRef = "master", bool forceTiled = false, CancellationToken cancellationToken = default)
{
if (!Directory.Exists(path))
throw new DirectoryNotFoundException($"Map import path not found: {path}");
Expand Down Expand Up @@ -93,7 +93,7 @@ public async Task<IList<Guid>> UpdateMapsFromFs(string path, string gitRef = "ma
GridId = gridData.GridId,
Extent = gridData.Extent,
Offset = gridData.Offset,
Tiled = gridData.Tiled,
Tiled = forceTiled || gridData.Tiled,
};
map.Grids.Add(grid);
_context.Add(grid);
Expand Down
4 changes: 3 additions & 1 deletion SS14.MapServer/MapProcessing/Services/MapUpdateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public MapUpdateService(
/// <param name="maps">A list of map file names to be generated</param>
/// <param name="repositoryUrl">The clone url of the repository to clone from</param>
/// <param name="syncAll">Ignore the maps parameter and update all maps</param>
/// <param name="forceTiled">Force the map to be tiled after rendering</param>
/// <param name="cancellationToken"></param>
/// <exception cref="ArgumentOutOfRangeException"></exception>
/// <returns>The commit that was checked out for building and running the map renderer</returns>
Expand All @@ -50,6 +51,7 @@ public async Task<MapProcessResult> UpdateMapsFromGit(string directory,
IEnumerable<string> maps,
string? repositoryUrl = null,
bool syncAll = false,
bool forceTiled = false,
CancellationToken cancellationToken = default)
{
var workingDirectory = _gitService.Sync(directory, gitRef, repositoryUrl);
Expand Down Expand Up @@ -94,7 +96,7 @@ public async Task<MapProcessResult> UpdateMapsFromGit(string directory,
_ => throw new ArgumentOutOfRangeException()
};

var mapIds = await _mapReaderService.UpdateMapsFromFs(path, strippedGitRef, cancellationToken);
var mapIds = await _mapReaderService.UpdateMapsFromFs(path, strippedGitRef, forceTiled, cancellationToken);
return new MapProcessResult(strippedGitRef, mapIds);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ await mapUpdateService.UpdateMapsFromGit(
processItem.Maps,
processItem.RepositoryUrl,
processItem.SyncAll,
processItem.ForceTiled,
cancellationToken)
.ContinueWith(
task =>
Expand Down
5 changes: 4 additions & 1 deletion SS14.MapServer/Services/FileUploadService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ private async Task<string> UploadAndProcessTiledImage(Guid mapGuid, string mapPa
{ProcessTiledImage.ProcessOptionsKey, processingOptions}
};

await _schedulingService.RunJob<ProcessTiledImage>(nameof(ProcessTiledImage), "Processing", data);
await _schedulingService.RunJob<ProcessTiledImage>(
$"{nameof(ProcessTiledImage)}-{mapGuid.ToString()}-{gridId}",
"Processing",
data);

return targetPath;
}
Expand Down
2 changes: 1 addition & 1 deletion SS14.MapServer/Services/Interfaces/IMapReaderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ namespace SS14.MapServer.Services.Interfaces;

public interface IMapReaderService
{
Task<IList<Guid>> UpdateMapsFromFs(string path, string gitRef = "master", CancellationToken cancellationToken = default);
Task<IList<Guid>> UpdateMapsFromFs(string path, string gitRef = "master", bool forceTiled = false, CancellationToken cancellationToken = default);

}

0 comments on commit 9b2357b

Please sign in to comment.