Skip to content

Commit

Permalink
PG-1250
Browse files Browse the repository at this point in the history
+ moved and renamed Communication.psm1 as only required by powerJobs jobs
+ refactored connection logic with same implementation as Sample.ConnectToPowerGateServer
  • Loading branch information
lustricker committed Oct 24, 2022
1 parent aa5282c commit b25c2a7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 75 deletions.
64 changes: 0 additions & 64 deletions Files/powerGate/Modules/Communication.psm1

This file was deleted.

12 changes: 6 additions & 6 deletions Files/powerJobs/Jobs/Erp.Service.CreatePDFFromItem.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Set-LogFilePath -Path $logPath

Write-Host "Starting job 'Create PDF as attachment' for item '$($item._Name)' ..."

ConnectToConfiguredErpServer
ConnectToPowerGateServer

$attachedDrawings = Get-VaultItemAssociations -Number $item._Number
foreach ($drawing in $attachedDrawings) {
Expand All @@ -35,7 +35,7 @@ foreach ($drawing in $attachedDrawings) {
Log -Message "Files with extension: '$($drawing._Extension)' are not supported"
continue
}

$drawing = Get-VaultFile -File $drawing._FullPath -DownloadPath $workingDirectory

$ipjVaultPath = $vault.DocumentService.GetInventorProjectFileLocation()
Expand All @@ -45,18 +45,18 @@ foreach ($drawing in $attachedDrawings) {
$fastOpen = $openReleasedDrawingsFast -and $drawing._ReleasedRevision
$downloadedFiles = Save-VaultFile -File $drawing._FullPath -ExcludeChildren:$fastOpen -ExcludeLibraryContents:$fastOpen
$drawing = $downloadedFiles | select -First 1
# InventorServer does not support all target & source formats, you can find all supportet formats here:
# InventorServer does not support all target & source formats, you can find all supportet formats here:
# https://doc.coolorange.com/projects/powerjobsprocessor/en/stable/jobprocessor/file_conversion/?highlight=InventorServer#supported-format-conversions"
$openResult = Open-Document -LocalFile $drawing.LocalPath -Options @{ "Project" = $localIpjFile.LocalPath; FastOpen = $fastOpen } -Application InventorServer
if ($openResult) {
if ($openResult.Application.Name -like 'Inventor*') {
$configFile = "$($env:POWERJOBS_MODULESDIR)Export\PDF_2D.ini"
}
else {
$configFile = "$($env:POWERJOBS_MODULESDIR)Export\PDF.dwg"
}
$configFile = "$($env:POWERJOBS_MODULESDIR)Export\PDF.dwg"
}
$exportResult = Export-Document -Format 'PDF' -To $localPDFfileLocation -Options $configFile
if ($exportResult) {
if ($exportResult) {
$PDFfile = Add-VaultFile -From $localPDFfileLocation -To $vaultPDFfileLocation -FileClassification DesignVisualization -Hidden $hidePDF
$item = Update-VaultItem -Number $item._Number -AddAttachments @($PDFfile.'Full Path')

Expand Down
10 changes: 5 additions & 5 deletions Files/powerJobs/Jobs/ErpService.Create.PDF.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if ( @("idw", "dwg") -notcontains $file._Extension ) {
return
}

ConnectToConfiguredErpServer
ConnectToPowerGateServer

$ipjVaultPath = $vault.DocumentService.GetInventorProjectFileLocation()
$localWorkspaceFolder = ($vaultConnection.WorkingFoldersManager.GetWorkingFolder("$/")).FullPath
Expand All @@ -40,7 +40,7 @@ $localIpjFile = (Save-VaultFile -File $ipjVaultPath -DownloadDirectory $localWor
$fastOpen = $openReleasedDrawingsFast -and $file._ReleasedRevision
$downloadedFiles = Save-VaultFile -File $file._FullPath -ExcludeChildren:$fastOpen -ExcludeLibraryContents:$fastOpen
$file = $downloadedFiles | select -First 1
# InventorServer does not support all target & source formats, you can find all supportet formats here:
# InventorServer does not support all target & source formats, you can find all supportet formats here:
# https://doc.coolorange.com/projects/powerjobsprocessor/en/stable/jobprocessor/file_conversion/?highlight=InventorServer#supported-format-conversions"
$openResult = Open-Document -LocalFile $file.LocalPath -Options @{ "Project" = $localIpjFile.LocalPath; FastOpen = $fastOpen } -Application InventorServer

Expand All @@ -49,10 +49,10 @@ if ($openResult) {
$configFile = "$($env:POWERJOBS_MODULESDIR)Export\PDF_2D.ini"
}
else {
$configFile = "$($env:POWERJOBS_MODULESDIR)Export\PDF.dwg"
}
$configFile = "$($env:POWERJOBS_MODULESDIR)Export\PDF.dwg"
}
$exportResult = Export-Document -Format 'PDF' -To $localPDFfileLocation -Options $configFile
if ($exportResult) {
if ($exportResult) {
$PDFfile = Add-VaultFile -From $localPDFfileLocation -To $vaultPDFfileLocation -FileClassification DesignVisualization -Hidden $hidePDF
$file = Update-VaultFile -File $file._FullPath -AddAttachments @($PDFfile._FullPath)

Expand Down
25 changes: 25 additions & 0 deletions Files/powerJobs/Modules/ConnectToPowerGateServer.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
$services = @(
'/PGS/ERP/BomService',
'/PGS/ERP/MaterialService'
)

$vaultToPgsMapping = @{
'Vault' = '$($vaultConnection.Server)';
'TestVault' = '$env:COMPUTERNAME';
}

function ConnectToPowerGateServer() {
$connectedVault = $vaultConnection.Vault
if ($connectedVault -in $vaultToPgsMapping.Keys) {
$pgsHost = "http://" + $ExecutionContext.InvokeCommand.ExpandString($vaultToPgsMapping[$connectedVault]) + ":8080"
foreach ($serviceUrl in $services) {
$powerGateServerPluginUrl = $pgsHost + $serviceUrl
Write-Host "Connecting to: $powerGateServerPluginUrl"
$connected = Connect-ERP -Service $powerGateServerPluginUrl
Write-Host "Connected: $connected"
}
}
else {
throw "The currently connected Vault '$($vaultConnection.Vault)' is not mapped in the configuration to any powerGateServer.`r`nPlease extend the configuration and restart the application."
}
}

0 comments on commit b25c2a7

Please sign in to comment.