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

Commit

Permalink
Mdb support
Browse files Browse the repository at this point in the history
!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+
  • Loading branch information
bgelens authored Dec 19, 2018
1 parent 3f312d9 commit f69d01c
Show file tree
Hide file tree
Showing 78 changed files with 5,398 additions and 550 deletions.
6 changes: 3 additions & 3 deletions .build/Release/MergeModule.Release.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

[string] $ModuleVersion = (property ModuleVersion $(
if($resolvedModuleVersion = Get-NextNugetPackageVersion -Name $ProjectName -ErrorAction SilentlyContinue) {
if ($resolvedModuleVersion -gt [version]'0.3.0') {
if ($resolvedModuleVersion -gt [version]'0.4.0') {
$resolvedModuleVersion
} else {
'0.3.0'
'0.4.0'
}
} else {
'0.3.0'
'0.4.0'
}
)),

Expand Down
64 changes: 1 addition & 63 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,63 +1 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
* text=auto eol=lf
10 changes: 7 additions & 3 deletions DSCPullServerAdmin/DSCPullServerAdmin.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ RootModule = 'DSCPullServerAdmin.psm1'
ModuleVersion = '0.0.1.0'

# Supported PSEditions
# CompatiblePSEditions = @()
CompatiblePSEditions = 'Core', 'Desktop'

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

# Minimum version of the Windows PowerShell engine required by this module
# PowerShellVersion = ''
PowerShellVersion = '5.1'

# Name of the Windows PowerShell host required by this module
# PowerShellHostName = ''
Expand Down Expand Up @@ -126,7 +126,11 @@ PrivateData = @{
# IconUri = ''

# ReleaseNotes of this module
ReleaseNotes = 'Fix where Copy-DSCPullServerAdmin would only copy 5 StatusReports. Now copies all'
ReleaseNotes = '* 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+'

} # End of PSData hashtable

Expand Down
2 changes: 1 addition & 1 deletion DSCPullServerAdmin/DSCPullServerAdmin.psm1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$enums = Get-ChildItem -Path $PSScriptRoot\enums\*.ps1 -ErrorAction SilentlyContinue | ForEach-Object -Process {
$enums = Get-ChildItem -Path $PSScriptRoot\enums\*.ps1 -ErrorAction SilentlyContinue | ForEach-Object -Process {
Get-Content $_.FullName
}

Expand Down
152 changes: 152 additions & 0 deletions DSCPullServerAdmin/classes/DSCBaseClass.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
class DSCBaseClass {
hidden [DSCDatabaseTable] $TableName

DSCBaseClass ([DSCDatabaseTable] $tableName) {
$this.TableName = $tableName
}

hidden [string] GetKey () {
$key = switch ($this.GetType().Name) {
DSCDevice {
'TargetName'
}
DSCNodeStatusReport {
'JobId'
}
DSCNodeRegistration {
'AgentId'
}
}
return $key
}

hidden [string] GetExcludedProperties () {
if ($this.GetType().Name -eq 'DSCDevice') {
return 'Status'
} elseif ($this.GetType().Name -eq 'DSCNodeStatusReport') {
return 'LastModifiedTime'
} else {
return $null
}
}

hidden [string] GetInsert ([bool] $isMDB) {
$excludeProperties = $this.GetExcludedProperties()

$query = ('INSERT INTO {0} ({1}) VALUES ({2})' -f @(
$this.TableName,
(($this | Get-Member -MemberType Property | Where-Object -FilterScript {$_.Name -notin $excludeProperties}).Name -join ','),
(($this | Get-Member -MemberType Property).ForEach{
if ($_.Name -in $excludeProperties) {
return
} else {
if ($_.Name -eq 'ConfigurationNames') {
if ($this.ConfigurationNames.Count -ge 1) {
"'[`"{0}`"]'" -f ($this."$($_.Name)" -join '","')
} else {
"'[]'"
}
} elseif ($_.Name -eq 'IPAddress') {
"'{0}'" -f ($this."$($_.Name)" -join ';')
} elseif ($_.Name -in 'StatusData', 'Errors') {
"'[{0}]'" -f (($this."$($_.Name)" | ConvertTo-Json -Compress -Depth 100) | ConvertTo-Json -Compress)
} elseif ($_.Name -eq 'AdditionalData') {
"'{0}'" -f ($this."$($_.Name)" | ConvertTo-Json -Compress -Depth 100)
} elseif ($_.Definition.Split(' ')[0] -like '*datetime*' -and -not $null -eq $this."$($_.Name)") {
if ($this."$($_.Name)".ToString('yyyy-MM-dd HH:mm:ss') -eq '0001-01-01 00:00:00') {
'NULL'
} else {
"'{0}'" -f $this."$($_.Name)".ToString('yyyy-MM-dd HH:mm:ss')
}
} elseif ($_.Definition.Split(' ')[0] -like '*nullable*' -and $null -eq $this."$($_.Name)") {
'NULL'
} elseif ($_.Definition.Split(' ')[0] -like '*bool*' -and $isMDB) {
if ($this."$($_.Name)" -eq $false) {
"'{0}'" -f '0'
} else {
"'{0}'" -f '-1'
}
} else {
"'{0}'" -f $this."$($_.Name)"
}
}
} -join ',')
))
return $query
}

hidden [string] GetUpdate ([bool] $isMDB) {
$excludeProperties = $this.GetExcludedProperties()
$key = $this.GetKey()
$query = "UPDATE {0} Set {1} WHERE {2} = '{3}'" -f @(
$this.TableName,
(($this | Get-Member -MemberType Property).Where{
$_.Name -ne $key
}.foreach{
if ($_.Name -in $excludeProperties) {
# skip
} elseif ($_.Name -in 'StatusData', 'Errors') {
"$($_.Name) = '[{0}]'" -f (($this."$($_.Name)" | ConvertTo-Json -Compress -Depth 100) | ConvertTo-Json -Compress)
} elseif ($_.Name -eq 'AdditionalData') {
"$($_.Name) = '[{0}]'" -f ($this."$($_.Name)" | ConvertTo-Json -Compress -Depth 100)
} elseif ($_.Name -eq 'ConfigurationNames') {
if ($this.ConfigurationNames.Count -ge 1) {
"$($_.Name) = '[`"{0}`"]'" -f ($this."$($_.Name)" -join '","')
} else {
"$($_.Name) = '[]'"
}
} elseif ($_.Name -eq 'IPAddress') {
"$($_.Name) = '{0}'" -f ($this."$($_.Name)" -join ';')
} elseif ($_.Definition.Split(' ')[0] -like '*datetime*' -and -not $null -eq $this."$($_.Name)") {
if ($this."$($_.Name)".ToString('yyyy-MM-dd HH:mm:ss') -eq '0001-01-01 00:00:00') {
"$($_.Name) = NULL"
} else {
"$($_.Name) = '{0}'" -f $this."$($_.Name)".ToString('yyyy-MM-dd HH:mm:ss')
}
} elseif ($_.Definition.Split(' ')[0] -like '*nullable*' -and $null -eq $this."$($_.Name)") {
"$($_.Name) = NULL"
} elseif ($_.Definition.Split(' ')[0] -like '*bool*' -and $isMDB) {
if ($this."$($_.Name)" -eq $false) {
"$($_.Name) = '{0}'" -f '0'
} else {
"$($_.Name) = '{0}'" -f '-1'
}
} else {
"$($_.Name) = '{0}'" -f $this."$($_.Name)"
}
} -join ','),
$key,
$this.$key
)
return $query
}

hidden [string] GetDelete () {
$key = $this.GetKey()
return ("DELETE FROM {0} WHERE {1} = '{2}'" -f $this.TableName, $key, $this.$key)
}

[string] GetSQLDelete () {
return $this.GetDelete()
}

[string] GetMDBDelete () {
return $this.GetDelete()
}

[string] GetSQLInsert () {
return $this.GetInsert($false)
}

[string] GetMDBInsert () {
return $this.GetInsert($true)
}

[string] GetSQLUpdate () {
return $this.GetUpdate($false)
}

[string] GetMDBUpdate () {
return $this.GetUpdate($true)
}
}
56 changes: 3 additions & 53 deletions DSCPullServerAdmin/classes/DSCDevice.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class DSCDevice {
class DSCDevice : DSCBaseClass {
[string] $TargetName

[guid] $ConfigurationID
Expand All @@ -21,9 +21,9 @@ class DSCDevice {
$this.GetStatus()
})"

DSCDevice () {}
DSCDevice () : base([DSCDatabaseTable]::Devices) { }

DSCDevice ([System.Data.Common.DbDataRecord] $Input) {
DSCDevice ([System.Data.Common.DbDataRecord] $Input) : base([DSCDatabaseTable]::Devices) {
for ($i = 0; $i -lt $Input.FieldCount; $i++) {
$name = $Input.GetName($i)
if (([DBNull]::Value).Equals($Input[$i])) {
Expand Down Expand Up @@ -69,54 +69,4 @@ class DSCDevice {
}
return $deviceStatusCodeMap[$this.StatusCode]
}

[string] GetSQLUpdate () {
$query = "UPDATE Devices Set {0} WHERE TargetName = '{1}'" -f @(
(($this | Get-Member -MemberType Property).Where{
$_.Name -notin 'TargetName', 'Status'
}.foreach{
if ($_.Definition.Split(' ')[0] -like '*datetime*' -and -not $null -eq $this."$($_.Name)") {
if ($this."$($_.Name)".ToString('yyyy-MM-dd HH:mm:ss') -eq '0001-01-01 00:00:00') {
"$($_.Name) = NULL"
} else {
"$($_.Name) = '{0}'" -f $this."$($_.Name)".ToString('yyyy-MM-dd HH:mm:ss')
}
} elseif ($_.Definition.Split(' ')[0] -like '*nullable*' -and $null -eq $this."$($_.Name)") {
"$($_.Name) = NULL"
} else {
"$($_.Name) = '{0}'" -f $this."$($_.Name)"
}
} -join ','),
$this.TargetName
)
return $query
}

[string] GetSQLInsert () {
$query = ("INSERT INTO Devices ({0}) VALUES ({1})" -f @(
(($this | Get-Member -MemberType Property | Where-Object -FilterScript {$_.Name -ne 'Status'}).Name -join ','),
(($this | Get-Member -MemberType Property).ForEach{
if ($_.Name -eq 'Status') {
return
} else {
if ($_.Definition.Split(' ')[0] -like '*datetime*' -and -not $null -eq $this."$($_.Name)") {
if ($this."$($_.Name)".ToString('yyyy-MM-dd HH:mm:ss') -eq '0001-01-01 00:00:00') {
'NULL'
} else {
"'{0}'" -f $this."$($_.Name)".ToString('yyyy-MM-dd HH:mm:ss')
}
} elseif ($_.Definition.Split(' ')[0] -like '*nullable*' -and $null -eq $this."$($_.Name)") {
'NULL'
} else {
"'{0}'" -f $this."$($_.Name)"
}
}
} -join ',')
))
return $query
}

[string] GetSQLDelete () {
return ("DELETE FROM Devices WHERE TargetName = '{0}'" -f $this.TargetName)
}
}
Loading

0 comments on commit f69d01c

Please sign in to comment.