Exemplo n.º 1
0
     /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
     /// <exception cref="SwaggerException">A server side error occurred.</exception>
     public async System.Threading.Tasks.Task SaveItemsAsync(GenericRequestOfAddressAndPerson request, System.Threading.CancellationToken cancellationToken)
     {
         var url_ = string.Format("{0}/{1}", BaseUrl, "api/Geo/SaveItems");
 
         using (var client_ = new System.Net.Http.HttpClient())
 		{
 			var request_ = new System.Net.Http.HttpRequestMessage();
 			PrepareRequest(client_, ref url_);
 			var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(request, new Newtonsoft.Json.JsonConverter[] { new Newtonsoft.Json.Converters.StringEnumConverter(), new JsonExceptionConverter() }));
 			content_.Headers.ContentType.MediaType = "application/json";
 			request_.Content = content_;
 			request_.Method = new System.Net.Http.HttpMethod("POST");
 			request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
 			var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false);
 			ProcessResponse(client_, response_);
 
 			var responseData_ = await response_.Content.ReadAsByteArrayAsync().ConfigureAwait(false); 
 			var status_ = ((int)response_.StatusCode).ToString();
 
 			if (status_ == "204") 
 			{
 				return;
 			}
 			else
 			if (status_ == "450") 
 			{
 				var result_ = default(System.Exception); 
 				try
 				{
 					if (responseData_.Length > 0)
 						result_ = Newtonsoft.Json.JsonConvert.DeserializeObject<System.Exception>(System.Text.Encoding.UTF8.GetString(responseData_, 0, responseData_.Length), new Newtonsoft.Json.JsonConverter[] { new Newtonsoft.Json.Converters.StringEnumConverter(), new JsonExceptionConverter() });                                
 				} 
 				catch (System.Exception exception) 
 				{
 					throw new SwaggerException("Could not deserialize the response body.", status_, responseData_, exception);
 				}
 				if (result_ == null)
 					result_ = new System.Exception();
 				result_.Data.Add("HttpStatus", status_);
 				result_.Data.Add("ResponseData", System.Text.Encoding.UTF8.GetString(responseData_, 0, responseData_.Length));
 				throw new SwaggerException<System.Exception>("A custom error occured.", status_, responseData_, result_, result_);
 			}
 			else
 			if (status_ != "200" && status_ != "204")
 				throw new SwaggerException("The HTTP status code of the response was not expected (" + (int)response_.StatusCode + ").", status_, responseData_, null);
 		}
 	}
Exemplo n.º 2
0
 /// <exception cref="SwaggerException">A server side error occurred.</exception>
 public System.Threading.Tasks.Task SaveItemsAsync(GenericRequestOfAddressAndPerson request)
 {
     return SaveItemsAsync(request, System.Threading.CancellationToken.None);
 }