NAVObjectMgt/Release-NCHNAVApplicationObjects.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
function Release-NCHNAVApplicationObjects {
    param(
        [Parameter(Mandatory = $true)]
        [String] $ContainerName,
        [Parameter(Mandatory = $true)]
        [Object] $ReleaseSettings
    )


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

    $Session = Get-NavContainerSession -containerName $ContainerName
    Invoke-Command -Session $Session -ScriptBlock {
        param(
            $ReleaseSettings
        )

        Write-Host "Releasing $($ReleaseSettings.ContainerPath)"

        $WorkingFolder = (Get-Item $ReleaseSettings.ContainerPath).Directory
        $SplitFolder   = (Join-Path $WorkingFolder '\Split\') 
        
        if (Test-Path $SplitFolder){
            $null = remove-item -Path $SplitFolder -Recurse
        } 
        Write-host "Splitting $($ReleaseSettings.ContainerPath) to $SplitFolder"
        $null = Split-NAVApplicationObjectFile -Source $ReleaseSettings.ContainerPath -Destination $SplitFolder -Force
        
        $OriginalFile = (join-path $WorkingFolder 'Original.txt')
        if (!(Test-Path $OriginalFile)){
            Write-host "Creating original file $OriginalFile"
            $null = join-navapplicationObjectFile -Source $SplitFolder -Destination $OriginalFile -Force
        }
                
        Write-host "Reading objects to memory from $SplitFolder"
        $Objects = Get-NAVApplicationObjectProperty -Source $SplitFolder 
        
        $VersionlistCompare = @()
        Write-host "Start VersionList-Merge"
        foreach ($object in $Objects) {
            $ObjectComparison = New-object System.Object
            $ObjectComparison | Add-Member -MemberType NoteProperty -Name 'OldVersionList' -Value $object.VersionList
            $ObjectComparison | Add-Member -MemberType NoteProperty -Name 'NewVersionList' -Value (Release-NAVVersionList -VersionList $object.VersionList -ProductVersion $ReleaseSettings.ProductVersion -Versionprefix $ReleaseSettings.VersionPrefix)
            $ObjectComparison | Add-Member -MemberType NoteProperty -Name 'WasModified' -Value $Object.Modified
            
            
            if ((-not($ReleaseSettings.ModifiedOnly)) -or ($ReleaseSettings.ModifiedOnly -and ($object.Modified))){
                Write-Host "$($object.FileName) - $($ObjectComparison.NewVersionList)"
                Set-NAVApplicationObjectProperty -TargetPath $object.FileName `
                                -ModifiedProperty No `
                                -DateTimeProperty (get-date -Hour 12 -Minute 0 -Second 0 -Format g) `
                                -VersionListProperty $ObjectComparison.NewVersionList                
        
                $VersionlistCompare += $ObjectComparison
            }
        }
        
        $ReleasedFile = (join-path $WorkingFolder 'Released.txt')
        Write-host "Writing released file $ReleasedFile"
        $null = Join-NAVApplicationObjectFile -Source (join-path $SplitFolder '\*.txt') -Destination $ReleasedFile -Force
        
        $null = Remove-Item $SplitFolder -Recurse -Force
        
        $ReleaseResult = @{}
        $ReleaseResult.VersionlistCompare = $VersionlistCompare 
        $ReleaseResult.ContainerFilePath = $ReleasedFile

        return $ReleaseResult
        
    } -ArgumentList $ReleaseSettings

}