Пример #1
0
        internal async Task <HttpOperationResponse <Channel> > DeleteChannelInternalAsync(
            int id,
            CancellationToken cancellationToken = default
            )
        {
            if (id == default(int))
            {
                throw new ArgumentNullException(nameof(id));
            }

            const string apiVersion = "2019-01-16";

            var _path = "/api/channels/{id}";

            _path = _path.Replace("{id}", Client.Serialize(id));

            var _query = new QueryBuilder();

            _query.Add("api-version", Client.Serialize(apiVersion));

            var _uriBuilder = new UriBuilder(Client.BaseUri);

            _uriBuilder.Path  = _uriBuilder.Path.TrimEnd('/') + _path;
            _uriBuilder.Query = _query.ToString();
            var _url = _uriBuilder.Uri;

            HttpRequestMessage  _req = null;
            HttpResponseMessage _res = null;

            try
            {
                _req = new HttpRequestMessage(HttpMethod.Delete, _url);

                if (Client.Credentials != null)
                {
                    await Client.Credentials.ProcessHttpRequestAsync(_req, cancellationToken).ConfigureAwait(false);
                }

                _res = await Client.SendAsync(_req, cancellationToken).ConfigureAwait(false);

                if (!_res.IsSuccessStatusCode)
                {
                    await OnDeleteChannelFailed(_req, _res);
                }
                string _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false);

                return(new HttpOperationResponse <Channel>
                {
                    Request = _req,
                    Response = _res,
                    Body = Client.Deserialize <Channel>(_responseContent),
                });
            }
            catch (Exception)
            {
                _req?.Dispose();
                _res?.Dispose();
                throw;
            }
        }
Пример #2
0
        internal async Task <HttpOperationResponse <IImmutableList <Channel> > > ListChannelsInternalAsync(
            string classification = default,
            CancellationToken cancellationToken = default
            )
        {
            const string apiVersion = "2019-01-16";

            var _path = "/api/channels";

            var _query = new QueryBuilder();

            if (!string.IsNullOrEmpty(classification))
            {
                _query.Add("classification", Client.Serialize(classification));
            }
            _query.Add("api-version", Client.Serialize(apiVersion));

            var _uriBuilder = new UriBuilder(Client.BaseUri);

            _uriBuilder.Path  = _uriBuilder.Path.TrimEnd('/') + _path;
            _uriBuilder.Query = _query.ToString();
            var _url = _uriBuilder.Uri;

            HttpRequestMessage  _req = null;
            HttpResponseMessage _res = null;

            try
            {
                _req = new HttpRequestMessage(HttpMethod.Get, _url);

                if (Client.Credentials != null)
                {
                    await Client.Credentials.ProcessHttpRequestAsync(_req, cancellationToken).ConfigureAwait(false);
                }

                _res = await Client.SendAsync(_req, cancellationToken).ConfigureAwait(false);

                if (!_res.IsSuccessStatusCode)
                {
                    await OnListChannelsFailed(_req, _res);
                }
                string _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false);

                return(new HttpOperationResponse <IImmutableList <Channel> >
                {
                    Request = _req,
                    Response = _res,
                    Body = Client.Deserialize <IImmutableList <Channel> >(_responseContent),
                });
            }
            catch (Exception)
            {
                _req?.Dispose();
                _res?.Dispose();
                throw;
            }
        }
