functions/process-map.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
162
163
164
165
166
167
168
169
170
171
172
function import-map {
    [cmdletbinding()]
    param([Parameter(Mandatory=$true)] $maps)
    
    if ($maps -is [System.Collections.IDictionary] ) {
        return import-mapobject $maps
    }    
    else {
        return import-mapfile $maps
    }
}

function import-mapfile {
    [cmdletbinding()]
    param([Parameter(Mandatory=$true)] $maps)

    write-verbose "processing publishmap..."

    if ($maps -ne $null) {
        $maps = @($maps)
    }
        
    $publishmap = @{}

    foreach($m in $maps) {
        $publishmap += import-singlemapfile $m
    }

    write-verbose "processing publishmap... DONE"

    return $publishmap
}


function import-mapobject { 
[cmdletbinding()]
param([Parameter(Mandatory=$true)] $map) 
   $pmap = @{}
    
   $pmap = import-genericgroup $map ""   
   $pmap = add-metaproperties $pmap ""
   return $pmap
}

function import-singlemapfile($file) {
    $fullname = $file
    if ($fullname.FullName -ne $null) { $Fullname =$Fullname.FullName }
    $map = & "$FullName"
    
    #$publishmap_obj = ConvertTo-Object $publishmap
    $pmap = import-mapobject $map

   return $pmap
}


function import-genericgroup($group,
    $fullpath, 
    $settings = $null,
    $settingskey = "settings",
    $specialkeys = @("settings", "global_profiles")
) {
    Write-Verbose "processing map path $fullpath"
   
    $keys = get-propertynames $group
    
    
   
    $result = {}
        

    $onelevelsettingsinheritance = $true

    $childsettings = $null 
    #get settings for children
    if ($group.$settingskey -ne $null) {
        $childsettings = $group.$settingskey
    } else {
        if (!$onelevelsettingsinheritance) {
            $childsettings = $settings
        }
    }
    
    foreach($projk in $keys) {
     #do not process special global settings
            if ($projk -in $specialkeys) {
                continue
            }
            $subgroup = $group.$projk
            if (!($subgroup -is [System.Collections.IDictionary])) {
                continue
            }
            $path = "$fullpath.$projk"            


            inherit-properties -from $group -to $subgroup -valuesonly
                    
            $r = import-genericgroup $subgroup $path -settings $childsettings -settingskey $settingskey -specialkeys $specialkeys

    }


    if ($settings -ne $null) {
        inherit-globalsettings $group $settings 
    }
    
    

    return $map
}

function add-metaproperties($group, $fullpath, $specialkeys = @("settings", "global_profiles")
) {
    if ($group -isnot [System.Collections.IDictionary]) {
        return
    }
    $level = $fullpath.split('.').length - 1
    
    $null = $group | add-property -name _level -value $level
    $null = $group | add-property -name _fullpath -value $fullpath.trim('.')

      $keys = get-propertynames $group

        
    foreach($projk in $keys) {
     #do not process special global settings
        if ($projk -in $specialkeys) {
                continue
        }
        $path = "$fullpath.$projk"
        $null = add-metaproperties $group.$projk $path -specialkeys $specialkeys
    }
  
    return $group
}

function import-mapgroup(
    $publishmapgroup, $groupk,     
    $settings = $null,
    $stripsettingswrapper = $false
) {
    Write-Verbose "processing map $groupk"
   
    $globalProffiles = $publishmapgroup.global_profiles
    $keys = get-propertynames $publishmapgroup
    
    $null = add-property $publishmapgroup "level" 1
    $null = add-property $publishmapgroup -name fullpath -value "$groupk"
    
    $group = $publishmapgroup
    $result = {}
    foreach($projk in $keys) {
     #do not process special global settings
            if ($projk -in "settings","global_profiles") {
                continue
            }
            $proj = $group.$projk            
            $r = import-mapproject $proj $projk $level
            
            $null = add-property $proj "level" 2
            $null = add-property $proj -name fullpath  -value "$groupk.$projk"
                       
        }

    return $publishmapgroup
}


<#

#>