diff --git a/AptecoPSFramework/boilerplate/upload.ps1 b/AptecoPSFramework/boilerplate/upload.ps1 index e38fe57..e3a7764 100644 --- a/AptecoPSFramework/boilerplate/upload.ps1 +++ b/AptecoPSFramework/boilerplate/upload.ps1 @@ -377,7 +377,7 @@ try { # return If ( $useJob -eq $true ) { - $jobReturn = Get-JobLog -JobId $jobId -ConvertOutputAsHashtable + $jobReturn = Get-JobLog -JobId $jobId -ConvertOutput $return = $jobReturn.output } diff --git a/AptecoPSFramework/plugins/InxmailPro/Public/PeopleStage/invoke-upload.ps1 b/AptecoPSFramework/plugins/InxmailPro/Public/PeopleStage/invoke-upload.ps1 index 0fc0e6d..e5e0c02 100644 --- a/AptecoPSFramework/plugins/InxmailPro/Public/PeopleStage/invoke-upload.ps1 +++ b/AptecoPSFramework/plugins/InxmailPro/Public/PeopleStage/invoke-upload.ps1 @@ -55,7 +55,7 @@ function Invoke-Upload{ "Job" { # Get the jobs information - $job = Get-JobLog -JobId $JobId -ConvertInputAsHashtable + $job = Get-JobLog -JobId $JobId -ConvertInput $InputHashtable = $job.input # Update the job with more information @@ -569,7 +569,7 @@ function Invoke-Upload{ "OutputParam" = $return } Update-JobLog @jobReturnParams - Close-DuckDBConnection -Name "JobLog" + Close-JobLogDatabase -Name "JobLog" # return the results Switch ( $PSCmdlet.ParameterSetName ) { diff --git a/AptecoPSFramework/public/jobs/Get-JobLog.ps1 b/AptecoPSFramework/public/jobs/Get-JobLog.ps1 index c616d7d..77d78da 100644 --- a/AptecoPSFramework/public/jobs/Get-JobLog.ps1 +++ b/AptecoPSFramework/public/jobs/Get-JobLog.ps1 @@ -6,10 +6,10 @@ Function Get-JobLog { [Parameter(Mandatory=$true, ParameterSetName = 'Single')][Int]$JobId ,[Parameter(Mandatory=$false, ParameterSetName = 'Single')] - [Switch]$ConvertInputAsHashtable = $false + [Switch]$ConvertInput = $false ,[Parameter(Mandatory=$false, ParameterSetName = 'Single')] - [Switch]$ConvertOutputAsHashtable = $false + [Switch]$ConvertOutput = $false #,[Parameter(Mandatory=$true)][String]$ConnectionString @@ -35,12 +35,31 @@ Function Get-JobLog { throw "Multiple jobs found with id $( $JobId )" } else { - If ( $ConvertInputAsHashtable -eq $true) { + If ( $ConvertInput -eq $true) { $job.input = ConvertFrom-JsonAsHashtable $job.input } - If ( $ConvertOutputAsHashtable -eq $true) { - $job.output = ConvertFrom-JsonAsHashtable $job.output + If ( $ConvertOutput -eq $true) { + Switch ( $job.returnformat ) { + + # "ARRAY" { + # ConvertFrom-Json $job.output + # break + # } + + "HASHTABLE" { + $job.output = ConvertFrom-JsonAsHashtable $job.output + break + + } + + default { + ConvertFrom-Json $job.output + break + } + + } + } } @@ -60,10 +79,37 @@ Function Get-JobLog { #$job = Read-DuckDBQueryAsReader -Name "JobLog" -Query -ReturnAsPSCustom $job = Invoke-SqlQuery -Query $q -ConnectionName "JobLog" -Stream - $job | ForEach-Object { - $j = $_ - $j.input = ConvertFrom-JsonAsHashtable $j.input - $j.output = ConvertFrom-JsonAsHashtable $j.input + If ( $ConvertInput -eq $true -or $ConvertOutput -eq $true ) { + + $job | ForEach-Object { + $j = $_ + If ( $ConvertInput -eq $true ) { + $j.input = ConvertFrom-JsonAsHashtable $j.input + } + If ( $ConvertOutput -eq $true ) { + Switch ( $j.returnformat ) { + + # "ARRAY" { + # ConvertFrom-Json $job.output + # break + # } + + "HASHTABLE" { + $j.output = ConvertFrom-JsonAsHashtable $j.output + break + } + + default { + $j.output = ConvertFrom-Json $j.output + break + } + + } + + } + + } + } break @@ -72,7 +118,7 @@ Function Get-JobLog { $job - + } } \ No newline at end of file diff --git a/AptecoPSFramework/public/jobs/Update-JobLog.ps1 b/AptecoPSFramework/public/jobs/Update-JobLog.ps1 index e9863f5..45b4000 100644 --- a/AptecoPSFramework/public/jobs/Update-JobLog.ps1 +++ b/AptecoPSFramework/public/jobs/Update-JobLog.ps1 @@ -4,24 +4,58 @@ Function Update-JobLog { ... #> - [cmdletbinding()] + [CmdletBinding(DefaultParameterSetName = 'Hashtable')] param( - [Parameter(Mandatory=$true)][Int]$JobId # The Job ID that you have already got from the database + [Parameter(Mandatory=$true, ParameterSetName = 'Hashtable')] + [Parameter(Mandatory=$true, ParameterSetName = 'Array')] + [Int]$JobId # The Job ID that you have already got from the database # Values to change - ,[Parameter(Mandatory=$false)][Switch]$Finished = $false # Finished like 0 or 1 - ,[Parameter(Mandatory=$false)][String]$Status = "" # Status like "Finished" and others + ,[Parameter(Mandatory=$false, ParameterSetName = 'Hashtable')] + [Parameter(Mandatory=$false, ParameterSetName = 'Array')] + [Switch]$Finished = $false # Finished like 0 or 1 + + ,[Parameter(Mandatory=$false, ParameterSetName = 'Hashtable')] + [Parameter(Mandatory=$false, ParameterSetName = 'Array')] + [String]$Status = "" # Status like "Finished" and others + #,[Parameter(Mandatory=$false)][String]$Process = "" # Process ID - ,[Parameter(Mandatory=$false)][String]$Plugin = "" # Plugin guid - ,[Parameter(Mandatory=$false)][Int]$DebugMode = -1 # Debug mode like 0 or 1 - ,[Parameter(Mandatory=$false)][String]$Type = "" # Type like UPLOAD, MESSAGES, LISTS etc. - ,[Parameter(Mandatory=$false)][Hashtable]$InputParam = [Hashtable]@{} # Input hashtable - ,[Parameter(Mandatory=$false)][Int]$Inputrecords = -1 # Number of records that have been put in - ,[Parameter(Mandatory=$false)][Int]$Successful = -1 # Successful records, only needed on uploads - ,[Parameter(Mandatory=$false)][Int]$Failed = -1 # Failed records, only needed on uploads - ,[Parameter(Mandatory=$false)][Int]$Totalseconds = -1 # Seconds in total, logged at the end - ,[Parameter(Mandatory=$false)][Hashtable]$OutputParam = [Hashtable]@{} # Output hashtable (if it is suitable) + ,[Parameter(Mandatory=$false, ParameterSetName = 'Hashtable')] + [Parameter(Mandatory=$false, ParameterSetName = 'Array')] + [String]$Plugin = "" # Plugin guid + + ,[Parameter(Mandatory=$false, ParameterSetName = 'Hashtable')] + [Parameter(Mandatory=$false, ParameterSetName = 'Array')] + [Int]$DebugMode = -1 # Debug mode like 0 or 1 + + ,[Parameter(Mandatory=$false, ParameterSetName = 'Hashtable')] + [Parameter(Mandatory=$false, ParameterSetName = 'Array')] + [String]$Type = "" # Type like UPLOAD, MESSAGES, LISTS etc. + + ,[Parameter(Mandatory=$false, ParameterSetName = 'Hashtable')] + [Parameter(Mandatory=$false, ParameterSetName = 'Array')] + [Hashtable]$InputParam = [Hashtable]@{} # Input hashtable + + ,[Parameter(Mandatory=$false, ParameterSetName = 'Hashtable')] + [Parameter(Mandatory=$false, ParameterSetName = 'Array')] + [Int]$Inputrecords = -1 # Number of records that have been put in + + ,[Parameter(Mandatory=$false, ParameterSetName = 'Hashtable')] + [Parameter(Mandatory=$false, ParameterSetName = 'Array')] + [Int]$Successful = -1 # Successful records, only needed on uploads + + ,[Parameter(Mandatory=$false, ParameterSetName = 'Hashtable')] + [Parameter(Mandatory=$false, ParameterSetName = 'Array')] + [Int]$Failed = -1 # Failed records, only needed on uploads + + ,[Parameter(Mandatory=$false, ParameterSetName = 'Hashtable')] + [Parameter(Mandatory=$false, ParameterSetName = 'Array')] + [Int]$Totalseconds = -1 # Seconds in total, logged at the end + + # Only one Output should be allowed + ,[Parameter(Mandatory=$false, ParameterSetName = 'Hashtable')][Hashtable]$OutputParam = [Hashtable]@{} # Output hashtable (if it is suitable) + ,[Parameter(Mandatory=$false, ParameterSetName = 'Array')][System.Collections.ArrayList]$OutputArray = [System.Collections.ArrayList]@() # Output array (if it is suitable) ) Process { @@ -80,8 +114,23 @@ Function Update-JobLog { [void]$upd.Add("totalseconds = $( $Totalseconds )") } - If ( $OutputParam.Keys.Count -gt 0 ) { - [void]$upd.Add("output = '$( ( ConvertTo-Json $OutputParam -Depth 99 ) )'") + Switch ( $PSCmdlet.ParameterSetName ) { + + "Array" { + If ( $OutputArray.Count -gt 0 ) { + [void]$upd.Add("output = '$( ( ConvertTo-Json $OutputArray -Depth 99 ) )'") + } + [void]$upd.Add("returnformat = 'ARRAY'") + } + + default { + If ( $OutputParam.Keys.Count -gt 0 ) { + [void]$upd.Add("output = '$( ( ConvertTo-Json $OutputParam -Depth 99 ) )'") + } + [void]$upd.Add("returnformat = 'HASHTABLE'") + break + } + } $updateValues = $upd -join ", " diff --git a/AptecoPSFramework/sql/joblog_create.sql b/AptecoPSFramework/sql/joblog_create.sql index 44a6730..eb48698 100644 --- a/AptecoPSFramework/sql/joblog_create.sql +++ b/AptecoPSFramework/sql/joblog_create.sql @@ -14,6 +14,7 @@ CREATE TABLE IF NOT EXISTS joblog ( ,successful INTEGER ,failed INTEGER ,totalseconds INTEGER + ,returnformat TEXT ,output TEXT );