adds pending changes command
All checks were successful
PiwigoDirectorySync/pipeline/head This commit looks good
All checks were successful
PiwigoDirectorySync/pipeline/head This commit looks good
This commit is contained in:
parent
3b8dad1af2
commit
58206c9347
41
PiwigoDirectorySync/Commands/SyncPendingChangesCommand.cs
Normal file
41
PiwigoDirectorySync/Commands/SyncPendingChangesCommand.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
using PiwigoDirectorySync.Infrastructure;
|
||||||
|
using PiwigoDirectorySync.Services;
|
||||||
|
using Spectre.Console;
|
||||||
|
using Spectre.Console.Cli;
|
||||||
|
|
||||||
|
namespace PiwigoDirectorySync.Commands;
|
||||||
|
|
||||||
|
internal class SyncPendingChangesCommand : CancellableAsyncCommand<SyncPendingChangesCommand.SyncPendingChangesSettings>
|
||||||
|
{
|
||||||
|
private readonly IAlbumSynchronizer _albumSynchronizer;
|
||||||
|
private readonly IImageSynchronizer _imageSynchronizer;
|
||||||
|
|
||||||
|
public SyncPendingChangesCommand(IAlbumSynchronizer albumSynchronizer, IImageSynchronizer imageSynchronizer)
|
||||||
|
{
|
||||||
|
_albumSynchronizer = albumSynchronizer;
|
||||||
|
_imageSynchronizer = imageSynchronizer;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task<int> ExecuteAsync(CommandContext context, SyncPendingChangesSettings settings, CancellationToken cancellation)
|
||||||
|
{
|
||||||
|
var pendingAlbumChanges = await _albumSynchronizer.GetPendingChangesAsync(settings.PiwigoServerId, cancellation);
|
||||||
|
var pendingImageChanges = await _imageSynchronizer.GetPendingChangesAsync(settings.PiwigoServerId, cancellation);
|
||||||
|
|
||||||
|
var table = new Table();
|
||||||
|
table.AddColumn("Entity");
|
||||||
|
table.AddColumn(new TableColumn("Check or adds").Centered());
|
||||||
|
table.AddColumn(new TableColumn("updates").Centered());
|
||||||
|
table.AddColumn(new TableColumn("deletes").Centered());
|
||||||
|
|
||||||
|
table.AddRow("Albums", $"[orange3]{pendingAlbumChanges.CheckOrAdds}[/]", $"[orange3]{pendingAlbumChanges.Updates}[/]", $"[red]{pendingAlbumChanges.Deletes}[/]");
|
||||||
|
table.AddRow("Images", $"[orange3]{pendingImageChanges.CheckOrAdds}[/]", $"[orange3]{pendingImageChanges.Updates}[/]", $"[red]{pendingImageChanges.Deletes}[/]");
|
||||||
|
|
||||||
|
AnsiConsole.Write(table);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class SyncPendingChangesSettings : SyncCommandSettings
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -60,6 +60,7 @@ app.Configure(config =>
|
|||||||
c.AddCommand<SyncFullCommand>("full");
|
c.AddCommand<SyncFullCommand>("full");
|
||||||
c.AddCommand<SyncAlbumsCommand>("albums");
|
c.AddCommand<SyncAlbumsCommand>("albums");
|
||||||
c.AddCommand<SyncImagesCommand>("images");
|
c.AddCommand<SyncImagesCommand>("images");
|
||||||
|
c.AddCommand<SyncPendingChangesCommand>("pending");
|
||||||
});
|
});
|
||||||
config.AddBranch("piwigo", c =>
|
config.AddBranch("piwigo", c =>
|
||||||
{
|
{
|
||||||
|
@ -42,6 +42,15 @@ internal class AlbumSynchronizer : IAlbumSynchronizer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<PendingChange> GetPendingChangesAsync(int piwigoServerId, CancellationToken ct)
|
||||||
|
{
|
||||||
|
var getOrAdds = await _persistenceContext.PiwigoAlbums.Where(a => a.ServerAlbumId == null).CountAsync(ct);
|
||||||
|
const int updates = 0; // not yet supported
|
||||||
|
const int deletes = 0; // not yet supported
|
||||||
|
|
||||||
|
return new PendingChange(getOrAdds, updates, deletes);
|
||||||
|
}
|
||||||
|
|
||||||
private async Task AddMissingAlbumsToServerAsync(IPiwigoClient piwigoClient, ServerEntity piwigoServer, CancellationToken ct)
|
private async Task AddMissingAlbumsToServerAsync(IPiwigoClient piwigoClient, ServerEntity piwigoServer, CancellationToken ct)
|
||||||
{
|
{
|
||||||
var albumsToCreate = await _persistenceContext.PiwigoAlbums.Where(a => a.ServerAlbumId == null && a.ServerId == piwigoServer.Id)
|
var albumsToCreate = await _persistenceContext.PiwigoAlbums.Where(a => a.ServerAlbumId == null && a.ServerId == piwigoServer.Id)
|
||||||
|
@ -3,4 +3,5 @@ namespace PiwigoDirectorySync.Services;
|
|||||||
internal interface IAlbumSynchronizer
|
internal interface IAlbumSynchronizer
|
||||||
{
|
{
|
||||||
Task SynchronizeAlbums(int piwigoServerId, bool readOnly, CancellationToken ct);
|
Task SynchronizeAlbums(int piwigoServerId, bool readOnly, CancellationToken ct);
|
||||||
|
Task<PendingChange> GetPendingChangesAsync(int piwigoServerId, CancellationToken ct);
|
||||||
}
|
}
|
@ -4,4 +4,5 @@ internal interface IImageSynchronizer
|
|||||||
{
|
{
|
||||||
Task SynchronizeImagesAsync(int piwigoServerId, bool readOnly, CancellationToken ct);
|
Task SynchronizeImagesAsync(int piwigoServerId, bool readOnly, CancellationToken ct);
|
||||||
Task DownloadImagesAsync(int piwigoServerId, CancellationToken ct);
|
Task DownloadImagesAsync(int piwigoServerId, CancellationToken ct);
|
||||||
|
Task<PendingChange> GetPendingChangesAsync(int piwigoServerId, CancellationToken ct);
|
||||||
}
|
}
|
@ -21,6 +21,15 @@ internal class ImageSynchronizer : IImageSynchronizer
|
|||||||
_persistenceContext = persistenceContext;
|
_persistenceContext = persistenceContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<PendingChange> GetPendingChangesAsync(int piwigoServerId, CancellationToken ct)
|
||||||
|
{
|
||||||
|
var getOrAdds = await _persistenceContext.PiwigoImages.Where(i => i.ServerImageId == null).CountAsync(ct);
|
||||||
|
var updates = await _persistenceContext.PiwigoImages.Where(i => i.ServerImageId != null && i.UploadRequired).CountAsync(ct);
|
||||||
|
var deletes = await _persistenceContext.PiwigoImages.Where(i => i.ServerImageId != null && i.DeleteRequired).CountAsync(ct);
|
||||||
|
|
||||||
|
return new PendingChange(getOrAdds, updates, deletes);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task DownloadImagesAsync(int piwigoServerId, CancellationToken ct)
|
public async Task DownloadImagesAsync(int piwigoServerId, CancellationToken ct)
|
||||||
{
|
{
|
||||||
var piwigoServer = await _persistenceContext.PiwigoServers.FindAsync(new object?[] { piwigoServerId }, ct);
|
var piwigoServer = await _persistenceContext.PiwigoServers.FindAsync(new object?[] { piwigoServerId }, ct);
|
||||||
|
3
PiwigoDirectorySync/Services/PendingChange.cs
Normal file
3
PiwigoDirectorySync/Services/PendingChange.cs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
namespace PiwigoDirectorySync.Services;
|
||||||
|
|
||||||
|
internal record PendingChange(int CheckOrAdds, int Updates, int Deletes);
|
Loading…
Reference in New Issue
Block a user