Esempio n. 1
0
        private static async Task<IList<JToken>> GetIssues(string user, string password, Dictionary<string, string> parameters = null)
        {
            var httpClient = new HttpClient();
            httpClient.SetBasicAuthCredentials(user, password);
            var issues = new List<JToken>();
            string resource = AddParameters("https://api.github.com/repos/signalr/signalr/issues", parameters);
            string lastResource = null;

            while (true)
            {
                Console.WriteLine("GET " + resource);
                var response = await httpClient.GetAsync(resource);

                if (!response.IsSuccessStatusCode)
                {
                    Console.WriteLine(response);
                    break;
                }
                else
                {
                    var rateLimitRemainingValue = response.Headers.GetValues("X-RateLimit-Remaining").First();
                    int rateLimitRemaining;
                    if (Int32.TryParse(rateLimitRemainingValue, out rateLimitRemaining) && rateLimitRemaining < 10)
                    {
                        Console.WriteLine(rateLimitRemainingValue + " requests remaining");
                    }

                    var pageIssues = JArray.Parse(await response.Content.ReadAsStringAsync());
                    issues.AddRange(pageIssues);

                    if (resource.Equals(lastResource, StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }

                    var resourceLinks = response.GetResourceLinks();

                    resource = resourceLinks[0];

                    if (String.IsNullOrEmpty(lastResource))
                    {
                        lastResource = resourceLinks[1];
                    }
                }
            }

            return issues;
        }