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

Commit

Permalink
xPlat support (#49) (#50)
Browse files Browse the repository at this point in the history
!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
  • Loading branch information
bgelens authored Dec 19, 2018
1 parent f69d01c commit f4138a7
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 22 deletions.
13 changes: 7 additions & 6 deletions DSCPullServerAdmin/DSCPullServerAdmin.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ PowerShellVersion = '5.1'
# RequiredModules = @()

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

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

# ReleaseNotes of this module
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+'
ReleaseNotes = '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'

} # End of PSData hashtable

Expand Down
1 change: 0 additions & 1 deletion DSCPullServerAdmin/DSCPullServerAdmin.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ $private = Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -Exclude WIP* -ErrorA
}

$moduleContent = @'
Add-Type -Path 'C:\Windows\Microsoft.NET\assembly\GAC_MSIL\microsoft.isam.esent.interop\*\Microsoft.Isam.Esent.Interop.dll'
$DSCPullServerConnections = [System.Collections.ArrayList]::new()
{0}
{1}
Expand Down
11 changes: 11 additions & 0 deletions DSCPullServerAdmin/private/Assert-DSCPullServerESEPreReq.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function Assert-DSCPullServerESEPreReq {
# see if type is already available, don't load when already loaded
if ($null -eq ('Microsoft.Isam.Esent.Interop.Api'-as [type])) {
# try to load
try {
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.Isam.Esent.Interop')
} catch {
Write-Error -Message 'To access EDB files, please use PowerShell on Windows' -ErrorAction Stop
}
}
}
17 changes: 4 additions & 13 deletions DSCPullServerAdmin/private/Get-DSCPullServerESERecord.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ function Get-DSCPullServerESERecord {
'LCMVersion',
'ReportFormatVersion',
'ConfigurationVersion',
'RebootRequested'
'RebootRequested',
'JobId',
'Id',
'ConfigurationID'
)

$boolColumns = @(
Expand All @@ -67,12 +70,6 @@ function Get-DSCPullServerESERecord {
'LastModifiedTime'
)

$guidColumns = @(
'JobId',
'Id',
'ConfigurationID'
)

$deserializeColumns = @(
'Errors',
'StatusData',
Expand Down Expand Up @@ -141,12 +138,6 @@ function Get-DSCPullServerESERecord {
$Connection.TableId,
$column.Columnid
)
} elseif ($column.Name -in $guidColumns) {
$result."$($column.Name)" = [Microsoft.Isam.Esent.Interop.Api]::RetrieveColumnAsGuid(
$Connection.SessionId,
$Connection.TableId,
$column.Columnid
)
} elseif ($column.Name -in $datetimeColumns) {
$result."$($column.Name)" = [Microsoft.Isam.Esent.Interop.Api]::RetrieveColumnAsDateTime(
$Connection.SessionId,
Expand Down
9 changes: 9 additions & 0 deletions DSCPullServerAdmin/private/PreProc.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ function PreProc {

[string] $ESEFilePath,

[string] $MDBFilePath,

[Parameter(ValueFromRemainingArguments)]
$DroppedParams
)
Expand Down Expand Up @@ -43,5 +45,12 @@ function PreProc {
}
New-DSCPullServerAdminConnection @newESEArgs
}
*MDB {
$newMDBArgs = @{
MDBFilePath = $MDBFilePath
DontStore = $true
}
New-DSCPullServerAdminConnection @newMDBArgs
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ function New-DSCPullServerAdminConnection {
Assert-DSCPullServerMDBPreReq
}

if ($PSCmdlet.ParameterSetName -eq 'ESE') {
Assert-DSCPullServerESEPreReq
}

$currentConnections = Get-DSCPullServerAdminConnection
$lastIndex = $currentConnections |
Sort-Object -Property Index -Descending |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ InModuleScope $moduleName {
Mock -CommandName Test-DSCPullServerDatabase -MockWith {
$true
}
Mock -CommandName Assert-DSCPullServerESEPreReq

$null = New-Item -Path TestDrive: -Name pull.edb -ItemType File -Force
$result = New-DSCPullServerAdminConnection -ESEFilePath $tempEDBFile.FullName
$result.Index | Should -Be 0
$result.Type | SHould -Be 'ESE'
$script:DSCPullServerConnections | Should -Not -BeNullOrEmpty

Assert-MockCalled -CommandName Assert-DSCPullServerESEPreReq -Times 1 -Exactly -Scope it
}

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

Mock -CommandName Assert-DSCPullServerESEPreReq

$result = New-DSCPullServerAdminConnection -ESEFilePath $tempEDBFile.FullName
$result.Index | Should -Be 1
$result.Type | SHould -Be 'ESE'
Expand All @@ -48,9 +53,12 @@ InModuleScope $moduleName {
Mock -CommandName Test-DSCPullServerDatabase -MockWith {
$true
}
Mock -CommandName Assert-DSCPullServerMDBPreReq

$null = New-DSCPullServerAdminConnection -ESEFilePath $tempEDBFile.FullName -DontStore
$null = New-DSCPullServerAdminConnection -MDBFilePath $tempMDBFile.FullName -DontStore
$script:DSCPullServerConnections | Should -BeNullOrEmpty

Assert-MockCalled -CommandName Assert-DSCPullServerMDBPreReq -Times 1 -Exactly -Scope it
}

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

Mock -CommandName Assert-DSCPullServerESEPreReq
Mock -CommandName Assert-DSCPullServerMDBPreReq

$result = New-DSCPullServerAdminConnection -SQLServer 'Server\Instance' -Database 'DSCDB'
$result.Index | Should -Be 0
$result.Type | Should -Be 'SQL'
$result.SQLServer | Should -Be 'Server\Instance'
$result.Credential | Should -BeNullOrEmpty
$result.Database | Should -Be 'DSCDB'
$script:DSCPullServerConnections | Should -Not -BeNullOrEmpty

Assert-MockCalled -CommandName Assert-DSCPullServerESEPreReq -Times 0 -Exactly -Scope it
Assert-MockCalled -CommandName Assert-DSCPullServerMDBPreReq -Times 0 -Exactly -Scope it
}

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

0 comments on commit f4138a7

Please sign in to comment.