| 1 | param([Parameter(Mandatory=$true)][string]$Root, [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 | foreach ($name in @('Removed.one', 'Retired.one')) { |
| 10 | $section = '' |
| 11 | $app.OpenHierarchy($name, $notebook, [ref]$section, 3) |
| 12 | $page = '' |
| 13 | $app.CreateNewPage($section, [ref]$page, 2) |
| 14 | $xml = '<one:Page xmlns:one="http://schemas.microsoft.com/office/onenote/2010/onenote" ID="' + $page + '"><one:Outline><one:OEChildren><one:OE><one:T>' + $name + ' fixture.</one:T></one:OE></one:OEChildren></one:Outline></one:Page>' |
| 15 | $app.UpdatePageContent($xml, [DateTime]::MinValue, 1, $false) |
| 16 | } |
| 17 | $app.SyncHierarchy($notebook) |
| 18 | $app.CloseNotebook($notebook, $false) |
| 19 | Copy-Item (Join-Path $Root 'notebook') (Join-Path $Root 'before') -Recurse |
| 20 | $app.OpenHierarchy((Join-Path $Root 'notebook'), '', [ref]$notebook, 0) |
| 21 | foreach ($name in @('Removed.one', 'Retired.one')) { |
| 22 | $section = '' |
| 23 | $app.OpenHierarchy($name, $notebook, [ref]$section, 0) |
| 24 | $app.DeleteHierarchy($section, [DateTime]::MinValue, ($name -eq 'Retired.one')) |
| 25 | } |
| 26 | $app.SyncHierarchy($notebook) |
| 27 | } finally { |
| 28 | if ($notebook) { $app.CloseNotebook($notebook, $false) } |
| 29 | [void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($app) |
| 30 | $app = $null |
| 31 | [GC]::Collect() |
| 32 | [GC]::WaitForPendingFinalizers() |
| 33 | } |