-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #429 from Laixer/develop
v2.9.4
- Loading branch information
Showing
36 changed files
with
435 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace FunderMaps.Cli.Drivers | ||
{ | ||
internal abstract class CommandDriver | ||
{ | ||
protected static Task ResolveSelfScope<TDriver>(IServiceProvider services, Func<TDriver, Task> shadowFunc) | ||
{ | ||
var scopeFactory = services.GetRequiredService<IServiceScopeFactory>(); | ||
using var serviceScope = scopeFactory.CreateScope(); | ||
var serviceProvider = serviceScope.ServiceProvider; | ||
TDriver driver = serviceProvider.GetService<TDriver>(); | ||
return shadowFunc(driver); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using System.CommandLine.Invocation; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace FunderMaps.Cli | ||
{ | ||
/// <summary> | ||
/// Driver command handler. | ||
/// </summary> | ||
public static class DriverHandler | ||
{ | ||
/// <summary> | ||
/// Create delegate with default parametes. | ||
/// </summary> | ||
/// <param name="action">Handler action.</param> | ||
/// <returns>See <see cref="ICommandHandler"/>.</returns> | ||
public static ICommandHandler InstantiateDriver(Func<FileInfo, IHost, Task> action) | ||
=> CommandHandler.Create<FileInfo, IHost>(action); | ||
|
||
/// <summary> | ||
/// Create delegate with default parametes. | ||
/// </summary> | ||
/// <param name="action">Handler action.</param> | ||
/// <returns>See <see cref="ICommandHandler"/>.</returns> | ||
public static ICommandHandler InstantiateDriver<T0>(Func<FileInfo, IHost, T0, Task> action) | ||
=> CommandHandler.Create<FileInfo, IHost, T0>(action); | ||
|
||
/// <summary> | ||
/// Create delegate with default parametes. | ||
/// </summary> | ||
/// <param name="action">Handler action.</param> | ||
/// <returns>See <see cref="ICommandHandler"/>.</returns> | ||
public static ICommandHandler InstantiateDriver<T0, T1>(Func<FileInfo, IHost, T0, T1, Task> action) | ||
=> CommandHandler.Create<FileInfo, IHost, T0, T1>(action); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using FunderMaps.Core.Interfaces; | ||
using FunderMaps.Core.MapBundle; | ||
using FunderMaps.Core.Threading; | ||
using FunderMaps.Core.Types; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace FunderMaps.Cli.Drivers | ||
{ | ||
/// <summary> | ||
/// gRPC channel factory. | ||
/// </summary> | ||
internal class BatchDriver : CommandDriver | ||
{ | ||
private readonly IBatchService _batchService; | ||
private readonly IBundleService _bundleService; | ||
|
||
/// <summary> | ||
/// Create new instance. | ||
/// </summary> | ||
public BatchDriver(IBatchService batchService, IBundleService bundleService) | ||
=> (_batchService, _bundleService) = (batchService, bundleService); | ||
|
||
private async Task StatusAsync(CancellationToken token = default) | ||
{ | ||
DispatchManagerStatus status = await _batchService.StatusAsync(token); | ||
Console.WriteLine($"Jobs failed: {status.JobsFailed}"); | ||
Console.WriteLine($"Jobs succeeded: {status.JobsSucceeded}"); | ||
} | ||
|
||
private async Task BuildBundleAsync(IEnumerable<Guid> bundleIdList, CancellationToken token = default) | ||
{ | ||
foreach (var bundleId in bundleIdList) | ||
{ | ||
await _bundleService.BuildAsync(new BundleBuildingContext | ||
{ | ||
BundleId = bundleId, | ||
Formats = new List<GeometryFormat> { GeometryFormat.GeoPackage }, | ||
}); | ||
} | ||
} | ||
|
||
private async Task BuildAllAsync(CancellationToken token = default) | ||
{ | ||
await _bundleService.BuildAllAsync(new BundleBuildingContext | ||
{ | ||
Formats = new List<GeometryFormat> { GeometryFormat.GeoPackage }, | ||
}); | ||
} | ||
|
||
#region Factory Methods | ||
|
||
public static Task StatusAsync(FileInfo config, IHost host) | ||
=> ResolveSelfScope<BatchDriver>(host.Services, self => self.StatusAsync()); | ||
|
||
public static Task BuildBundleAsync(FileInfo config, IHost host, IEnumerable<Guid> bundleId) | ||
=> ResolveSelfScope<BatchDriver>(host.Services, self => self.BuildBundleAsync(bundleId)); | ||
|
||
public static Task BuildAllAsync(FileInfo config, IHost host) | ||
=> ResolveSelfScope<BatchDriver>(host.Services, self => self.BuildAllAsync()); | ||
|
||
#endregion Factory Methods | ||
} | ||
} |
Oops, something went wrong.