private async Task ProcessSourceFolder( OversawCollection oversawCollection, SourceFolder collectionSourceFolder) { using var loggerScope = _logger.BeginScope( "Looking at {SourceFolderPath}...", collectionSourceFolder.Path); var newFiles = await _sourceFolderService.GetNewFiles(collectionSourceFolder); if (!newFiles.Any()) { return; } _logger.LogInformation("{NewFilesCount} new files found", newFiles.Count); var movedFiles = await MoveFiles(newFiles, oversawCollection); await _dbStateService.SaveChanges(); _logger.LogInformation("{NewFilesSavedCount} files saved", movedFiles.Count); await movedFiles.Select(x => _remoteCommandService.SaveTags(x.FileId, x.MovedInformation.SourceTags)) .WhenAll(); await movedFiles .Select( x => _remoteCommandService.UpdateMetadataRequest(x.FileId, x.MovedInformation.SystemFile.Md5)) .WhenAll(); _logger.LogDebug("Update metadata requests are sent"); }
public async Task PryCollection(OversawCollection oversawCollection) { _logger.LogTrace("Prying collection {CollectionName}", oversawCollection.Collection.Name); foreach (var collectionSourceFolder in oversawCollection.SourceFolders) { await ProcessSourceFolder(oversawCollection, collectionSourceFolder); } }
private MovedInformation MoveFile(OversawCollection oversawCollection, MoveInformation moveInformation) { using var loggerScope = _logger.BeginScope( "Processing new file in source: {NewFile}, {MoveProblem}, {@SourceTags}", moveInformation.SystemFile.File.FullName, moveInformation.MoveProblem, moveInformation.SourceTags); try { return(_destinationFolderService.Move(oversawCollection.DestinationFolder, moveInformation)); } catch (Exception e) { _logger.LogError(e, "Error occurred while moving file"); return(new MovedInformation(moveInformation, false, moveInformation.SystemFile.File)); } }
private async Task <IReadOnlyCollection <(Guid FileId, MovedInformation MovedInformation)> > MoveFiles( IEnumerable <MoveInformation> preparedFiles, OversawCollection oversawCollection) { var result = new List <(Guid FileId, MovedInformation movedInformation)>(); foreach (var moveInformation in preparedFiles) { var movedInformation = MoveFile(oversawCollection, moveInformation); if (!movedInformation.RequireSave) { continue; } var fileId = await _collectionFileService.SaveNew(movedInformation, oversawCollection.Collection.Id); result.Add((fileId, movedInformation)); } return(result); }