adds errorhandling to not fully stop if one file fails
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
0670bdd97e
commit
f924c2a7d7
@ -191,17 +191,34 @@ internal class ImageSynchronizer : IImageSynchronizer
|
|||||||
|
|
||||||
foreach (var imageEntity in imagesToUpload)
|
foreach (var imageEntity in imagesToUpload)
|
||||||
{
|
{
|
||||||
var fileInfo = new FileInfo(Path.Combine(piwigoServer.RootDirectory, imageEntity.FilePath));
|
try
|
||||||
var imageUpload = GetImageUpload(imageEntity, fileInfo.CreationTime);
|
{
|
||||||
var imageUploaded = await piwigoClient.UploadImageAsync(fileInfo, imageUpload, ct);
|
var fileInfo = new FileInfo(Path.Combine(piwigoServer.RootDirectory, imageEntity.FilePath));
|
||||||
|
|
||||||
imageEntity.ServerImageId = imageUploaded.ImageId;
|
var fileSizeInKb = fileInfo.Length / 1024f;
|
||||||
imageEntity.UploadRequired = false;
|
_logger.Information("Updating image {ImageFilePath} ({ImageId}) to piwigo server ({Size} KiB)", imageEntity.FilePath, imageEntity.ServerImageId, fileSizeInKb);
|
||||||
|
|
||||||
_logger.Information("Updated image {ImageEntityName} ({ImageEntityId}) on piwigo server with id {ImageEntityServerImageId}", imageEntity.Name, imageEntity.Id,
|
var imageUpload = GetImageUpload(imageEntity, fileInfo.CreationTime);
|
||||||
imageEntity.ServerImageId);
|
var imageUploaded = await piwigoClient.UploadImageAsync(fileInfo, imageUpload, ct);
|
||||||
|
|
||||||
await _persistenceContext.SaveChangesAsync(ct);
|
imageEntity.ServerImageId = imageUploaded.ImageId;
|
||||||
|
imageEntity.UploadRequired = false;
|
||||||
|
|
||||||
|
_logger.Information("Updated image {ImageEntityPath} ({ImageEntityId}) on piwigo server with id {ImageEntityServerImageId}", imageEntity.FilePath, imageEntity.Id,
|
||||||
|
imageEntity.ServerImageId);
|
||||||
|
|
||||||
|
await _persistenceContext.SaveChangesAsync(ct);
|
||||||
|
}
|
||||||
|
catch (OperationCanceledException)
|
||||||
|
{
|
||||||
|
Log.Debug("Cancel of image upload requested");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
catch (PiwigoException ex)
|
||||||
|
{
|
||||||
|
_logger.Error(ex,"Could not update image {ImageEntityPath} ({ImageEntityId}) on piwigo server with id {ImageEntityServerImageId}", imageEntity.FilePath,
|
||||||
|
imageEntity.Id, imageEntity.ServerImageId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,22 +233,34 @@ internal class ImageSynchronizer : IImageSynchronizer
|
|||||||
|
|
||||||
foreach (var imageEntity in imagesToUpload)
|
foreach (var imageEntity in imagesToUpload)
|
||||||
{
|
{
|
||||||
var fileInfo = new FileInfo(Path.Combine(piwigoServer.RootDirectory, imageEntity.FilePath));
|
try
|
||||||
|
{
|
||||||
|
var fileInfo = new FileInfo(Path.Combine(piwigoServer.RootDirectory, imageEntity.FilePath));
|
||||||
|
|
||||||
var fileSizeInKb = fileInfo.Length / 1024f;
|
var fileSizeInKb = fileInfo.Length / 1024f;
|
||||||
_logger.Information("Uploading image {ImageFilePath} ({ImageId}) to piwigo server with id {ImageServerImageId} ({Size} KiB)", imageEntity.FilePath, imageEntity.Id,
|
_logger.Information("Uploading image {ImageFilePath} ({ImageId}) to piwigo server ({Size} KiB)", imageEntity.FilePath, imageEntity.ServerImageId, fileSizeInKb);
|
||||||
imageEntity.ServerImageId, fileSizeInKb);
|
|
||||||
|
|
||||||
var imageUpload = GetImageUpload(imageEntity, fileInfo.CreationTime);
|
var imageUpload = GetImageUpload(imageEntity, fileInfo.CreationTime);
|
||||||
var imageUploaded = await piwigoClient.UploadImageAsync(fileInfo, imageUpload, ct);
|
var imageUploaded = await piwigoClient.UploadImageAsync(fileInfo, imageUpload, ct);
|
||||||
|
|
||||||
imageEntity.ServerImageId = imageUploaded.ImageId;
|
imageEntity.ServerImageId = imageUploaded.ImageId;
|
||||||
imageEntity.UploadRequired = false;
|
imageEntity.UploadRequired = false;
|
||||||
|
|
||||||
_logger.Information("Uploaded image {ImageFilePath} ({ImageId}) to piwigo server with id {ImageServerImageId}", imageEntity.FilePath, imageEntity.Id,
|
_logger.Information("Uploaded image {ImageFilePath} ({ImageId}) to piwigo server with id {ImageServerImageId}", imageEntity.FilePath, imageEntity.Id,
|
||||||
imageEntity.ServerImageId);
|
imageEntity.ServerImageId);
|
||||||
|
|
||||||
await _persistenceContext.SaveChangesAsync(ct);
|
await _persistenceContext.SaveChangesAsync(ct);
|
||||||
|
}
|
||||||
|
catch (OperationCanceledException)
|
||||||
|
{
|
||||||
|
Log.Debug("Cancel of image upload requested");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
catch (PiwigoException ex)
|
||||||
|
{
|
||||||
|
_logger.Error(ex, "Could not upload image {ImageEntityPath} ({ImageEntityId}) on piwigo server with id {ImageEntityServerImageId}", imageEntity.FilePath,
|
||||||
|
imageEntity.Id, imageEntity.ServerImageId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user