DbaClientX.Libraries.ps1

# DbaClientX.Libraries.ps1
# Auto-generated by PowerForge. Do not edit.

$LibrariesByFolder = @{
    'Core' = @(
        'Lib\Core\DBAClientX.PowerShell.dll'
        'Lib\Core\DbaClientX.Core.dll'
        'Lib\Core\DbaClientX.MySql.dll'
        'Lib\Core\DbaClientX.Oracle.dll'
        'Lib\Core\DbaClientX.PostgreSql.dll'
        'Lib\Core\DbaClientX.SQLite.dll'
        'Lib\Core\DbaClientX.SqlServer.dll'
        'Lib\Core\Microsoft.Bcl.Cryptography.dll'
        'Lib\Core\Microsoft.Data.SqlClient.dll'
        'Lib\Core\Microsoft.Data.SqlClient.Extensions.Abstractions.dll'
        'Lib\Core\Microsoft.Data.SqlClient.Internal.Logging.dll'
        'Lib\Core\Microsoft.Data.Sqlite.dll'
        'Lib\Core\Microsoft.Extensions.Caching.Abstractions.dll'
        'Lib\Core\Microsoft.Extensions.Caching.Memory.dll'
        'Lib\Core\Microsoft.Extensions.DependencyInjection.Abstractions.dll'
        'Lib\Core\Microsoft.Extensions.Logging.Abstractions.dll'
        'Lib\Core\Microsoft.Extensions.Options.dll'
        'Lib\Core\Microsoft.Extensions.Primitives.dll'
        'Lib\Core\Microsoft.IdentityModel.Abstractions.dll'
        'Lib\Core\Microsoft.IdentityModel.JsonWebTokens.dll'
        'Lib\Core\Microsoft.IdentityModel.Logging.dll'
        'Lib\Core\Microsoft.IdentityModel.Protocols.dll'
        'Lib\Core\Microsoft.IdentityModel.Protocols.OpenIdConnect.dll'
        'Lib\Core\Microsoft.IdentityModel.Tokens.dll'
        'Lib\Core\Microsoft.SqlServer.Server.dll'
        'Lib\Core\MySqlConnector.dll'
        'Lib\Core\Npgsql.dll'
        'Lib\Core\Oracle.ManagedDataAccess.dll'
        'Lib\Core\SQLitePCLRaw.batteries_v2.dll'
        'Lib\Core\SQLitePCLRaw.core.dll'
        'Lib\Core\SQLitePCLRaw.provider.e_sqlite3.dll'
        'Lib\Core\System.Collections.Immutable.dll'
        'Lib\Core\System.Configuration.ConfigurationManager.dll'
        'Lib\Core\System.Diagnostics.DiagnosticSource.dll'
        'Lib\Core\System.Diagnostics.EventLog.dll'
        'Lib\Core\System.Diagnostics.PerformanceCounter.dll'
        'Lib\Core\System.DirectoryServices.Protocols.dll'
        'Lib\Core\System.IdentityModel.Tokens.Jwt.dll'
        'Lib\Core\System.Security.Cryptography.Pkcs.dll'
        'Lib\Core\System.Security.Cryptography.ProtectedData.dll'
    )
    'Default' = @(
        'Lib\Default\DBAClientX.PowerShell.dll'
        'Lib\Default\DbaClientX.Core.dll'
        'Lib\Default\DbaClientX.MySql.dll'
        'Lib\Default\DbaClientX.Oracle.dll'
        'Lib\Default\DbaClientX.PostgreSql.dll'
        'Lib\Default\DbaClientX.SQLite.dll'
        'Lib\Default\DbaClientX.SqlServer.dll'
        'Lib\Default\e_sqlite3.dll'
        'Lib\Default\Microsoft.Bcl.AsyncInterfaces.dll'
        'Lib\Default\Microsoft.Bcl.Cryptography.dll'
        'Lib\Default\Microsoft.Bcl.HashCode.dll'
        'Lib\Default\Microsoft.Bcl.TimeProvider.dll'
        'Lib\Default\Microsoft.Data.SqlClient.dll'
        'Lib\Default\Microsoft.Data.SqlClient.Extensions.Abstractions.dll'
        'Lib\Default\Microsoft.Data.SqlClient.Internal.Logging.dll'
        'Lib\Default\Microsoft.Data.Sqlite.dll'
        'Lib\Default\Microsoft.Extensions.Caching.Abstractions.dll'
        'Lib\Default\Microsoft.Extensions.Caching.Memory.dll'
        'Lib\Default\Microsoft.Extensions.DependencyInjection.Abstractions.dll'
        'Lib\Default\Microsoft.Extensions.Logging.Abstractions.dll'
        'Lib\Default\Microsoft.Extensions.Options.dll'
        'Lib\Default\Microsoft.Extensions.Primitives.dll'
        'Lib\Default\Microsoft.IdentityModel.Abstractions.dll'
        'Lib\Default\Microsoft.IdentityModel.JsonWebTokens.dll'
        'Lib\Default\Microsoft.IdentityModel.Logging.dll'
        'Lib\Default\Microsoft.IdentityModel.Protocols.dll'
        'Lib\Default\Microsoft.IdentityModel.Protocols.OpenIdConnect.dll'
        'Lib\Default\Microsoft.IdentityModel.Tokens.dll'
        'Lib\Default\MySqlConnector.dll'
        'Lib\Default\Npgsql.dll'
        'Lib\Default\Oracle.ManagedDataAccess.dll'
        'Lib\Default\SQLitePCLRaw.batteries_v2.dll'
        'Lib\Default\SQLitePCLRaw.core.dll'
        'Lib\Default\SQLitePCLRaw.provider.e_sqlite3.dll'
        'Lib\Default\System.Buffers.dll'
        'Lib\Default\System.Collections.Immutable.dll'
        'Lib\Default\System.Diagnostics.DiagnosticSource.dll'
        'Lib\Default\System.Formats.Asn1.dll'
        'Lib\Default\System.IdentityModel.Tokens.Jwt.dll'
        'Lib\Default\System.IO.Pipelines.dll'
        'Lib\Default\System.Memory.dll'
        'Lib\Default\System.Numerics.Vectors.dll'
        'Lib\Default\System.Runtime.CompilerServices.Unsafe.dll'
        'Lib\Default\System.Security.Cryptography.Pkcs.dll'
        'Lib\Default\System.Text.Encodings.Web.dll'
        'Lib\Default\System.Text.Json.dll'
        'Lib\Default\System.Threading.Channels.dll'
        'Lib\Default\System.Threading.Tasks.Extensions.dll'
    )
}


