13. Januar 2016 17:53
AttachTagToVersionList -AddOnTag CH -PathObjectPack C:\temp\original.txt -PathIndexFolder C:\Indexlisten\ZVCHindex
The tag CH already exists in Version List of PAG254.TXT
function AttachTagToVersionList
{
[CmdletBinding()]
Param
(
[String][Parameter(Mandatory=$True,Position=1)]
$AddOnTag,
[String][Parameter(Mandatory=$True)]
$PathObjectPack,
[String][Parameter(Mandatory=$True)]
$PathIndexFolder
)
if (-not (Test-Path $PathObjectPack))
{Throw "File $PathObjectPack does not exist"}
$WorkingFolder = "$env:temp\TempNAVobjects"
if (-not (Test-Path $WorkingFolder)) {New-item $WorkingFolder -ItemType Directory -force}
else {Remove-Item -path $WorkingFolder\*.* -recurse}
$ObjectPackFileBaseName = (Get-Item $PathObjectPack).Basename
$NewObjectPackFullName = (Get-Item $PathObjectPack).DirectoryName + '\' + (Get-Item $PathObjectPack).Basename + $AddOnTag + (Get-Item $PathObjectPack).Extension
Split-NAVApplicationObjectFile -Source $PathObjectPack -Destination $WorkingFolder -PreserveFormatting
Get-ChildItem -Path $WorkingFolder\*.txt |
ForEach `
(
{
# $_ -> C:\Users\KAIKOW~1\AppData\Local\Temp\TempNAVobjects\TAB25.TXT
# $_.Name -> TAB25.TXT
# $_.FullName -> C:\Users\Kai Kowalewski\AppData\Local\Temp\TempNAVobjects\TAB25.TXT
$CurrFileName = (Get-Item $_).name
Write-host "Checking for $CurrFileName in $PathIndexFolder"
if (Test-Path "$PathIndexFolder\$CurrFileName" -PathType Leaf)
{
$CurrVersionList = (Get-NAVApplicationObjectProperty -Source $_ ).VersionList
Write-host "Version list in $_ : $CurrVersionList"
$Token = ",$AddonTag"
if (-not ($CurrVersionList.contains($Token)))
{
$NewVersionList = $CurrVersionList + ',' + $AddonTag
Set-NAVApplicationObjectProperty -Target $_ -VersionListProperty $NewVersionList
Write-host "New version list in $_ : $NewVersionList " -ForegroundColor Green
}
else {Write-host "The tag $AddonTag already exists in Version List of $CurrFileName" -ForegroundColor Yellow}
}
}
)
Join-NAVApplicationObjectFile -Destination $NewObjectPackFullName -Source $WorkingFolder\*.txt -Force
Remove-Item -path $WorkingFolder -recurse
}
Import-Module 'C:\Program Files (x86)\Microsoft Dynamics NAV\90\RoleTailored Client\Microsoft.Dynamics.Nav.Model.Tools.psd1' -WarningAction SilentlyContinue | out-null
18. Januar 2016 18:13
function RemoveTagFromVersionList
{
[CmdletBinding()]
Param
(
[String][Parameter(Mandatory=$True,Position=1)]
$AddOnTag,
[String][Parameter(Mandatory=$True)]
$PathObjectPack
)
if (-not (Test-Path $PathObjectPack))
{Throw "File $PathObjectPack does not exist"}
$WorkingFolder = "$env:temp\TempNAVobjects"
if (-not (Test-Path $WorkingFolder)) {New-item $WorkingFolder -ItemType Directory -force}
else {Remove-Item -path $WorkingFolder\*.* -recurse}
$ObjectPackFileBaseName = (Get-Item $PathObjectPack).Basename
$NewObjectPackFullName = (Get-Item $PathObjectPack).DirectoryName + '\' + (Get-Item $PathObjectPack).Basename + '_' + $AddOnTag +'removed' +(Get-Item $PathObjectPack).Extension
Split-NAVApplicationObjectFile -Source $PathObjectPack -Destination $WorkingFolder -PreserveFormatting
Get-ChildItem -Path $WorkingFolder\*.txt |
ForEach `
(
{
# $_ -> C:\Users\KAIKOW~1\AppData\Local\Temp\TempNAVobjects\TAB25.TXT
# $_.Name -> TAB25.TXT
# $_.FullName -> C:\Users\Kai Kowalewski\AppData\Local\Temp\TempNAVobjects\TAB25.TXT
$CurrFileName = (Get-Item $_).name
$CurrVersionList = (Get-NAVApplicationObjectProperty -Source $_ ).VersionList
# $AddOnIndex = $CurrVersionList.indexOf($AddOnTag);
Write-host
Write-host "Version list in $_ : $CurrVersionList"
#Write-host 'Length:' $CurrVersionList.length
if ($CurrVersionList.length -gt 0)
{
$Comma = ','
$Addonpos = $Comma + $Addonpos
$Addonpos = $CurrVersionList.IndexOf($AddOnTag)
if (-not ($Addonpos -eq -1))
{
if ($Addonpos -ge 1)
{$leftPart = $CurrVersionList.Substring(0,$Addonpos - 1)}
else
{$leftPart = $CurrVersionList}
$rightPart = $CurrVersionList.Substring($Addonpos + 1 )
$posCommaRightPart = $RightPart.IndexOf($Comma)
if ($posCommaRightPart -ne -1)
{$NewRightPart = $RightPart.substring($posCommaRightPart + 1)}
else
{$NewRightPart = ''}
if ($NewRightPart -ne '')
{$NewVersionList = $LeftPart + ',' + $NewRightPart}
else
{$NewVersionList = $LeftPart}
Set-NAVApplicationObjectProperty -Target $_ -VersionListProperty $NewVersionList
Write-host "New version list in $_ : $NewVersionList " -ForegroundColor Green
}
else
{Write-host "The $AddonTag tag does not exist in Version List of $CurrFileName" -ForegroundColor Yellow}
}
}
)
Join-NAVApplicationObjectFile -Destination $NewObjectPackFullName -Source $WorkingFolder\*.txt -Force
Remove-Item -path $WorkingFolder -recurse
}