Пример #3
0
        internal async Task <HttpOperationResponse> TriggerDailyUpdateInternalAsync(
            CancellationToken cancellationToken = default
            )
        {
            const string apiVersion = "2019-01-16";

            var _path = "/api/subscriptions/triggerDaily";

            var _query = new QueryBuilder();

            _query.Add("api-version", Client.Serialize(apiVersion));

            var _uriBuilder = new UriBuilder(Client.BaseUri);

            _uriBuilder.Path  = _uriBuilder.Path.TrimEnd('/') + _path;
            _uriBuilder.Query = _query.ToString();
            var _url = _uriBuilder.Uri;

            HttpRequestMessage  _req = null;
            HttpResponseMessage _res = null;

            try
            {
                _req = new HttpRequestMessage(HttpMethod.Post, _url);

                if (Client.Credentials != null)
                {
                    await Client.Credentials.ProcessHttpRequestAsync(_req, cancellationToken).ConfigureAwait(false);
                }

                _res = await Client.SendAsync(_req, cancellationToken).ConfigureAwait(false);

                if (!_res.IsSuccessStatusCode)
                {
                    await OnTriggerDailyUpdateFailed(_req, _res);
                }
                string _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false);

                return(new HttpOperationResponse
                {
                    Request = _req,
                    Response = _res,
                });
            }
            catch (Exception)
            {
                _req?.Dispose();
                _res?.Dispose();
                throw;
            }
        }
Пример #4
0
        internal async Task <HttpOperationResponse <IImmutableList <MergePolicy> > > GetMergePoliciesInternalAsync(
            string branch,
            string repository,
            CancellationToken cancellationToken = default
            )
        {
            if (string.IsNullOrEmpty(branch))
            {
                throw new ArgumentNullException(nameof(branch));
            }

            if (string.IsNullOrEmpty(repository))
            {
                throw new ArgumentNullException(nameof(repository));
            }

            const string apiVersion = "2019-01-16";

            var _path = "/api/repo-config/merge-policy";

            var _query = new QueryBuilder();

            if (!string.IsNullOrEmpty(repository))
            {
                _query.Add("repository", Client.Serialize(repository));
            }
            if (!string.IsNullOrEmpty(branch))
            {
                _query.Add("branch", Client.Serialize(branch));
            }
            _query.Add("api-version", Client.Serialize(apiVersion));

            var _uriBuilder = new UriBuilder(Client.BaseUri);

            _uriBuilder.Path  = _uriBuilder.Path.TrimEnd('/') + _path;
            _uriBuilder.Query = _query.ToString();
            var _url = _uriBuilder.Uri;

            HttpRequestMessage  _req = null;
            HttpResponseMessage _res = null;

            try
            {
                _req = new HttpRequestMessage(HttpMethod.Get, _url);

                if (Client.Credentials != null)
                {
                    await Client.Credentials.ProcessHttpRequestAsync(_req, cancellationToken).ConfigureAwait(false);
                }

                _res = await Client.SendAsync(_req, cancellationToken).ConfigureAwait(false);

                if (!_res.IsSuccessStatusCode)
                {
                    await OnGetMergePoliciesFailed(_req, _res);
                }
                string _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false);

                return(new HttpOperationResponse <IImmutableList <MergePolicy> >
                {
                    Request = _req,
                    Response = _res,
                    Body = Client.Deserialize <IImmutableList <MergePolicy> >(_responseContent),
                });
            }
            catch (Exception)
            {
                _req?.Dispose();
                _res?.Dispose();
                throw;
            }
        }
