コード例 #1
0
 public ProjectFileReader(
     INugetRestoreProcess nugetRestoreProcess = null,
     IAnalyzerManager manager = null)
 {
     _nugetRestoreProcess = nugetRestoreProcess ?? new NugetRestoreProcess();
     _manager             = manager ?? new AnalyzerManager();
     _logger = ApplicationLogging.LoggerFactory.CreateLogger <ProjectFileReader>();
 }
コード例 #2
0
 public InvokerCore()
 {
     Configuration = CreateConfiguration();
     InitLoggers();
     Services = new Container();
     Services.Configure(x =>
     {
         x.For <Container>().Singleton().Add(Services);
         x.For <ICommandManager>().Singleton().Use <CommandManager>();
         x.For <IAnalyzerManager>().Singleton().Use <AnalyzerManager>();
         x.For <IMessenger>().Add(MessengerManager.GetMessenger());
         x.For <ICommandBus>().Use <CommandBus>();
     });
     CommandManager  = Services.GetInstance <ICommandManager>();
     Analyzermanager = Services.GetInstance <IAnalyzerManager>();
     Analyzermanager.AddAnalyzer <Analyzer>();
 }
コード例 #3
0
        protected CodeGenerator(IDirectoryProvider directoryProvider, IAnalyzerManager analyzerManager)
        {
            var projectPath = Path.Combine(directoryProvider.GetSolutionDirectory().FullName, @"src\ProblemTemplateGenerator.Cli\ProblemTemplateGenerator.Cli.csproj");
            var analyzer    = analyzerManager.GetProject(projectPath);

            Workspace = analyzer.GetWorkspace();

            UnitSyntax = CompilationUnit();
            UnitSyntax = UnitSyntax.AddUsings(new[]
            {
                UsingDirective(ParseName("System")),
                UsingDirective(ParseName("System.Collections")),
                UsingDirective(ParseName("System.Collections.Generic")),
                UsingDirective(ParseName("System.Linq")),
                UsingDirective(ParseName("System.Text"))
            });
        }
コード例 #4
0
        public static AdhocWorkspace GetWorkspace(this IAnalyzerManager manager)
        {
            // Run builds in parallel
            List <IAnalyzerResult> results = manager.Projects.Values
                                             .AsParallel()
                                             .Select(p => p.Build().FirstOrDefault())
                                             .Where(x => x != null)
                                             .ToList();

            // Add each result to a new workspace
            AdhocWorkspace workspace = new AdhocWorkspace();

            foreach (AnalyzerResult result in results)
            {
                result.AddToWorkspace(workspace);
            }
            return(workspace);
        }
コード例 #5
0
        public IAnalyzerResult AnalyzeProject(
            string projectFilePath,
            string solutionFilePath,
            string targetFramework)
        {
            if (solutionFilePath != null)
            {
                _logger.LogDebug("Analyzing solution file {0}", solutionFilePath);
                try
                {
                    _manager = new AnalyzerManager(solutionFilePath);
                }
                catch (InvalidProjectFileException)
                {
                    throw new InputException($"Incorrect solution path \"{solutionFilePath}\". Solution file not found. Please review your solution path setting.");
                }
            }

            _logger.LogDebug("Analyzing project file {0}", projectFilePath);
            var analyzerResults = _manager.GetProject(projectFilePath).Build();
            var analyzerResult  = SelectAnalyzerResult(analyzerResults, targetFramework);

            LogAnalyzerResult(analyzerResult);

            if (!analyzerResult.Succeeded)
            {
                if (analyzerResult.GetTargetFramework() == Framework.DotNetClassic)
                {
                    // buildalyzer failed to find restored packages, retry after nuget restore
                    _logger.LogDebug("Project analyzer result not successful, restoring packages");
                    _nugetRestoreProcess.RestorePackages(solutionFilePath);
                    analyzerResult = _manager.GetProject(projectFilePath).Build(targetFramework).First();
                }
                else
                {
                    // buildalyzer failed, but seems to work anyway.
                    _logger.LogDebug("Project analyzer result not successful");
                }
            }

            return(analyzerResult);
        }
