async Task CheckForDuplicates(LocalImage[] inDirectory)
        {
            // Here, we create a list that contains all the names of files
            // that we already processed. This is so we don't re-process the
            // same images, when we pass over them again.
            var visited = new List <string>();

            // Using a `for` loop here against the LocalImage array, to focus
            // more on performance.
            for (var index = 0; index < inDirectory.Length; index++)
            {
                if (visited.Contains(inDirectory[index].Name))
                {
                    continue;
                }

                var duplicates = await VisitOthers(inDirectory, inDirectory[index], visited);

                if (duplicates.Any())
                {
                    var duplicateResult = new DeDupifyrResult(inDirectory[index]);
                    duplicateResult.Duplicates.AddRange(duplicates);
                    duplicateResults.Add(duplicateResult);
                }

                visited.Add(inDirectory[index].Name);
            }

            // We no longer need to keep the visited list in scope,
            // clear it out.
            visited.Clear();
        }
Example #2
0
        public async Task <List <DeDupifyrResult> > Run(ComparisonRequest request)
        {
            // If the paths are equal, print that we were given the same image path.
            if (request.FirstImagePath.Value == request.SecondImagePath.Value)
            {
                Console.WriteLine("The two paths given point to the same image.");
            }

            Console.WriteLine($"Comparing images at {request.FirstImagePath.Value} and {request.SecondImagePath.Value}...");

            var sourceImage = await BuildLocalImage(request.FirstImagePath.Value);

            var targetImage = await BuildLocalImage(request.SecondImagePath.Value);

            var duplicateResult = new DeDupifyrResult(sourceImage);

            await UpdateDuplicationCollection(
                sourceImage,
                targetImage,
                duplicateResult.Duplicates);

            duplicateResults.Add(duplicateResult);

            return(duplicateResults);
        }
Example #3
0
        public async Task <List <DeDupifyrResult> > Run(ComparisonRequest request)
        {
            Console.WriteLine($"Comparing the image at '{request.FirstImagePath.Value}' with all images in '{request.DirectoryPath.Value}'...");

            var sourceImage = await BuildLocalImage(request.FirstImagePath.Value);

            var otherImageBuilders = ImageBuildersFromDirectory(
                request.DirectoryPath.Value,
                file => ValidExtensions.ForImage.Contains(Path.GetExtension(file)) &&
                file != request.FirstImagePath.Value);

            var otherImages = await Task.WhenAll(otherImageBuilders);

            var duplicateResult = new DeDupifyrResult(sourceImage);
            var duplicateImages = await CompareToOthers(sourceImage, otherImages);

            duplicateResult.Duplicates.AddRange(duplicateImages);

            duplicateResults.Add(duplicateResult);

            return(duplicateResults);
        }