Last active
June 11, 2022 20:34
-
-
Save paulodiogo/9b51a5e3df50acf1af2ae5522a9041ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var response = await webDavClient.GetProcessedFile(uri, new GetFileParameters { CancellationToken = cancellationTokenSource.Token }); | |
var size = response.ContentLength(); | |
var destination = new MemoryStream(); | |
byte[] buffer = new byte[bufferSize]; | |
int read; | |
long totalRead = 0; | |
while ((read = await response.Stream.ReadAsync(buffer, 0, buffer.Length, cancellationTokenSource.Token)) != 0) | |
{ | |
await destination.WriteAsync(buffer, 0, read); | |
totalRead += read; | |
Progress = totalRead / (double)size; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class WebDavStreamResponseExtensions | |
{ | |
public static long? ContentLength(this WebDavStreamResponse message) | |
{ | |
FieldInfo fields = typeof(WebDavStreamResponse).GetFields(BindingFlags.NonPublic | BindingFlags.Instance) | |
.FirstOrDefault(x => x.FieldType == typeof(HttpResponseMessage)); | |
HttpResponseMessage response = fields.GetValue(message) as HttpResponseMessage; | |
return response?.Content?.Headers?.ContentLength ?? 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment