public void UpdateDestination(bool deleteSource = false) { var ignoreFiles = CheckSourceForDuplicates(); foreach (var destination in _filesByDestination) { _filesUtility.EmptyDirectory(destination.Key); foreach (var copyFile in destination.Value) { if (!ignoreFiles.Contains(copyFile.File)) { if (deleteSource) { _filesUtility.SafeMoveFile(copyFile.File, copyFile.Target); } else { _filesUtility.SafeCopyFile(copyFile.File, copyFile.Target); } } else { if (deleteSource) { _filesUtility.SafeDeleteFile(copyFile.File); } } } } _filesByDestination.Clear(); }
/// <param name="deleteSource">Deleting the source files might improve performance because it moves the files instead of copying them.</param> public void UpdateDestination(bool deleteSource = false) { var sw = Stopwatch.StartNew(); int countDestination = 0; int countMoved = 0; int countCopied = 0; int countDeleted = 0; var ignoreFiles = CheckSourceForDuplicates(); foreach (var destination in _filesByDestination) { _filesUtility.EmptyDirectory(destination.Key); countDestination++; foreach (var copyFile in destination.Value) { if (!ignoreFiles.Contains(copyFile.File)) { if (deleteSource) { _filesUtility.SafeMoveFile(copyFile.File, copyFile.Target); countMoved++; } else { _filesUtility.SafeCopyFile(copyFile.File, copyFile.Target); countCopied++; } } else { if (deleteSource) { _filesUtility.SafeDeleteFile(copyFile.File); countDeleted++; } } } } _filesByDestination.Clear(); var report = new StringBuilder(100); report.Append("UpdateDestination ").Append(countDestination).Append(" destinations"); if (countMoved > 0) { report.Append($", {countMoved} moved"); } if (countCopied > 0) { report.Append($", {countCopied} copied"); } if (countDeleted > 0) { report.Append($", {countDeleted} deleted"); } report.Append("."); _performanceLogger.Write(sw, () => report.ToString()); }