public virtual IEnumerable <Diff> GetDifferences() { string[] exclusions = Exclusions.ToArray(); // Directories Directory[] leftDirectories = Left.GetAllDirectories(exclusions).ToArray(); Directory[] rightDirectories = Right.GetAllDirectories(exclusions).ToArray(); // Compute directory differences IEnumerable <DirectoryDiff> directoryDiffs = FullOuterJoin(leftDirectories, rightDirectories, l => l.Path, r => r.Path, (l, r, p) => new DirectoryDiff(Left, l, Right, r)) .Where(d => d.Left == null || d.Right == null); foreach (DirectoryDiff directoryDiff in directoryDiffs) { yield return(directoryDiff); } // Files File[] leftFiles = Left.GetAllFiles(exclusions).ToArray(); File[] rightFiles = Right.GetAllFiles(exclusions).ToArray(); // Compute file differences FileComparer comparer = new FileComparer(DiffType); IEnumerable <FileDiff> fileDiffs = FullOuterJoin(leftFiles, rightFiles, l => l, r => r, (l, r, p) => new FileDiff(Left, l, Right, r, comparer), keyComparer: new FileComparer(DiffType.Paths)) .Where(d => d.Left == null || d.Right == null || !comparer.Equals(d.Left, d.Right)); foreach (FileDiff fileDiff in fileDiffs) { yield return(fileDiff); } }
public FileDiff(Storage leftStorage, File leftFile, Storage rightStorage, File rightFile, FileComparer comparer) { this.leftStorage = leftStorage; this.rightStorage = rightStorage; this.leftFile = leftFile; this.rightFile = rightFile; this.comparer = comparer; }
public Action GetAction(SyncType syncType) { switch (syncType) { case SyncType.Backup: { if (Right == null) { return(new CopyFileAction(Left, RightStorage, Left.Parent.Path, Left.Name)); } else if (Left != null) { return(new ReplaceFileAction(Left, Right)); } break; } case SyncType.Clone: { if (Left == null) { return(new DeleteFileAction(Right)); } else if (Right == null) { return(new CopyFileAction(Left, RightStorage, Left.Parent.Path, Left.Name)); } else { return(new ReplaceFileAction(Left, Right)); } } case SyncType.Sync: { if (Left == null) { return(new CopyFileAction(Right, LeftStorage, Right.Parent.Path, Right.Name)); } else if (Right == null) { return(new CopyFileAction(Left, RightStorage, Left.Parent.Path, Left.Name)); } else { int diff = FileComparer.CompareFileDates(Left, Right); if (diff > 0) { return(new ReplaceFileAction(Left, Right)); } else if (diff < 0) { return(new ReplaceFileAction(Right, Left)); } else { throw new NotImplementedException("Files are different, but they have the same date"); } } } } return(null); }