Da trifft es sich ja gut, dass ich just einen Objektsplitter kreiert habe
.
FĂĽr die Objekte
ohne Documentation-Trigger solltest du hiermit schon mal weiterkommen, da reicht eine kleine Erweiterung um den zu erzeugen, die ich da mal dazugebaut habe.
Der Export der Objekte ist hierbei in den Unterordner SPLITNAVOBJCPYRT, ansonsten alles wie
hier.Der erzeugte Beispieltrigger sieht dann jeweils so aus:
- Code: Alles auswählen
BEGIN
{
(c) Natalie's Software Enterprises
}
END.
- Code: Alles auswählen
function Split-NAVObjectFileDocuTrigger
{
$ErrorActionPreference = "Stop"
$PSDefaultParameterValues['*:ErrorAction']='Stop'
Function Get-FileName($initialDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = "NAV Object Files (*.txt)|*.txt"
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
}
$inputfile = Get-FileName "C:\temp" # This is the default path in OpenFile window.
if ($inputfile -eq "") {throw 'Please select a file'}
[decimal]$filesize = ((Get-Item $inputfile).length/1MB)
$filesize =[math]::round($filesize,2)
$LineCnt = $inputfile.count
$inputfile = resolve-path $inputfile
$WorkingFolder = Split-Path -Parent $inputfile
if (Test-path "$WorkingFolder\SPLITNAVOBJCPYRT\")
{Remove-Item -path "$WorkingFolder\SPLITNAVOBJCPYRT\" -Recurse -Force}
Write-Host "Splitting NAV objects from $inputfile (Size: $filesize MB) to $WorkingFolder\SPLITNAVOBJCPYRT\, this may take a while..." -ForegroundColor Yellow
$startime = date
$Sr = new-object System.IO.StreamReader($inputfile,[system.text.encoding]::GetEncoding(850))
[int]$ObjCnt = 0
[int]$TabCnt = 0
[int]$PagCnt = 0
[int]$RepCnt = 0
[int]$CodCnt = 0
[int]$XmlCnt = 0
[int]$ForCnt = 0
[int]$DatCnt = 0
[int]$QueCnt = 0
[int]$MenCnt = 0
$LastLine = ''
while (-not $Sr.EndOfStream)
{
$Currline = $sr.ReadLine()
if ($Currline.StartsWith('OBJECT'))
{
[String]$ObjectChar = $Currline.Substring(7,1)
$ObjectLine = $currline.Split(' ')
$ObjCnt++
Switch ($ObjectChar)
{
'T' {$TabCnt++}
'P' {$PagCnt++}
'R' {$RepCnt++}
'C' {$CodCnt++}
'X' {$XmlCnt++}
'F' {$ForCnt++}
'D' {$DatCnt++}
'Q' {$QueCnt++}
'M' {$MenCnt++}
}
$ObjectFileName = $ObjectLine[1].Substring(0,3).ToUpper() + $ObjectLine[2] + ".TXT"
$Objectfile = New-Item -path "$WorkingFolder\SPLITNAVOBJCPYRT\$ObjectFileName" -type file -force
IF (Test-Path $ObjectFile) {Remove-Item $ObjectFile}
$sw = new-object System.IO.Streamwriter($Objectfile,$false,[system.text.encoding]::GetEncoding(850))
}
if (($Currline -eq ' END.') -and ($LastLine -eq ' BEGIN'))
{
$sw.writeline(' {')
$sw.writeline(" (c) Natalie's Software Enterprises" )
$sw.writeline()
$sw.writeline(' }')
$sw.writeline(' END.')
$LastLine = $CurrLine
}
elseif (-not $Currline.StartsWith('}'))
{
$sw.writeline($Currline)
$Lastline = $CurrLine
}
else
{
$sw.writeline($Currline)
$Lastline = $CurrLine
$sw.writeline()
$sw.Flush()
}
}
$endtime = date
$time = $endtime - $startime
Write-Host "$ObjCnt NAV objects splitted to $WorkingFolder\SPLITNAVOBJCPYRT\ in $($time.Minutes)m:$($time.Seconds)s:$($time.Milliseconds)ms" -ForegroundColor Yellow
Write-Host "Tables: $TabCnt" -ForegroundColor Yellow
Write-Host "Pages: $PagCnt" -ForegroundColor Yellow
Write-Host "Reports: $RepCnt" -ForegroundColor Yellow
Write-Host "Codeunits: $CodCnt" -ForegroundColor Yellow
Write-Host "XMLPorts: $XMLCnt" -ForegroundColor Yellow
Write-Host "MenuSuites: $MenCnt" -ForegroundColor Yellow
if ($ForCnt -gt 0)
{Write-Host "Forms: $ForCnt" -ForegroundColor Yellow}
if ($DatCnt -gt 0)
{Write-Host "Dataports: $DatCnt" -ForegroundColor Yellow}
$sr.Close()
$sr.Dispose()
$sw.close()
$sw.Dispose()
Invoke-item "$WorkingFolder\SPLITNAVOBJCPYRT\"
}
Für die Objekte mit vorhandenem Documentation-Trigger wird es natürlich komplizierter, da muss ja der ganze Trigger durchgekämmt werden, wenn die Zeilen oben eingeschoben werden müssen. [Edit]: Das fertige Skript gibt es jetzt auch
Dokumentations-Trigger pflegen