added base settings, console command to sync images and empty image synchronizer
This commit is contained in:
parent
105c69fbcb
commit
f705babdc3
9
PiwigoDirectorySync/Commands/CommonCommandSettings.cs
Normal file
9
PiwigoDirectorySync/Commands/CommonCommandSettings.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
using Spectre.Console.Cli;
|
||||||
|
|
||||||
|
namespace PiwigoDirectorySync.Commands;
|
||||||
|
|
||||||
|
public class CommonCommandSettings : CommandSettings
|
||||||
|
{
|
||||||
|
[CommandArgument(0, "<PiwigoServerId>")]
|
||||||
|
public int PiwigoServerId { get; set; }
|
||||||
|
}
|
@ -5,11 +5,8 @@ using Spectre.Console.Cli;
|
|||||||
namespace PiwigoDirectorySync.Commands;
|
namespace PiwigoDirectorySync.Commands;
|
||||||
|
|
||||||
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")]
|
[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")]
|
[CommandOption("-d|--mark-for-delete")]
|
||||||
[DefaultValue(false)]
|
[DefaultValue(false)]
|
||||||
public bool MarkForDelete { get; set; }
|
public bool MarkForDelete { get; set; }
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using Spectre.Console.Cli;
|
|
||||||
|
|
||||||
namespace PiwigoDirectorySync.Commands;
|
namespace PiwigoDirectorySync.Commands;
|
||||||
|
|
||||||
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")]
|
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")]
|
||||||
public class SyncAlbumsSettings : CommandSettings
|
public class SyncAlbumsSettings : CommonCommandSettings
|
||||||
{
|
{
|
||||||
[CommandArgument(0, "<PiwigoServerId>")]
|
|
||||||
public int PiwigoServerId { get; set; }
|
|
||||||
}
|
}
|
33
PiwigoDirectorySync/Commands/SyncImagesCommand.cs
Normal file
33
PiwigoDirectorySync/Commands/SyncImagesCommand.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
5
PiwigoDirectorySync/Commands/SyncImagesSettings.cs
Normal file
5
PiwigoDirectorySync/Commands/SyncImagesSettings.cs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
namespace PiwigoDirectorySync.Commands;
|
||||||
|
|
||||||
|
public class SyncImagesSettings : CommonCommandSettings
|
||||||
|
{
|
||||||
|
}
|
@ -17,6 +17,7 @@ registrations.AddTransient<IPiwigoClientFactory, PiwigoClientFactory>();
|
|||||||
registrations.AddTransient<IFileIndexer, FileIndexer>();
|
registrations.AddTransient<IFileIndexer, FileIndexer>();
|
||||||
registrations.AddTransient<IFileSystemScanner, FileSystemScanner>();
|
registrations.AddTransient<IFileSystemScanner, FileSystemScanner>();
|
||||||
registrations.AddTransient<IAlbumSynchronizer, AlbumSynchronizer>();
|
registrations.AddTransient<IAlbumSynchronizer, AlbumSynchronizer>();
|
||||||
|
registrations.AddTransient<IImageSynchronizer, ImageSynchronizer>();
|
||||||
|
|
||||||
var registrar = new DependencyInjectionTypeRegistrar(registrations);
|
var registrar = new DependencyInjectionTypeRegistrar(registrations);
|
||||||
|
|
||||||
@ -29,7 +30,11 @@ app.Configure(config =>
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
config.AddCommand<ScanCommand>("scan");
|
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);
|
return app.Run(args);
|
@ -18,6 +18,12 @@
|
|||||||
"commandLineArgs": "sync albums 1",
|
"commandLineArgs": "sync albums 1",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"SyncImages": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"commandLineArgs": "sync images 1",
|
||||||
|
"environmentVariables": {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
6
PiwigoDirectorySync/Services/IImageSynchronizer.cs
Normal file
6
PiwigoDirectorySync/Services/IImageSynchronizer.cs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
namespace PiwigoDirectorySync.Services;
|
||||||
|
|
||||||
|
public interface IImageSynchronizer
|
||||||
|
{
|
||||||
|
Task SynchronizeImages(int piwigoServerId, CancellationToken ct);
|
||||||
|
}
|
6
PiwigoDirectorySync/Services/ImageSynchronizer.cs
Normal file
6
PiwigoDirectorySync/Services/ImageSynchronizer.cs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
namespace PiwigoDirectorySync.Services;
|
||||||
|
|
||||||
|
public class ImageSynchronizer : IImageSynchronizer
|
||||||
|
{
|
||||||
|
public Task SynchronizeImages(int piwigoServerId, CancellationToken ct) => throw new NotImplementedException();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user