Ejemplo n.º 1
0
        public MetricDict GenerateMetrics(IProgressReceiver progressReceiver)
        {
            int fileCount = 0;
            //get the total count of files asynchronously so we can start collecting metrics using the enumerator
            var fileCountTask = new Task(() =>
            {
                var getFiles = FileFinder.GetFiles(targetDir, extensionsToProcess, searchOption);
                fileCount    = getFiles.Length;
            });

            fileCountTask.Start();

            MetricDict metrics = new MetricDict();

            var files       = FileFinder.EnumerateFiles(targetDir, extensionsToProcess, searchOption);
            int currentFile = 0; //TODO: make atomic increments to mitigate race conditions

            Parallel.ForEach(files, new Action <FileInfo>((f) =>
            {
                var metric = metricGen.Generate(f);
                if (metric != null)
                {
                    metrics[f] = metric;
                }
                currentFile++;
                progressReceiver?.Update(new FractionalProgress(currentFile, fileCount, f.FullName));
            }));

            return(metrics);
        }