Skip to content
This repository was archived by the owner on Jul 20, 2023. It is now read-only.

Commit f69d01c

Browse files
authored
Mdb support
!Deploy * MDB Support * Bug fixes * Added wildcard attribute to parameters that support it (MDB does not support wildcards) * Added single char ? wildcard support besides * * Locked to PSv5.1+
1 parent 3f312d9 commit f69d01c

File tree

78 files changed

+5398
-550
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+5398
-550
lines changed

.build/Release/MergeModule.Release.build.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
[string] $ModuleVersion = (property ModuleVersion $(
99
if($resolvedModuleVersion = Get-NextNugetPackageVersion -Name $ProjectName -ErrorAction SilentlyContinue) {
10-
if ($resolvedModuleVersion -gt [version]'0.3.0') {
10+
if ($resolvedModuleVersion -gt [version]'0.4.0') {
1111
$resolvedModuleVersion
1212
} else {
13-
'0.3.0'
13+
'0.4.0'
1414
}
1515
} else {
16-
'0.3.0'
16+
'0.4.0'
1717
}
1818
)),
1919

.gitattributes

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1 @@
1-
###############################################################################
2-
# Set default behavior to automatically normalize line endings.
3-
###############################################################################
4-
* text=auto
5-
6-
###############################################################################
7-
# Set default behavior for command prompt diff.
8-
#
9-
# This is need for earlier builds of msysgit that does not have it on by
10-
# default for csharp files.
11-
# Note: This is only used by command line
12-
###############################################################################
13-
#*.cs diff=csharp
14-
15-
###############################################################################
16-
# Set the merge driver for project and solution files
17-
#
18-
# Merging from the command prompt will add diff markers to the files if there
19-
# are conflicts (Merging from VS is not affected by the settings below, in VS
20-
# the diff markers are never inserted). Diff markers may cause the following
21-
# file extensions to fail to load in VS. An alternative would be to treat
22-
# these files as binary and thus will always conflict and require user
23-
# intervention with every merge. To do so, just uncomment the entries below
24-
###############################################################################
25-
#*.sln merge=binary
26-
#*.csproj merge=binary
27-
#*.vbproj merge=binary
28-
#*.vcxproj merge=binary
29-
#*.vcproj merge=binary
30-
#*.dbproj merge=binary
31-
#*.fsproj merge=binary
32-
#*.lsproj merge=binary
33-
#*.wixproj merge=binary
34-
#*.modelproj merge=binary
35-
#*.sqlproj merge=binary
36-
#*.wwaproj merge=binary
37-
38-
###############################################################################
39-
# behavior for image files
40-
#
41-
# image files are treated as binary by default.
42-
###############################################################################
43-
#*.jpg binary
44-
#*.png binary
45-
#*.gif binary
46-
47-
###############################################################################
48-
# diff behavior for common document formats
49-
#
50-
# Convert binary document formats to text before diffing them. This feature
51-
# is only available from the command line. Turn it on by uncommenting the
52-
# entries below.
53-
###############################################################################
54-
#*.doc diff=astextplain
55-
#*.DOC diff=astextplain
56-
#*.docx diff=astextplain
57-
#*.DOCX diff=astextplain
58-
#*.dot diff=astextplain
59-
#*.DOT diff=astextplain
60-
#*.pdf diff=astextplain
61-
#*.PDF diff=astextplain
62-
#*.rtf diff=astextplain
63-
#*.RTF diff=astextplain
1+
* text=auto eol=lf

DSCPullServerAdmin/DSCPullServerAdmin.psd1

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ RootModule = 'DSCPullServerAdmin.psm1'
1515
ModuleVersion = '0.0.1.0'
1616

1717
# Supported PSEditions
18-
# CompatiblePSEditions = @()
18+
CompatiblePSEditions = 'Core', 'Desktop'
1919

2020
# ID used to uniquely identify this module
2121
GUID = 'eb129ddc-06f0-4394-aee7-6ccd9392263c'
@@ -33,7 +33,7 @@ Copyright = '(c) 2018 Ben Gelens. All rights reserved.'
3333
Description = 'Get, manipulate and migrate data from your DSC Pull Server database (EDB and SQL)'
3434

3535
# Minimum version of the Windows PowerShell engine required by this module
36-
# PowerShellVersion = ''
36+
PowerShellVersion = '5.1'
3737

3838
# Name of the Windows PowerShell host required by this module
3939
# PowerShellHostName = ''
@@ -126,7 +126,11 @@ PrivateData = @{
126126
# IconUri = ''
127127

128128
# ReleaseNotes of this module
129-
ReleaseNotes = 'Fix where Copy-DSCPullServerAdmin would only copy 5 StatusReports. Now copies all'
129+
ReleaseNotes = '* MDB Support
130+
* Bug fixes
131+
* Added wildcard attribute to parameters that support it (MDB does not support wildcards)
132+
* Added single char ? wildcard support besides *
133+
* Locked to PSv5.1+'
130134

131135
} # End of PSData hashtable
132136

DSCPullServerAdmin/DSCPullServerAdmin.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$enums = Get-ChildItem -Path $PSScriptRoot\enums\*.ps1 -ErrorAction SilentlyContinue | ForEach-Object -Process {
1+
$enums = Get-ChildItem -Path $PSScriptRoot\enums\*.ps1 -ErrorAction SilentlyContinue | ForEach-Object -Process {
22
Get-Content $_.FullName
33
}
44

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
class DSCBaseClass {
2+
hidden [DSCDatabaseTable] $TableName
3+
4+
DSCBaseClass ([DSCDatabaseTable] $tableName) {
5+
$this.TableName = $tableName
6+
}
7+
8+
hidden [string] GetKey () {
9+
$key = switch ($this.GetType().Name) {
10+
DSCDevice {
11+
'TargetName'
12+
}
13+
DSCNodeStatusReport {
14+
'JobId'
15+
}
16+
DSCNodeRegistration {
17+
'AgentId'
18+
}
19+
}
20+
return $key
21+
}
22+
23+
hidden [string] GetExcludedProperties () {
24+
if ($this.GetType().Name -eq 'DSCDevice') {
25+
return 'Status'
26+
} elseif ($this.GetType().Name -eq 'DSCNodeStatusReport') {
27+
return 'LastModifiedTime'
28+
} else {
29+
return $null
30+
}
31+
}
32+
33+
hidden [string] GetInsert ([bool] $isMDB) {
34+
$excludeProperties = $this.GetExcludedProperties()
35+
36+
$query = ('INSERT INTO {0} ({1}) VALUES ({2})' -f @(
37+
$this.TableName,
38+
(($this | Get-Member -MemberType Property | Where-Object -FilterScript {$_.Name -notin $excludeProperties}).Name -join ','),
39+
(($this | Get-Member -MemberType Property).ForEach{
40+
if ($_.Name -in $excludeProperties) {
41+
return
42+
} else {
43+
if ($_.Name -eq 'ConfigurationNames') {
44+
if ($this.ConfigurationNames.Count -ge 1) {
45+
"'[`"{0}`"]'" -f ($this."$($_.Name)" -join '","')
46+
} else {
47+
"'[]'"
48+
}
49+
} elseif ($_.Name -eq 'IPAddress') {
50+
"'{0}'" -f ($this."$($_.Name)" -join ';')
51+
} elseif ($_.Name -in 'StatusData', 'Errors') {
52+
"'[{0}]'" -f (($this."$($_.Name)" | ConvertTo-Json -Compress -Depth 100) | ConvertTo-Json -Compress)
53+
} elseif ($_.Name -eq 'AdditionalData') {
54+
"'{0}'" -f ($this."$($_.Name)" | ConvertTo-Json -Compress -Depth 100)
55+
} elseif ($_.Definition.Split(' ')[0] -like '*datetime*' -and -not $null -eq $this."$($_.Name)") {
56+
if ($this."$($_.Name)".ToString('yyyy-MM-dd HH:mm:ss') -eq '0001-01-01 00:00:00') {
57+
'NULL'
58+
} else {
59+
"'{0}'" -f $this."$($_.Name)".ToString('yyyy-MM-dd HH:mm:ss')
60+
}
61+
} elseif ($_.Definition.Split(' ')[0] -like '*nullable*' -and $null -eq $this."$($_.Name)") {
62+
'NULL'
63+
} elseif ($_.Definition.Split(' ')[0] -like '*bool*' -and $isMDB) {
64+
if ($this."$($_.Name)" -eq $false) {
65+
"'{0}'" -f '0'
66+
} else {
67+
"'{0}'" -f '-1'
68+
}
69+
} else {
70+
"'{0}'" -f $this."$($_.Name)"
71+
}
72+
}
73+
} -join ',')
74+
))
75+
return $query
76+
}
77+
78+
hidden [string] GetUpdate ([bool] $isMDB) {
79+
$excludeProperties = $this.GetExcludedProperties()
80+
$key = $this.GetKey()
81+
$query = "UPDATE {0} Set {1} WHERE {2} = '{3}'" -f @(
82+
$this.TableName,
83+
(($this | Get-Member -MemberType Property).Where{
84+
$_.Name -ne $key
85+
}.foreach{
86+
if ($_.Name -in $excludeProperties) {
87+
# skip
88+
} elseif ($_.Name -in 'StatusData', 'Errors') {
89+
"$($_.Name) = '[{0}]'" -f (($this."$($_.Name)" | ConvertTo-Json -Compress -Depth 100) | ConvertTo-Json -Compress)
90+
} elseif ($_.Name -eq 'AdditionalData') {
91+
"$($_.Name) = '[{0}]'" -f ($this."$($_.Name)" | ConvertTo-Json -Compress -Depth 100)
92+
} elseif ($_.Name -eq 'ConfigurationNames') {
93+
if ($this.ConfigurationNames.Count -ge 1) {
94+
"$($_.Name) = '[`"{0}`"]'" -f ($this."$($_.Name)" -join '","')
95+
} else {
96+
"$($_.Name) = '[]'"
97+
}
98+
} elseif ($_.Name -eq 'IPAddress') {
99+
"$($_.Name) = '{0}'" -f ($this."$($_.Name)" -join ';')
100+
} elseif ($_.Definition.Split(' ')[0] -like '*datetime*' -and -not $null -eq $this."$($_.Name)") {
101+
if ($this."$($_.Name)".ToString('yyyy-MM-dd HH:mm:ss') -eq '0001-01-01 00:00:00') {
102+
"$($_.Name) = NULL"
103+
} else {
104+
"$($_.Name) = '{0}'" -f $this."$($_.Name)".ToString('yyyy-MM-dd HH:mm:ss')
105+
}
106+
} elseif ($_.Definition.Split(' ')[0] -like '*nullable*' -and $null -eq $this."$($_.Name)") {
107+
"$($_.Name) = NULL"
108+
} elseif ($_.Definition.Split(' ')[0] -like '*bool*' -and $isMDB) {
109+
if ($this."$($_.Name)" -eq $false) {
110+
"$($_.Name) = '{0}'" -f '0'
111+
} else {
112+
"$($_.Name) = '{0}'" -f '-1'
113+
}
114+
} else {
115+
"$($_.Name) = '{0}'" -f $this."$($_.Name)"
116+
}
117+
} -join ','),
118+
$key,
119+
$this.$key
120+
)
121+
return $query
122+
}
123+
124+
hidden [string] GetDelete () {
125+
$key = $this.GetKey()
126+
return ("DELETE FROM {0} WHERE {1} = '{2}'" -f $this.TableName, $key, $this.$key)
127+
}
128+
129+
[string] GetSQLDelete () {
130+
return $this.GetDelete()
131+
}
132+
133+
[string] GetMDBDelete () {
134+
return $this.GetDelete()
135+
}
136+
137+
[string] GetSQLInsert () {
138+
return $this.GetInsert($false)
139+
}
140+
141+
[string] GetMDBInsert () {
142+
return $this.GetInsert($true)
143+
}
144+
145+
[string] GetSQLUpdate () {
146+
return $this.GetUpdate($false)
147+
}
148+
149+
[string] GetMDBUpdate () {
150+
return $this.GetUpdate($true)
151+
}
152+
}
Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class DSCDevice {
1+
class DSCDevice : DSCBaseClass {
22
[string] $TargetName
33

44
[guid] $ConfigurationID
@@ -21,9 +21,9 @@ class DSCDevice {
2121
$this.GetStatus()
2222
})"
2323

24-
DSCDevice () {}
24+
DSCDevice () : base([DSCDatabaseTable]::Devices) { }
2525

26-
DSCDevice ([System.Data.Common.DbDataRecord] $Input) {
26+
DSCDevice ([System.Data.Common.DbDataRecord] $Input) : base([DSCDatabaseTable]::Devices) {
2727
for ($i = 0; $i -lt $Input.FieldCount; $i++) {
2828
$name = $Input.GetName($i)
2929
if (([DBNull]::Value).Equals($Input[$i])) {
@@ -69,54 +69,4 @@ class DSCDevice {
6969
}
7070
return $deviceStatusCodeMap[$this.StatusCode]
7171
}
72-
73-
[string] GetSQLUpdate () {
74-
$query = "UPDATE Devices Set {0} WHERE TargetName = '{1}'" -f @(
75-
(($this | Get-Member -MemberType Property).Where{
76-
$_.Name -notin 'TargetName', 'Status'
77-
}.foreach{
78-
if ($_.Definition.Split(' ')[0] -like '*datetime*' -and -not $null -eq $this."$($_.Name)") {
79-
if ($this."$($_.Name)".ToString('yyyy-MM-dd HH:mm:ss') -eq '0001-01-01 00:00:00') {
80-
"$($_.Name) = NULL"
81-
} else {
82-
"$($_.Name) = '{0}'" -f $this."$($_.Name)".ToString('yyyy-MM-dd HH:mm:ss')
83-
}
84-
} elseif ($_.Definition.Split(' ')[0] -like '*nullable*' -and $null -eq $this."$($_.Name)") {
85-
"$($_.Name) = NULL"
86-
} else {
87-
"$($_.Name) = '{0}'" -f $this."$($_.Name)"
88-
}
89-
} -join ','),
90-
$this.TargetName
91-
)
92-
return $query
93-
}
94-
95-
[string] GetSQLInsert () {
96-
$query = ("INSERT INTO Devices ({0}) VALUES ({1})" -f @(
97-
(($this | Get-Member -MemberType Property | Where-Object -FilterScript {$_.Name -ne 'Status'}).Name -join ','),
98-
(($this | Get-Member -MemberType Property).ForEach{
99-
if ($_.Name -eq 'Status') {
100-
return
101-
} else {
102-
if ($_.Definition.Split(' ')[0] -like '*datetime*' -and -not $null -eq $this."$($_.Name)") {
103-
if ($this."$($_.Name)".ToString('yyyy-MM-dd HH:mm:ss') -eq '0001-01-01 00:00:00') {
104-
'NULL'
105-
} else {
106-
"'{0}'" -f $this."$($_.Name)".ToString('yyyy-MM-dd HH:mm:ss')
107-
}
108-
} elseif ($_.Definition.Split(' ')[0] -like '*nullable*' -and $null -eq $this."$($_.Name)") {
109-
'NULL'
110-
} else {
111-
"'{0}'" -f $this."$($_.Name)"
112-
}
113-
}
114-
} -join ',')
115-
))
116-
return $query
117-
}
118-
119-
[string] GetSQLDelete () {
120-
return ("DELETE FROM Devices WHERE TargetName = '{0}'" -f $this.TargetName)
121-
}
12272
}

0 commit comments

Comments
 (0)