functions/invoke-d365modulefullcompilesync.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161

<#
    .SYNOPSIS
        Compile and sync a module
         
    .DESCRIPTION
        Compile and sync a package using
        - Invoke-D365ModuleFullCompile function
        - Invoke-D365DBSyncPartial to sync the table and extension elements for module
         
    .PARAMETER ModuleName
        Name of the module that you are looking for
         
        Accepts wildcards for searching. E.g. -Name "Application*Adaptor"
         
        Default value is "*" which will search for all modules
         
    .PARAMETER OutputDir
        The path to the folder to save assemblies
         
    .PARAMETER LogDir
        The path to the folder to save logs
         
    .PARAMETER MetaDataDir
        The path to the meta data directory for the environment
         
    .PARAMETER ReferenceDir
        The full path of a folder containing all assemblies referenced from X++ code
         
    .PARAMETER BinDir
        The path to the bin directory for the environment
         
        Default path is the same as the aos service PackagesLocalDirectory\bin
         
    .PARAMETER ShowOriginalProgress
        Instruct the cmdlet to show the standard output in the console
         
        Default is $false which will silence the standard output
         
    .PARAMETER OutputCommandOnly
        Instruct the cmdlet to only output the command that you would have to execute by hand
         
        Will include full path to the executable and the needed parameters based on your selection
         
    .EXAMPLE
        PS C:\> Invoke-D365ModuleFullCompileSync -ModuleName MyModel
         
        This will use the default paths and start:
        * Invoke-D365ModuleFullCompile with the needed parameters to compile MyModel package.
        * Invoke-D365DBSyncPartial with the needed parameters to sync MyModel table and extesion elements.
         
        The default output from all the different steps will be silenced.
         
    .EXAMPLE
        PS C:\> Invoke-D365ModuleFullCompileSync -ModuleName "Application*Adaptor"
         
        Retrieve the list of installed packages / modules where the name fits the search "Application*Adaptor".
         
        For every value of the list perform the following:
        * Invoke-D365ModuleFullCompile with the needed parameters to compile current module value package.
        * Invoke-D365DBSyncPartial with the needed parameters to sync current module value table and extesion elements.
         
        The default output from all the different steps will be silenced.
         
    .NOTES
        Tags: Compile, Model, Servicing, Database, Synchronization
         
        Author: Jasper Callens - Cegeka
#>


function Invoke-D365ModuleFullCompileSync {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [string] $ModuleName,

        [Alias('Output')]
        [string] $OutputDir = $Script:MetaDataDir,

        [string] $LogDir = $Script:DefaultTempPath,

        [string] $MetaDataDir = $Script:MetaDataDir,

        [string] $ReferenceDir = $Script:MetaDataDir,

        [string] $BinDir = $Script:BinDirTools,

        [switch] $ShowOriginalProgress,

        [switch] $OutputCommandOnly
    )

    begin {
        Invoke-TimeSignal -Start
    }

    process {
        # Retrieve all modules that match provided $ModuleName
        $moduleResults = Get-D365Module -Name $ModuleName

        # Output information on which modules that will be compiled and synced
        Write-PSFMessage -Level Debug -Message "Modules retrieved: "
        $moduleResults | ForEach-Object {
            Write-PSFMessage -Level Debug -Message "$($_.Module) "
        }
        
        # Create empty lists for all sync-base and sync-extension elements
        $syncList = @()
        $syncExtensionsList = @()

        foreach($moduleElement in $moduleResults)
        {
            Write-PSFMessage -Level Debug -Message "Processing module: $($moduleElement.Module)"

            # Build parameters for the full compile function
            $fullCompileParams = @{
                Module=$moduleElement.Module;
                OutputDir=$OutputDir;
                LogDir=$LogDir;
                MetaDataDir=$MetaDataDir;
                ReferenceDir=$ReferenceDir;
                BinDir=$BinDir;
                ShowOriginalProgress=$ShowOriginalProgress;
                OutputCommandOnly=$OutputCommandOnly
            }

            # Call the full compile using required parameters
            $resModuleCompileFull = Invoke-D365ModuleFullCompile @fullCompileParams

            # Retrieve the sync element of current module
            $moduleSyncElements = Get-SyncElements -ModuleName $moduleElement.Module

            # Add base and extensions elements to the sync lists
            $syncList +=$moduleSyncElements.BaseSyncElements
            $syncExtensionsList += $moduleSyncElements.ExtensionSyncElements
    
            # Output results of full compile and partial sync
            $resModuleCompileFull
            
        }

        # Build parameters for the partial sync function
        $syncParams = @{
            SyncList=$syncList;
            SyncExtensionsList = $syncExtensionsList;
            BinDirTools=$BinDir;
            MetadataDir=$MetaDataDir;
            ShowOriginalProgress=$ShowOriginalProgress;
            OutputCommandOnly=$OutputCommandOnly
        }

        # Call the partial sync using required parameters
        $resSyncModule = Invoke-D365DBSyncPartial @syncParams

        $resSyncModule
    }

    end {
        Invoke-TimeSignal -End
    }
}