Пример #1
0
        private void CompareSubdirectory(string relativeDirectory)
        {
            DirectoryInfo sourceDirectory = new DirectoryInfo(Path.Combine(sourceBaseDirectory, relativeDirectory));
            DirectoryInfo targetDirectory = new DirectoryInfo(Path.Combine(targetBaseDirectory, relativeDirectory));

            var childDictionary = new SortedDictionary <string, InternalCompareInfo>(StringComparer.OrdinalIgnoreCase);

            // Enumerate the child files in source and target.
            AddWithAction(childDictionary, sourceDirectory.EnumerateFiles(), i => i.InSource = true);
            AddWithAction(childDictionary, targetDirectory.EnumerateFiles(), i => i.InTarget = true);
            foreach (var childInfo in childDictionary.Values)
            {
                AddFileResult(relativeDirectory, childInfo);
            }

            // Clear the files from the dictionary and now enumerate the child directories.
            childDictionary.Clear();
            AddWithAction(childDictionary, sourceDirectory.EnumerateDirectories(), i => i.InSource = true);
            AddWithAction(childDictionary, targetDirectory.EnumerateDirectories(), i => i.InTarget = true);
            foreach (var childInfo in childDictionary.Values)
            {
                if (childInfo.InSource && childInfo.InTarget)
                {
                    CompareSubdirectory(Path.Combine(relativeDirectory, childInfo.Name));
                }
                else
                {
                    FileCompareInfo result = ToFileCompareInfo(relativeDirectory, childInfo);
                    result.IsDirectory = true;
                    results.Add(result);
                }
            }
        }
Пример #2
0
        private void AddFileResult(string relativeDirectory, InternalCompareInfo internalInfo)
        {
            FileCompareInfo result = ToFileCompareInfo(relativeDirectory, internalInfo);

            if (internalInfo.InSource && internalInfo.InTarget)
            {
                result.Status = FileComparer.Compare(result.SourcePath, result.TargetPath);
            }
            this.results.Add(result);
        }
Пример #3
0
        private FileCompareInfo ToFileCompareInfo(string relativeDirectory, InternalCompareInfo internalInfo)
        {
            string relativePath = Path.Combine(relativeDirectory, internalInfo.Name);
            var    result       = new FileCompareInfo
            {
                Name         = internalInfo.Name,
                RelativePath = relativePath
            };

            result.SourcePath = Path.Combine(sourceBaseDirectory, relativePath);
            result.TargetPath = Path.Combine(targetBaseDirectory, relativePath);
            if (!internalInfo.InSource)
            {
                result.Status = FileCompareStatus.TargetOnly;
            }
            else if (!internalInfo.InTarget)
            {
                result.Status = FileCompareStatus.SourceOnly;
            }
            return(result);
        }