diff --git a/RMuseum/Controllers/ExternalFTPController.cs b/RMuseum/Controllers/ExternalFTPController.cs index 952c90ae..caa8618b 100644 --- a/RMuseum/Controllers/ExternalFTPController.cs +++ b/RMuseum/Controllers/ExternalFTPController.cs @@ -49,7 +49,7 @@ namespace RMuseum.Controllers [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] public async Task ProcessQueueAsync() { - var res = await _ftpService.ProcessQueueAsync(); + var res = await _ftpService.ProcessQueueAsync(null); if (!string.IsNullOrEmpty(res.ExceptionString)) return BadRequest(res.ExceptionString); return Ok(); diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 4a96b468..89effdb5 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -18573,19 +18573,21 @@ Queued FTP Upload Service Implementation - + add upload (you should call ProcessQueue manually) + s - + process queue + @@ -19625,19 +19627,21 @@ Queued FTP Upload Service - + add upload (you should call ProcessQueue manually) + s - + process queue + diff --git a/RMuseum/Services/IQueuedFTPUploadService.cs b/RMuseum/Services/IQueuedFTPUploadService.cs index 0a84a1d3..48290ab7 100644 --- a/RMuseum/Services/IQueuedFTPUploadService.cs +++ b/RMuseum/Services/IQueuedFTPUploadService.cs @@ -1,4 +1,5 @@ -using RMuseum.Models.ExternalFTPUpload; +using RMuseum.DbContext; +using RMuseum.Models.ExternalFTPUpload; using RSecurityBackend.Models.Generic; using System.Threading.Tasks; @@ -12,17 +13,19 @@ namespace RMuseum.Services /// /// add upload (you should call ProcessQueue manually) /// + /// s /// /// /// /// - Task> AddAsync(string localFilePath, string remoteFilePath, bool deleteFileAfterUpload); + Task> AddAsync(RMuseumDbContext context, string localFilePath, string remoteFilePath, bool deleteFileAfterUpload); /// /// process queue /// + /// /// - Task> ProcessQueueAsync(); + Task> ProcessQueueAsync(RMuseumDbContext callContext); /// /// reset queue diff --git a/RMuseum/Services/Implementation/PDFLibraryService-Partials/PDFLibraryService-LocalPDF.cs b/RMuseum/Services/Implementation/PDFLibraryService-Partials/PDFLibraryService-LocalPDF.cs index aa22e843..132e81a1 100644 --- a/RMuseum/Services/Implementation/PDFLibraryService-Partials/PDFLibraryService-LocalPDF.cs +++ b/RMuseum/Services/Implementation/PDFLibraryService-Partials/PDFLibraryService-LocalPDF.cs @@ -457,7 +457,7 @@ namespace RMuseum.Services.Implementation var remotePDFFilePath = $"{Configuration.GetSection("ExternalFTPServer")["RootPath"]}/pdf/{book.StorageFolderName}/{Path.GetFileName(localPDFFilePath)}"; if (!skipUpload) { - var res = await _ftpService.AddAsync(localPDFFilePath, remotePDFFilePath, true); + var res = await _ftpService.AddAsync(context, localPDFFilePath, remotePDFFilePath, true); if(!string.IsNullOrEmpty(res.ExceptionString)) { return new RServiceResult(false, $"ftp {localPDFFilePath} => {remotePDFFilePath} {res.ExceptionString}"); @@ -467,7 +467,7 @@ namespace RMuseum.Services.Implementation var remoteCoverImageFilePath = $"{Configuration.GetSection("ExternalFTPServer")["RootPath"]}/pdf/{book.StorageFolderName}/{Path.GetFileName(localCoverImageFilePath)}"; if (!skipUpload) { - var res = await _ftpService.AddAsync(localCoverImageFilePath, remoteCoverImageFilePath, true); + var res = await _ftpService.AddAsync(context, localCoverImageFilePath, remoteCoverImageFilePath, true); if (!string.IsNullOrEmpty(res.ExceptionString)) { return new RServiceResult(false, $"ftp {localCoverImageFilePath} => {remoteCoverImageFilePath} {res.ExceptionString}"); @@ -484,7 +484,7 @@ namespace RMuseum.Services.Implementation if (!skipUpload) { var remoteFilePath = $"{Configuration.GetSection("ExternalFTPServer")["RootPath"]}/pdf/{book.CoverImage.FolderName}/{Path.GetFileName(localFilePath)}"; - var res = await _ftpService.AddAsync(localFilePath, remoteFilePath, true); + var res = await _ftpService.AddAsync(context, localFilePath, remoteFilePath, true); if (!string.IsNullOrEmpty(res.ExceptionString)) { return new RServiceResult(false, $"ftp {localFilePath} => {remoteFilePath} {res.ExceptionString}"); @@ -495,7 +495,7 @@ namespace RMuseum.Services.Implementation { if(false == await context.QueuedFTPUploads.AsNoTracking().Where(p => p.Processing).AnyAsync()) { - var res = await _ftpService.ProcessQueueAsync(); + var res = await _ftpService.ProcessQueueAsync(context); if (!string.IsNullOrEmpty(res.ExceptionString)) { return new RServiceResult(false, $"FTP ProcessQueueAsync : {res.ExceptionString}"); diff --git a/RMuseum/Services/Implementation/QueuedFTPUploadService.cs b/RMuseum/Services/Implementation/QueuedFTPUploadService.cs index a8b7a04d..f1366498 100644 --- a/RMuseum/Services/Implementation/QueuedFTPUploadService.cs +++ b/RMuseum/Services/Implementation/QueuedFTPUploadService.cs @@ -22,11 +22,12 @@ namespace RMuseum.Services.Implementation /// /// add upload (you should call ProcessQueue manually) /// + /// s /// /// /// /// - public async Task> AddAsync(string localFilePath, string remoteFilePath, bool deleteFileAfterUpload) + public async Task> AddAsync(RMuseumDbContext context, string localFilePath, string remoteFilePath, bool deleteFileAfterUpload) { try { @@ -38,8 +39,8 @@ namespace RMuseum.Services.Implementation QueueDate = DateTime.Now, Processing = false, }; - _context.QueuedFTPUploads.Add(q); - await _context.SaveChangesAsync(); + context.QueuedFTPUploads.Add(q); + await context.SaveChangesAsync(); return new RServiceResult(q); } catch (Exception exp) @@ -51,12 +52,17 @@ namespace RMuseum.Services.Implementation /// /// process queue /// + /// /// - public async Task> ProcessQueueAsync() + public async Task> ProcessQueueAsync(RMuseumDbContext callContext) { try { - var processing = await _context.QueuedFTPUploads.AsNoTracking().Where(q => q.Processing).FirstOrDefaultAsync(); + if(callContext == null) + { + callContext = _context; + } + var processing = await callContext.QueuedFTPUploads.AsNoTracking().Where(q => q.Processing).FirstOrDefaultAsync(); if(processing != null) { return new RServiceResult(false, $"already processing {processing.Id}.");