private Populate ( System.Net.Http.Headers.HttpRequestHeaders headers ) : void | ||
headers | System.Net.Http.Headers.HttpRequestHeaders | |
Résultat | void |
public async Task<OssObject> GetObject(GetObjectRequest getObjectRequest, Action<HttpProcessData> downloadProcessCallback = null, CancellationToken? cancellationToken = null) { OssObject result = null; HttpClientHandler hand = null; // ProgressMessageHandler processMessageHander = null; HttpClient localHttpClient = null; OssHttpRequestMessage httpRequestMessage = null; HttpResponseMessage response = null; try { hand = new HttpClientHandler(); // processMessageHander = new ProgressMessageHandler(hand); localHttpClient = new HttpClient(); localHttpClient.Timeout += new TimeSpan(2 * TimeSpan.TicksPerHour); httpRequestMessage = new OssHttpRequestMessage(getObjectRequest.BucketName, getObjectRequest.Key); getObjectRequest.ResponseHeaders.Populate(httpRequestMessage.Headers); getObjectRequest.Populate(httpRequestMessage.Headers); httpRequestMessage.Method = HttpMethod.Get; httpRequestMessage.Headers.Date = DateTime.UtcNow; OssRequestSigner.Sign(httpRequestMessage, networkCredential); //if (downloadProcessCallback != null) //{ // processMessageHander.HttpReceiveProgress += (sender, e) => // { // downloadProcessCallback(new HttpProcessData() // { // TotalBytes = e.TotalBytes, // BytesTransferred = e.BytesTransferred, // ProgressPercentage = e.ProgressPercentage // }); ; // }; //} if (cancellationToken != null) response = await localHttpClient.SendAsync(httpRequestMessage, (CancellationToken)cancellationToken); else response = await localHttpClient.SendAsync(httpRequestMessage); if (response.IsSuccessStatusCode == false) { await ErrorResponseHandler.Handle(response); } var temp = DeserializerFactory.GetFactory().CreateGetObjectResultDeserializer(getObjectRequest); result = await temp.Deserialize(response); } catch (Exception ex) { throw ex; } finally { if (hand != null) hand.Dispose(); //if (processMessageHander != null) // processMessageHander.Dispose(); if (localHttpClient != null) localHttpClient.Dispose(); if (httpRequestMessage != null) httpRequestMessage.Dispose(); } return result; }
public async Task <OssObject> GetObject(GetObjectRequest getObjectRequest, Action <HttpProcessData> downloadProcessCallback = null, CancellationToken?cancellationToken = null) { OssObject result = null; HttpClientHandler hand = null; ProgressMessageHandler processMessageHander = null; HttpClient localHttpClient = null; OssHttpRequestMessage httpRequestMessage = null; HttpResponseMessage response = null; try { hand = new HttpClientHandler(); processMessageHander = new ProgressMessageHandler(hand); localHttpClient = new HttpClient(processMessageHander); localHttpClient.Timeout += new TimeSpan(2 * TimeSpan.TicksPerHour); httpRequestMessage = new OssHttpRequestMessage(getObjectRequest.BucketName, getObjectRequest.Key); getObjectRequest.ResponseHeaders.Populate(httpRequestMessage.Headers); getObjectRequest.Populate(httpRequestMessage.Headers); httpRequestMessage.Method = HttpMethod.Get; httpRequestMessage.Headers.Date = DateTime.UtcNow; OssRequestSigner.Sign(httpRequestMessage, networkCredential); if (downloadProcessCallback != null) { processMessageHander.HttpReceiveProgress += (sender, e) => { downloadProcessCallback(new HttpProcessData() { TotalBytes = e.TotalBytes, BytesTransferred = e.BytesTransferred, ProgressPercentage = e.ProgressPercentage });; }; } if (cancellationToken != null) { response = await localHttpClient.SendAsync(httpRequestMessage, (CancellationToken)cancellationToken); } else { response = await localHttpClient.SendAsync(httpRequestMessage); } if (response.IsSuccessStatusCode == false) { await ErrorResponseHandler.Handle(response); } var temp = DeserializerFactory.GetFactory().CreateGetObjectResultDeserializer(getObjectRequest); result = await temp.Deserialize(response); } catch (Exception ex) { throw ex; } finally { if (hand != null) { hand.Dispose(); } if (processMessageHander != null) { processMessageHander.Dispose(); } if (localHttpClient != null) { localHttpClient.Dispose(); } if (httpRequestMessage != null) { httpRequestMessage.Dispose(); } } return(result); }