Пример #5
0
        internal async Task <HttpOperationResponse> RetryActionAsyncInternalAsync(
            string branch,
            string repository,
            long timestamp,
            CancellationToken cancellationToken = default
            )
        {
            if (string.IsNullOrEmpty(branch))
            {
                throw new ArgumentNullException(nameof(branch));
            }

            if (string.IsNullOrEmpty(repository))
            {
                throw new ArgumentNullException(nameof(repository));
            }

            if (timestamp == default)
            {
                throw new ArgumentNullException(nameof(timestamp));
            }

            const string apiVersion = "2019-01-16";

            var _path = "/api/repo-config/retry/{timestamp}";

            _path = _path.Replace("{timestamp}", Client.Serialize(timestamp));

            var _query = new QueryBuilder();

            if (!string.IsNullOrEmpty(repository))
            {
                _query.Add("repository", Client.Serialize(repository));
            }
            if (!string.IsNullOrEmpty(branch))
            {
                _query.Add("branch", Client.Serialize(branch));
            }
            _query.Add("api-version", Client.Serialize(apiVersion));

            var _uriBuilder = new UriBuilder(Client.BaseUri);

            _uriBuilder.Path  = _uriBuilder.Path.TrimEnd('/') + _path;
            _uriBuilder.Query = _query.ToString();
            var _url = _uriBuilder.Uri;

            HttpRequestMessage  _req = null;
            HttpResponseMessage _res = null;

            try
            {
                _req = new HttpRequestMessage(HttpMethod.Post, _url);

                if (Client.Credentials != null)
                {
                    await Client.Credentials.ProcessHttpRequestAsync(_req, cancellationToken).ConfigureAwait(false);
                }

                _res = await Client.SendAsync(_req, cancellationToken).ConfigureAwait(false);

                if (!_res.IsSuccessStatusCode)
                {
                    await OnRetryActionAsyncFailed(_req, _res);
                }
                string _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false);

                return(new HttpOperationResponse
                {
                    Request = _req,
                    Response = _res,
                });
            }
            catch (Exception)
            {
                _req?.Dispose();
                _res?.Dispose();
                throw;
            }
        }
Пример #6
0
        internal async Task <HttpOperationResponse <AssetLocation> > AddAssetLocationToAssetInternalAsync(
            int assetId,
            AddAssetLocationToAssetAssetLocationType assetLocationType,
            string location,
            CancellationToken cancellationToken = default
            )
        {
            if (assetId == default(int))
            {
                throw new ArgumentNullException(nameof(assetId));
            }

            if (assetLocationType == default(AddAssetLocationToAssetAssetLocationType))
            {
                throw new ArgumentNullException(nameof(assetLocationType));
            }

            if (string.IsNullOrEmpty(location))
            {
                throw new ArgumentNullException(nameof(location));
            }

            const string apiVersion = "2019-01-16";

            var _path = "/api/assets/{assetId}/locations";

            _path = _path.Replace("{assetId}", Client.Serialize(assetId));

            var _query = new QueryBuilder();

            if (!string.IsNullOrEmpty(location))
            {
                _query.Add("location", Client.Serialize(location));
            }
            if (assetLocationType != default(AddAssetLocationToAssetAssetLocationType))
            {
                _query.Add("assetLocationType", Client.Serialize(assetLocationType));
            }
            _query.Add("api-version", Client.Serialize(apiVersion));

            var _uriBuilder = new UriBuilder(Client.BaseUri);

            _uriBuilder.Path  = _uriBuilder.Path.TrimEnd('/') + _path;
            _uriBuilder.Query = _query.ToString();
            var _url = _uriBuilder.Uri;

            HttpRequestMessage  _req = null;
            HttpResponseMessage _res = null;

            try
            {
                _req = new HttpRequestMessage(HttpMethod.Post, _url);

                if (Client.Credentials != null)
                {
                    await Client.Credentials.ProcessHttpRequestAsync(_req, cancellationToken).ConfigureAwait(false);
                }

                _res = await Client.SendAsync(_req, cancellationToken).ConfigureAwait(false);

                if (!_res.IsSuccessStatusCode)
                {
                    await OnAddAssetLocationToAssetFailed(_req, _res);
                }
                string _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false);

                return(new HttpOperationResponse <AssetLocation>
                {
                    Request = _req,
                    Response = _res,
                    Body = Client.Deserialize <AssetLocation>(_responseContent),
                });
            }
            catch (Exception)
            {
                _req?.Dispose();
                _res?.Dispose();
                throw;
            }
        }
