Skip to content

Commit 45d9510

Browse files
author
Matt Wilkinson
committed
Convert progress reporting to use Write-Progress to give powershell-native feedback on import progress
1 parent ec7dee9 commit 45d9510

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

Microsoft.Xrm.Data.PowerShell/Microsoft.Xrm.Data.PowerShell.psm1

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,13 +2146,13 @@ function Import-CrmSolution{
21462146
}
21472147

21482148
Write-Verbose "Calling .ImportSolutionToCrm() this process can take minutes..."
2149+
Write-Progress -Id 1 -Activity "Importing Solution" -CurrentOperation "Initiating import" -PercentComplete -1
21492150
$result = $conn.ImportSolutionToCrm($SolutionFilePath, [ref]$importId, $ActivatePlugIns,
21502151
$OverwriteUnManagedCustomizations, $SkipDependancyOnProductUpdateCheckOnInstall,$ImportAsHoldingSolution)
21512152
Write-Verbose "ImportId: $result"
21522153
if ($result -eq [guid]::Empty) {
21532154
throw LastCrmConnectorException($conn)
21542155
}
2155-
$pollingStart = Get-Date
21562156
$isProcessing = $true
21572157
$secondsSpentPolling = 0
21582158
$pollingDelaySeconds = 5
@@ -2162,6 +2162,7 @@ function Import-CrmSolution{
21622162
$transientFailureCount = 0;
21632163
Write-Host "Import of file completed, waiting on completion of importId: $importId"
21642164
try{
2165+
Write-Progress -Id 1 -Activity "Importing Solution" -CurrentOperation "Solution file uploaded, import initiated" -PercentComplete -1
21652166
while($isProcessing -and $secondsSpentPolling -lt $MaxWaitTimeInSeconds){
21662167

21672168
#check the import job for success/fail/inProgress
@@ -2180,6 +2181,8 @@ function Import-CrmSolution{
21802181
$importManifest = ([xml]($import).data).importexportxml.solutionManifests.solutionManifest
21812182
$ProcPercent = [double](Coalesce $import.progress "0")
21822183

2184+
Write-Progress -Id 1 -Activity "Importing $($import.solutionname)" -CurrentOperation "Import processing" -PercentComplete $ProcPercent
2185+
21832186
#check if processing percentage reduced at any given time
21842187
if($TopPrevProcPercent -gt $ProcPercent)
21852188
{
@@ -2192,8 +2195,6 @@ function Import-CrmSolution{
21922195
#Check for import completion
21932196
if($import.completedon -eq $null -and $importManifest.result.result -ne "success"){
21942197
$isProcessing = $true
2195-
$secondsSpentPolling = ([Int]((Get-Date) - $pollingStart).TotalSeconds)
2196-
Write-Host "$($secondsSPentPolling.ToString("000")) seconds of max: $MaxWaitTimeInSeconds ... ImportJob%: $ProcPercent"
21972198
}
21982199
else {
21992200
Write-Verbose "Processing Completed at: $($import.completedon) with ImportJob%: $ProcPercent"
@@ -2244,12 +2245,14 @@ function Import-CrmSolution{
22442245
break
22452246
}
22462247

2248+
Write-Progress -Id 2 -ParentId 1 -Activity "Maximum Wait Time ($(New-TimeSpan -Seconds $MaxWaitTimeInSeconds))" -CurrentOperation "Remaining Time: $(New-TimeSpan -Seconds ($MaxWaitTimeInSeconds - $secondsSpentPolling))" -PercentComplete ([double]($MaxWaitTimeInSeconds - $secondsSpentPolling) * 100 / $MaxWaitTimeInSeconds)
22472249
Start-Sleep -Seconds $pollingDelaySeconds
22482250
}
22492251
} Catch {
22502252
Write-Error "ImportJob with ID: $importId has encountered an exception: $_ "
22512253
} Finally{
22522254
$ProcPercent = ([double](Coalesce $ProcPercent 0))
2255+
Write-Progress -Id 2 -Completed -Activity "_"
22532256
}
22542257
#User provided timeout and exit function with an error
22552258
if($secondsSpentPolling -gt $MaxWaitTimeInSeconds){
@@ -2284,7 +2287,12 @@ function Import-CrmSolution{
22842287
catch
22852288
{
22862289
Write-Error $_.Exception
2287-
}
2290+
}
2291+
finally
2292+
{
2293+
Write-Progress -Id 1 -Completed -Activity "_"
2294+
Write-Progress -Id 2 -Completed -Activity "_"
2295+
}
22882296
}
22892297

22902298
#MergeHoldingSolution

0 commit comments

Comments
 (0)