Esempio n. 1
0
        private async Task IndexProjectAsync(SearchCode repoInfo, ConcurrentDictionary <PackageReference, HashSet <RepoInfo> > graph)
        {
            var projectContent = await _client.Repository.Content.GetAllContents(repoInfo.Repository.Id, repoInfo.Path);

            var repo      = RepoInfo.Parse(repoInfo.Repository.FullName, repoInfo.Repository.HtmlUrl);
            var nugetRefs = ProjectFileParser.Parse(projectContent[0].Content);

            Console.WriteLine($"Repo name {repoInfo.Repository.Name} file name {repoInfo.Name}");

            foreach (var nugetRef in nugetRefs)
            {
                if (!graph.TryGetValue(nugetRef, out var repoInfos))
                {
                    repoInfos = new HashSet <RepoInfo>();
                }

                repoInfos.Add(repo);
                graph[nugetRef] = repoInfos;
            }

            ++_scannedProjectFilesCount;
        }
        private void IndexProject(SrcFileInfo searchFile, ConcurrentDictionary <PackageReference, HashSet <RepoInfo> > graph)
        {
            var fileName = Path.GetFileName(searchFile.path);

            if (!fileName.EndsWith(".csproj"))
            {
                return;
            }

            var repoSlug     = ExtractSlugFromUrl(searchFile.links.self.href);
            var repoResource = _client.RepositoriesEndPoint().RepositoryResource(_bbAccount, repoSlug);

            if (!_reposCache.TryGetValue(repoSlug, out var repo))
            {
                var repoInfo = repoResource.GetRepository();
                repo = RepoInfo.Parse(repoInfo.slug, repoInfo.links.html.href);
                _reposCache.Add(repoSlug, repo);
                ++_foundReposCount;
            }

            var projectContent = repoResource.SrcResource().GetFileContent(searchFile.path);
            var nugetRefs      = ProjectFileParser.Parse(projectContent);

            foreach (var nugetRef in nugetRefs)
            {
                if (!graph.TryGetValue(nugetRef, out var repoInfos))
                {
                    repoInfos = new HashSet <RepoInfo>();
                }

                repoInfos.Add(repo);
                graph[nugetRef] = repoInfos;
            }

            ++_scannedProjectFilesCount;

            Console.WriteLine($"Processed {fileName} from {repo.Name}");
        }