Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lustricker committed Jan 28, 2021
2 parents 5b4d881 + 6b27f12 commit 130118f
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@ $modules = Get-ChildItem -path $commonModulePath -Recurse -Filter *.ps*
$modules | ForEach-Object { Import-Module -Name $_.FullName -Global }

$cfgPath = "c:\temp\powerGateCfg\powerGateConfiguration.xml"
[xml]$cfg = GetConfigFromVault
[xml]$cfg = Get-PowerGateConfigFromVault
New-Item -Path "c:\temp\powerGateCfg" -ItemType Directory -Force
if ($null -eq $cfg) {
Copy-Item "C:\ProgramData\coolOrange\powerGate\powerGateConfigurationTemplate.xml" $cfgPath -Force
}
else {
$cfg.Save($cfgPath)
}
$cfg.Save($cfgPath)

Start-Process -FilePath C:\Windows\explorer.exe -ArgumentList "/select, ""$cfgPath"""
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ $modules | ForEach-Object { Import-Module -Name $_.FullName -Global }
$cfgPath = "c:\temp\powerGateCfg\powerGateConfiguration.xml"
$testPath = Test-Path $cfgPath
if ($testPath -eq $false) {
ShowMessageBox -Message "No config file found. Please download/edit the config file first and then save it back to the Vault server" -Button "OK" -Icon "Warning" | Out-Null
ShowMessageBox -Message "No config file found in '$cfgPath' `n Please download/edit the config file first and then save it back to the Vault server!" -Button "OK" -Icon "Warning" | Out-Null
return
}

[byte[]]$cfg = [System.IO.File]::ReadAllBytes($cfgPath)
SetConfigFromVault -Content $cfg
Set-PowerGateConfigFromVault -Content $cfg
ShowMessageBox -Message "Config file saved to Vault server" -Button "OK" -Icon "Information" | Out-Null

