private bool?RaiseEventIfDifferent(CompareFileSystemItemsEventArgs e) { FileSystemItemDifferences diffs = e.Differences; if (diffs != FileSystemItemDifferences.None) { EventHandler <FoundDifferentFileSystemItemsEventArgs> diffHandler = this.DifferentItemsFound; if (diffHandler != null) { FoundDifferentFileSystemItemsEventArgs de = new FoundDifferentFileSystemItemsEventArgs(e.Source, e.Destination, diffs); diffHandler(this, de); return(true); } return(false); } return(null); }
// Private Methods (3) private void CompareDirectories(DirectoryInfo src, DirectoryInfo dest, ICollection <Exception> errList) { if (this.IsCanceling) { return; } EventHandler <CompareFileSystemItemsEventArgs> compareHandler = this.ComparingItems; if (src.Exists == false || dest.Exists == false) { if (compareHandler != null) { FileSystemItemDifferences diffs = FileSystemItemDifferences.None; if (src.Exists == false) { diffs |= FileSystemItemDifferences.SourceDoesNotExist; } if (dest.Exists == false) { diffs |= FileSystemItemDifferences.DestionationDoesNotExist; } CompareFileSystemItemsEventArgs e = new CompareFileSystemItemsEventArgs(src, dest); compareHandler(this, e); } return; } if (this.IsCanceling) { return; } IEnumerable <DirectoryInfo> subDirsOfSource; try { subDirsOfSource = src.GetDirectories(); } catch (Exception ex) { errList.Add(ex); subDirsOfSource = CollectionHelper.Empty <DirectoryInfo>(); } if (this.IsCanceling) { return; } // compare directories try { foreach (DirectoryInfo subDir in subDirsOfSource) { if (this.IsCanceling) { return; } try { DirectoryInfo destDir = new DirectoryInfo(Path.Combine(dest.FullName, subDir.Name)); CompareFileSystemItemsEventArgs e = new CompareFileSystemItemsEventArgs(subDir, destDir); if (compareHandler != null) { compareHandler(this, e); } if (e.Handled == false) { // use default logic if (destDir.Exists) { } else { e.Differences |= FileSystemItemDifferences.IsMissing; } } this.RaiseEventIfDifferent(e); } catch (Exception ex) { errList.Add(ex); } } } catch (Exception ex) { errList.Add(ex); } if (this.IsCanceling) { return; } // check for extra directories try { foreach (DirectoryInfo subDir in dest.GetDirectories()) { if (this.IsCanceling) { return; } try { DirectoryInfo srcDir = new DirectoryInfo(Path.Combine(src.FullName, subDir.Name)); CompareFileSystemItemsEventArgs e = new CompareFileSystemItemsEventArgs(srcDir, subDir); if (compareHandler != null) { compareHandler(this, e); } if (e.Handled == false) { // use default logic if (srcDir.Exists) { } else { e.Differences |= FileSystemItemDifferences.IsExtra; } } this.RaiseEventIfDifferent(e); } catch (Exception ex) { errList.Add(ex); } } } catch (Exception ex) { errList.Add(ex); } if (this.IsCanceling) { return; } // compare files try { foreach (FileInfo file in src.GetFiles()) { if (this.IsCanceling) { return; } try { FileInfo destFile = new FileInfo(Path.Combine(dest.FullName, file.Name)); CompareFileSystemItemsEventArgs e = new CompareFileSystemItemsEventArgs(file, destFile); if (compareHandler != null) { compareHandler(this, e); } if (e.Handled == false) { // use default logic if (destFile.Exists) { #if WINDOWS_PHONE if (NormalizeTimestamp(file.LastWriteTime) != NormalizeTimestamp(destFile.LastWriteTime)) #else if (NormalizeTimestamp(file.LastWriteTimeUtc) != NormalizeTimestamp(destFile.LastWriteTimeUtc)) #endif { e.Differences |= FileSystemItemDifferences.LastWriteTime; } } else { e.Differences |= FileSystemItemDifferences.IsMissing; } } this.RaiseEventIfDifferent(e); } catch (Exception ex) { errList.Add(ex); } } } catch (Exception ex) { errList.Add(ex); } if (this.IsCanceling) { return; } // check for extra files try { foreach (FileInfo file in dest.GetFiles()) { if (this.IsCanceling) { return; } try { FileInfo srcFile = new FileInfo(Path.Combine(src.FullName, file.Name)); CompareFileSystemItemsEventArgs e = new CompareFileSystemItemsEventArgs(srcFile, file); if (compareHandler != null) { compareHandler(this, e); } if (e.Handled == false) { // use default logic if (srcFile.Exists) { } else { e.Differences |= FileSystemItemDifferences.IsExtra; } } this.RaiseEventIfDifferent(e); } catch (Exception ex) { errList.Add(ex); } } } catch (Exception ex) { errList.Add(ex); } if (this.IsCanceling) { return; } if (this.Recursive) { foreach (DirectoryInfo subDir in subDirsOfSource) { if (this.IsCanceling) { return; } try { DirectoryInfo destDir = new DirectoryInfo(Path.Combine(dest.FullName, subDir.Name)); this.CompareDirectories(subDir, destDir, errList); } catch (Exception ex) { errList.Add(ex); } } } }