Пример #1
0
        public override WorkflowResult Process(WorkflowResult workflowResult       = null,
                                               CancellationToken cancellationToken = default)
        {
            CultureInfo.DefaultThreadCurrentCulture   = CultureInfo.InvariantCulture;
            CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;

            var result = workflowResult ??
                         new WorkflowResult(AnalyzedLanguages.ToList(), ThreadCount, Stage);

            result.BaseLanguages   = GetBaseLanguages(AnalyzedLanguages).ToList();
            result.RenderStages    = RenderStages;
            result.IsFoldConstants = IsFoldConstants;

            IEnumerable <string> fileNames = SourceRepository.GetFileNames();

            if (fileNames is IList <string> fileNamesList)
            {
                result.TotalFilesCount = fileNamesList.Count;
            }
            else
            {
                Task.Factory.StartNew(() => result.TotalFilesCount = fileNames.Count());
            }

            try
            {
                List <PatternRoot> patterns = ConvertPatterns(result);

                var parallelOptions = PrepareParallelOptions(cancellationToken);
                Parallel.ForEach(
                    fileNames,
                    parallelOptions,
                    fileName =>
                {
                    var patternMatcher = new PatternMatcher
                    {
                        Logger   = Logger,
                        Patterns = patterns,
                        IsIgnoreFilenameWildcards = IsIgnoreFilenameWildcards,
                        UstConstantFolder         = IsFoldConstants ? new UstConstantFolder() : null
                    };

                    ProcessFileWithTimeout(fileName, patternMatcher, result, parallelOptions.CancellationToken);
                });
            }
            catch (OperationCanceledException)
            {
                Logger.LogInfo("Scan cancelled");
            }

            DumpJsonOutput(result);
            result.ErrorCount = logger?.ErrorCount ?? 0;

            result.RootPath = SourceRepository.RootPath;

            return(result);
        }