From 662df35f6a36d0aea661c8b464e778c29b372300 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=A4felfinger?= Date: Tue, 3 Oct 2023 22:15:14 +0200 Subject: [PATCH] adds a bit of logging when creating missing albums --- .../Services/AlbumSynchronizer.cs | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/PiwigoDirectorySync/Services/AlbumSynchronizer.cs b/PiwigoDirectorySync/Services/AlbumSynchronizer.cs index 1180198..4f02bcd 100644 --- a/PiwigoDirectorySync/Services/AlbumSynchronizer.cs +++ b/PiwigoDirectorySync/Services/AlbumSynchronizer.cs @@ -53,20 +53,26 @@ internal class AlbumSynchronizer : IAlbumSynchronizer private async Task AddMissingAlbumsToServerAsync(IPiwigoClient piwigoClient, ServerEntity piwigoServer, CancellationToken ct) { - var albumsToCreate = await _persistenceContext.PiwigoAlbums.Where(a => a.ServerAlbumId == null && a.ServerId == piwigoServer.Id) - .OrderBy(a => a.Path) - .Select(a => a.Id) - .ToListAsync(ct); + var albumsToCreate = await _persistenceContext.PiwigoAlbums.Where(a => a.ServerAlbumId == null && a.ServerId == piwigoServer.Id).OrderBy(a => a.Path).ToListAsync(ct); - foreach (var albumId in albumsToCreate) + foreach (var albumEntity in albumsToCreate) { - var albumEntity = await _persistenceContext.PiwigoAlbums.GetByIdAsync(albumId, ct); - var piwigoParentId = albumEntity.ParentId.HasValue ? (await _persistenceContext.PiwigoAlbums.GetByIdAsync(albumEntity.ParentId.Value, ct)).ServerAlbumId : null; + try + { + var piwigoParentId = albumEntity.ParentId.HasValue ? (await _persistenceContext.PiwigoAlbums.GetByIdAsync(albumEntity.ParentId.Value, ct)).ServerAlbumId : null; + _logger.Information("Creating album {AlbumName} ({AlbumPath}) on piwigo server {PiwigoServerName} ({PiwigoServerId})", albumEntity.Name, albumEntity.Path, + piwigoServer.Name, piwigoServer.Id); - albumEntity.ServerAlbumId = await piwigoClient.Album.AddAsync(albumEntity.Name, piwigoParentId, visible: true, position: AlbumPosition.First, - status: AlbumStatus.Public, cancellationToken: ct); + albumEntity.ServerAlbumId = await piwigoClient.Album.AddAsync(albumEntity.Name, piwigoParentId, visible: true, position: AlbumPosition.First, + status: AlbumStatus.Public, cancellationToken: ct); - await _persistenceContext.SaveChangesAsync(ct); + await _persistenceContext.SaveChangesAsync(ct); + } + catch (OperationCanceledException) + { + _logger.Debug("Cancel adding missing albums to server {PiwigoServerName} ({PiwigoServerId})", piwigoServer.Name, piwigoServer.Id); + return; + } } }