Пример #7
0
        internal async Task <HttpOperationResponse <IImmutableList <Asset> > > ListAssetsInternalAsync(
            int?buildId        = default,
            bool?loadLocations = default,
            string name        = default,
            bool?nonShipping   = default,
            int?page           = default,
            int?perPage        = default,
            string version     = default,
            CancellationToken cancellationToken = default
            )
        {
            const string apiVersion = "2019-01-16";

            var _path = "/api/assets";

            var _query = new QueryBuilder();

            if (!string.IsNullOrEmpty(name))
            {
                _query.Add("name", Client.Serialize(name));
            }
            if (!string.IsNullOrEmpty(version))
            {
                _query.Add("version", Client.Serialize(version));
            }
            if (buildId != default(int))
            {
                _query.Add("buildId", Client.Serialize(buildId));
            }
            if (nonShipping != default(bool))
            {
                _query.Add("nonShipping", Client.Serialize(nonShipping));
            }
            if (loadLocations != default(bool))
            {
                _query.Add("loadLocations", Client.Serialize(loadLocations));
            }
            if (page != default(int))
            {
                _query.Add("page", Client.Serialize(page));
            }
            if (perPage != default(int))
            {
                _query.Add("perPage", Client.Serialize(perPage));
            }
            _query.Add("api-version", Client.Serialize(apiVersion));

            var _uriBuilder = new UriBuilder(Client.BaseUri);

            _uriBuilder.Path  = _uriBuilder.Path.TrimEnd('/') + _path;
            _uriBuilder.Query = _query.ToString();
            var _url = _uriBuilder.Uri;

            HttpRequestMessage  _req = null;
            HttpResponseMessage _res = null;

            try
            {
                _req = new HttpRequestMessage(HttpMethod.Get, _url);

                if (Client.Credentials != null)
                {
                    await Client.Credentials.ProcessHttpRequestAsync(_req, cancellationToken).ConfigureAwait(false);
                }

                _res = await Client.SendAsync(_req, cancellationToken).ConfigureAwait(false);

                if (!_res.IsSuccessStatusCode)
                {
                    await OnListAssetsFailed(_req, _res);
                }
                string _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false);

                return(new HttpOperationResponse <IImmutableList <Asset> >
                {
                    Request = _req,
                    Response = _res,
                    Body = Client.Deserialize <IImmutableList <Asset> >(_responseContent),
                });
            }
            catch (Exception)
            {
                _req?.Dispose();
                _res?.Dispose();
                throw;
            }
        }
Пример #8
0
        internal async Task <HttpOperationResponse <IImmutableList <SubscriptionHistoryItem> > > GetSubscriptionHistoryInternalAsync(
            Guid id,
            int?page    = default,
            int?perPage = default,
            CancellationToken cancellationToken = default
            )
        {
            if (id == default)
            {
                throw new ArgumentNullException(nameof(id));
            }

            const string apiVersion = "2019-01-16";

            var _path = "/api/subscriptions/{id}/history";

            _path = _path.Replace("{id}", Client.Serialize(id));

            var _query = new QueryBuilder();

            if (page != default)
            {
                _query.Add("page", Client.Serialize(page));
            }
            if (perPage != default)
            {
                _query.Add("perPage", Client.Serialize(perPage));
            }
            _query.Add("api-version", Client.Serialize(apiVersion));

            var _uriBuilder = new UriBuilder(Client.BaseUri);

            _uriBuilder.Path  = _uriBuilder.Path.TrimEnd('/') + _path;
            _uriBuilder.Query = _query.ToString();
            var _url = _uriBuilder.Uri;

            HttpRequestMessage  _req = null;
            HttpResponseMessage _res = null;

            try
            {
                _req = new HttpRequestMessage(HttpMethod.Get, _url);

                if (Client.Credentials != null)
                {
                    await Client.Credentials.ProcessHttpRequestAsync(_req, cancellationToken).ConfigureAwait(false);
                }

                _res = await Client.SendAsync(_req, cancellationToken).ConfigureAwait(false);

                if (!_res.IsSuccessStatusCode)
                {
                    await OnGetSubscriptionHistoryFailed(_req, _res);
                }
                string _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false);

                return(new HttpOperationResponse <IImmutableList <SubscriptionHistoryItem> >
                {
                    Request = _req,
                    Response = _res,
                    Body = Client.Deserialize <IImmutableList <SubscriptionHistoryItem> >(_responseContent),
                });
            }
            catch (Exception)
            {
                _req?.Dispose();
                _res?.Dispose();
                throw;
            }
        }
