Merge remote-tracking branch 'origin/main' into Onlinesync

This commit is contained in:
Esa Kataja
2025-04-07 09:41:27 +03:00
+4 -23
View File
@@ -10,17 +10,12 @@ function Get-AllCodeServerPages!NAME! {
param ( param (
[Parameter(Mandatory=$true)] [Parameter(Mandatory=$true)]
[string]$Resource, [string]$Resource,
[Parameter(Mandatory=$true)] [Parameter(Mandatory=$true)]
[string]$RootProperty, [string]$RootProperty,
[Parameter(Mandatory=$false)] [Parameter(Mandatory=$false)]
[string]$CacheKeyProperty = "conceptCodeId", [string]$CacheKeyProperty = "conceptCodeId",
[Parameter(Mandatory=$false)] [Parameter(Mandatory=$false)]
[ScriptBlock]$Converter = ${function:ConvertFrom-CodeServerObject!NAME!}, [ScriptBlock]$Converter = ${function:ConvertFrom-CodeServerObject!NAME!},
[Parameter(Mandatory=$false)] [Parameter(Mandatory=$false)]
[int]$PageSize = 500 [int]$PageSize = 500
) )
@@ -32,7 +27,6 @@ function Get-AllCodeServerPages!NAME! {
$cacheKey = $Resource.GetHashCode() $cacheKey = $Resource.GetHashCode()
$cache[$cacheKey] = @{} $cache[$cacheKey] = @{}
} }
process { process {
$currentPage = 0; $currentPage = 0;
$Global:debugOut = @() $Global:debugOut = @()
@@ -56,16 +50,12 @@ function Get-AllCodeServerPages!NAME! {
$Global:cache[$cacheKey].Add($key, $codeObject.attributes) $Global:cache[$cacheKey].Add($key, $codeObject.attributes)
} }
} }
} }
} }
write-output $cache[$cacheKey].Values write-output $cache[$cacheKey].Values
} }
end { end {
} }
} }
""" """
@@ -76,32 +66,25 @@ function Get-CodeServerObject!NAME! {
param ( param (
[Parameter(Mandatory=$true)] [Parameter(Mandatory=$true)]
[string]$conceptCodeId, [string]$conceptCodeId,
[Parameter(Mandatory=$true)] [Parameter(Mandatory=$true)]
[string]$Resource, [string]$Resource,
[Parameter(Mandatory=$true)] [Parameter(Mandatory=$true)]
[string]$RootProperty, [string]$RootProperty,
[Parameter(Mandatory=$false)] [Parameter(Mandatory=$false)]
[string]$CacheKeyProperty = "conceptCodeId" [string]$CacheKeyProperty = "conceptCodeId"
) )
begin { begin {
if ($null -eq $Global:cache) { if ($null -eq $Global:cache) {
$params = @{ $params = @{
Resource = $Resource; Resource = $Resource;
RootProperty = $RootProperty; RootProperty = $RootProperty;
} }
if ($PSBoundParameters.ContainsKey("CacheKeyProperty")) { if ($PSBoundParameters.ContainsKey("CacheKeyProperty")) {
$params.Add("CacheKeyProperty", $CacheKeyProperty) $params.Add("CacheKeyProperty", $CacheKeyProperty)
} }
[void](Get-AllCodeServerPages!NAME! @params) [void](Get-AllCodeServerPages!NAME! @params)
} }
$cacheKey = $Resource.GetHashCode() $cacheKey = $Resource.GetHashCode()
} }
@@ -109,9 +92,7 @@ function Get-CodeServerObject!NAME! {
Write-Debug $cacheKey Write-Debug $cacheKey
Write-Output $cache[$cacheKey][$conceptCodeId] Write-Output $cache[$cacheKey][$conceptCodeId]
} }
end { end {
} }
} }
""" """
@@ -151,9 +132,7 @@ class CodeServer!NAME! {
} }
Export-ModuleMember ConvertFrom-CodeServerObject!NAME! Export-ModuleMember ConvertFrom-CodeServerObject!NAME!, Get-AllCodeServerPages!NAME!,Get-CodeServerObject!NAME!
Export-ModuleMember Get-AllCodeServerPages!NAME!
Export-ModuleMember Get-CodeServerObject!NAME!
""" """
def define_maps(items: list[str]) -> str: def define_maps(items: list[str]) -> str:
@@ -171,10 +150,12 @@ def write_psm(name, items: list[str], filename: Path = Path("CodeServerConnector
backup_filename = str(filename) + f".{datetime.now().strftime('%Y-%m-%d.%H%M%S')}.bak" backup_filename = str(filename) + f".{datetime.now().strftime('%Y-%m-%d.%H%M%S')}.bak"
shutil.copy2(filename, backup_filename) shutil.copy2(filename, backup_filename)
output = get_all_code.replace("!NAME!", name) output = "# ------- BEGIN CODE BLOCK -------\n"
output += get_all_code.replace("!NAME!", name)
output += get_code.replace("!NAME!", name) output += get_code.replace("!NAME!", name)
output += convert_from.replace("!NAME!", name).replace("!MAPS!", define_maps(items)) output += convert_from.replace("!NAME!", name).replace("!MAPS!", define_maps(items))
output += class_definition.replace("!NAME!", name).replace("!VARIABLES!", define_variables(items)).replace("!STRINGS!", define_strings(items)) output += class_definition.replace("!NAME!", name).replace("!VARIABLES!", define_variables(items)).replace("!STRINGS!", define_strings(items))
output += "# ------- END CODE BLOCK -------\n"
with open(filename, "a", encoding="utf-8-sig") as f: with open(filename, "a", encoding="utf-8-sig") as f:
f.write(output) f.write(output)
pass pass