public static T Get <T>(vCloudClient client, string url, int statusCode) { try { return(SdkUtil.ValidateResponse <T>(RestUtil.Get(client, url), statusCode)); } catch (Exception ex) { throw new VCloudException(ex.Message); } }
public static T Put <T>( vCloudClient client, string url, string requestString, string mediaType, int statusCode) { try { return(SdkUtil.ValidateResponse <T>(RestUtil.Put(client, url, requestString, mediaType, "UTF-8"), statusCode)); } catch (Exception ex) { throw new VCloudException(ex.Message); } }
public static void UploadFile( vCloudClient client, FileType file, Stream stream, long size, long startByte, long endByte) { try { string defaultUploadUrl = RestUtil.GetDefaultUploadURL(file); RestUtil.UploadFile(client, file.name, defaultUploadUrl, stream, size, startByte, endByte); } catch (Exception ex) { throw new VCloudException(ex.Message); } }
internal static Response Login( vCloudClient client, string url, HttpRequestHeaders authHeader) { HttpClient httpClient = client.HttpClient; Response response = new Response(); string str = (string)null; int num = 0; Logger.Log(TraceLevel.Information, SdkUtil.GetI18nString(SdkMessage.LOGIN_URL_MSG) + " - " + url); try { httpClient.DefaultRequestHeaders.Add("Accept", vCloudClient.SUPPORTED_SDK_VERSIONS[client.VcloudClientVersion]); HttpRequestMessage request1 = new HttpRequestMessage(HttpMethod.Post, url); HttpResponseMessage result; using (result = httpClient.SendAsync(request1).Result) { if (result != null) { if (result.StatusCode == HttpStatusCode.MovedPermanently) { if (!httpClient.DefaultRequestHeaders.Contains("Accept")) { httpClient.DefaultRequestHeaders.Add("Accept", vCloudClient.SUPPORTED_SDK_VERSIONS[client.VcloudClientVersion]); } System.Uri uri = new System.Uri(RestUtil.RedirectURL(result)); HttpRequestMessage request2 = (HttpRequestMessage)null; request2.RequestUri.MakeRelativeUri(uri); result = httpClient.SendAsync(request2).Result; } if (result.Headers.GetValues("x-vcloud-authorization") != null) { client.VcloudTokenHeader = "x-vcloud-authorization"; client.VcloudToken = result.Headers.GetValues("x-vcloud-authorization").FirstOrDefault <string>(); } num = (int)result.StatusCode; str = SerializationUtil.UTF8ByteArrayToString(result.Content.ReadAsByteArrayAsync().Result); } response.ResponseStatusCode = num; Logger.Log(TraceLevel.Information, SdkUtil.GetI18nString(SdkMessage.STATUS_CODE_MSG) + " - " + (object)num); Logger.Log(TraceLevel.Information, SdkUtil.GetI18nString(SdkMessage.STATUS_MSG) + " - " + result.StatusCode.ToString()); response.ResponseXml = str; Logger.Log(TraceLevel.Information, SdkUtil.GetI18nString(SdkMessage.RESPONSE_MSG) + " - " + str); } } catch (HttpRequestException ex) { Logger.Log(TraceLevel.Critical, ex.Message); throw new VCloudRuntimeException((Exception)ex); } catch (NotSupportedException ex) { Logger.Log(TraceLevel.Critical, ex.Message); throw new VCloudRuntimeException((Exception)ex); } catch (IOException ex) { Logger.Log(TraceLevel.Critical, ex.Message); throw new VCloudRuntimeException((Exception)ex); } catch (Exception ex) { Logger.Log(TraceLevel.Critical, ex.Message); throw new VCloudRuntimeException(ex); } finally { httpClient.DefaultRequestHeaders.Clear(); } return(response); }