Пример #9
0
        internal async Task <HttpOperationResponse <Subscription> > UpdateSubscriptionInternalAsync(
            Guid id,
            SubscriptionUpdate body             = default,
            CancellationToken cancellationToken = default
            )
        {
            if (id == default)
            {
                throw new ArgumentNullException(nameof(id));
            }

            const string apiVersion = "2019-01-16";

            var _path = "/api/subscriptions/{id}";

            _path = _path.Replace("{id}", Client.Serialize(id));

            var _query = new QueryBuilder();

            _query.Add("api-version", Client.Serialize(apiVersion));

            var _uriBuilder = new UriBuilder(Client.BaseUri);

            _uriBuilder.Path  = _uriBuilder.Path.TrimEnd('/') + _path;
            _uriBuilder.Query = _query.ToString();
            var _url = _uriBuilder.Uri;

            HttpRequestMessage  _req = null;
            HttpResponseMessage _res = null;

            try
            {
                _req = new HttpRequestMessage(new HttpMethod("PATCH"), _url);

                string _requestContent = null;
                if (body != default)
                {
                    _requestContent = Client.Serialize(body);
                    _req.Content    = new StringContent(_requestContent, Encoding.UTF8)
                    {
                        Headers =
                        {
                            ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8"),
                        },
                    };
                }

                if (Client.Credentials != null)
                {
                    await Client.Credentials.ProcessHttpRequestAsync(_req, cancellationToken).ConfigureAwait(false);
                }

                _res = await Client.SendAsync(_req, cancellationToken).ConfigureAwait(false);

                if (!_res.IsSuccessStatusCode)
                {
                    await OnUpdateSubscriptionFailed(_req, _res);
                }
                string _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false);

                return(new HttpOperationResponse <Subscription>
                {
                    Request = _req,
                    Response = _res,
                    Body = Client.Deserialize <Subscription>(_responseContent),
                });
            }
            catch (Exception)
            {
                _req?.Dispose();
                _res?.Dispose();
                throw;
            }
        }
Пример #10
0
        internal async Task <HttpOperationResponse <Build> > GetLatestInternalAsync(
            string buildNumber                  = default,
            int?channelId                       = default,
            string commit                       = default,
            bool?loadCollections                = default,
            DateTimeOffset?notAfter             = default,
            DateTimeOffset?notBefore            = default,
            string repository                   = default,
            CancellationToken cancellationToken = default
            )
        {
            const string apiVersion = "2019-01-16";

            var _path = "/api/builds/latest";

            var _query = new QueryBuilder();

            if (!string.IsNullOrEmpty(repository))
            {
                _query.Add("repository", Client.Serialize(repository));
            }
            if (!string.IsNullOrEmpty(commit))
            {
                _query.Add("commit", Client.Serialize(commit));
            }
            if (!string.IsNullOrEmpty(buildNumber))
            {
                _query.Add("buildNumber", Client.Serialize(buildNumber));
            }
            if (channelId != default)
            {
                _query.Add("channelId", Client.Serialize(channelId));
            }
            if (notBefore != default)
            {
                _query.Add("notBefore", Client.Serialize(notBefore));
            }
            if (notAfter != default)
            {
                _query.Add("notAfter", Client.Serialize(notAfter));
            }
            if (loadCollections != default)
            {
                _query.Add("loadCollections", Client.Serialize(loadCollections));
            }
            _query.Add("api-version", Client.Serialize(apiVersion));

            var _uriBuilder = new UriBuilder(Client.BaseUri);

            _uriBuilder.Path  = _uriBuilder.Path.TrimEnd('/') + _path;
            _uriBuilder.Query = _query.ToString();
            var _url = _uriBuilder.Uri;

            HttpRequestMessage  _req = null;
            HttpResponseMessage _res = null;

            try
            {
                _req = new HttpRequestMessage(HttpMethod.Get, _url);

                if (Client.Credentials != null)
                {
                    await Client.Credentials.ProcessHttpRequestAsync(_req, cancellationToken).ConfigureAwait(false);
                }

                _res = await Client.SendAsync(_req, cancellationToken).ConfigureAwait(false);

                if (!_res.IsSuccessStatusCode)
                {
                    await OnGetLatestFailed(_req, _res);
                }
                string _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false);

                return(new HttpOperationResponse <Build>
                {
                    Request = _req,
                    Response = _res,
                    Body = Client.Deserialize <Build>(_responseContent),
                });
            }
            catch (Exception)
            {
                _req?.Dispose();
                _res?.Dispose();
                throw;
            }
        }
