public DirectoryTreeData AddDirectory(string name) { var dir = new DirectoryTreeData(this, name, ChecksumProvider); _directories.Add(dir); return(dir); }
public DirectoryTreeData(DirectoryTreeData parent, string name, IChecksumProvider checksumProvider) => (Parent, Name, Level, ChecksumProvider) = (parent, name, " " + parent?.Level, checksumProvider);
private void CompareDirectory(DirectoryTreeData source, DirectoryTreeData diff) { var statuses = new List <ItemStatus>(); foreach (var sourceFile in source?.Files ?? Enumerable.Empty <DirectoryTreeFileData>()) { var diffFile = diff.AddFile(sourceFile.Name); diffFile.Source = sourceFile; diffFile.Target = diff.Target?.Files?.FirstOrDefault(f => f.Name == sourceFile.Name); diffFile.Status = GetFileStatus(diffFile); AddUniqueStatus(diffFile.Status); if (diffFile.Target is null) { diffFile.Target = new DirectoryTreeFileData(diffFile.Parent.Target, diffFile.Name); } } foreach (var targetFile in diff.Target?.Files ?? Enumerable.Empty <DirectoryTreeFileData>()) { if (source is null || !source.Files.Any(f => f.Name == targetFile.Name)) { var diffFile = diff.AddFile(targetFile.Name); diffFile.Target = targetFile; diffFile.Status = GetFileStatus(diffFile); AddUniqueStatus(diffFile.Status); } } foreach (var sourceDirectory in source?.Directories ?? Enumerable.Empty <DirectoryTreeData>()) { var diffDirectory = diff.AddDirectory(sourceDirectory.Name); diffDirectory.Target = diff.Target?.Directories?.FirstOrDefault(d => d.Name == sourceDirectory.Name); CompareDirectory(sourceDirectory, diffDirectory); AddUniqueStatus(diffDirectory.Status); if (diffDirectory.Target is null) { diffDirectory.Target = new DirectoryTreeData(diffDirectory.Parent.Target, diffDirectory.Name, new EmptyChecksumProvider()); } } foreach (var targetDirectory in diff.Target?.Directories ?? Enumerable.Empty <DirectoryTreeData>()) { if (source is null || !source.Directories.Any(d => d.Name == targetDirectory.Name)) { var diffDirectory = diff.AddDirectory(targetDirectory.Name); diffDirectory.Target = targetDirectory; CompareDirectory(null, diffDirectory); AddUniqueStatus(diffDirectory.Status); } } diff.Status = statuses.Count == 0 ? statuses[0] : ItemStatus.ItemToUpdate; void AddUniqueStatus(ItemStatus status) { if (!statuses.Contains(status)) { statuses.Add(status); } } }