added base settings, console command to sync images and empty image synchronizer

This commit is contained in:
Philipp Häfelfinger 2023-09-02 11:52:03 +02:00
parent 105c69fbcb
commit f705babdc3
9 changed files with 73 additions and 9 deletions

View File

@ -0,0 +1,9 @@
using Spectre.Console.Cli;
namespace PiwigoDirectorySync.Commands;
public class CommonCommandSettings : CommandSettings
{
[CommandArgument(0, "<PiwigoServerId>")]
public int PiwigoServerId { get; set; }
}

View File

@ -5,11 +5,8 @@ using Spectre.Console.Cli;
namespace PiwigoDirectorySync.Commands;
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")]
public class ScanSettings : CommandSettings
public class ScanSettings : CommonCommandSettings
{
[CommandArgument(0, "<PiwigoServerId>")]
public int PiwigoServerId { get; set; }
[CommandOption("-d|--mark-for-delete")]
[DefaultValue(false)]
public bool MarkForDelete { get; set; }

View File

@ -1,11 +1,8 @@
using System.Diagnostics.CodeAnalysis;
using Spectre.Console.Cli;
namespace PiwigoDirectorySync.Commands;
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")]
public class SyncAlbumsSettings : CommandSettings
public class SyncAlbumsSettings : CommonCommandSettings
{
[CommandArgument(0, "<PiwigoServerId>")]
public int PiwigoServerId { get; set; }
}

View File

@ -0,0 +1,33 @@
using System.Diagnostics;
using Microsoft.Extensions.Logging;
using PiwigoDirectorySync.Services;
using Spectre.Console.Cli;
namespace PiwigoDirectorySync.Commands;
public class SyncImagesCommand : AsyncCommand<SyncImagesSettings>
{
private readonly IImageSynchronizer _imageSynchronizer;
private readonly ILogger<SyncImagesCommand> _logger;
public SyncImagesCommand(ILogger<SyncImagesCommand> logger, IImageSynchronizer imageSynchronizer)
{
_logger = logger;
_imageSynchronizer = imageSynchronizer;
}
public override async Task<int> ExecuteAsync(CommandContext context, SyncImagesSettings settings)
{
_logger.LogInformation("Starting image synchronization");
var stopWatch = Stopwatch.StartNew();
var cancellationTokenSource = new CancellationTokenSource();
await _imageSynchronizer.SynchronizeImages(settings.PiwigoServerId, cancellationTokenSource.Token);
stopWatch.Stop();
_logger.LogInformation("Synchronized all images with piwigo server {SettingsPiwigoServerId} in {ElapsedTotalSeconds} seconds", settings.PiwigoServerId,
stopWatch.Elapsed.TotalSeconds);
return 0;
}
}

View File

@ -0,0 +1,5 @@
namespace PiwigoDirectorySync.Commands;
public class SyncImagesSettings : CommonCommandSettings
{
}

View File

@ -17,6 +17,7 @@ registrations.AddTransient<IPiwigoClientFactory, PiwigoClientFactory>();
registrations.AddTransient<IFileIndexer, FileIndexer>();
registrations.AddTransient<IFileSystemScanner, FileSystemScanner>();
registrations.AddTransient<IAlbumSynchronizer, AlbumSynchronizer>();
registrations.AddTransient<IImageSynchronizer, ImageSynchronizer>();
var registrar = new DependencyInjectionTypeRegistrar(registrations);
@ -29,7 +30,11 @@ app.Configure(config =>
#endif
config.AddCommand<ScanCommand>("scan");
config.AddBranch("sync", c => { c.AddCommand<SyncAlbumsCommand>("albums"); });
config.AddBranch("sync", c =>
{
c.AddCommand<SyncAlbumsCommand>("albums");
c.AddCommand<SyncImagesCommand>("images");
});
});
return app.Run(args);

View File

@ -18,6 +18,12 @@
"commandLineArgs": "sync albums 1",
"environmentVariables": {
}
},
"SyncImages": {
"commandName": "Project",
"commandLineArgs": "sync images 1",
"environmentVariables": {
}
}
}
}

View File

@ -0,0 +1,6 @@
namespace PiwigoDirectorySync.Services;
public interface IImageSynchronizer
{
Task SynchronizeImages(int piwigoServerId, CancellationToken ct);
}

View File

@ -0,0 +1,6 @@
namespace PiwigoDirectorySync.Services;
public class ImageSynchronizer : IImageSynchronizer
{
public Task SynchronizeImages(int piwigoServerId, CancellationToken ct) => throw new NotImplementedException();
}