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

Commit f4138a7

Browse files
authored
xPlat support (#49) (#50)
!Deploy Cross Platform support (Only SQL is supported xPlat. MDB and ESE are not) * Removed Microsoft.Isam.Esent.Interop from RequiredAssemblies * Load Microsoft.Isam.Esent.Interop when available * removed RetrieveColumnAsGuid and moved properties to RetrieveColumnAsString as something broke on latest w10 insiders * Fix ad-hoc mdb database access did not process as PreProc was missing MDB logic
1 parent f69d01c commit f4138a7

File tree

8 files changed

+51
-22
lines changed

8 files changed

+51
-22
lines changed

DSCPullServerAdmin/DSCPullServerAdmin.psd1

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ PowerShellVersion = '5.1'
5454
# RequiredModules = @()
5555

5656
# Assemblies that must be loaded prior to importing this module
57-
RequiredAssemblies = @('Microsoft.Isam.Esent.Interop')
57+
# RequiredAssemblies = @()
5858

5959
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
6060
# ScriptsToProcess = @()
@@ -126,11 +126,12 @@ PrivateData = @{
126126
# IconUri = ''
127127

128128
# ReleaseNotes of this module
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+'
129+
ReleaseNotes = 'Cross Platform support (Only SQL is supported xPlat. MDB and ESE are not)
130+
* Removed Microsoft.Isam.Esent.Interop from RequiredAssemblies
131+
* Load Microsoft.Isam.Esent.Interop when available
132+
* removed RetrieveColumnAsGuid and moved properties to RetrieveColumnAsString as something broke on latest w10 insiders
133+
134+
* Fix ad-hoc mdb database access did not process as PreProc was missing MDB logic'
134135

135136
} # End of PSData hashtable
136137

DSCPullServerAdmin/DSCPullServerAdmin.psm1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ $private = Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -Exclude WIP* -ErrorA
2323
}
2424

2525
$moduleContent = @'
26-
Add-Type -Path 'C:\Windows\Microsoft.NET\assembly\GAC_MSIL\microsoft.isam.esent.interop\*\Microsoft.Isam.Esent.Interop.dll'
2726
$DSCPullServerConnections = [System.Collections.ArrayList]::new()
2827
{0}
2928
{1}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function Assert-DSCPullServerESEPreReq {
2+
# see if type is already available, don't load when already loaded
3+
if ($null -eq ('Microsoft.Isam.Esent.Interop.Api'-as [type])) {
4+
# try to load
5+
try {
6+
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.Isam.Esent.Interop')
7+
} catch {
8+
Write-Error -Message 'To access EDB files, please use PowerShell on Windows' -ErrorAction Stop
9+
}
10+
}
11+
}

DSCPullServerAdmin/private/Get-DSCPullServerESERecord.ps1

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ function Get-DSCPullServerESERecord {
5151
'LCMVersion',
5252
'ReportFormatVersion',
5353
'ConfigurationVersion',
54-
'RebootRequested'
54+
'RebootRequested',
55+
'JobId',
56+
'Id',
57+
'ConfigurationID'
5558
)
5659

5760
$boolColumns = @(
@@ -67,12 +70,6 @@ function Get-DSCPullServerESERecord {
6770
'LastModifiedTime'
6871
)
6972

70-
$guidColumns = @(
71-
'JobId',
72-
'Id',
73-
'ConfigurationID'
74-
)
75-
7673
$deserializeColumns = @(
7774
'Errors',
7875
'StatusData',
@@ -141,12 +138,6 @@ function Get-DSCPullServerESERecord {
141138
$Connection.TableId,
142139
$column.Columnid
143140
)
144-
} elseif ($column.Name -in $guidColumns) {
145-
$result."$($column.Name)" = [Microsoft.Isam.Esent.Interop.Api]::RetrieveColumnAsGuid(
146-
$Connection.SessionId,
147-
$Connection.TableId,
148-
$column.Columnid
149-
)
150141
} elseif ($column.Name -in $datetimeColumns) {
151142
$result."$($column.Name)" = [Microsoft.Isam.Esent.Interop.Api]::RetrieveColumnAsDateTime(
152143
$Connection.SessionId,

DSCPullServerAdmin/private/PreProc.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ function PreProc {
1313

1414
[string] $ESEFilePath,
1515

16+
[string] $MDBFilePath,
17+
1618
[Parameter(ValueFromRemainingArguments)]
1719
$DroppedParams
1820
)
@@ -43,5 +45,12 @@ function PreProc {
4345
}
4446
New-DSCPullServerAdminConnection @newESEArgs
4547
}
48+
*MDB {
49+
$newMDBArgs = @{
50+
MDBFilePath = $MDBFilePath
51+
DontStore = $true
52+
}
53+
New-DSCPullServerAdminConnection @newMDBArgs
54+
}
4655
}
4756
}

