-
Notifications
You must be signed in to change notification settings - Fork 247
/
Import-DeltasToNavContainer.ps1
85 lines (75 loc) · 4.28 KB
/
Import-DeltasToNavContainer.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
<#
.Synopsis
Merge deltas and import Objects to Nav Container
.Description
Create a session to a Nav Container and run Update-NavApplicationObject,
merginge deltas with original objects from that container and create object file
Import object file using Import-NavApplicationObject
.Parameter containerName
Name of the container in which you want to import deltas
.Parameter deltaFolder
Path of the folder containing the delta files you want to import
.Parameter sqlCredential
Credentials for the SQL admin user if using NavUserPassword authentication. User will be prompted if not provided
.Parameter compile
Include this switch to compile uncompiled objects after the import
.Example
Import-DeltasToNavContainer -containerName test2 -deltaFolder c:\temp\mydeltas
#>
function Import-DeltasToNavContainer {
Param (
[string] $containerName = $bcContainerHelperConfig.defaultContainerName,
[Parameter(Mandatory=$true)]
[string] $deltaFolder,
[PSCredential] $sqlCredential = $null,
[switch] $compile
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
AssumeNavContainer -containerOrImageName $containerName -functionName $MyInvocation.MyCommand.Name
$sqlCredential = Get-DefaultSqlCredential -containerName $containerName -sqlCredential $sqlCredential -doNotAskForCredential
$containerDeltaFolder = Get-NavContainerPath -containerName $containerName -path $deltaFolder
if ("$containerDeltaFolder" -eq "") {
throw "The deltaFolder ($deltaFolder) is not shared with the container."
}
$navversion = Get-NavContainerNavversion -containerOrImageName $containerName
$originalFolder = Join-Path $bcContainerHelperConfig.hostHelperFolder "Extensions\Original-$navversion"
$mergeResultFile = Join-Path $bcContainerHelperConfig.hostHelperFolder "Extensions\$containerName\mergeresult.txt"
Remove-Item $mergeResultFile -Force -ErrorAction Ignore
$mergedObjectsFile = Join-Path $bcContainerHelperConfig.hostHelperFolder "Extensions\$containerName\mergedobjects.txt"
Remove-Item $mergedObjectsFile -Force -ErrorAction Ignore
$myOriginalFolder = Join-Path $bcContainerHelperConfig.hostHelperFolder "Extensions\$containerName\original"
Remove-Item $myOriginalFolder -Force -Recurse -ErrorAction Ignore
Create-MyOriginalFolder -originalFolder $originalFolder `
-modifiedFolder $deltaFolder `
-myOriginalFolder $myOriginalFolder
$containerMyOriginalFolder = Get-NavContainerPath -containerName $containerName -path $myOriginalFolder -throw
$containerMergeResultFile = Get-NavContainerPath -containerName $containerName -path $mergeResultFile -throw
$containerMergedObjectsFile = Get-NavContainerPath -containerName $containerName -path $mergedObjectsFile -throw
Invoke-ScriptInNavContainer -containerName $containerName -ScriptBlock { Param($deltaFolder, $originalFolder, $mergedObjectsFile, $mergeResultFile)
Write-Host "Merging Deltas from $deltaFolder (container path)"
Update-NAVApplicationObject -TargetPath $originalFolder `
-DeltaPath $deltaFolder `
-ResultPath $mergedObjectsFile `
-ModifiedProperty Yes `
-VersionListProperty FromModified `
-DateTimeProperty FromModified | Set-Content $mergeResultFile
} -ArgumentList $containerDeltaFolder, $containerMyOriginalFolder, $containerMergedObjectsFile, $containerMergeResultFile
if (Test-Path $mergedObjectsFile) {
Import-ObjectsToNavContainer -containerName $containerName `
-objectsFile $mergedObjectsFile `
-sqlcredential $sqlCredential
if ($compile) {
Compile-ObjectsInNavContainer -containerName $containerName
}
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Export-ModuleMember -Function Import-DeltasToNavContainer