Private/ContextUtil.ps1

function Write-Context() {
    if (!$NavVersionCode) {
        Write-Warning "Context doesn't exist! It can't be written."
        return
    }

    $P1context = @{
        NavVersionCode = $NavVersionCode
        NavVersion = $NavVersion
        NavInstance = $NavInstance
        NavDatabase = $NavDatabase
    }

    $data = $P1context | ConvertTo-Json

    if (!(Test-Path -Path $ContextStorePath)) {
        New-Item -Path $ContextStorePath
    }

    [System.IO.File]::WriteAllText($ContextStorePath, $data)
    Write-Verbose "Context registered in $ContextStorePath"    
}

function Read-Context() {
    Write-Verbose "Reading context from $ContextStorePath"
    if (!(Test-Path -Path $ContextStorePath)) {
        Write-Warning "Context file doesn't exist! It can't be read."
        return
    }
    
    $data = [System.IO.File]::ReadAllText($ContextStorePath)

    $P1context = $data | ConvertFrom-Json

    Write-Output "Curent context has the following values:"
    Write-Output "- NavVersionCode = $NavVersionCode"
    Write-Output "- NavVersion = $NavVersion"
    Write-Output "- NavInstance = $NavInstance"
    Write-Output "- NavDatabase = $NavDatabase"
}