Exemplo n.º 1
0
        public void DownloadTestProjects()
        {
            _tempDirName = Path.Combine("Projects", "TempFD");
            _tempBaseDir = Path.Combine(TestUtils.GetTstPath(), _tempDirName);
            var tempDownloadDir = Path.Combine(_tempBaseDir, "d");

            // Download test solutions
            DownloadTestProjects(tempDownloadDir);

            // Get directory of each solution
            var tempCoreMvcSolutionDir                 = GetSolutionDir(tempDownloadDir, CoreMvcSolutionName);
            var tempCoreWebApiSolutionDir              = GetSolutionDir(tempDownloadDir, CoreWebApiSolutionName);
            var tempEfSolutionDir                      = GetSolutionDir(tempDownloadDir, EfSolutionName);
            var tempMvcSolutionDir                     = GetSolutionDir(tempDownloadDir, MvcSolutionName);
            var tempWebApiSolutionDir                  = GetSolutionDir(tempDownloadDir, WebApiSolutionName);
            var tempWebClassLibrarySolutionDir         = GetSolutionDir(tempDownloadDir, WebClassLibrarySolutionName);
            var tempWindowsAuthenticationSolutionDir   = GetSolutionDir(tempDownloadDir, WindowsAuthenticationSolutionName);
            var tempFormsAuthenticationSolutionDir     = GetSolutionDir(tempDownloadDir, FormsAuthenticationSolutionName);
            var tempFederatedAuthenticationSolutionDir = GetSolutionDir(tempDownloadDir, FederatedAuthenticationSolutionName);

            // Copy solutions to a directory with a shorter path
            var destDir = "dest";

            _targetDir = Path.Combine(_tempBaseDir, destDir);
            TestUtils.CopyDirectory(tempCoreMvcSolutionDir, new DirectoryInfo(Path.Combine(_targetDir, _coreMvcDir)));
            TestUtils.CopyDirectory(tempCoreWebApiSolutionDir, new DirectoryInfo(Path.Combine(_targetDir, _coreWebApiDir)));
            TestUtils.CopyDirectory(tempEfSolutionDir, new DirectoryInfo(Path.Combine(_targetDir, _efDir)));
            TestUtils.CopyDirectory(tempMvcSolutionDir, new DirectoryInfo(Path.Combine(_targetDir, _mvcDir)));
            TestUtils.CopyDirectory(tempWebApiSolutionDir, new DirectoryInfo(Path.Combine(_targetDir, _webApiDir)));
            TestUtils.CopyDirectory(tempWebClassLibrarySolutionDir, new DirectoryInfo(Path.Combine(_targetDir, _webClassLibraryDir)));
            TestUtils.CopyDirectory(tempWindowsAuthenticationSolutionDir, new DirectoryInfo(Path.Combine(_targetDir, _windowsAuthenticationDir)));
            TestUtils.CopyDirectory(tempFormsAuthenticationSolutionDir, new DirectoryInfo(Path.Combine(_targetDir, _formsAuthenticationDir)));
            TestUtils.CopyDirectory(tempFederatedAuthenticationSolutionDir, new DirectoryInfo(Path.Combine(_targetDir, _federatedAuthenticationDir)));

            // Run source code analysis
            CoreMvcAnalyzerResults                 = AnalyzerResultsFactory.GetAnalyzerResults(CoreMvcSolutionPath);
            CoreWebApiAnalyzerResults              = AnalyzerResultsFactory.GetAnalyzerResults(CoreWebApiSolutionPath);
            EfAnalyzerResults                      = AnalyzerResultsFactory.GetAnalyzerResults(EfSolutionPath);
            MvcAnalyzerResults                     = AnalyzerResultsFactory.GetAnalyzerResults(MvcSolutionPath);
            WebApiAnalyzerResults                  = AnalyzerResultsFactory.GetAnalyzerResults(WebApiSolutionPath);
            WebClassLibraryAnalyzerResults         = AnalyzerResultsFactory.GetAnalyzerResults(WebClassLibrarySolutionPath);
            WindowsAuthenticationAnalyzerResults   = AnalyzerResultsFactory.GetAnalyzerResults(WindowsAuthenticationSolutionPath);
            FormsAuthenticationAnalyzerResults     = AnalyzerResultsFactory.GetAnalyzerResults(FormsAuthenticationSolutionPath);
            FederatedAuthenticationAnalyzerResults = AnalyzerResultsFactory.GetAnalyzerResults(FederatedAuthenticationSolutionPath);

            // Detect features in each solution
            FeatureDetector = new FeatureDetector(ConfigFile);
            CoreMvcFeatureDetectionResult                 = FeatureDetector.DetectFeaturesInProjects(CoreMvcAnalyzerResults)[CoreMvcProjectPath];
            CoreWebApiFeatureDetectionResult              = FeatureDetector.DetectFeaturesInProjects(CoreWebApiAnalyzerResults)[CoreWebApiProjectPath];
            Ef6FeatureDetectionResult                     = FeatureDetector.DetectFeaturesInProjects(EfAnalyzerResults)[Ef6ProjectPath];
            MvcFeatureDetectionResult                     = FeatureDetector.DetectFeaturesInProjects(MvcAnalyzerResults)[MvcProjectPath];
            WebApiFeatureDetectionResult                  = FeatureDetector.DetectFeaturesInProjects(WebApiAnalyzerResults)[WebApiProjectPath];
            WebClassLibraryFeatureDetectionResult         = FeatureDetector.DetectFeaturesInProjects(WebClassLibraryAnalyzerResults)[WebClassLibraryProjectPath];
            WindowsAuthenticationFeatureDetectionResult   = FeatureDetector.DetectFeaturesInProjects(WindowsAuthenticationAnalyzerResults)[WindowsAuthenticationProjectPath];
            FormsAuthenticationFeatureDetectionResult     = FeatureDetector.DetectFeaturesInProjects(FormsAuthenticationAnalyzerResults)[FormsAuthenticationProjectPath];
            FederatedAuthenticationFeatureDetectionResult = FeatureDetector.DetectFeaturesInProjects(FederatedAuthenticationAnalyzerResults)[FederatedAuthenticationProjectPath];
        }
