This repository was archived by the owner on Nov 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunDiffQuery.ps1
More file actions
79 lines (67 loc) · 2.6 KB
/
Copy pathrunDiffQuery.ps1
File metadata and controls
79 lines (67 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#############################################################
# This script creates a runs a diff query using the
# parameters supplied below and downloads the restults to an
# .\out\restults.json file.
#############################################################
param
(
# The project containing the index
[Parameter(Mandatory=$true, ValueFromPipeline=$false)]
[guid] $ProjectId,
# The index to run the query against
[Parameter(Mandatory=$true, ValueFromPipeline=$false)]
[string] $IndexId,
# The JSON query specification
[Parameter(Mandatory=$true, ValueFromPipeline=$false)]
[string] $QueryJson,
# Forge auth token.
[Parameter(Mandatory=$true, ValueFromPipeline=$false)]
[string] $ForgeToken
)
#############################################################
# Forge CLI module import
#############################################################
$modulePath = Join-Path $PSScriptRoot '..\src\ForgeCLI.psd1' -Resolve;
Import-Module $modulePath;
#############################################################
# Output variables
#############################################################
$outDir = "$PSScriptRoot\out";
#############################################################
# Main
#############################################################
try {
# create the token
Set-ForgeToken -Token $ForgeToken;
# create the output dir if it does not exist
if (-not(Test-Path $outDir))
{
New-Item -Path $outDir -ItemType Directory | Out-Null;
}
Write-Verbose "Run query $QueryJson";
# start a new query
$response = New-BimPropertyDiffQuery -ProjectId $ProjectId -DiffId $IndexId -QueryJson $QueryJson;
# poll the query for success
while ($response.state -eq 'PROCESSING')
{
Write-Verbose "Query $($response.diffId) state $($response.state), retrying...";
Start-Sleep -Seconds 5;
$response = Get-BimPropertyDiffQuery -ProjectId $ProjectId -DiffId $response.diffId -QueryId $response.queryId;
}
# serialize the query
$queryPath = "$outDir\$($response.diffId).$($response.queryId).query.json";
$response | ConvertTo-Json | Out-File -FilePath $queryPath -Encoding utf8 -Force | Out-Null;
if ($response.state -eq 'FINISHED')
{
# download the retsults to file
$resultsPath = "$outDir\$($response.diffId).$($response.queryId).results.json";
Get-ResourceUrl -Url $response.queryResultsUrl -Path $resultsPath;
}
else
{
throw "Query status $($response.state) != FINISHED, check $queryPath for more informaiton";
}
}
catch {
$_;
}