public async Task <Stream> GetArtifactContentZipAsync(Guid projectId, int buildId, string artifactName, CancellationToken cancellationToken)
        {
            var retryEventHandler = new RetryEventHandler("Vsts_GetArtifactContentZipAsync", eventProperties: null, cancellationToken: cancellationToken, brokerInstrumentation: null);

            return(await retryer.TryActionAsync(
                       async() => await this.client.GetArtifactContentZipAsync(projectId, buildId, artifactName, userState : null, cancellationToken : cancellationToken).ConfigureAwait(false),
                       retryEventHandler).ConfigureAwait(false));
        }
        public async Task <BuildDefinitionReference> GetBuildDefinitionAsync(Guid projectId, string buildName, CancellationToken cancellationToken)
        {
            var retryEventHandler = new RetryEventHandler("Vsts_GetBuildDefinitionAsync", eventProperties: null, cancellationToken: cancellationToken, brokerInstrumentation: null);

            return(await this.retryer.TryActionAsync(
                       async() =>
            {
                var buildDefs = await this.client.GetDefinitionsAsync(projectId, name: buildName, cancellationToken: cancellationToken).ConfigureAwait(false);

                return buildDefs.FirstOrDefault();
            },
                       retryEventHandler).ConfigureAwait(false));
        }
        public async Task <BuildArtifact> GetArtifactAsync(Guid projectId, int buildId, string artifactName, CancellationToken cancellationToken)
        {
            var retryEventHandler = new RetryEventHandler("Vsts_GetArtifactAsync", eventProperties: null, cancellationToken: cancellationToken, brokerInstrumentation: null);

            var artifact = await retryer.TryActionAsync(
                async() => await this.client.GetArtifactAsync(projectId, buildId, artifactName, null, cancellationToken).ConfigureAwait(false),
                retryEventHandler).ConfigureAwait(false);

            // if you give a bad artifact name then you can get a artifact with a null resource it seems?
            if (artifact == null || artifact.Resource == null)
            {
                return(null);
            }

            return(artifact);
        }
        public async Task <Build> GetBuildAsync(Guid projectId, int buildId, CancellationToken cancellationToken)
        {
            var retryEventHandler = new RetryEventHandler("Vsts_GetBuildAsync", eventProperties: null, cancellationToken: cancellationToken, brokerInstrumentation: null);

            return(await this.retryer.TryActionAsync(
                       async() =>
            {
                Build build;

                try
                {
                    build = await this.client.GetBuildAsync(projectId, buildId, cancellationToken: cancellationToken).ConfigureAwait(false);
                }
                catch (BuildNotFoundException)
                {
                    return null;
                }

                return build;
            },
                       retryEventHandler).ConfigureAwait(false));
        }