Пример #1
0
        private async Task ProcessQueueAsync(List <AssetFileCleanupQueueItem> queueItems)
        {
            _logger.LogInformation("Processing {NumItems} items from the queue.", queueItems.Count);

            foreach (var item in queueItems)
            {
                var fileName = Path.ChangeExtension(item.FileNameOnDisk, item.FileExtension);
                item.LastAttemptDate = DateTime.UtcNow;

                try
                {
                    // This could be pluggable in the future if there was a need
                    switch (item.EntityDefinitionCode)
                    {
                    case ImageAssetEntityDefinition.DefinitionCode:
                        await _fileStoreService.DeleteAsync(ImageAssetConstants.FileContainerName, fileName);

                        await _resizedImageAssetFileService.ClearAsync(item.FileNameOnDisk);
                        await MarkCompleteAsync(item);

                        break;

                    case DocumentAssetEntityDefinition.DefinitionCode:
                        await _fileStoreService.DeleteAsync(DocumentAssetConstants.FileContainerName, fileName);
                        await MarkCompleteAsync(item);

                        break;

                    default:
                        _logger.LogError("Invalid asset EntityDefinitionCode for queue item {AssetFileCleanupQueueItemId}: {EntityDefinitionCode}", item.AssetFileCleanupQueueItemId, item.EntityDefinitionCode);
                        await MarkCannotRetryAsync(item);

                        break;
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "Error cleaning asset file queue item {AssetFileCleanupQueueItemId} of type {EntityDefinitionCode} and filename: {FileName}", item.AssetFileCleanupQueueItemId, item.EntityDefinitionCode, fileName);
                    await MarkFailedAsync(item);
                }
            }
        }
Пример #2
0
 public async Task <UseCaseResult <bool> > Handle(DeleteFile request, CancellationToken cancellationToken)
 {
     try
     {
         if (!string.IsNullOrEmpty(request.FileReference))
         {
             return(UseCaseResult <bool> .Create(await _fileStoreService.DeleteAsync(request.FileReference)));
         }
         else
         {
             return(UseCaseResult <bool> .CreateError(resultText : "File Reference not provided"));
         }
     }
     catch (Exception e)
     {
         return(UseCaseResult <bool> .CreateError(resultText : e.Message));
     }
 }