/// <summary>
        /// Deletes lower resolution copies of images from directory.
        /// </summary>
        /// <param name="imageDataCollection">List of image data from db.</param>
        /// <param name="ownerId">Id of imageDataCollection owner.</param>
        /// <param name="directoryPath">Directory to check.</param>
        public void DeleteDuplicateImagesFromDirectoryAndDb(ICollection <ImageData> imageDataCollection, int ownerId, string directoryPath)
        {
            //search for duplicates in album images directory.
            var imagePaths          = _fileManager.GetImageSimpleFileInfosFromDirectory(directoryPath).Select(sfi => sfi.Path).ToList();
            var imageComparer       = new ImageSizeComparer();
            var duplicateImagePaths = _imageDuplicateFinder.GetDuplicateImagePaths(imagePaths, imageComparer);

            //delete lower resolution image duplicates
            foreach (var duplicateImagePath in duplicateImagePaths)
            {
                var duplicateImageName = Path.GetFileName(duplicateImagePath);
                //delete file from image directory
                //TODO: Add TryDeleteFile to IFileManager
                _fileManager.DeleteFile(duplicateImagePath);
                //delete imageDataCollection from image data collection
                var imageDataToRemove = imageDataCollection.FirstOrDefault(img => img.Name.Equals(duplicateImageName));
                //skip images with no records in collection
                if (imageDataToRemove == null)
                {
                    continue;
                }
                //delete imageDataCollection from db and collection
                DeleteImageDataFromCollectionAndDb(imageDataCollection, imageDataToRemove);
            }
        }
Ejemplo n.º 2
0
        public void GetDuplicateImagePaths_ShouldReturnListOFDuplicateImagePaths()
        {
            var imagePathList = new List <string>()
            {
                _image1FilePath, _image3FilePath, _image2FilePath, _image4FilePath
            };
            var imageSizeComparer = new ImageSizeComparer();

            var duplicates = _sut.GetDuplicateImagePaths(imagePathList, imageSizeComparer, 3, 0.1f).ToList();

            Assert.That(duplicates, Has.Count.EqualTo(2));
            Assert.That(duplicates, Contains.Item(_image3FilePath).And.Contains(_image4FilePath));
        }