Пример #11
0
        internal async Task <HttpOperationResponse <Build> > CreateInternalAsync(
            BuildData body,
            CancellationToken cancellationToken = default
            )
        {
            if (body == default(BuildData))
            {
                throw new ArgumentNullException(nameof(body));
            }

            if (!body.IsValid)
            {
                throw new ArgumentException("The parameter is not valid", nameof(body));
            }

            const string apiVersion = "2019-01-16";

            var _path = "/api/builds";

            var _query = new QueryBuilder();

            _query.Add("api-version", Client.Serialize(apiVersion));

            var _uriBuilder = new UriBuilder(Client.BaseUri);

            _uriBuilder.Path  = _uriBuilder.Path.TrimEnd('/') + _path;
            _uriBuilder.Query = _query.ToString();
            var _url = _uriBuilder.Uri;

            HttpRequestMessage  _req = null;
            HttpResponseMessage _res = null;

            try
            {
                _req = new HttpRequestMessage(HttpMethod.Post, _url);

                string _requestContent = null;
                if (body != default(BuildData))
                {
                    _requestContent = Client.Serialize(body);
                    _req.Content    = new StringContent(_requestContent, Encoding.UTF8)
                    {
                        Headers =
                        {
                            ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8"),
                        },
                    };
                }

                if (Client.Credentials != null)
                {
                    await Client.Credentials.ProcessHttpRequestAsync(_req, cancellationToken).ConfigureAwait(false);
                }

                _res = await Client.SendAsync(_req, cancellationToken).ConfigureAwait(false);

                if (!_res.IsSuccessStatusCode)
                {
                    await OnCreateFailed(_req, _res);
                }
                string _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false);

                return(new HttpOperationResponse <Build>
                {
                    Request = _req,
                    Response = _res,
                    Body = Client.Deserialize <Build>(_responseContent),
                });
            }
            catch (Exception)
            {
                _req?.Dispose();
                _res?.Dispose();
                throw;
            }
        }
