1
+ <#
2
+ . Synopsis
3
+ Flushes the Request Queue
4
+ . Description
5
+ Flushes the Queue of pending Invoke-ADORestApi calls.
6
+ #>
7
+ param (
8
+ # The name of the invoker command
9
+ [Parameter (Mandatory )]
10
+ [ValidateSet (' Invoke-ADORestAPI' , ' Invoke-GitHubRESTApi' )]
11
+ [string ]
12
+ $Invoker
13
+ )
14
+ if ((-not $t ) -or (-not $progId )) {
15
+ $c , $t , $progId = 0 , $rq.Count , $ (Get-Random )
16
+ }
17
+
18
+ while ($rq.Count ) {
19
+ $invokeSplat = $rq.Dequeue ()
20
+
21
+ if ($invokeParams ) {
22
+ $invokeSplat += $invokeParams
23
+ }
24
+ $invokeSplatUrl = $invokeSplat.Url , $invokeSplat.uri -ne $null
25
+ if (" $invokeSplatUrl " .StartsWith(' /' )) {
26
+ $invokeSplatUrl =
27
+ @ (
28
+ " $server " .TrimEnd(' /' ) # * The Server
29
+ " /$organization "
30
+ $invokeSplatUrl
31
+ ) -join ' '
32
+ $invokeSplat.Remove (' Url' )
33
+ $invokeSplat.Remove (' Uri' )
34
+ $invokeSplat.Url = $invokeSplatUrl
35
+ }
36
+ if ($ApiVersion -and -not $invokeSplat.QueryParameter.apiVersion ) {
37
+ if (-not $invokeSplat.QueryParameter ) {
38
+ $invokeSplat.QueryParameter = @ {}
39
+ }
40
+ $invokeSplat.QueryParameter .' api-version' = $ApiVersion
41
+ }
42
+
43
+ $status =
44
+ if ($invokeSplat.Status ) {
45
+ $invokeSplat.Status
46
+ $invokeSplat.Remove (' Status' )
47
+ }
48
+ elseif ($invokeSplat.Method ) {
49
+ $invokeSplat.Method
50
+ } else
51
+ {
52
+ " GET"
53
+ }
54
+
55
+ $activity =
56
+ if ($invokeSplat.Activity ) {
57
+ $invokeSplat.Activity
58
+ $invokeSplat.Remove (' Activity' )
59
+ }
60
+ elseif ($invokeSplatUrl ) {
61
+ $invokeSplatUrl
62
+ } else
63
+ {
64
+ " "
65
+ }
66
+
67
+ if (-not $InvokeSplat.Property ) {
68
+ $InvokeSplat.Property = [Ordered ]@ {}
69
+ }
70
+ if ($organization -and -not $InvokeSplat.Property.Organization ) {
71
+ $InvokeSplat.Property.Organization = $organization
72
+ }
73
+ if ($ProjectID -and -not $InvokeSplat.Property.Organization ) {
74
+ $InvokeSplat.Property.ProjectID = $ProjectID
75
+ }
76
+ $c ++
77
+ $p = $c * 100 / $t
78
+ Write-Progress $status $activity - PercentComplete $p - Id $progId
79
+ & $ExecutionContext.SessionState.InvokeCommand.GetCommand ($Invoker , ' Function' ) @invokeSplat
80
+ }
81
+ if ($c -eq $t ) {
82
+ Write-Progress $status $activity - Completed $progId
83
+ }
0 commit comments