Exemple #1
0
        private void ProcessFiles(IEnumerable <string> fs)
        {
            var files = fs.Select(f => Path.GetFullPath(f).Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar)).ToList();

            List <FileDigests> digests = new List <FileDigests>();
            List <CCR>         results = new List <CCR>();
            var totalTimerId           = _PerformanceTracker?.StartTimer("Total");

            for (int iteration = 0; iteration < _Iterations; iteration++)
            {
                var digestIterationTimerId = _PerformanceTracker?.StartTimer("Digest Iteration");
                digests = files.AsParallel().Select(f =>
                {
                    var digestTimerId = _PerformanceTracker?.StartTimer("Digest");
                    var digest        = new FileDigests(f);
                    _PerformanceTracker?.EndTimer(digestTimerId.GetValueOrDefault(), "Digest");
                    return(digest);
                }).ToList();
                _PerformanceTracker?.EndTimer(digestIterationTimerId.GetValueOrDefault(), "Digest Iteration");
                results = digests.SelectMany((d1, i) => digests.Skip(i).Select((d2, j) => new CCR
                {
                    i = i,
                    j = j + i,
                    m = ImagePhash.GetCrossCorrelation(d1.BitmapSourceHash, d2.BitmapSourceHash)
                })).OrderBy(v => v.m).ToList();
            }
            _PerformanceTracker?.EndTimer(totalTimerId.GetValueOrDefault(), "Total");
            var bd         = GetCommonPath(files);
            var perfReport = _PerformanceTracker?.GenerateReport();

            _Output?.Invoke(bd, digests, results, perfReport);
        }
Exemple #2
0
 private static string GetShortPath(string bd, FileDigests d)
 => bd?.Length > 0 ? d.fi.FullName.Substring(bd.Length) : d.fi.FullName;