From c10a851df57b33910ac13b11931080f1c347f892 Mon Sep 17 00:00:00 2001 From: Patrick Gruber Date: Fri, 23 Jul 2021 12:24:59 +0200 Subject: [PATCH] fixed #179 Vault process remains open after closing the Vault Client --- .../Vault.Custom/addinVault/Default.ps1 | 15 +++++++++++++++ .../Vault.Custom/addinVault/powerGateMain.ps1 | 6 +----- Files/powerGate/Modules/Logging.psm1 | 13 ++++++++++--- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/Files/DataStandard/Vault.Custom/addinVault/Default.ps1 b/Files/DataStandard/Vault.Custom/addinVault/Default.ps1 index 7777a44..a36d741 100644 --- a/Files/DataStandard/Vault.Custom/addinVault/Default.ps1 +++ b/Files/DataStandard/Vault.Custom/addinVault/Default.ps1 @@ -15,4 +15,19 @@ $assocFiles = @(GetAssociatedFiles $itemids $([System.IO.Path]::GetDirectoryName($VaultContext.UserControl.XamlFile))) $dsWindow.FindName("AssoicatedFiles").ItemsSource = $assocFiles } +} + +function OnLogOn { + #Executed when User logs on Vault + #$vaultUsername can be used to get the username, which is used in Vault on login + + Import-Module "C:\ProgramData\coolOrange\powerGate\Modules\Initialize.psm1" -Global + Initialize-CoolOrange + + $logPath = Join-Path $env:LOCALAPPDATA "coolOrange\Projects\VDS_Vault-powerGate.log" + Set-LogFilePath -Path $logPath +} +function OnLogOff { + #Executed when User logs off Vault + Remove-CoolOrangeLogging } \ No newline at end of file diff --git a/Files/DataStandard/Vault.Custom/addinVault/powerGateMain.ps1 b/Files/DataStandard/Vault.Custom/addinVault/powerGateMain.ps1 index cbf8654..f257b71 100644 --- a/Files/DataStandard/Vault.Custom/addinVault/powerGateMain.ps1 +++ b/Files/DataStandard/Vault.Custom/addinVault/powerGateMain.ps1 @@ -1,10 +1,6 @@ $global:addinPath = $PSScriptRoot Import-Module "C:\ProgramData\coolOrange\powerGate\Modules\Initialize.psm1" -Global -Initialize-CoolOrange - -$logPath = Join-Path $env:LOCALAPPDATA "coolOrange\Projects\VDS_Vault-powerGate.log" -Set-LogFilePath -Path $logPath - +Initialize-CoolOrange ConnectToErpServerWithMessageBox diff --git a/Files/powerGate/Modules/Logging.psm1 b/Files/powerGate/Modules/Logging.psm1 index d6b0902..9030f1d 100644 --- a/Files/powerGate/Modules/Logging.psm1 +++ b/Files/powerGate/Modules/Logging.psm1 @@ -13,6 +13,10 @@ function Initialize-CoolOrangeLogging { $LogPath, $DeleteLogFilesOlderThenDays = '4d' # Format example for 30 days: "30d" ) + # PSFramework Version 1.5.172 + $commonModulePath = "C:\ProgramData\coolOrange\powerGate\PSFramework\PSFramework" + Import-Module -Name $commonModulePath -Global -Verbose + $paramSetPSFLoggingProvider = @{ # For all parameters of the "Logfile" provider read here: https://psframework.org/documentation/documents/psframework/logging/providers/logfile.html @@ -103,9 +107,12 @@ function Log { } } -# PSFramework Version 1.5.172 -$commonModulePath = "C:\ProgramData\coolOrange\powerGate\PSFramework\PSFramework" -Import-Module -Name $commonModulePath -Global -Verbose +function Remove-CoolOrangeLogging { + # Fixes https://github.com/coolOrangeLabs/powerGateTemplate/issues/179 + Wait-PSFMessage + Get-PSFRunspace | Stop-PSFRunspace + [PSFramework.PSFCore.PSFCoreHost]::Uninitialize() +} $generalLogPath = Join-Path $env:LOCALAPPDATA "coolOrange\Projects\default.log" Initialize-CoolOrangeLogging -LogPath $generalLogPath \ No newline at end of file