| 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 | $files = @(Get-ChildItem (Join-Path $Root 'notebook') | Where-Object { $_.Extension -eq '.one' }) |
| 10 | if ($files.Count -ne 1) { throw 'Provide exactly one copied section for the template probe.' } |
| 11 | $sectionId = '' |
| 12 | $app.OpenHierarchy($files[0].Name, $notebookId, [ref]$sectionId, 0) |
| 13 | $pageId = '' |
| 14 | $app.CreateNewPage($sectionId, [ref]$pageId, 0) |
| 15 | $xml = '<one:Page xmlns:one="http://schemas.microsoft.com/office/onenote/2010/onenote" ID="' + $pageId + '"><one:Title><one:OE><one:T>Native template probe</one:T></one:OE></one:Title></one:Page>' |
| 16 | $app.UpdatePageContent($xml, [DateTime]::MinValue, 1, $true) |
| 17 | @{ page = $pageId; operation = 'CreateNewPage with npsDefault, then set title' } | ConvertTo-Json | Set-Content (Join-Path $Root 'expected.json') -Encoding UTF8 |
| 18 | $app.SyncHierarchy($notebookId) |
| 19 | $app.CloseNotebook($notebookId, $false) |
| 20 | $notebookId = '' |
| 21 | } finally { |
| 22 | if ($notebookId) { $app.CloseNotebook($notebookId, $false) } |
| 23 | [void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($app) |
| 24 | [GC]::Collect() |
| 25 | [GC]::WaitForPendingFinalizers() |
| 26 | } |