From f705babdc386e86858feeb03a54fc677b95ea172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=A4felfinger?= Date: Sat, 2 Sep 2023 11:52:03 +0200 Subject: [PATCH] added base settings, console command to sync images and empty image synchronizer --- .../Commands/CommonCommandSettings.cs | 9 +++++ PiwigoDirectorySync/Commands/ScanSettings.cs | 5 +-- .../Commands/SyncAlbumsSettings.cs | 5 +-- .../Commands/SyncImagesCommand.cs | 33 +++++++++++++++++++ .../Commands/SyncImagesSettings.cs | 5 +++ PiwigoDirectorySync/Program.cs | 7 +++- .../Properties/launchSettings.json | 6 ++++ .../Services/IImageSynchronizer.cs | 6 ++++ .../Services/ImageSynchronizer.cs | 6 ++++ 9 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 PiwigoDirectorySync/Commands/CommonCommandSettings.cs create mode 100644 PiwigoDirectorySync/Commands/SyncImagesCommand.cs create mode 100644 PiwigoDirectorySync/Commands/SyncImagesSettings.cs create mode 100644 PiwigoDirectorySync/Services/IImageSynchronizer.cs create mode 100644 PiwigoDirectorySync/Services/ImageSynchronizer.cs diff --git a/PiwigoDirectorySync/Commands/CommonCommandSettings.cs b/PiwigoDirectorySync/Commands/CommonCommandSettings.cs new file mode 100644 index 0000000..7442047 --- /dev/null +++ b/PiwigoDirectorySync/Commands/CommonCommandSettings.cs @@ -0,0 +1,9 @@ +using Spectre.Console.Cli; + +namespace PiwigoDirectorySync.Commands; + +public class CommonCommandSettings : CommandSettings +{ + [CommandArgument(0, "")] + public int PiwigoServerId { get; set; } +} \ No newline at end of file diff --git a/PiwigoDirectorySync/Commands/ScanSettings.cs b/PiwigoDirectorySync/Commands/ScanSettings.cs index 848e89c..a3faab2 100644 --- a/PiwigoDirectorySync/Commands/ScanSettings.cs +++ b/PiwigoDirectorySync/Commands/ScanSettings.cs @@ -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, "")] - public int PiwigoServerId { get; set; } - [CommandOption("-d|--mark-for-delete")] [DefaultValue(false)] public bool MarkForDelete { get; set; } diff --git a/PiwigoDirectorySync/Commands/SyncAlbumsSettings.cs b/PiwigoDirectorySync/Commands/SyncAlbumsSettings.cs index 7b79840..6f4c8b6 100644 --- a/PiwigoDirectorySync/Commands/SyncAlbumsSettings.cs +++ b/PiwigoDirectorySync/Commands/SyncAlbumsSettings.cs @@ -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, "")] - public int PiwigoServerId { get; set; } } \ No newline at end of file diff --git a/PiwigoDirectorySync/Commands/SyncImagesCommand.cs b/PiwigoDirectorySync/Commands/SyncImagesCommand.cs new file mode 100644 index 0000000..c70dfe7 --- /dev/null +++ b/PiwigoDirectorySync/Commands/SyncImagesCommand.cs @@ -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 +{ + private readonly IImageSynchronizer _imageSynchronizer; + private readonly ILogger _logger; + + public SyncImagesCommand(ILogger logger, IImageSynchronizer imageSynchronizer) + { + _logger = logger; + _imageSynchronizer = imageSynchronizer; + } + + public override async Task 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; + } +} \ No newline at end of file diff --git a/PiwigoDirectorySync/Commands/SyncImagesSettings.cs b/PiwigoDirectorySync/Commands/SyncImagesSettings.cs new file mode 100644 index 0000000..dd2ebac --- /dev/null +++ b/PiwigoDirectorySync/Commands/SyncImagesSettings.cs @@ -0,0 +1,5 @@ +namespace PiwigoDirectorySync.Commands; + +public class SyncImagesSettings : CommonCommandSettings +{ +} \ No newline at end of file diff --git a/PiwigoDirectorySync/Program.cs b/PiwigoDirectorySync/Program.cs index 54a5a97..933ec69 100644 --- a/PiwigoDirectorySync/Program.cs +++ b/PiwigoDirectorySync/Program.cs @@ -17,6 +17,7 @@ registrations.AddTransient(); registrations.AddTransient(); registrations.AddTransient(); registrations.AddTransient(); +registrations.AddTransient(); var registrar = new DependencyInjectionTypeRegistrar(registrations); @@ -29,7 +30,11 @@ app.Configure(config => #endif config.AddCommand("scan"); - config.AddBranch("sync", c => { c.AddCommand("albums"); }); + config.AddBranch("sync", c => + { + c.AddCommand("albums"); + c.AddCommand("images"); + }); }); return app.Run(args); \ No newline at end of file diff --git a/PiwigoDirectorySync/Properties/launchSettings.json b/PiwigoDirectorySync/Properties/launchSettings.json index bd02b9c..fa6d61a 100644 --- a/PiwigoDirectorySync/Properties/launchSettings.json +++ b/PiwigoDirectorySync/Properties/launchSettings.json @@ -18,6 +18,12 @@ "commandLineArgs": "sync albums 1", "environmentVariables": { } + }, + "SyncImages": { + "commandName": "Project", + "commandLineArgs": "sync images 1", + "environmentVariables": { + } } } } diff --git a/PiwigoDirectorySync/Services/IImageSynchronizer.cs b/PiwigoDirectorySync/Services/IImageSynchronizer.cs new file mode 100644 index 0000000..31c63ec --- /dev/null +++ b/PiwigoDirectorySync/Services/IImageSynchronizer.cs @@ -0,0 +1,6 @@ +namespace PiwigoDirectorySync.Services; + +public interface IImageSynchronizer +{ + Task SynchronizeImages(int piwigoServerId, CancellationToken ct); +} \ No newline at end of file diff --git a/PiwigoDirectorySync/Services/ImageSynchronizer.cs b/PiwigoDirectorySync/Services/ImageSynchronizer.cs new file mode 100644 index 0000000..151ac5a --- /dev/null +++ b/PiwigoDirectorySync/Services/ImageSynchronizer.cs @@ -0,0 +1,6 @@ +namespace PiwigoDirectorySync.Services; + +public class ImageSynchronizer : IImageSynchronizer +{ + public Task SynchronizeImages(int piwigoServerId, CancellationToken ct) => throw new NotImplementedException(); +} \ No newline at end of file