コード例 #6
0
        public static AdhocWorkspace GetWorkspace(this IAnalyzerManager manager)
        {
            // Run builds in parallel
            List <IAnalyzerResult> results = manager.Projects.Values
                                             .AsParallel()
                                             .Select(p => p.Build().FirstOrDefault())
                                             .Where(x => x != null)
                                             .ToList();

            // Add each result to a new workspace
            AdhocWorkspace workspace = new AdhocWorkspace();

            if (!string.IsNullOrEmpty(manager.SolutionFilePath))
            {
                SolutionInfo solutionInfo = SolutionInfo.Create(SolutionId.CreateNewId(), VersionStamp.Default, manager.SolutionFilePath);
                workspace.AddSolution(solutionInfo);
            }

            foreach (AnalyzerResult result in results)
            {
                result.AddToWorkspace(workspace);
            }
            return(workspace);
        }
 public AnalyzerReportsViewModel(ISharperCryptoAnalysisServiceProvider serviceProvider)
 {
     _serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
     AnalyzerManager  = _serviceProvider.GetService <IAnalyzerManager>();
 }
コード例 #8
0
 public CommandBus(ICommandManager commandManager, IAnalyzerManager analyzerManager, IMessenger messenger)
 {
     CommandManager  = commandManager;
     AnalyzerManager = analyzerManager;
     Messenger       = messenger;
 }
コード例 #9
0
        /*
         *   Build all the projects in workspace
         *   TODO: Need to handle different type of projects like VB, CSharp, etc.,
         *   TODO: Fix needed from Buildalyzer: https://github.com/daveaglick/Buildalyzer/issues/113
         * */
        private void BuildSolution(IAnalyzerManager manager)
        {
            //If we are building only, we don't need to run through the rest of the logic
            if (_analyzerConfiguration.BuildSettings.BuildOnly)
            {
                if (TryGetRequiresNetFramework(manager.Projects.First().Value.ProjectFile, out var isFramework))
                {
                    BuildSolutionOnlyWithoutOutput(WorkspacePath, isFramework);
                }
                return;
            }
            var options = new ParallelOptions()
            {
                MaxDegreeOfParallelism = _analyzerConfiguration.ConcurrentThreads
            };

            BlockingCollection <IAnalyzerResult> concurrentResults = new BlockingCollection <IAnalyzerResult>();

            Parallel.ForEach(manager.Projects.Values, options, p =>
            {
                Logger.LogDebug("Building the project : " + p.ProjectFile.Path);

                if (IsProjectFile(p.ProjectInSolution))
                {
                    var buildResult = BuildProject(p);
                    if (buildResult != null)
                    {
                        concurrentResults.Add(buildResult);
                        Logger.LogDebug("Building complete for {0} - {1}", p.ProjectFile.Path, buildResult.Succeeded ? "Success" : "Fail");
                    }
                    else
                    {
                        FailedProjects.Add(new ProjectAnalysisResult()
                        {
                            ProjectAnalyzer = p
                        });
                        Logger.LogDebug("Building complete for {0} - {1}", p.ProjectFile.Path, "Fail");
                    }
                }
                else
                {
                    Logger.LogDebug("Building skipped for {0} - {1}", p.ProjectFile.Path, "Skipped");
                }
            });

            List <IAnalyzerResult> results = concurrentResults.ToList();

            var dict = new Dictionary <Guid, IAnalyzerResult>();

            // Add each result to a new workspace
            using (AdhocWorkspace workspace = new AdhocWorkspace())
            {
                foreach (var result in results)
                {
                    try
                    {
                        result.AddToWorkspace(workspace);
                        dict[result.ProjectGuid] = result;
                    }
                    catch (Exception ex)
                    {
                        Logger.LogDebug("Exception : " + result.ProjectFilePath);
                        Logger.LogDebug(ex.StackTrace);
                    }
                }

                foreach (var project in workspace.CurrentSolution.Projects)
                {
                    try
                    {
                        var result = dict[project.Id.Id];

                        var projectAnalyzer = manager.Projects.Values.FirstOrDefault(p =>
                                                                                     p.ProjectGuid.Equals(project.Id.Id));

                        Projects.Add(new ProjectAnalysisResult()
                        {
                            Project         = project,
                            AnalyzerResult  = result,
                            ProjectAnalyzer = projectAnalyzer
                        });
                    }
                    catch (Exception ex)
                    {
                        Logger.LogDebug(ex.StackTrace);
                    }
                }
            }
        }
