mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Complete the progress bar rendering in Invoke-WebRequest when downloading is complete or cancelled (#18130)
This commit is contained in:
+17
-7
@@ -298,6 +298,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
Task copyTask = input.CopyToAsync(output, cancellationToken);
|
||||
|
||||
bool wroteProgress = false;
|
||||
ProgressRecord record = new(
|
||||
ActivityId,
|
||||
WebCmdletStrings.WriteRequestProgressActivity,
|
||||
@@ -313,23 +314,32 @@ namespace Microsoft.PowerShell.Commands
|
||||
Utils.DisplayHumanReadableFileSize(output.Position),
|
||||
totalDownloadSize);
|
||||
|
||||
if (contentLength != null && contentLength > 0)
|
||||
if (contentLength > 0)
|
||||
{
|
||||
record.PercentComplete = Math.Min((int)(output.Position * 100 / (long)contentLength), 100);
|
||||
}
|
||||
|
||||
cmdlet.WriteProgress(record);
|
||||
}
|
||||
|
||||
if (copyTask.IsCompleted)
|
||||
{
|
||||
record.StatusDescription = StringUtil.Format(WebCmdletStrings.WriteRequestComplete, output.Position);
|
||||
cmdlet.WriteProgress(record);
|
||||
wroteProgress = true;
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (wroteProgress)
|
||||
{
|
||||
// Write out the completion progress record only if we did render the progress.
|
||||
record.StatusDescription = StringUtil.Format(
|
||||
copyTask.IsCompleted
|
||||
? WebCmdletStrings.WriteRequestComplete
|
||||
: WebCmdletStrings.WriteRequestCancelled,
|
||||
output.Position);
|
||||
record.RecordType = ProgressRecordType.Completed;
|
||||
cmdlet.WriteProgress(record);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -199,7 +199,7 @@
|
||||
<value>The cmdlet cannot run because the following parameter is missing: Proxy. Provide a valid proxy URI for the Proxy parameter when using the ProxyCredential or ProxyUseDefaultCredentials parameters, then retry.</value>
|
||||
</data>
|
||||
<data name="ReadResponseComplete" xml:space="preserve">
|
||||
<value>Reading web response stream completed. Downloaded: {0}</value>
|
||||
<value>Reading web response stream completed. Bytes downloaded: {0}</value>
|
||||
</data>
|
||||
<data name="ReadResponseProgressActivity" xml:space="preserve">
|
||||
<value>Reading web response stream</value>
|
||||
@@ -219,6 +219,9 @@
|
||||
<data name="WriteRequestComplete" xml:space="preserve">
|
||||
<value>Web request completed. (Number of bytes processed: {0})</value>
|
||||
</data>
|
||||
<data name="WriteRequestCancelled" xml:space="preserve">
|
||||
<value>Web request cancelled. (Number of bytes processed: {0})</value>
|
||||
</data>
|
||||
<data name="WriteRequestProgressActivity" xml:space="preserve">
|
||||
<value>Web request status</value>
|
||||
</data>
|
||||
|
||||
Reference in New Issue
Block a user