/// <summary>
        ///     Move all from Input-Directory to Output-Directory, well named.
        ///     Then for each new item, invoke "duplicate" check. For that, hash needs to be calculated first
        /// </summary>
        /// <returns></returns>
        public Task Run()
        {
            var fileScannerBlock = BlockCreator.CreateFileScannerBlock();
            var hashBlock        = this.CreateHashBlock();

            // either move to recycle as duplicate
            var moveToRecycleBin = BlockCreator.CreateMoverAction(this.recycleBin.FullName);
            var finish           = new ActionBlock <PhotoContext>(context => { });

            // or continue with the meta data analysis
            var analysis = BlockCreator.ReadImageMetadataBlock();

            var suggestion       = BlockCreator.CreateSuggestionBlock();
            var mover            = BlockCreator.CreateMoverAction();
            var batched          = new BatchBlock <PhotoContext>(100);
            var registerMetadata = this.CreateRegisterMetadataBlock();

            fileScannerBlock.LinkTo(hashBlock, DataflowLinkOptions);

            // if hash is known -> move to recycle
            // if unknown, calculate other metrics and continue processing...
            var checkDuplicate = this.CreateCheckDuplicateBlock(analysis, moveToRecycleBin);

            hashBlock.LinkTo(checkDuplicate, DataflowLinkOptions);

            analysis.LinkTo(suggestion, DataflowLinkOptions);
            suggestion.LinkTo(mover, DataflowLinkOptions);
            mover.LinkTo(batched, DataflowLinkOptions);
            batched.LinkTo(registerMetadata, DataflowLinkOptions);

            moveToRecycleBin.LinkTo(finish, DataflowLinkOptions);
            finish.Completion.ContinueWith(task =>
            {
                Log.Information("Moving to recycle bin completed..");
            });

            var dbDisposed = registerMetadata.Completion.ContinueWith(task =>
            {
                Log.Information("Processing of new pictures completed..");
                this.db.Dispose();
            });

            var processContext = new ProcessContext(this.inputDirectoryInfo, this.outputDirectoryInfo);

            fileScannerBlock.Post(processContext);
            fileScannerBlock.Complete();

            return(Task.WhenAll(
                       dbDisposed,
                       finish.Completion));
        }
Exemple #2
0
        public Task Run()
        {
            var fileScannerBlock = BlockCreator.CreateFileScannerBlock();
            var analysis         = BlockCreator.ReadImageMetadataBlock();

            var filter     = BlockCreator.CreateFilterBlock();
            var suggestion = BlockCreator.CreateSuggestionBlock();
            var mover      = BlockCreator.CreateMoverAction();

            fileScannerBlock.LinkTo(analysis, DataflowLinkOptions);
            analysis.LinkTo(filter, DataflowLinkOptions);
            filter.LinkTo(suggestion, DataflowLinkOptions);
            suggestion.LinkTo(mover, DataflowLinkOptions);

            var processContext = new ProcessContext(this.inputDirectoryInfo, this.outputDirectoryInfo);

            fileScannerBlock.Post(processContext);
            fileScannerBlock.Complete();

            return(mover.Completion);
        }
Exemple #3
0
        public Task Run()
        {
            var fileScannerBlock = BlockCreator.CreateFileScannerBlock(false);

            //var analysis = ReadImageMetadataBlock();
            var hashCalculator    = BlockCreator.CreateHashCalculator(this.imageHasher);
            var collectedHashes   = BlockCreator.CollectAll <PhotoContext>();
            var findDuplicates    = BlockCreator.FindExactMatches();
            var processDuplicates = new ActionBlock <Dictionary <ulong, List <PhotoContext> > >(
                dict =>
            {
                Log.Warning($"Found {dict.Count}# images with duplicates:");
                foreach (var entry in dict)
                {
                    var fullNames = entry.Value.Select(pc => pc.Source.FullName).OrderBy(fn => fn).ToList();

                    var allImages = string.Join(", ", fullNames);
                    Log.Warning($"- {entry.Key}: {allImages}");

                    foreach (var fn in fullNames.Skip(1))
                    {
                        var target = Path.Combine(this.recycleBin.FullName, Path.GetFileName(fn));
                        File.Move(fn, target);
                    }
                }
            });

            fileScannerBlock.LinkTo(hashCalculator, DataflowLinkOptions);

            hashCalculator.LinkTo(collectedHashes, DataflowLinkOptions);
            collectedHashes.LinkTo(findDuplicates, DataflowLinkOptions);
            findDuplicates.LinkTo(processDuplicates, DataflowLinkOptions);

            var processContext = new ProcessContext(this.inputDirectoryInfo, this.outputDirectoryInfo);

            fileScannerBlock.Post(processContext);
            fileScannerBlock.Complete();

            return(processDuplicates.Completion);
        }