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