| 1 | param([Parameter(Mandatory=$true)][string]$Root, [Parameter(Mandatory=$true)][string]$CloneHost) |
| 2 | Set-StrictMode -Version Latest |
| 3 | $ErrorActionPreference = 'Stop' |
| 4 | & "$PSScriptRoot\page-lifecycle.ps1" -Root $Root -CloneHost $CloneHost -CaptureOnly before |
| 5 | $request = Get-Content (Join-Path $Root 'removal.json') -Raw | ConvertFrom-Json |
| 6 | $app = New-Object -ComObject OneNote.Application |
| 7 | try { |
| 8 | $notebook = '' |
| 9 | $section = '' |
| 10 | $app.OpenHierarchy((Join-Path $Root 'notebook'), '', [ref]$notebook, 0) |
| 11 | $app.OpenHierarchy('Lifecycle.one', $notebook, [ref]$section, 0) |
| 12 | $hierarchy = '' |
| 13 | $app.GetHierarchy($section, 4, [ref]$hierarchy, 1) |
| 14 | [xml]$tree = $hierarchy |
| 15 | $pages = @($tree.SelectNodes('//*[local-name()="Page"]')) |
| 16 | if ($pages.Count -ne 9) { throw 'The removal fixture must have nine original pages.' } |
| 17 | $ids = @() |
| 18 | foreach ($index in $request.selected) { |
| 19 | if ($index -lt 0 -or $index -ge $pages.Count) { throw 'Choose an original page in the fixture.' } |
| 20 | $ids += $pages[$index].GetAttribute('ID') |
| 21 | } |
| 22 | ConvertTo-Json -InputObject $ids | Set-Content (Join-Path $Root 'removed-ids.json') -Encoding UTF8 |
| 23 | foreach ($id in $ids) { |
| 24 | $app.DeleteHierarchy($id, [DateTime]::MinValue, [bool]$request.permanent) |
| 25 | } |
| 26 | } finally { |
| 27 | [void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($app) |
| 28 | [GC]::Collect() |
| 29 | [GC]::WaitForPendingFinalizers() |
| 30 | } |
| 31 | & "$PSScriptRoot\page-lifecycle.ps1" -Root $Root -CloneHost $CloneHost -CaptureOnly after |