Remove-Item $cfgPath -Force
14 changes: 7 additions & 7 deletions Files/powerGate/Modules/BomFunctions.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ $rawMaterialQuantityProperty = "Raw Quantity"
function GetErpBomHeader($number) {
Log -Begin
$erpBomHeader = Get-ERPObject -EntitySet $bomHeaderEntitySet -Keys @{Number = $number } -Expand "BomRows"
$erpBomHeader = CheckResponse -entity $erpBomHeader
$erpBomHeader = Edit-ResponseWithErrorMessage -Entity $erpBomHeader
Log -End
return $erpBomHeader
}
Expand All @@ -31,7 +31,7 @@ function CreateErpBomHeader($erpBomHeader) {
$erpBomHeader.ModifiedDate = [DateTime]::Now

$erpBomHeader = Add-ERPObject -EntitySet $bomHeaderEntitySet -Properties $erpBomHeader
$erpBomHeader = CheckResponse -entity $erpBomHeader
$erpBomHeader = Edit-ResponseWithErrorMessage -Entity $erpBomHeader -WriteOperation
Log -End
return $erpBomHeader
}
Expand All @@ -42,7 +42,7 @@ function UpdateErpBomHeader($erpBomHeader) {
$erpBomHeader.ModifiedDate = [DateTime]::Now

$erpBomHeader = Update-ERPObject -EntitySet $bomHeaderEntitySet -keys $erpBomHeader._Keys -Properties $erpBomHeader._Properties
$erpBomHeader = CheckResponse -entity $erpBomHeader
$erpBomHeader = Edit-ResponseWithErrorMessage -Entity $erpBomHeader -WriteOperation
Log -End
return $erpBomHeader
}
Expand All @@ -52,7 +52,7 @@ function UpdateErpBomHeader($erpBomHeader) {
function GetErpBomRow($parentNumber, $childNumber, $position) {
Log -Begin
$erpBomRow = Get-ERPObject -EntitySet $bomRowEntitySet -Keys @{ParentNumber = $parentNumber; ChildNumber = $childNumber; Position = $position }
$erpBomRow = CheckResponse -entity $erpBomRow
$erpBomRow = Edit-ResponseWithErrorMessage -Entity $erpBomRow
Log -End
return $erpBomRow
}
Expand All @@ -70,7 +70,7 @@ function CreateErpBomRow($erpBomRow) {
$erpBomRow.ModifiedDate = [DateTime]::Now

$erpBomRow = Add-ERPObject -EntitySet $bomRowEntitySet -Properties $erpBomRow
$erpBomRow = CheckResponse -entity $erpBomRow
$erpBomRow = Edit-ResponseWithErrorMessage -Entity $erpBomRow -WriteOperation
Log -End
return $erpBomRow
}
Expand All @@ -81,15 +81,15 @@ function UpdateErpBomRow($erpBomRow) {
$erpBomRow.ModifiedDate = [DateTime]::Now

$erpBomRow = Update-ERPObject -EntitySet $bomRowEntitySet -Keys $erpBomRow._Keys -Properties @{Quantity = $erpBomRow.Quantity }
$erpBomRow = CheckResponse -entity $erpBomRow
$erpBomRow = Edit-ResponseWithErrorMessage -Entity $erpBomRow -WriteOperation
Log -End
return $erpBomRow
}

function RemoveErpBomRow($parentNumber, $childNumber, $position) {
Log -Begin
$erpBomRow = Remove-ERPObject -EntitySet $bomRowEntitySet -Keys @{ParentNumber = $parentNumber; ChildNumber = $childNumber; Position = $position }
$erpBomRow = CheckResponse -entity $erpBomRow
$erpBomRow = Edit-ResponseWithErrorMessage -Entity $erpBomRow -WriteOperation
Log -End
return $erpBomRow
}
Expand Down
13 changes: 11 additions & 2 deletions Files/powerGate/Modules/Communication.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,22 @@ function GetPowerGateError {
return $powerGateErrMsg
}

function CheckResponse($entity) {
function Edit-ResponseWithErrorMessage {
param(
$Entity,
[Switch]$WriteOperation = $false
)
Log -Begin
if ($null -eq $entity) {
$entity = $false
if($WriteOperation) {
# In case NO error message from the ERP returned and this means that no request at all was sent out by powerGate, therefore its required to look for a internal error in the powerGate Logs file.
$logFileLocation = "$($env:LocalAppdata)\coolOrange\powerGate\Logs\powerGate.log"
Add-Member -InputObject $entity -Name "_ErrorMessage" -Value "Unexpected error:`n Failed bacause probably some passed values for the create/update operation are not valid, for example 'the input was a text but should be a number'. Therefore check the last error message in the log file, then change your inputs and re-execute the operation: $logFileLocation" -MemberType NoteProperty -Force
}
$pGError = GetPowerGateError
if ($pGError) {
$message = "The communication with ERP failed!`n '$pGError'"
$message = "Direct error message from the ERP:`n '$pGError'"
Add-Member -InputObject $entity -Name "_ErrorMessage" -Value $message -MemberType NoteProperty -Force
}
}
Expand Down
6 changes: 3 additions & 3 deletions Files/powerGate/Modules/MaterialFunctions.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function GetErpMaterial($number) {
}
$number = $number.ToUpper()
$erpMaterial = Get-ERPObject -EntitySet $materialEntitySet -Key @{ Number = $number }
$erpMaterial = CheckResponse -entity $erpMaterial
$erpMaterial = Edit-ResponseWithErrorMessage -Entity $erpMaterial

Add-Member -InputObject $erpMaterial -Name "IsCreate" -Value $false -MemberType NoteProperty -Force
Add-Member -InputObject $erpMaterial -Name "IsUpdate" -Value $true -MemberType NoteProperty -Force
Expand Down Expand Up @@ -56,7 +56,7 @@ function CreateErpMaterial($erpMaterial) {

$erpMaterial = TransformErpMaterial -erpMaterial $erpMaterial
$erpMaterial = Add-ErpObject -EntitySet $materialEntitySet -Properties $erpMaterial
$erpMaterial = CheckResponse -entity $erpMaterial
$erpMaterial = Edit-ResponseWithErrorMessage -Entity $erpMaterial -WriteOperation
Log -End
return $erpMaterial
}
Expand All @@ -68,7 +68,7 @@ function UpdateErpMaterial($erpMaterial) {

$erpMaterial = TransformErpMaterial -erpMaterial $erpMaterial
$erpMaterial = Update-ERPObject -EntitySet $materialEntitySet -Key $erpMaterial._Keys -Properties $erpMaterial._Properties
$erpMaterial = CheckResponse -entity $erpMaterial
$erpMaterial = Edit-ResponseWithErrorMessage -Entity $erpMaterial -WriteOperation
Log -End
return $erpMaterial
}
Expand Down
4 changes: 3 additions & 1 deletion Files/powerGate/Modules/SearchFunctions.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $materialEntityType = "Material"

function SearchErpMaterials ($filter, $top = 100) {
$erpMaterials = Get-ERPObjects -EntitySet $materialEntitySet -Filter $filter -Top $top
$erpMaterials = CheckResponse -entity $erpMaterials
$erpMaterials = Edit-ResponseWithErrorMessage -Entity $erpMaterials
return $erpMaterials
}

Expand Down Expand Up @@ -117,13 +117,15 @@ function ApplyFilter($key, $value) {

function ExecuteErpSearch {
Log -Begin
$dsWindow.Cursor = "Wait"
$dsDiag.Clear()
$searchCriteria = $searchWindow.FindName("SearchCriteria").DataContext
$CaseSensitive = $searchWindow.FindName("CaseSensitive").IsChecked
$topa = $searchWindow.FindName("NumberOfRecords").SelectedValue
$filter = ConvertSearchCriteriaToFilter -SearchCriteria $searchCriteria -CaseSensitive $CaseSensitive
$dsDiag.Trace("filter = $filter")
$results = SearchErpMaterials -filter $filter -top $topa
$dsWindow.Cursor = "Arrow"
if (-not $results -or $false -eq $results) {
$searchWindow.FindName("SearchResults").ItemsSource = $null
$searchWindow.FindName("RecordsFound").Content = "Results found: 0"
Expand Down
51 changes: 30 additions & 21 deletions Files/powerGate/Modules/SelectionLists.psm1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function SetConfigFromVault {
function Set-PowerGateConfigFromVault {
param(
[byte[]]$Content
)
Expand All @@ -13,21 +13,31 @@
Log -End
}

function GetConfigFromVault {
function Get-PowerGateConfigFromVault {
Log -Begin
$xmlString = $vault.KnowledgeVaultService.GetVaultOption("powerGateConfig")
if($xmlString -match "^?") {
$xmlString = $xmlString.SubString(1)

if (-not $xmlString) {
$xmlTemplatePath = "C:\ProgramData\coolOrange\powerGate\powerGateConfigurationTemplate.xml"
[byte[]]$cfg = [System.IO.File]::ReadAllBytes($xmlTemplatePath)
Set-PowerGateConfigFromVault -Content $cfg
$xmlString = $vault.KnowledgeVaultService.GetVaultOption("powerGateConfig")
if (-not $xmlString) {
throw "PowerGateConfiguration is not saved in the Vault options! An administrator must import the XML via the command 'powerGate->Save Configuration' in the Vault Client."
}
}
if($xmlString) {
try{
$xmlObject = New-Object -TypeName System.Xml.XmlDocument
$xmlObject.LoadXml($xmlString)
return $xmlObject
} catch{
Log -message "Unable to parse XML-String to XML-Object!"
return $null
}

try{
$byteOrderMarkUtf8 = [System.Text.Encoding]::UTF8.GetString([System.Text.Encoding]::UTF8.GetPreamble())
if ($xmlString.StartsWith($byteOrderMarkUtf8)) {
$xmlString = $xmlString.Remove(0, $byteOrderMarkUtf8.Length);
}

$xmlObject = New-Object -TypeName System.Xml.XmlDocument
$xmlObject.LoadXml($xmlString)
return $xmlObject
} catch {
throw "Unable to parse powerGateConfiguration from the Vault Options to a valid XML-Object! An administrator must import a new XML via the command 'powerGate->Save Configuration' in the Vault Client.`n $($_.Exception.Message)"
}
Log -End
}
Expand All @@ -37,14 +47,13 @@ function GetSelectionList($section, $withBlank = $false) {
$list = @()
if (-not $vault) { return $list }

[xml]$cfg = GetConfigFromVault
if ($null -eq $cfg) {
[byte[]]$cfg = [System.IO.File]::ReadAllBytes("C:\ProgramData\coolOrange\powerGate\powerGateConfigurationTemplate.xml")
SetConfigFromVault -Content $cfg
[xml]$cfg = GetConfigFromVault
}
[xml]$cfg = Get-PowerGateConfigFromVault

$entries = Select-Xml -Xml $cfg -XPath "//$section"
try {
$entries = Select-Xml -Xml $cfg -XPath "//$section"
} catch {
throw "Failed to find XML node '$section' in the powerGateConfiguration! An administrator must edit and import the XML via the command 'powerGate->Save Configuration' in the Vault Client!"
}
if ($entries) {
foreach ($entry in $entries.Node.ChildNodes) {
if ($entry.NodeType -eq "Comment") { continue }
Expand Down Expand Up @@ -78,7 +87,7 @@ function GetBOMStateList($withBlank = $false) {
function GetCategoryList($withBlank = $false) {
$list = @()
$categories = Get-ERPObjects -EntitySet "Categories"
$categories = CheckResponse -entity $categories
$categories = Edit-ResponseWithErrorMessage -entity $categories
if (-not $categories -or $false -eq $categories) {
return $list
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected IEnumerable<ErpMaterialSearchSettings> GetSearchSettings(IExpression<T

if (!Enum.TryParse(whereToken.PropertyName, out ErpSearchProperty searchProperty))
{
Log.WarnFormat("Search query for property name '{0}' is not supported by ERP, therefore making bigger search in order to filter the values!", searchValue);
Log.WarnFormat("Search query for property name '{0}' is not supported by ERP, therefore make a search with other properties in order to filter the values!", searchValue);
continue;
}

Expand Down

0 comments on commit 130118f

Please sign in to comment.