AppMgt/Convert-NCHTxtToAl.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
function Convert-NCHTxtToAl {
    <#
    .SYNOPSIS
    Converts txt to al.
         
    .PARAMETER ContainerName
    The Container
     
    .PARAMETER TxtFile
    Path to the txt-file that needs to be converted
     
    .PARAMETER sqlCredential
    SQL credential to be able to use the finsql
     
    .PARAMETER startId
    The startID for extension objects
     
    .PARAMETER objectsFilter
    The object filter that would identify all objects
    #>

    param(
        [Parameter(Mandatory = $true)]
        [String] $ContainerName,
        [Parameter(Mandatory = $true)]
        [String] $TxtFile,
        [Parameter(Mandatory = $true)]
        [System.Management.Automation.PSCredential] $sqlCredential,
        [Parameter(Mandatory = $false)]
        [int] $startId = 50000,
        [Parameter(Mandatory = $false)]
        [String] $objectsFilter = ''
    )

    Write-Host -ForegroundColor Green "$($MyInvocation.MyCommand.Name) on $env:COMPUTERNAME"

    $MainFolder = "C:\ProgramData\navcontainerhelper\ConvertTxt2Al"
    Write-host -ForegroundColor Green "Performing Txt2Al conversion on folder '$MainFolder'"

    $OriginalFolder = "$Mainfolder\Original"
    $ModifiedFolder = "$Mainfolder\Modified"
    $DeltaFolder = "$Mainfolder\Delta"
    $AlFolder = "$Mainfolder\Al"
    
    $OriginalObjectsStore = "C:\ProgramData\NavContainerHelper\Extensions\Original-$(Get-NavContainerNavVersion -containerOrImageName $ContainerName)-newsyntax"

    if (!(Test-path $OriginalObjectsStore)) {
        Export-NavContainerObjects `
            -containerName $ContainerName `
            -objectsFolder $OriginalObjectsStore `
            -sqlCredential $sqlCredential `
            -exportTo 'txt folder (new syntax)' `
            -filter ''
    }

    Import-ObjectsToNavContainer `
        -containerName $ContainerName `
        -ObjectsFile $TxtFile `
        -sqlCredential $sqlCredential

    Compile-ObjectsInNavContainer `
        -containerName $ContainerName `
        -filter 'Compiled=0' `
        -sqlCredential $sqlCredential `
        -ErrorAction Continue

    Remove-Item -Path $OriginalFolder -Recurse -Force -ErrorAction SilentlyContinue
    Remove-Item -Path $ModifiedFolder -Recurse -Force -ErrorAction SilentlyContinue
    Remove-Item -Path $DeltaFolder -Recurse -Force -ErrorAction SilentlyContinue
    Remove-Item -Path $AlFolder -Recurse -Force -ErrorAction SilentlyContinue
    
    Export-NavContainerObjects `
        -containerName $ContainerName `
        -objectsFolder $ModifiedFolder `
        -sqlCredential $sqlCredential `
        -exportTo 'txt file (new syntax)' `
        -filter $objectsFilter 
    
    Create-MyOriginalFolder `
        -originalFolder $OriginalObjectsStore `
        -modifiedFolder $ModifiedFolder `
        -myOriginalFolder $OriginalFolder

    Create-MyDeltaFolder `
        -containerName $ContainerName `
        -modifiedFolder $ModifiedFolder `
        -myOriginalFolder $OriginalFolder `
        -myDeltaFolder $DeltaFolder 
    
    Convert-Txt2Al `
        -containerName $ContainerName `
        -myDeltaFolder $DeltaFolder `
        -myAlFolder $AlFolder `
        -startId $startId

    Compress-Archive `
        -Path "$AlFolder\*.*" `
        -DestinationPath "$AlFolder.zip" `
        -Force

}