コード例 #1
0
        protected override void Handle(FindDuplicatesRequest request)
        {
            Snapshot snapshotLeft  = projectRepository.GetSnapshot(request.PathLeft);
            Snapshot snapshotRight = null;

            if (request.PathRight != null)
            {
                snapshotRight = projectRepository.GetSnapshot(request.PathRight);
            }

            FileDuplicates fileDuplicates = new FileDuplicates
            {
                SnapshotLeft    = snapshotLeft,
                SnapshotRight   = snapshotRight,
                CheckFilesExist = request.CheckFilesExist
            };

            IEnumerable <FileDuplicate> duplicates = fileDuplicates.Compare();

            int  duplicateCount = 0;
            long totalSize      = 0;

            foreach (FileDuplicate duplicate in duplicates)
            {
                if (duplicate.AreEqual)
                {
                    duplicateCount++;
                    totalSize += duplicate.Size;
                    request.Exporter.WriteDuplicate(duplicate.FullPath1, duplicate.FullPath2, duplicate.Size);
                }
            }

            request.Exporter.WriteSummary(duplicateCount, totalSize);
        }
コード例 #2
0
        protected override void Handle(RemoveDuplicatesRequest request)
        {
            Snapshot snapshotLeft  = projectRepository.GetSnapshot(request.PathLeft);
            Snapshot snapshotRight = null;

            if (request.PathRight != null)
            {
                snapshotRight = projectRepository.GetSnapshot(request.PathRight);
            }

            FileDuplicates fileDuplicates = new FileDuplicates
            {
                SnapshotLeft    = snapshotLeft,
                SnapshotRight   = snapshotRight,
                CheckFilesExist = true
            };

            IEnumerable <FileDuplicate> duplicates = fileDuplicates.Compare();

            int  removeCount = 0;
            long totalSize   = 0;

            foreach (FileDuplicate duplicate in duplicates)
            {
                if (!duplicate.AreEqual)
                {
                    continue;
                }

                bool file1Exists = duplicate.File1Exists;
                bool file2Exists = duplicate.File2Exists;

                if (file1Exists && file2Exists)
                {
                    switch (request.FileToRemove)
                    {
                    case ComparisonSide.Left:
                        File.Delete(duplicate.FullPath1);
                        removeCount++;
                        totalSize += duplicate.Size;
                        request.Exporter.WriteRemove(duplicate.FullPath1);
                        break;

                    case ComparisonSide.Right:
                        File.Delete(duplicate.FullPath2);
                        removeCount++;
                        totalSize += duplicate.Size;
                        request.Exporter.WriteRemove(duplicate.FullPath2);
                        break;
                    }
                }
            }

            request.Exporter.WriteSummary(removeCount, totalSize);
        }