private/Read-JsonConfigFile.ps1
function Read-JsonConfigFile { [CmdletBinding()] param ( [Parameter(Mandatory)] [string] $Path, [Parameter(Mandatory)] [Adf] $adf, [Parameter(Mandatory)] [AdfPublishOption] $option ) Write-Debug "BEGIN: Read-JsonConfigFile(path=$path)" $configFileName = $Path Write-Debug "Testing config file..." Test-Path -Path $configFileName -PathType Leaf | Out-Null #$configFileName = "X:\!WORK\GitHub\!SQLPlayer\azure.datafactory.tools\test\BigFactorySample2\deployment\config-c100.json" $configtxt = Get-Content $configFileName -Raw | Out-String $json = ConvertFrom-Json $configtxt # Creating CSV-like an object [System.Collections.ArrayList] $config = @{} Set-StrictMode -Version 1.0 # Due to field 'action' which may not exist $json.psobject.properties.name | ForEach-Object { $name = $_ $o = $json.($name) $o | ForEach-Object { $dst = $adf.AllObjects() | Where-Object { $_.Name -eq $name } | Select-Object -First 1 if ($null -ne $dst) { $cl = New-Object -TypeName ConfigLine $cl.name = $name $cl.type = $dst.Type $cl.value = $_.value $cl.path = $_.name if ($_.action -eq "remove") { $cl.path = "-$($cl.path)" } if ($_.action -eq "add") { $cl.path = "+$($cl.path)" } $null = $config.Add($cl) } else { if ($option.FailsWhenConfigItemNotFound -eq $false) { Write-Warning "Object [$name] could not be found, skipping..." } else { Write-Error "Object [$name] could not be found." } } } } # Expanding string (replace Environment Variables with values) $config | ForEach-Object { $_.value = $ExecutionContext.InvokeCommand.ExpandString($_.value); } return $config.ToArray() Write-Debug "END: Read-JsonConfigFile" } |