navcontainerhelper/ObjectHandling/Convert-Txt2Al.ps1

115 строки
5.7 KiB
PowerShell
Исходник Обычный вид История

2019-05-22 08:58:08 +03:00
<#
.Synopsis
Convert txt and delta files to AL
.Description
Convert objects in myDeltaFolder to AL. Page and Table extensions are created as new objects using the startId as object Id offset.
Code modifications and other things not supported in extensions will not be converted to AL.
Manual modifications are required after the conversion.
.Parameter containerName
Name of the container in which the txt2al tool will be executed
.Parameter myDeltaFolder
Folder containing delta files
.Parameter myAlFolder
Folder in which the AL files are created
.Parameter startId
Starting offset for objects created by the tool (table and page extensions)
2019-09-03 12:42:17 +03:00
.Parameter dotNetAddInsPackage
Path to folder where dotnet add-ins are located (folder must be shared with container)
2019-05-22 08:58:08 +03:00
.Example
2020-07-27 18:56:22 +03:00
Convert-Txt2Al -containerName test -mydeltaFolder c:\programdata\bccontainerhelper\mydeltafiles -myAlFolder c:\programdata\bccontainerhelper\myAlFiles -startId 50100
2019-05-22 08:58:08 +03:00
#>
function Convert-Txt2Al {
2019-09-03 12:42:17 +03:00
Param (
2020-07-31 10:16:25 +03:00
[string] $containerName = $bcContainerHelperConfig.defaultContainerName,
2019-05-22 08:58:08 +03:00
[Parameter(Mandatory=$true)]
[string] $myDeltaFolder,
[Parameter(Mandatory=$true)]
[string] $myAlFolder,
2019-09-03 12:42:17 +03:00
[int] $startId = 50100,
2019-05-22 08:58:08 +03:00
[string] $dotNetAddInsPackage
)
2021-07-06 12:03:31 +03:00
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
2019-05-22 08:58:08 +03:00
$containerMyDeltaFolder = Get-NavContainerPath -containerName $containerName -path $myDeltaFolder -throw
$containerMyAlFolder = Get-NavContainerPath -containerName $containerName -path $myAlFolder -throw
$containerDotNetAddInsPackage = ""
if ($dotNetAddInsPackage) {
$containerDotNetAddInsPackage = Get-NavContainerPath -containerName $containerName -path $dotNetAddInsPackage -throw
}
$navversion = Get-NavContainerNavversion -containerOrImageName $containerName
$version = [System.Version]($navversion.split('-')[0])
$ignoreSystemObjects = ($version.Major -ge 14)
2019-08-02 08:04:51 +03:00
$platformVersion = Get-NavContainerPlatformVersion -containerOrImageName $containerName
2019-05-22 08:58:08 +03:00
2019-08-02 08:04:51 +03:00
$dummy = Invoke-ScriptInNavContainer -containerName $containerName -ScriptBlock { Param($myDeltaFolder, $myAlFolder, $startId, $dotNetAddInsPackage, $platformVersion)
2019-05-22 08:58:08 +03:00
$erroractionpreference = 'Continue'
if (!($txt2al)) {
2019-06-06 14:29:45 +03:00
throw "You cannot run Convert-Txt2Al on this Container"
2019-05-22 08:58:08 +03:00
}
Write-Host "Converting files in $myDeltaFolder to .al files in $myAlFolder with startId $startId (container paths)"
Remove-Item -Path $myAlFolder -Recurse -Force -ErrorAction Ignore
New-Item -Path $myAlFolder -ItemType Directory -ErrorAction Ignore | Out-Null
2019-06-27 18:15:27 +03:00
if ([System.Text.Encoding]::Default.BodyName -eq "utf-8") {
$cp = (Get-Culture).TextInfo.OEMCodePage
$encoding = [System.Text.Encoding]::GetEncoding($cp)
Write-Host "Converting my delta files from OEM($cp) to UTF8 before converting"
Get-ChildItem -Path (Join-Path $myDeltaFolder "*.*") | ForEach-Object {
$content = [System.IO.File]::ReadAllText($_.FullName, $encoding )
[System.IO.File]::WriteAllText($_.FullName, $content, [System.Text.Encoding]::UTF8 )
}
}
2019-05-22 08:58:08 +03:00
$txt2alParameters = @("--source=""$myDeltaFolder""", "--target=""$myAlFolder""", "--rename", "--extensionStartId=$startId")
if ($dotNetAddInsPackage) {
$txt2alParameters += @("--dotNetAddInsPackage=""$dotNetAddInsPackage""")
}
2019-08-02 08:04:51 +03:00
if ($platformVersion) {
$ver = [System.Version]($platformVersion)
if (($ver.Major -eq 14 -and $ver.Build -ge 34429) -or ($ver.Major -eq 15 -and $ver.Build -ge 34399)) {
Write-Host "Using Compiler CodeAnalysis to format documents"
if (-not (Test-Path (Join-Path ([System.IO.Path]::GetDirectoryName($txt2al)) "Microsoft.Dynamics.Nav.CodeAnalysis.Workspaces.dll"))) {
Write-Host "Copying Microsoft.Dynamics.Nav.CodeAnalysis.Workspaces.dll from vsix"
if (!(Test-Path "c:\build" -PathType Container)) {
2022-12-09 15:33:51 +03:00
$tempZip = Join-Path ([System.IO.Path]::GetTempPath()) "alc.zip"
2019-08-02 08:04:51 +03:00
Copy-item -Path (Get-Item -Path "c:\run\*.vsix").FullName -Destination $tempZip
Expand-Archive -Path $tempZip -DestinationPath "c:\build\vsix"
}
$alcPath = 'C:\build\vsix\extension\bin'
Copy-Item -Path (Join-Path $alcPath "Microsoft.Dynamics.Nav.CodeAnalysis.Workspaces.dll") -Destination ([System.IO.Path]::GetDirectoryName($txt2al))
}
}
}
2019-05-22 08:58:08 +03:00
Write-Host "txt2al.exe $([string]::Join(' ', $txt2alParameters))"
& $txt2al $txt2alParameters 2> $null
2019-06-27 18:15:27 +03:00
if ([System.Text.Encoding]::Default.BodyName -eq "utf-8") {
Write-Host "Converting my delta files from UTF8 to OEM($cp) after converting"
Get-ChildItem -Path (Join-Path $myDeltaFolder "*.*") | ForEach-Object {
$content = [System.IO.File]::ReadAllText($_.FullName, [System.Text.Encoding]::UTF8 )
[System.IO.File]::WriteAllText($_.FullName, $content, $encoding )
}
}
2019-05-22 08:58:08 +03:00
$erroractionpreference = 'Stop'
2019-08-02 08:04:51 +03:00
} -ArgumentList $containerMyDeltaFolder, $containerMyAlFolder, $startId, $containerDotNetAddInsPackage, $platformVersion
2019-05-22 08:58:08 +03:00
}
2021-07-06 12:03:31 +03:00
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Export-ModuleMember -Function Convert-Txt2Al