| 1 | param([Parameter(Mandatory=$true)][string]$Root, [Parameter(Mandatory=$true)][string]$CloneHost) |
| 2 | Set-StrictMode -Version Latest |
| 3 | $ErrorActionPreference = 'Stop' |
| 4 | & "$PSScriptRoot\cold-current.ps1" -Root $Root -CloneHost $CloneHost |
| 5 | $app = New-Object -ComObject OneNote.Application |
| 6 | $notebookId = '' |
| 7 | try { |
| 8 | $app.OpenHierarchy((Join-Path $Root 'notebook'), '', [ref]$notebookId, 0) |
| 9 | $names = @() |
| 10 | foreach ($index in 0..79) { |
| 11 | $name = 'Boundary section {0:d3}.one' -f $index |
| 12 | $section = '' |
| 13 | $app.OpenHierarchy($name, $notebookId, [ref]$section, 3) |
| 14 | $app.SyncHierarchy($notebookId) |
| 15 | $app.CloseNotebook($notebookId, $false) |
| 16 | $notebookId = '' |
| 17 | $app.OpenHierarchy((Join-Path $Root 'notebook'), '', [ref]$notebookId, 0) |
| 18 | $names += $name |
| 19 | } |
| 20 | $names | ConvertTo-Json | Set-Content (Join-Path $Root 'expected.json') -Encoding UTF8 |
| 21 | $app.CloseNotebook($notebookId, $false) |
| 22 | $notebookId = '' |
| 23 | } finally { |
| 24 | if ($notebookId) { $app.CloseNotebook($notebookId, $false) } |
| 25 | [void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($app) |
| 26 | [GC]::Collect() |
| 27 | [GC]::WaitForPendingFinalizers() |
| 28 | } |