Пример #12
0
        internal async Task <HttpOperationResponse> SetMergePoliciesInternalAsync(
            string branch,
            string repository,
            IImmutableList <MergePolicy> body   = default,
            CancellationToken cancellationToken = default
            )
        {
            if (string.IsNullOrEmpty(branch))
            {
                throw new ArgumentNullException(nameof(branch));
            }

            if (string.IsNullOrEmpty(repository))
            {
                throw new ArgumentNullException(nameof(repository));
            }

            const string apiVersion = "2019-01-16";

            var _path = "/api/repo-config/merge-policy";

            var _query = new QueryBuilder();

            if (!string.IsNullOrEmpty(repository))
            {
                _query.Add("repository", Client.Serialize(repository));
            }
            if (!string.IsNullOrEmpty(branch))
            {
                _query.Add("branch", Client.Serialize(branch));
            }
            _query.Add("api-version", Client.Serialize(apiVersion));

            var _uriBuilder = new UriBuilder(Client.BaseUri);

            _uriBuilder.Path  = _uriBuilder.Path.TrimEnd('/') + _path;
            _uriBuilder.Query = _query.ToString();
            var _url = _uriBuilder.Uri;

            HttpRequestMessage  _req = null;
            HttpResponseMessage _res = null;

            try
            {
                _req = new HttpRequestMessage(HttpMethod.Post, _url);

                string _requestContent = null;
                if (body != default(IImmutableList <MergePolicy>))
                {
                    _requestContent = Client.Serialize(body);
                    _req.Content    = new StringContent(_requestContent, Encoding.UTF8)
                    {
                        Headers =
                        {
                            ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8"),
                        },
                    };
                }

                if (Client.Credentials != null)
                {
                    await Client.Credentials.ProcessHttpRequestAsync(_req, cancellationToken).ConfigureAwait(false);
                }

                _res = await Client.SendAsync(_req, cancellationToken).ConfigureAwait(false);

                if (!_res.IsSuccessStatusCode)
                {
                    await OnSetMergePoliciesFailed(_req, _res);
                }
                string _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false);

                return(new HttpOperationResponse
                {
                    Request = _req,
                    Response = _res,
                });
            }
            catch (Exception)
            {
                _req?.Dispose();
                _res?.Dispose();
                throw;
            }
        }
Пример #13
0
        internal async Task <HttpOperationResponse <ReleasePipeline> > CreatePipelineInternalAsync(
            string organization,
            int pipelineIdentifier,
            string project,
            CancellationToken cancellationToken = default
            )
        {
            if (string.IsNullOrEmpty(organization))
            {
                throw new ArgumentNullException(nameof(organization));
            }

            if (pipelineIdentifier == default(int))
            {
                throw new ArgumentNullException(nameof(pipelineIdentifier));
            }

            if (string.IsNullOrEmpty(project))
            {
                throw new ArgumentNullException(nameof(project));
            }

            const string apiVersion = "2019-01-16";

            var _path = "/api/pipelines";

            var _query = new QueryBuilder();

            if (pipelineIdentifier != default(int))
            {
                _query.Add("pipelineIdentifier", Client.Serialize(pipelineIdentifier));
            }
            if (!string.IsNullOrEmpty(organization))
            {
                _query.Add("organization", Client.Serialize(organization));
            }
            if (!string.IsNullOrEmpty(project))
            {
                _query.Add("project", Client.Serialize(project));
            }
            _query.Add("api-version", Client.Serialize(apiVersion));

            var _uriBuilder = new UriBuilder(Client.BaseUri);

            _uriBuilder.Path  = _uriBuilder.Path.TrimEnd('/') + _path;
            _uriBuilder.Query = _query.ToString();
            var _url = _uriBuilder.Uri;

            HttpRequestMessage  _req = null;
            HttpResponseMessage _res = null;

            try
            {
                _req = new HttpRequestMessage(HttpMethod.Post, _url);

                if (Client.Credentials != null)
                {
                    await Client.Credentials.ProcessHttpRequestAsync(_req, cancellationToken).ConfigureAwait(false);
                }

                _res = await Client.SendAsync(_req, cancellationToken).ConfigureAwait(false);

                if (!_res.IsSuccessStatusCode)
                {
                    await OnCreatePipelineFailed(_req, _res);
                }
                string _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false);

                return(new HttpOperationResponse <ReleasePipeline>
                {
                    Request = _req,
                    Response = _res,
                    Body = Client.Deserialize <ReleasePipeline>(_responseContent),
                });
            }
            catch (Exception)
            {
                _req?.Dispose();
                _res?.Dispose();
                throw;
            }
        }