$AssemblyFolders = Get-ChildItem -Path $PSScriptRoot\Lib -Directory -ErrorAction SilentlyContinue

$Default = $false
$Core = $false
$Standard = $false
foreach ($A in $AssemblyFolders.Name) {
    if ($A -eq 'Default') {
        $Default = $true
    } elseif ($A -eq 'Core') {
        $Core = $true
    } elseif ($A -eq 'Standard') {
        $Standard = $true
    }
}
if ($Standard -and $Core -and $Default) {
    $FrameworkNet = 'Default'
    $Framework = 'Standard'
} elseif ($Standard -and $Core) {
    $Framework = 'Standard'
    $FrameworkNet = 'Standard'
} elseif ($Core -and $Default) {
    $Framework = 'Core'
    $FrameworkNet = 'Default'
} elseif ($Standard -and $Default) {
    $Framework = 'Standard'
    $FrameworkNet = 'Default'
} elseif ($Standard) {
    $Framework = 'Standard'
    $FrameworkNet = 'Standard'
} elseif ($Core) {
    $Framework = 'Core'
    $FrameworkNet = ''
} elseif ($Default) {
    $Framework = ''
    $FrameworkNet = 'Default'
} else {
    #Write-Error -Message 'No assemblies found'
}

if ($PSEdition -eq 'Core') {
    $LibFolder = $Framework
} else {
    $LibFolder = $FrameworkNet
}

$LibrariesToLoad = $LibrariesByFolder[$LibFolder]
if ($null -eq $LibrariesToLoad) { $LibrariesToLoad = @() }
foreach ($L in $LibrariesToLoad) {
    try {
        $LibraryPathParts = @($PSScriptRoot) + @($L -split '[\\/]' | Where-Object { -not [string]::IsNullOrWhiteSpace($_) })
        $LibraryPath = [IO.Path]::Combine([string[]] $LibraryPathParts)
        try {
            $null = [System.Reflection.AssemblyName]::GetAssemblyName($LibraryPath)
        } catch [System.BadImageFormatException] {
            Write-Verbose -Message "Skipping non-managed library '$L'."
            continue
        }

        Add-Type -Path $LibraryPath -ErrorAction Stop
    } catch {
        if ($_.Exception.Message -like '*Assembly with same name is already loaded*') {
            Write-Warning -Message "Assembly with same name is already loaded. Ignoring '$L'."
        } else {
            throw $_
        }
    }
}