28. Dezember 2017 18:08
function DowngradeNAVfileDlg
{
$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 2018 Object Files (*.txt)|*.txt"
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
}
$inputfile = Get-FileName "C:\temp" # This is the default path in OpenFile window. Use whatever you like :-)
if ($inputfile -eq "") {throw 'Please select a file'}
$ToggleExportOn = $true
$ToggleExportOff = $false
$OldValueToggleExportOff = $false
$inputfile = resolve-path $inputfile
$WorkingFolder = Split-Path -Parent $inputfile
$convertedFileName = [System.IO.Path]::GetFileNameWithoutExtension($inputfile) +"_DWGR" + [System.IO.Path]::GetExtension($inputfile)
$convertedfile = New-Item -path "$WorkingFolder\$convertedFileName" -type file -force
IF (Test-Path $ConvertedFile) {Remove-Item $ConvertedFile}
IF (Test-Path "$inputfile.tmp") {Remove-Item "$inputfile.tmp"}
$Sr = new-object System.IO.StreamReader($inputfile,[system.text.encoding]::GetEncoding(850))
$sw = new-object System.IO.Streamwriter("$inputfile.tmp",$false,[system.text.encoding]::GetEncoding(850))
while (-not $Sr.EndOfStream)
{
$Currline = $Sr.ReadLine()
if ($Currline.StartsWith(' RDLDATA')){
$ToggleExportOn = $true
$ToggleExportOff = $false
$OldValueToggleExportOff = $false}
$IsApplicationAreaLine = ($Currline.startswith(' ApplicationArea='))
$IsInternalLine = ($Currline.startswith(' [Internal]'))
$IsExternalLine = ($Currline.startswith(' [External]'))
# Events
$IsIntegrationLine = ($Currline.startswith(' [Integration'))
$IsBusinessLine = ($Currline.startswith(' [Business'))
$IsEventSubscriber = ($Currline.startswith(' [EventSubscriber('))
$IsObsoleteLine1 = ($Currline.startswith(' ObsoleteState=')) -or ($Currline.startswith(' ObsoleteState='))
$IsObsoleteLine2 = ($Currline.startswith(' ObsoleteReason=')) -or ($Currline.startswith(' ObsoleteReason='))
$IsOdataline = ($Currline.startswith(' ODataKeyFields='))
$SkipLineForNAV2015 = $IsInternalLine -or $IsExternalLine -or $IsApplicationAreaLine -or $IsIntegrationLine -or $IsBusinessLine -or -$IsEventSubscriber -or $IsObsoleteLine1 -or $IsObsoleteLine2 -or $IsOdataline
$SkipLineForNAV2016 = $IsInternalLine -or $IsExternalLine -or $IsApplicationAreaLine -or $IsObsoleteLine1 -or $IsObsoleteLine2 -or $IsOdataline
$SkipLineForNAV2017 = $IsInternalLine -or $IsExternalLine -or $IsObsoleteLine1 -or $IsObsoleteLine2 -or $IsOdataline
$ToggleExportOff = ($Currline -contains ' <ReportParametersLayout>')
if ($ToggleExportOff)
{$OldValueToggleExportOff = $true}
if ($OldValueToggleExportOff)
{$ToggleExportOn = ($Currline -contains ' </ReportParametersLayout>')}
if ($ToggleExporton)
{$OldValueToggleExportOff = $false}
if ($($ToggleExportOff)) {$ToggleExportOn = ($ToggleExportOn -eq ($Currline -contains ' </ReportParametersLayout>'))}
[string]$NewSchema = '<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">'
[string]$OldSchema = '<Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns:cl="http://schemas.microsoft.com/sqlserver/reporting/2010/01/componentdefinition" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition">'
if ($Currline -eq $NewSchema)
{$sw.writeline($OldSchema)}
elseif ((-not $OldValueToggleExportOff) -and (-not ($Currline -contains ' </ReportParametersLayout>') -and (-not $SkipLineForNAV2016)))
{$sw.writeline($Currline)}
}
$sr.Close()
$sr.Dispose()
$sw.close()
$sw.Dispose()
Rename-Item -path "$inputfile.tmp" -NewName $convertedFileName -force -verbose
}
19. Januar 2018 12:05
22. Januar 2018 15:21