Пример #1
0
        private async Task ProgressDuplicateAsync(FileRecord potentialDuplicate, CancellationToken cancellationToken)
        {
            _logger.LogInformation($"Processing {potentialDuplicate.Filename}...");

            var targetDirectory = potentialDuplicate.GetTargetDirectory(_directories.OutputDirectory.FullName);

            var targetFile = new FileInfo(Path.Combine(targetDirectory.FullName, potentialDuplicate.Filename));

            if (!targetFile.Exists)
            {
                _logger.LogInformation($"Matching file does not exist. This should not happen!");
                return;
            }

            var isDuplicate = await CheckFilesMatchAsync(potentialDuplicate.File, targetFile, cancellationToken);

            if (isDuplicate)
            {
                _logger.LogInformation($"The file {potentialDuplicate.File.FullName} is a duplicate and will be ignored.");
            }
            else
            {
                _logger.LogInformation($"The file {potentialDuplicate.File.FullName} is not a duplicate!");

                var newFilename = await GenerateFilenameForDuplicateAsync(targetDirectory, potentialDuplicate.File);

                _logger.LogInformation($"File will be called {newFilename}");
                var operation = FileOperation.From(_directories, potentialDuplicate, targetDirectory, newFilename);

                _logger.LogInformation("Running file operation...");
                var result = await operation.RunAsync();

                if (!result.Success)
                {
                    _logger.LogError(result.Message);
                }
            }
        }