Skip to content

Commit

Permalink
Implementing PS Core detection and switch for json formatting for #13
Browse files Browse the repository at this point in the history
  • Loading branch information
gitfvb committed Jul 16, 2024
1 parent 6c9768d commit 58a8ac3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
20 changes: 20 additions & 0 deletions AptecoPSFramework/AptecoPSFramework.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,32 @@ New-Variable -Name plugins -Value $null -Scope Script -Force # Plugins co
New-Variable -Name pluginPath -Value $null -Scope Script -Force # The path of the chosen plugin
New-Variable -Name plugin -value $null -Scope Script -Force # The plugin pscustomobject
New-Variable -Name duckDb -Value $null -Scope Script -Force # New Variable for saving the DuckDB connection
New-Variable -Name isCore -Value $null -Scope Script -Force
New-Variable -Name os -Value $null -Scope Script -Force

# Set the variables now
$Script:timestamp = [datetime]::Now
$Script:debugMode = $false
$Script:logDivider = "----------------------------------------------------" # String used to show a new part of the log
$Script:moduleRoot = $PSScriptRoot.ToString()
$Script:isCore = ($PSVersionTable.Keys -contains "PSEdition") -and ($PSVersionTable.PSEdition -ne 'Desktop')

# Check the operating system, if Core
if ($Script:isCore -eq $true) {
If ( $IsWindows -eq $true ) {
$Script:os = "Windows"
} elseif ( $IsLinux -eq $true ) {
$Script:os = "Linux"
} elseif ( $IsMacOS -eq $true ) {
$Script:os = "MacOS"
} else {
throw "Unknown operating system"
}
} else {
# [System.Environment]::OSVersion.VersionString()
# [System.Environment]::Is64BitOperatingSystem
$Script:os = "Windows"
}

# instantiate plugin with dummy values
# TODO remove this dummy values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,30 @@ Function ConvertFrom-JsonAsHashtable {
}

Begin {
$jsSerializer = [System.Web.Script.Serialization.JavaScriptSerializer]::new()

If ( $Script:isCore -eq $false ) {
$jsSerializer = [System.Web.Script.Serialization.JavaScriptSerializer]::new()
}

}

Process {

Write-Verbose $InputObject
$jsSerializer.Deserialize($InputObject, 'Hashtable')
If ( $Script:isCore -eq $false ) {
#Write-Verbose $InputObject
$jsSerializer.Deserialize($InputObject, 'Hashtable')
} else {
ConvertFrom-Json $InputObject -AsHashtable
}

}

end {
$jsSerializer = $null

If ( $Script:isCore -eq $false ) {
$jsSerializer = $null
}

}

}

0 comments on commit 58a8ac3

Please sign in to comment.