| 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('synthetic.one', $notebook, [ref]$section, 0) |
| 11 | $deadline = [DateTime]::UtcNow.AddSeconds(60) |
| 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 -gt 0) { break } |
| 18 | Start-Sleep -Milliseconds 100 |
| 19 | } while ([DateTime]::UtcNow -lt $deadline) |
| 20 | if ($pages.Count -ne 1) { throw 'The direction fixture requires one page.' } |
| 21 | $content = '' |
| 22 | $app.GetPageContent($pages[0].GetAttribute('ID'), [ref]$content, 1, 1) |
| 23 | [IO.File]::WriteAllText("$Root\before.xml", $content, [Text.Encoding]::UTF8) |
| 24 | [xml]$page = $content |
| 25 | $settings = $page.SelectSingleNode('//*[local-name()="PageSettings"]') |
| 26 | $settings.SetAttribute('RTL', 'true') |
| 27 | $columns = @($page.SelectNodes('//*[local-name()="Column"]')) |
| 28 | for ($i = 0; $i -lt $columns.Count; $i++) { |
| 29 | $columns[$i].SetAttribute('width', (96 + 48 * $i).ToString()) |
| 30 | $columns[$i].SetAttribute('isLocked', 'true') |
| 31 | } |
| 32 | $app.UpdatePageContent($page.OuterXml, [DateTime]::MinValue, 1, $true) |
| 33 | $app.GetPageContent($pages[0].GetAttribute('ID'), [ref]$content, 1, 1) |
| 34 | [IO.File]::WriteAllText("$Root\after.xml", $content, [Text.Encoding]::UTF8) |
| 35 | [xml]$after = $content |
| 36 | if ($after.SelectSingleNode('//*[local-name()="PageSettings"]').GetAttribute('RTL') -ne 'true') { throw 'Native page direction did not change.' } |
| 37 | $app.SyncHierarchy($notebook) |
| 38 | $app.CloseNotebook($notebook, $false) |
| 39 | $notebook = '' |
| 40 | } finally { |
| 41 | if ($notebook) { $app.CloseNotebook($notebook, $false) } |
| 42 | [void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($app) |
| 43 | [GC]::Collect() |
| 44 | [GC]::WaitForPendingFinalizers() |
| 45 | } |