/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> /// <returns>Success</returns> /// <exception cref="ApiException">A server side error occurred.</exception> public async System.Threading.Tasks.Task Put(System.Guid id, System.IO.Stream body, System.Threading.CancellationToken cancellationToken) { if (id == null) { throw new System.ArgumentNullException("id"); } if (body == null) { throw new System.ArgumentNullException("body"); } var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/Store/{id}/content"); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); var client_ = _httpClient; try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { var content_ = new System.Net.Http.StreamContent(body); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/pdf"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("PUT"); PrepareRequest(client_, request_, urlBuilder_); var url_ = urlBuilder_.ToString(); request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); PrepareRequest(client_, request_, url_); var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); try { var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value); if (response_.Content != null && response_.Content.Headers != null) { foreach (var item_ in response_.Content.Headers) { headers_[item_.Key] = item_.Value; } } ProcessResponse(client_, response_); var status_ = ((int)response_.StatusCode).ToString(); if (status_ == "200") { return; } else if (status_ == "404") { var objectResponse_ = await ReadObjectResponseAsync <NotFoundDTO>(response_, headers_).ConfigureAwait(false); throw new ApiException <NotFoundDTO>("Not Found", (int)response_.StatusCode, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == "500") { var objectResponse_ = await ReadObjectResponseAsync <ServerErrorDTO>(response_, headers_).ConfigureAwait(false); throw new ApiException <ServerErrorDTO>("Server Error", (int)response_.StatusCode, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == "400") { var objectResponse_ = await ReadObjectResponseAsync <BadRequestDTO>(response_, headers_).ConfigureAwait(false); throw new ApiException <BadRequestDTO>("Bad Request", (int)response_.StatusCode, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ != "200" && status_ != "204") { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new ApiException("The HTTP status code of the response was not expected (" + (int)response_.StatusCode + ").", (int)response_.StatusCode, responseData_, headers_, null); } } finally { if (response_ != null) { response_.Dispose(); } } } } finally { } }
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> /// <returns>Success</returns> /// <exception cref="ApiException">A server side error occurred.</exception> public async System.Threading.Tasks.Task UploadAsync(FileParameter file, System.Threading.CancellationToken cancellationToken) { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/Document/upload"); var client_ = _httpClient; var disposeClient_ = false; try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { var boundary_ = System.Guid.NewGuid().ToString(); var content_ = new System.Net.Http.MultipartFormDataContent(boundary_); content_.Headers.Remove("Content-Type"); content_.Headers.TryAddWithoutValidation("Content-Type", "multipart/form-data; boundary=" + boundary_); if (file != null) { var content_file_ = new System.Net.Http.StreamContent(file.Data); if (!string.IsNullOrEmpty(file.ContentType)) { content_file_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse(file.ContentType); } content_.Add(content_file_, "file", file.FileName ?? "file"); } request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); PrepareRequest(client_, request_, urlBuilder_); var url_ = urlBuilder_.ToString(); request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); PrepareRequest(client_, request_, url_); var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); var disposeResponse_ = true; try { var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value); if (response_.Content != null && response_.Content.Headers != null) { foreach (var item_ in response_.Content.Headers) { headers_[item_.Key] = item_.Value; } } ProcessResponse(client_, response_); var status_ = (int)response_.StatusCode; if (status_ == 200) { return; } else if (status_ == 400) { var objectResponse_ = await ReadObjectResponseAsync <string>(response_, headers_).ConfigureAwait(false); if (objectResponse_.Object == null) { throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } throw new ApiException <string>("Bad Request", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); } } finally { if (disposeResponse_) { response_.Dispose(); } } } } finally { if (disposeClient_) { client_.Dispose(); } } }
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> /// <summary>Provides search capability for the data set with the given search criteria.</summary> /// <param name="version">Version of the dataset.</param> /// <param name="dataset">Name of the dataset. In this case, the default value is oa_citations</param> /// <returns>successful operation</returns> /// <exception cref="ApiException">A server side error occurred.</exception> public async System.Threading.Tasks.Task <System.Collections.Generic.ICollection <System.Collections.Generic.IDictionary <string, object> > > RecordsAsync(string version, string dataset, System.IO.Stream body, System.Threading.CancellationToken cancellationToken) { if (version == null) { throw new System.ArgumentNullException("version"); } if (dataset == null) { throw new System.ArgumentNullException("dataset"); } var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/{dataset}/{version}/records"); urlBuilder_.Replace("{version}", System.Uri.EscapeDataString(ConvertToString(version, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{dataset}", System.Uri.EscapeDataString(ConvertToString(dataset, System.Globalization.CultureInfo.InvariantCulture))); var client_ = _httpClient; try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { var content_ = new System.Net.Http.StreamContent(body); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/x-www-form-urlencoded"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); PrepareRequest(client_, request_, urlBuilder_); var url_ = urlBuilder_.ToString(); request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); PrepareRequest(client_, request_, url_); var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); try { var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value); if (response_.Content != null && response_.Content.Headers != null) { foreach (var item_ in response_.Content.Headers) { headers_[item_.Key] = item_.Value; } } ProcessResponse(client_, response_); var status_ = ((int)response_.StatusCode).ToString(); if (status_ == "200") { var objectResponse_ = await ReadObjectResponseAsync <System.Collections.Generic.ICollection <System.Collections.Generic.IDictionary <string, object> > >(response_, headers_).ConfigureAwait(false); return(objectResponse_.Object); } else if (status_ == "404") { string responseText_ = (response_.Content == null) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new ApiException("No matching record found for the given criteria.", (int)response_.StatusCode, responseText_, headers_, null); } else if (status_ != "200" && status_ != "204") { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new ApiException("The HTTP status code of the response was not expected (" + (int)response_.StatusCode + ").", (int)response_.StatusCode, responseData_, headers_, null); } return(default(System.Collections.Generic.ICollection <System.Collections.Generic.IDictionary <string, object> >)); } finally { if (response_ != null) { response_.Dispose(); } } } } finally { } }