internal async Task <HttpOperationResponse <WaitResponse> > WaitInternalAsync( string job, CancellationToken cancellationToken = default ) { if (string.IsNullOrEmpty(job)) { throw new ArgumentNullException(nameof(job)); } var _path = "/api/2018-03-14/jobs/{job}/wait"; _path = _path.Replace("{job}", Client.Serialize(job)); var _query = new QueryBuilder(); 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); var _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false); if (!_res.IsSuccessStatusCode) { var ex = new RestApiException { Request = new HttpRequestMessageWrapper(_req, null), Response = new HttpResponseMessageWrapper(_res, _responseContent), }; HandleFailedWaitRequest(ex); HandleFailedRequest(ex); Client.OnFailedRequest(ex); throw ex; } return(new HttpOperationResponse <WaitResponse> { Request = _req, Response = _res, Body = Client.Deserialize <WaitResponse>(_responseContent), }); } catch (Exception) { _req?.Dispose(); _res?.Dispose(); throw; } }
internal async Task <HttpOperationResponse <IImmutableList <JobSummary> > > ListInternalAsync( int count = default, string filterBuild = default, string filterCreator = default, string filterName = default, string filterSource = default, string filterType = default, CancellationToken cancellationToken = default ) { var _path = "/api/2018-03-14/jobs"; var _query = new QueryBuilder(); if (count != default) { _query.Add("count", Client.Serialize(count)); } if (!string.IsNullOrEmpty(filterCreator)) { _query.Add("filter.creator", Client.Serialize(filterCreator)); } if (!string.IsNullOrEmpty(filterSource)) { _query.Add("filter.source", Client.Serialize(filterSource)); } if (!string.IsNullOrEmpty(filterType)) { _query.Add("filter.type", Client.Serialize(filterType)); } if (!string.IsNullOrEmpty(filterBuild)) { _query.Add("filter.build", Client.Serialize(filterBuild)); } if (!string.IsNullOrEmpty(filterName)) { _query.Add("filter.name", Client.Serialize(filterName)); } 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); var _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false); if (!_res.IsSuccessStatusCode) { var ex = new RestApiException { Request = new HttpRequestMessageWrapper(_req, null), Response = new HttpResponseMessageWrapper(_res, _responseContent), }; HandleFailedListRequest(ex); HandleFailedRequest(ex); Client.OnFailedRequest(ex); throw ex; } return(new HttpOperationResponse <IImmutableList <JobSummary> > { Request = _req, Response = _res, Body = Client.Deserialize <IImmutableList <JobSummary> >(_responseContent), }); } catch (Exception) { _req?.Dispose(); _res?.Dispose(); throw; } }
internal async Task <HttpOperationResponse <JobCreationResult> > NewInternalAsync( JobCreationRequest body, string idempotencyKey, CancellationToken cancellationToken = default ) { if (body == default) { throw new ArgumentNullException(nameof(body)); } if (!body.IsValid) { throw new ArgumentException("The parameter is not valid", nameof(body)); } if (string.IsNullOrEmpty(idempotencyKey)) { throw new ArgumentNullException(nameof(idempotencyKey)); } var _path = "/api/2019-06-17/jobs"; var _query = new QueryBuilder(); 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 (!string.IsNullOrEmpty(idempotencyKey)) { _req.Headers.Add("Idempotency-Key", idempotencyKey); } 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 OnNewFailed(_req, _res); } string _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false); return(new HttpOperationResponse <JobCreationResult> { Request = _req, Response = _res, Body = Client.Deserialize <JobCreationResult>(_responseContent), }); } catch (Exception) { _req?.Dispose(); _res?.Dispose(); throw; } }
internal async Task <HttpOperationResponse <JobCreationResult> > NewInternalAsync( JobCreationRequest newJob, CancellationToken cancellationToken = default ) { if (newJob == default) { throw new ArgumentNullException(nameof(newJob)); } if (!newJob.IsValid) { throw new ArgumentException("The parameter is not valid", nameof(newJob)); } var _path = "/api/2018-03-14/jobs"; var _query = new QueryBuilder(); 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 (newJob != default) { _requestContent = Client.Serialize(newJob); _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); var _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false); if (!_res.IsSuccessStatusCode) { var ex = new RestApiException { Request = new HttpRequestMessageWrapper(_req, _requestContent), Response = new HttpResponseMessageWrapper(_res, _responseContent), }; HandleFailedNewRequest(ex); HandleFailedRequest(ex); Client.OnFailedRequest(ex); throw ex; } return(new HttpOperationResponse <JobCreationResult> { Request = _req, Response = _res, Body = Client.Deserialize <JobCreationResult>(_responseContent), }); } catch (Exception) { _req?.Dispose(); _res?.Dispose(); throw; } }
internal async Task <HttpOperationResponse <ViewConfiguration> > GetRepositoriesInternalAsync( string vcb = default, CancellationToken cancellationToken = default ) { var _path = "/api/2018-03-14/repo"; var _query = new QueryBuilder(); if (!string.IsNullOrEmpty(vcb)) { _query.Add("_vcb", Client.Serialize(vcb)); } 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); var _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false); if (!_res.IsSuccessStatusCode) { var ex = new RestApiException { Request = new HttpRequestMessageWrapper(_req, null), Response = new HttpResponseMessageWrapper(_res, _responseContent), }; HandleFailedGetRepositoriesRequest(ex); HandleFailedRequest(ex); Client.OnFailedRequest(ex); throw ex; } return(new HttpOperationResponse <ViewConfiguration> { Request = _req, Response = _res, Body = Client.Deserialize <ViewConfiguration>(_responseContent), }); } catch (Exception) { _req?.Dispose(); _res?.Dispose(); throw; } }
internal async Task <HttpOperationResponse <IImmutableList <DetailedVMScalingHistory> > > GetDetailedVMScalingHistoryInternalAsync( DateTimeOffset date, string scaleSet = default, CancellationToken cancellationToken = default ) { if (date == default) { throw new ArgumentNullException(nameof(date)); } var _path = "/api/2018-03-14/scalesets/detailedHistory"; var _query = new QueryBuilder(); if (date != default) { _query.Add("date", Client.Serialize(date)); } if (!string.IsNullOrEmpty(scaleSet)) { _query.Add("scaleSet", Client.Serialize(scaleSet)); } 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); var _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false); if (!_res.IsSuccessStatusCode) { var ex = new RestApiException { Request = new HttpRequestMessageWrapper(_req, null), Response = new HttpResponseMessageWrapper(_res, _responseContent), }; HandleFailedGetDetailedVMScalingHistoryRequest(ex); HandleFailedRequest(ex); Client.OnFailedRequest(ex); throw ex; } return(new HttpOperationResponse <IImmutableList <DetailedVMScalingHistory> > { Request = _req, Response = _res, Body = Client.Deserialize <IImmutableList <DetailedVMScalingHistory> >(_responseContent), }); } catch (Exception) { _req?.Dispose(); _res?.Dispose(); throw; } }
internal async Task <HttpOperationResponse> LogInternalAsync( string id, string logUri, string xHelixJobToken, string format = default, string module = default, CancellationToken cancellationToken = default ) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id)); } if (string.IsNullOrEmpty(logUri)) { throw new ArgumentNullException(nameof(logUri)); } if (string.IsNullOrEmpty(xHelixJobToken)) { throw new ArgumentNullException(nameof(xHelixJobToken)); } var _path = "/api/2018-03-14/telemetry/job/workitem/{id}/log"; _path = _path.Replace("{id}", Client.Serialize(id)); var _query = new QueryBuilder(); if (!string.IsNullOrEmpty(logUri)) { _query.Add("logUri", Client.Serialize(logUri)); } if (!string.IsNullOrEmpty(format)) { _query.Add("format", Client.Serialize(format)); } if (!string.IsNullOrEmpty(module)) { _query.Add("module", Client.Serialize(module)); } 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 (!string.IsNullOrEmpty(xHelixJobToken)) { _req.Headers.Add("X-Helix-Job-Token", xHelixJobToken); } if (Client.Credentials != null) { await Client.Credentials.ProcessHttpRequestAsync(_req, cancellationToken).ConfigureAwait(false); } _res = await Client.SendAsync(_req, cancellationToken).ConfigureAwait(false); string _responseContent; if (!_res.IsSuccessStatusCode) { _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false); var ex = new RestApiException( new HttpRequestMessageWrapper(_req, null), new HttpResponseMessageWrapper(_res, _responseContent)); HandleFailedLogRequest(ex); HandleFailedRequest(ex); Client.OnFailedRequest(ex); throw ex; } _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false); return(new HttpOperationResponse { Request = _req, Response = _res, }); } catch (Exception) { _req?.Dispose(); _res?.Dispose(); throw; } }
internal async Task <HttpOperationResponse <string> > StartXUnitWorkItemInternalAsync( string friendlyName, string xHelixJobToken, CancellationToken cancellationToken = default ) { if (string.IsNullOrEmpty(friendlyName)) { throw new ArgumentNullException(nameof(friendlyName)); } if (string.IsNullOrEmpty(xHelixJobToken)) { throw new ArgumentNullException(nameof(xHelixJobToken)); } var _path = "/api/2018-03-14/telemetry/job/xunit"; var _query = new QueryBuilder(); if (!string.IsNullOrEmpty(friendlyName)) { _query.Add("friendlyName", Client.Serialize(friendlyName)); } 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 (!string.IsNullOrEmpty(xHelixJobToken)) { _req.Headers.Add("X-Helix-Job-Token", xHelixJobToken); } if (Client.Credentials != null) { await Client.Credentials.ProcessHttpRequestAsync(_req, cancellationToken).ConfigureAwait(false); } _res = await Client.SendAsync(_req, cancellationToken).ConfigureAwait(false); string _responseContent; if (!_res.IsSuccessStatusCode) { _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false); var ex = new RestApiException( new HttpRequestMessageWrapper(_req, null), new HttpResponseMessageWrapper(_res, _responseContent)); HandleFailedStartXUnitWorkItemRequest(ex); HandleFailedRequest(ex); Client.OnFailedRequest(ex); throw ex; } _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false); return(new HttpOperationResponse <string> { Request = _req, Response = _res, Body = Client.Deserialize <string>(_responseContent), }); } catch (Exception) { _req?.Dispose(); _res?.Dispose(); throw; } }
internal async Task <HttpOperationResponse <MachineInformation> > GetMachineStatusInternalAsync( string machineName, string queueId, CancellationToken cancellationToken = default ) { if (string.IsNullOrEmpty(machineName)) { throw new ArgumentNullException(nameof(machineName)); } if (string.IsNullOrEmpty(queueId)) { throw new ArgumentNullException(nameof(queueId)); } var _path = "/api/2018-03-14/machines/{queueId}/{machineName}/state"; _path = _path.Replace("{queueId}", Client.Serialize(queueId)); _path = _path.Replace("{machineName}", Client.Serialize(machineName)); var _query = new QueryBuilder(); 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); string _responseContent; if (!_res.IsSuccessStatusCode) { _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false); var ex = new RestApiException( new HttpRequestMessageWrapper(_req, null), new HttpResponseMessageWrapper(_res, _responseContent)); HandleFailedGetMachineStatusRequest(ex); HandleFailedRequest(ex); Client.OnFailedRequest(ex); throw ex; } _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false); return(new HttpOperationResponse <MachineInformation> { Request = _req, Response = _res, Body = Client.Deserialize <MachineInformation>(_responseContent), }); } catch (Exception) { _req?.Dispose(); _res?.Dispose(); throw; } }
internal async Task <HttpOperationResponse <Newtonsoft.Json.Linq.JToken> > ChangeStateInternalAsync( MachineStateChangeRequest body, string machineName, string queueId, CancellationToken cancellationToken = default ) { if (body == default) { throw new ArgumentNullException(nameof(body)); } if (string.IsNullOrEmpty(machineName)) { throw new ArgumentNullException(nameof(machineName)); } if (string.IsNullOrEmpty(queueId)) { throw new ArgumentNullException(nameof(queueId)); } var _path = "/api/2018-03-14/machines/{queueId}/{machineName}/state"; _path = _path.Replace("{queueId}", Client.Serialize(queueId)); _path = _path.Replace("{machineName}", Client.Serialize(machineName)); var _query = new QueryBuilder(); 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.Put, _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); string _responseContent; if (!_res.IsSuccessStatusCode) { _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false); var ex = new RestApiException( new HttpRequestMessageWrapper(_req, _requestContent), new HttpResponseMessageWrapper(_res, _responseContent)); HandleFailedChangeStateRequest(ex); HandleFailedRequest(ex); Client.OnFailedRequest(ex); throw ex; } _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false); return(new HttpOperationResponse <Newtonsoft.Json.Linq.JToken> { Request = _req, Response = _res, Body = Client.Deserialize <Newtonsoft.Json.Linq.JToken>(_responseContent), }); } catch (Exception) { _req?.Dispose(); _res?.Dispose(); throw; } }
internal async Task <HttpOperationResponse <IImmutableList <ContainerInformation> > > ListInternalAsync( bool getSasTokens = default, CancellationToken cancellationToken = default ) { var _path = "/api/2018-03-14/storage"; var _query = new QueryBuilder(); if (getSasTokens != default) { _query.Add("getSasTokens", Client.Serialize(getSasTokens)); } 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); var _responseContent = await _res.Content.ReadAsStringAsync().ConfigureAwait(false); if (!_res.IsSuccessStatusCode) { var ex = new RestApiException { Request = new HttpRequestMessageWrapper(_req, null), Response = new HttpResponseMessageWrapper(_res, _responseContent), }; HandleFailedListRequest(ex); HandleFailedRequest(ex); Client.OnFailedRequest(ex); throw ex; } return(new HttpOperationResponse <IImmutableList <ContainerInformation> > { Request = _req, Response = _res, Body = Client.Deserialize <IImmutableList <ContainerInformation> >(_responseContent), }); } catch (Exception) { _req?.Dispose(); _res?.Dispose(); throw; } }