Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
using System;
using System.Collections.Generic;
using System.Management.Automation;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.Azure.Commands.Compute.Strategies
Expand All @@ -32,6 +31,8 @@ public static void StartAndWait(
this Cmdlet cmdlet, Func<IAsyncCmdlet, Task> createAndStartTask)
{
var asyncCmdlet = new AsyncCmdlet(cmdlet);
string previousX = null;
string previousOperation = null;
asyncCmdlet.Scheduler.Wait(
createAndStartTask(asyncCmdlet),
() =>
Expand All @@ -52,17 +53,25 @@ public static void StartAndWait(
var percent = (int)(progress * 100.0);
var r = new[] { "|", "/", "-", "\\" };
var x = r[DateTime.Now.Second % 4];
cmdlet.WriteProgress(
new ProgressRecord(
0,
"Creating Azure resources",
percent + "% " + x)
{
CurrentOperation = activeTasks.Count > 0
? "Creating " + string.Join(", ", activeTasks) + "."
: null,
PercentComplete = percent,
});
var operation = activeTasks.Count > 0
? "Creating " + string.Join(", ", activeTasks) + "."
: null;

// write progress only if it's changed.
if (x != previousX || operation != previousOperation)
{
cmdlet.WriteProgress(
new ProgressRecord(
0,
"Creating Azure resources",
percent + "% " + x)
{
CurrentOperation = operation,
PercentComplete = percent,
});
previousX = x;
previousOperation = operation;
}
}
});
}
Expand Down