Example #1
0
        private async void Scan(object state)
        {
            _graph.Clear();
            var client = new GitHubClient(new ProductHeaderValue("MyAmazingApp2"), new InMemoryCredentialStore(new Credentials(_apiKey)));

            var repoClient = client.Repository;

            var scr = new SearchCodeRequest("PackageReference Lykke")
            {
                Organization = "LykkeCity",
                Extension    = "csproj"
            };

            try
            {
                _status = "Scanning";
                var searchResult = await client.Search.SearchCode(scr);

                _packagesFound = searchResult.TotalCount;

                for (int i = 0; i < _packagesFound; i += 100)
                {
                    var pageNumber = i / 100;
                    scr = new SearchCodeRequest("PackageReference Lykke")
                    {
                        Organization = "LykkeCity",
                        Extension    = "csproj",
                        Page         = pageNumber,
                    };

                    searchResult = await client.Search.SearchCode(scr);

                    Console.WriteLine($"Page {pageNumber} received {searchResult.Items.Count}");


                    foreach (var item in searchResult.Items)
                    {
                        var projectContent = await repoClient.Content.GetAllContents(item.Repository.Id, item.Path);

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

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

                        foreach (var nugetRef in nugetRefs)
                        {
                            if (!_graph.TryGetValue(nugetRef, out var repoInfos))
                            {
                                repoInfos = new HashSet <RepoInfo>();
                            }
                            repoInfos.Add(repo);
                            _graph[nugetRef] = repoInfos;
                        }

                        Thread.Sleep(500);
                    }
                }
                _lastUpDateTime = DateTime.UtcNow;
                _timer.Change(TimeSpan.FromHours(1), Timeout.InfiniteTimeSpan);
                _status = "Idle";
            }
            catch (Exception ex)
            {
                _status = $"Error. Restarting in 20 min. {ex.Message}";
                _timer.Change(TimeSpan.FromMinutes(20), Timeout.InfiniteTimeSpan);
            }
        }
 private bool Equals(RepoInfo other)
 {
     return(string.Equals(Name, other.Name) && Equals(Url, other.Url));
 }