| 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 | $notebook = '' |
| 7 | try { |
| 8 | $app.OpenHierarchy((Join-Path $Root 'notebook'), '', [ref]$notebook, 0) |
| 9 | $section = '' |
| 10 | $app.OpenHierarchy('Lifecycle.one', $notebook, [ref]$section, 0) |
| 11 | $deadline = [DateTime]::UtcNow.AddSeconds(30) |
| 12 | do { |
| 13 | $hierarchy = '' |
| 14 | $app.GetHierarchy($section, 4, [ref]$hierarchy, 1) |
| 15 | [xml]$tree = $hierarchy |
| 16 | $pages = @($tree.SelectNodes('//*[local-name()="Page"]')) |
| 17 | if ($pages.Count -eq 13) { break } |
| 18 | Start-Sleep -Milliseconds 200 |
| 19 | } while ([DateTime]::UtcNow -lt $deadline) |
| 20 | $targets = @($pages | Where-Object { $_.GetAttribute('name').StartsWith('New ') }) |
| 21 | if ($pages.Count -ne 13 -or $targets.Count -ne 2) { throw 'Expected thirteen pages and two created title controls.' } |
| 22 | $inputs = Join-Path $Root 'inputs' |
| 23 | [void](New-Item -ItemType Directory -Path $inputs) |
| 24 | for ($i = 0; $i -lt $targets.Count; $i++) { |
| 25 | $pageId = [Security.SecurityElement]::Escape($targets[$i].GetAttribute('ID')) |
| 26 | $xml = "<one:Page xmlns:one='http://schemas.microsoft.com/office/onenote/2010/onenote' ID='$pageId'><one:Outline><one:Position x='72' y='144'/><one:OEChildren><one:OE><one:T>Native body $i after Rust page creation.</one:T></one:OE></one:OEChildren></one:Outline></one:Page>" |
| 27 | [IO.File]::WriteAllText((Join-Path $inputs ("native-$i.xml")), $xml, [Text.Encoding]::UTF8) |
| 28 | $app.UpdatePageContent($xml, [DateTime]::MinValue, 1, $false) |
| 29 | } |
| 30 | $app.SyncHierarchy($notebook) |
| 31 | } finally { |
| 32 | [void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($app) |
| 33 | [GC]::Collect() |
| 34 | [GC]::WaitForPendingFinalizers() |
| 35 | } |