diff --git a/private/projectDatabase/project_database.ps1 b/private/projectDatabase/project_database.ps1 index 2e58785..e187011 100644 --- a/private/projectDatabase/project_database.ps1 +++ b/private/projectDatabase/project_database.ps1 @@ -56,10 +56,10 @@ function Get-ProjectFromDatabase{ $prj = getProjectDatabaseCache -KeyLock $keyLock if($null -ne $prj){ - "🟩 Get Project Database from MEMORY $Owner/$ProjectNumber" | Write-MyDebug -Section "ProjectDatabase" + "🟩 Get Project from MEMORY $Owner/$ProjectNumber" | Write-MyDebug -Section "ProjectDatabase" return $prj } else { - "🟧 Get Project Database from FILE $Owner/$ProjectNumber" | Write-MyDebug -Section "ProjectDatabase" + "🟧 Get Project from DATABASE $Owner/$ProjectNumber" | Write-MyDebug -Section "ProjectDatabase" } # No cache or cache mismatch, read from database @@ -73,7 +73,7 @@ function Get-ProjectFromDatabase{ $prj.items = $prj.items | Copy-MyHashTable $prj.Staged = $prj.Staged | Copy-MyHashTable - # Savige to cache for future calls + # Save to cache for future calls setProjectDatabaseCache -KeyLock $keyLock -SafeId $prj.safeId -Database $prj return $prj @@ -172,8 +172,7 @@ function Save-ProjectDatabase{ # Add safe mark $Database.safeId = [guid]::NewGuid().ToString() - # Trace - "🟥 Save Project Database from FILE $Owner/$ProjectNumber safeId [$($Database.safeId)]" | Write-MyDebug -Section "ProjectDatabase" + "🟥 Set Project from DATABASE $Owner/$ProjectNumber safeid [$($Database.safeId)]" | Write-MyDebug -Section "ProjectDatabase" # Save database Save-Database -Key $dbkey -Database $Database @@ -191,61 +190,4 @@ function Get-ProjectDatabaseKey{ $keylock = "$key-lock" return $key, $keylock -} - -$script:ProjectDatabaseCache = @{} - -function getProjectDatabaseCache{ - param( - [Parameter(Mandatory,Position = 0)][string]$KeyLock - ) - - $lock = Get-Database -Key $KeyLock - - if([string]::IsNullOrWhiteSpace($lock)){ - "No cache lock found for $KeyLock. Cache will be ignored." | Write-MyDebug -Section "ProjectDatabase" - return $null - } - - $cache = $script:ProjectDatabaseCache[$KeyLock] - - if($lock -cne $cache.safeId) { - "Cache lock mismatch for $KeyLock. Cache safeId [$($cache.SafeId)], lock [$lock]. Cache will be ignored." | Write-MyDebug -Section "ProjectDatabase" - resetProjectDatabaseCache -KeyLock $KeyLock - return $null - } - - "Getting fields cache for $KeyLock with lock [$lock] and cache safeId [$($cache.SafeId)]" | Write-MyDebug -Section "ProjectDatabase" - return $cache.Database -} - -function setProjectDatabaseCache{ - param( - [Parameter(Mandatory,Position = 0)][string]$KeyLock, - [Parameter(Mandatory,Position = 1)][string]$SafeId, - [Parameter(Mandatory,Position = 2)][object]$Database - ) - - "Setting project cache for $KeyLock with safeId [$SafeId]" | Write-MyDebug -Section "ProjectDatabase" - - # Save safeId to project-lock - Save-Database -Database $SafeId -Key $KeyLock - - # Set lock in database to prevent concurrent updates - $script:ProjectDatabaseCache[$KeyLock] = @{ - Database = $Database - SafeId = $SafeId - } -} - -function resetProjectDatabaseCache{ - param( - [Parameter(Mandatory,Position = 0)][string]$KeyLock - ) - - "Resetting project cache for $KeyLock" | Write-MyDebug -Section "ProjectDatabase" - - Reset-Database -Key $KeyLock - - $script:ProjectDatabaseCache.Remove($KeyLock) } \ No newline at end of file diff --git a/private/projectDatabase/project_database_cache.ps1 b/private/projectDatabase/project_database_cache.ps1 new file mode 100644 index 0000000..477a130 --- /dev/null +++ b/private/projectDatabase/project_database_cache.ps1 @@ -0,0 +1,56 @@ +$script:ProjectDatabaseCache = @{} + +function getProjectDatabaseCache{ + param( + [Parameter(Mandatory,Position = 0)][string]$KeyLock + ) + + $lock = Get-Database -Key $KeyLock + + if([string]::IsNullOrWhiteSpace($lock)){ + "No cache lock found for $KeyLock. Cache will be ignored." | Write-MyDebug -Section "ProjectDatabaseCache" + return $null + } + + $cache = $script:ProjectDatabaseCache[$KeyLock] + + if($lock -cne $cache.safeId) { + "Cache lock mismatch for $KeyLock. Cache safeId [$($cache.SafeId)], lock [$lock]. Cache will be ignored." | Write-MyDebug -Section "ProjectDatabaseCache" + resetProjectDatabaseCache -KeyLock $KeyLock + return $null + } + + "Getting fields cache for $KeyLock with lock [$lock] and cache safeId [$($cache.SafeId)]" | Write-MyDebug -Section "ProjectDatabaseCache" + return $cache.Database +} + +function setProjectDatabaseCache{ + param( + [Parameter(Mandatory,Position = 0)][string]$KeyLock, + [Parameter(Mandatory,Position = 1)][string]$SafeId, + [Parameter(Mandatory,Position = 2)][object]$Database + ) + + "Setting project cache for $KeyLock with safeId [$SafeId]" | Write-MyDebug -Section "ProjectDatabaseCache" + + # Save safeId to project-lock + Save-Database -Database $SafeId -Key $KeyLock + + # Set lock in database to prevent concurrent updates + $script:ProjectDatabaseCache[$KeyLock] = @{ + Database = $Database + SafeId = $SafeId + } +} + +function resetProjectDatabaseCache{ + param( + [Parameter(Mandatory,Position = 0)][string]$KeyLock + ) + + "Resetting project cache for $KeyLock" | Write-MyDebug -Section "ProjectDatabase" + + Reset-Database -Key $KeyLock + + $script:ProjectDatabaseCache.Remove($KeyLock) +} \ No newline at end of file diff --git a/public/fields/getValidNames.ps1 b/public/fields/getValidNames.ps1 index a1c03ae..aeccd70 100644 --- a/public/fields/getValidNames.ps1 +++ b/public/fields/getValidNames.ps1 @@ -14,10 +14,11 @@ function Get-ValidNames{ return $null } - $field = Get-ProjectFields -Owner $owner -ProjectNumber $projectNumber -Name $FieldName + $field = Get-ProjectFields -Owner $owner -ProjectNumber $projectNumber -Name $FieldName -Exact if($field.dataType -eq "SINGLE_SELECT"){ $ret = $field.MoreInfo + $ret +="" } else { throw "Get-ValidNames only supports fields with SINGLE_SELECT dataType. Field $FieldName has $($field.dataType) dataType." } diff --git a/public/fields/project_fields_list.ps1 b/public/fields/project_fields_list.ps1 index 8e62cee..622b67f 100644 --- a/public/fields/project_fields_list.ps1 +++ b/public/fields/project_fields_list.ps1 @@ -38,6 +38,7 @@ function Get-ProjectFields{ [Parameter()] [string]$Owner, [Parameter()] [string]$ProjectNumber, [Parameter(Position = 0)][string]$Name, + [Parameter()][switch]$Exact, [Parameter()][switch]$Force ) @@ -61,7 +62,11 @@ function Get-ProjectFields{ # if name if($Name){ # Filter fields by name - $fieldList = $fieldList | Where-Object { $_.name -like "*$Name*" } + if($Exact){ + $fieldList = $fieldList | Where-Object { $_.name -eq $Name } + } else { + $fieldList = $fieldList | Where-Object { $_.name -like "*$Name*" } + } } # return if #db is null diff --git a/public/items/edit_project_item.ps1 b/public/items/edit_project_item.ps1 index 4fed57a..7b4dd28 100644 --- a/public/items/edit_project_item.ps1 +++ b/public/items/edit_project_item.ps1 @@ -82,7 +82,7 @@ function Edit-ProjectItem { # Default if($DefaultValues){ - Write-MyWarning "No Default values are currently setup. Please use other parameters to set values or update the DefaultValues parameter with default values" + "DefaultValues EMPTY" | Write-MyDebug -section "Edit-ProjectItem" # Do not edit but leave this parameters flow the edit process } diff --git a/public/items/use_order.ps1 b/public/items/use_order.ps1 index 8c0b6be..c8155be 100644 --- a/public/items/use_order.ps1 +++ b/public/items/use_order.ps1 @@ -72,9 +72,7 @@ function Use-Order { #return item if($PassThru) { $i = Get-ProjectItem -ItemId $itemId - return [PsCustomObject]$i + Write-Output ([PsCustomObject]$i) } - - } } Export-ModuleMember -Function Use-Order -Alias "uo" \ No newline at end of file