コード例 #10
0
 internal EnvironmentFactory(IAnalyzerManager manager, IProjectFile projectFile)
 {
     _manager     = manager;
     _projectFile = projectFile;
     _logger      = _manager.LoggerFactory?.CreateLogger <EnvironmentFactory>();
 }
コード例 #11
0
        /*
         *   Build all the projects in workspace
         *   TODO: Need to handle different type of projects like VB, CSharp, etc.,
         *   TODO: Fix needed from Buildalyzer: https://github.com/daveaglick/Buildalyzer/issues/113
         * */
        private void BuildSolution(IAnalyzerManager manager)
        {
            var options = new ParallelOptions()
            {
                MaxDegreeOfParallelism = _analyzerConfiguration.ConcurrentThreads
            };

            BlockingCollection <IAnalyzerResult> concurrentResults = new BlockingCollection <IAnalyzerResult>();

            Parallel.ForEach(manager.Projects.Values, options, p =>
            {
                Logger.LogDebug("Building the project : " + p.ProjectFile.Path);
                var buildResult = BuildProject(p);
                if (buildResult != null)
                {
                    concurrentResults.Add(buildResult);
                    Logger.LogDebug("Building complete for {0} - {1}", p.ProjectFile.Path, buildResult.Succeeded ? "Success" : "Fail");
                }
                else
                {
                    FailedProjects.Add(new ProjectAnalysisResult()
                    {
                        ProjectAnalyzer = p
                    });
                    Logger.LogDebug("Building complete for {0} - {1}", p.ProjectFile.Path, "Fail");
                }
            });

            List <IAnalyzerResult> results = concurrentResults.ToList();

            var dict = new Dictionary <Guid, IAnalyzerResult>();

            // Add each result to a new workspace
            using (AdhocWorkspace workspace = new AdhocWorkspace())
            {
                foreach (var result in results)
                {
                    try
                    {
                        result.AddToWorkspace(workspace);
                        dict[result.ProjectGuid] = result;
                    }
                    catch (Exception ex)
                    {
                        Logger.LogDebug("Exception : " + result.ProjectFilePath);
                        Logger.LogDebug(ex.StackTrace);
                    }
                }

                foreach (var project in workspace.CurrentSolution.Projects)
                {
                    try
                    {
                        var result = dict[project.Id.Id];

                        var projectAnalyzer = manager.Projects.Values.FirstOrDefault(p =>
                                                                                     p.ProjectGuid.Equals(project.Id.Id));

                        Projects.Add(new ProjectAnalysisResult()
                        {
                            Project         = project,
                            AnalyzerResult  = result,
                            ProjectAnalyzer = projectAnalyzer
                        });
                    }
                    catch (Exception ex)
                    {
                        Logger.LogDebug(ex.StackTrace);
                    }
                }
            }
        }
コード例 #12
0
 public TestClassGenerator(IDirectoryProvider directoryProvider, IAnalyzerManager analyzerManager)
     : base(directoryProvider, analyzerManager)
 {
 }
コード例 #13
0
 public InterfaceGenerator(IDirectoryProvider directoryProvider, IAnalyzerManager analyzerManager)
     : base(directoryProvider, analyzerManager)
 {
 }