coolOrangeLabs / powerGateTemplate

powerGate full functional sample ERP integration
MIT License
3 stars 3 forks source link

Initialize coolOrange only in specific processes #200

Closed manuelcassan closed 2 years ago

manuelcassan commented 2 years ago

As a User I want to initialize the coolOrange customization only in specific processes in order to avoid loading it in applications that are not needed and avoid longer waiting times while the template connects to ERP.

Solution

Add a check for the process in which powerEvents is loaded in Files/powerEvents/Modules/Import.Modules.psm1 e.g.:

$allowedProcesses = @("Connectivity.VaultPro","Inventor", "Acad")
if ($allowedProcesses -contains $processName) {
    $initModulePath = "C:\ProgramData\coolOrange\powerGate\Modules\Initialize.psm1"
    $moduleName = [io.path]::GetFileNameWithoutExtension($initModulePath)
    if( (Get-Module -Name $moduleName) ) {
        Remove-Module -Name $moduleName
    }
    Import-Module -Name $initModulePath -Global -Force
    Initialize-CoolOrange

    $logPath = Join-Path $env:LOCALAPPDATA "coolOrange\Projects\powerEvents.log"
    Set-LogFilePath -Path $logPath

    ConnectToErpServer
}