DSCPullServerAdmin/public/New-DSCPullServerAdminConnection.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ function New-DSCPullServerAdminConnection {
7070
Assert-DSCPullServerMDBPreReq
7171
}
7272

73+
if ($PSCmdlet.ParameterSetName -eq 'ESE') {
74+
Assert-DSCPullServerESEPreReq
75+
}
76+
7377
$currentConnections = Get-DSCPullServerAdminConnection
7478
$lastIndex = $currentConnections |
7579
Sort-Object -Property Index -Descending |

DSCPullServerAdmin/tests/Unit/private/Assert-DSCPullServerESEPreReq.tests.ps1

Whitespace-only changes.

DSCPullServerAdmin/tests/Unit/public/New-DSCPullServerAdminConnection.tests.ps1

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@ InModuleScope $moduleName {
1717
Mock -CommandName Test-DSCPullServerDatabase -MockWith {
1818
$true
1919
}
20+
Mock -CommandName Assert-DSCPullServerESEPreReq
2021

2122
$null = New-Item -Path TestDrive: -Name pull.edb -ItemType File -Force
2223
$result = New-DSCPullServerAdminConnection -ESEFilePath $tempEDBFile.FullName
2324
$result.Index | Should -Be 0
2425
$result.Type | SHould -Be 'ESE'
2526
$script:DSCPullServerConnections | Should -Not -BeNullOrEmpty
27+
28+
Assert-MockCalled -CommandName Assert-DSCPullServerESEPreReq -Times 1 -Exactly -Scope it
2629
}
2730

28-
It 'Should assign index 1 when previous connecions are in module var DSCPullServerConnections' {
31+
It 'Should assign index 1 when previous connections are in module var DSCPullServerConnections' {
2932
Mock -CommandName Get-DSCPullServerAdminConnection -MockWith {
3033
$sqlConnection = [DSCPullServerSQLConnection]::new()
3134
$sqlConnection.Active = $true
@@ -37,6 +40,8 @@ InModuleScope $moduleName {
3740
$true
3841
}
3942

43+
Mock -CommandName Assert-DSCPullServerESEPreReq
44+
4045
$result = New-DSCPullServerAdminConnection -ESEFilePath $tempEDBFile.FullName
4146
$result.Index | Should -Be 1
4247
$result.Type | SHould -Be 'ESE'
@@ -48,9 +53,12 @@ InModuleScope $moduleName {
4853
Mock -CommandName Test-DSCPullServerDatabase -MockWith {
4954
$true
5055
}
56+
Mock -CommandName Assert-DSCPullServerMDBPreReq
5157

52-
$null = New-DSCPullServerAdminConnection -ESEFilePath $tempEDBFile.FullName -DontStore
58+
$null = New-DSCPullServerAdminConnection -MDBFilePath $tempMDBFile.FullName -DontStore
5359
$script:DSCPullServerConnections | Should -BeNullOrEmpty
60+
61+
Assert-MockCalled -CommandName Assert-DSCPullServerMDBPreReq -Times 1 -Exactly -Scope it
5462
}
5563

5664
It 'Should create a SQL Connection when no Credentials are specified and database is specified and connection is validated true' {
@@ -64,13 +72,19 @@ InModuleScope $moduleName {
6472
$true
6573
}
6674

75+
Mock -CommandName Assert-DSCPullServerESEPreReq
76+
Mock -CommandName Assert-DSCPullServerMDBPreReq
77+
6778
$result = New-DSCPullServerAdminConnection -SQLServer 'Server\Instance' -Database 'DSCDB'
6879
$result.Index | Should -Be 0
6980
$result.Type | Should -Be 'SQL'
7081
$result.SQLServer | Should -Be 'Server\Instance'
7182
$result.Credential | Should -BeNullOrEmpty
7283
$result.Database | Should -Be 'DSCDB'
7384
$script:DSCPullServerConnections | Should -Not -BeNullOrEmpty
85+
86+
Assert-MockCalled -CommandName Assert-DSCPullServerESEPreReq -Times 0 -Exactly -Scope it
87+
Assert-MockCalled -CommandName Assert-DSCPullServerMDBPreReq -Times 0 -Exactly -Scope it
7488
}
7589

7690
It 'Should create a SQL Connection when Credential is specified and database is specified and connection is validated true' {

0 commit comments

Comments
 (0)