Esempio n. 1
0
        private static void AnalyseStandalone(
            StandaloneAnalyser analyser,
            IEnumerable <string> sources,
            IEnumerable <string> referencePaths,
            CommonOptions options,
            IProgressMonitor progressMonitor,
            Stopwatch stopwatch)
        {
            Analyse(stopwatch, analyser, options,
                    references => GetResolvedReferencesStandalone(referencePaths, references),
                    (analyser, syntaxTrees) => ReadSyntaxTrees(sources, analyser, null, null, syntaxTrees),
                    (syntaxTrees, references) => CSharpCompilation.Create("csharp.dll", syntaxTrees, references),
                    (compilation, options) => analyser.InitializeStandalone(compilation, options),
                    () => { },
                    _ => { },
                    () =>
            {
                foreach (var type in analyser.MissingNamespaces)
                {
                    progressMonitor.MissingNamespace(type);
                }

                foreach (var type in analyser.MissingTypes)
                {
                    progressMonitor.MissingType(type);
                }

                progressMonitor.MissingSummary(analyser.MissingTypes.Count(), analyser.MissingNamespaces.Count());
            });
        }
Esempio n. 2
0
        public static void ExtractStandalone(
            IEnumerable <string> sources,
            IEnumerable <string> referencePaths,
            IProgressMonitor pm,
            ILogger logger,
            CommonOptions options)
        {
            using (var analyser = new Analyser(pm, logger))
                using (var references = new BlockingCollection <MetadataReference>())
                {
                    try
                    {
                        var referenceTasks = referencePaths.Select <string, Action>(path => () =>
                        {
                            var reference = MetadataReference.CreateFromFile(path);
                            references.Add(reference);
                        });

                        var syntaxTrees     = new List <SyntaxTree>();
                        var syntaxTreeTasks = ReadSyntaxTrees(sources, analyser, null, null, syntaxTrees);

                        var sw = new Stopwatch();
                        sw.Start();

                        Parallel.Invoke(
                            new ParallelOptions {
                            MaxDegreeOfParallelism = options.Threads
                        },
                            referenceTasks.Interleave(syntaxTreeTasks).ToArray());

                        if (syntaxTrees.Count == 0)
                        {
                            analyser.Logger.Log(Severity.Error, "  No source files");
                            ++analyser.CompilationErrors;
                        }

                        var compilation = CSharpCompilation.Create(
                            "csharp.dll",
                            syntaxTrees,
                            references
                            );

                        analyser.InitializeStandalone(compilation, options);
                        analyser.AnalyseReferences();

                        foreach (var tree in compilation.SyntaxTrees)
                        {
                            analyser.AnalyseTree(tree);
                        }

                        sw.Stop();
                        analyser.Logger.Log(Severity.Info, "  Models constructed in {0}", sw.Elapsed);

                        sw.Restart();
                        analyser.PerformExtraction(options.Threads);
                        sw.Stop();
                        analyser.Logger.Log(Severity.Info, "  Extraction took {0}", sw.Elapsed);

                        foreach (var type in analyser.MissingNamespaces)
                        {
                            pm.MissingNamespace(type);
                        }

                        foreach (var type in analyser.MissingTypes)
                        {
                            pm.MissingType(type);
                        }

                        pm.MissingSummary(analyser.MissingTypes.Count(), analyser.MissingNamespaces.Count());
                    }
                    catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
                    {
                        analyser.Logger.Log(Severity.Error, "  Unhandled exception: {0}", ex);
                    }
                }
        }