Exemplo n.º 2
0
        private void InitRules(List <PortCoreConfiguration> solutionConfiguration, List <AnalyzerResult> analyzerResults)
        {
            using var projectTypeFeatureDetector = new FeatureDetector();

            // sync up passed in configuration with analyze results
            solutionConfiguration      = solutionConfiguration.Where(s => analyzerResults.Select(a => a.ProjectResult?.ProjectFilePath).Contains(s.ProjectPath)).ToList();
            analyzerResults            = analyzerResults.Where(a => solutionConfiguration.Select(s => s.ProjectPath).Contains(a.ProjectResult?.ProjectFilePath)).ToList();
            _projectTypeFeatureResults = projectTypeFeatureDetector.DetectFeaturesInProjects(analyzerResults);

            var allReferences = new HashSet <string>();

            foreach (var projectConfiguration in solutionConfiguration)
            {
                var projectTypeFeatureResult = _projectTypeFeatureResults[projectConfiguration.ProjectPath];
                projectConfiguration.ProjectType = GetProjectType(projectTypeFeatureResult);
                if (projectConfiguration.UseDefaultRules)
                {
                    //If a rules dir was provided, copy files from that dir into the rules folder
                    if (!string.IsNullOrEmpty(projectConfiguration.RulesDir))
                    {
                        CopyOverrideRules(projectConfiguration.RulesDir);
                    }
                    projectConfiguration.RulesDir = Constants.RulesDefaultPath;
                    var projectResult = analyzerResults
                                        .FirstOrDefault(a => a.ProjectResult?.ProjectFilePath == projectConfiguration.ProjectPath)
                                        .ProjectResult;

                    projectResult?.SourceFileResults?.SelectMany(s => s.References)?.Select(r => r.Namespace).Distinct().ToList().ForEach(currentReference => {
                        if (currentReference != null && !allReferences.Contains(currentReference))
                        {
                            allReferences.Add(currentReference);
                        }
                    });

                    projectResult?.SourceFileResults?.SelectMany(s => s.Children.OfType <UsingDirective>())?.Select(u => u.Identifier).Distinct().ToList().ForEach(currentReference => {
                        if (currentReference != null && !allReferences.Contains(currentReference))
                        {
                            allReferences.Add(currentReference);
                        }
                    });
                }
                AddWCFReferences(projectConfiguration);

                projectConfiguration.AdditionalReferences.Add(Constants.ProjectRecommendationFile);

                allReferences.UnionWith(projectConfiguration.AdditionalReferences);
            }

            _portSolutionResult.References = allReferences.ToHashSet <string>();

            DownloadRecommendationFiles(allReferences);
        }
Exemplo n.º 3
0
        private void InitRules(List<PortCoreConfiguration> solutionConfiguration, List<AnalyzerResult> analyzerResults)
        {
            var projectTypeFeatureDetector = new FeatureDetector();
            var projectTypeFeatureResults = projectTypeFeatureDetector.DetectFeaturesInProjects(analyzerResults);

            foreach (var projectConfiguration in solutionConfiguration)
            {
                var projectTypeFeatureResult = projectTypeFeatureResults[projectConfiguration.ProjectPath];
                projectConfiguration.ProjectType = GetProjectType(projectTypeFeatureResult);
                if (projectConfiguration.UseDefaultRules)
                {
                    DownloadRecommendationFiles(analyzerResults);
                    projectConfiguration.RulesPath = Constants.RulesDefaultPath;
                }
            }
        }