Esempio n. 1
0
        /// <summary>
        /// https://docs.microsoft.com/en-us/rest/api/azure/devops/build/builds/list?view=azure-devops-rest-5.0
        /// </summary>
        private async IAsyncEnumerable <T> EnumerateItemsAsync <T>(
            RequestBuilder builder,
            int?limit = null)
        {
            Debug.Assert(string.IsNullOrEmpty(builder.ContinuationToken));
            var count = 0;

            do
            {
                var(json, token) = await GetJsonAndContinuationTokenAsync(builder.ToString()).ConfigureAwait(false);

                var items = AzureJsonUtil.GetArray <T>(json);
                foreach (var item in items)
                {
                    yield return(item);
                }

                count += items.Length;
                if (token is null)
                {
                    break;
                }

                if (limit.HasValue && count >= limit.Value)
                {
                    break;
                }

                builder.ContinuationToken = token;
            } while (true);
        }
Esempio n. 2
0
        public async Task <TestRun[]> ListTestRunsAsync(
            string project,
            Uri buildUri,
            ResultDetail?detail,
            int?skip = null,
            int?top  = null)
        {
            EnsureAuthorizationToken();
            var builder = GetBuilder(project, $"test/runs");

            builder.AppendUri("buildUri", buildUri);
            builder.AppendEnum("detailsToInclude", detail);
            builder.AppendInt("$skip", top);
            builder.AppendInt("$top", top);

            var count = 0;
            var json  = await GetJsonWithRetryAsync(
                builder.ToString(),
                async response =>
            {
                count++;
                if (response.StatusCode == HttpStatusCode.InternalServerError && count <= 5)
                {
                    // There is an AzDO bug where the first time we request test run they will return
                    // HTTP 500. After a few seconds though they will begin returning the proper
                    // test run info. Hence the only solution is to just wait :(
                    await Task.Delay(TimeSpan.FromSeconds(5 * count)).ConfigureAwait(false);
                    return(true);
                }

                return(false);
            }).ConfigureAwait(false);

            return(AzureJsonUtil.GetArray <TestRun>(json));
        }
Esempio n. 3
0
        private async Task <T[]> GetJsonArrayAsync <T>(RequestBuilder builder)
        {
            var json = await GetJsonAsync(builder.ToString()).ConfigureAwait(false);

            return(AzureJsonUtil.GetArray <T>(json));
        }
Esempio n. 4
0
        private async Task <T> GetJsonAsync <T>(string uri)
        {
            var json = await GetJsonAsync(uri).ConfigureAwait(false);

            return(AzureJsonUtil.GetObject <T>(json));
        }