MONSTER: Rename Monorepo to Modules, only keep Projects under Modules.*
This commit is contained in:
350
Database/Adapters/Firebird.vb
Normal file
350
Database/Adapters/Firebird.vb
Normal file
@@ -0,0 +1,350 @@
|
||||
Imports FirebirdSql.Data.FirebirdClient
|
||||
Imports System.Text.RegularExpressions
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports System.ComponentModel
|
||||
|
||||
''' <summary>
|
||||
''' MODULE: Firebird
|
||||
'''
|
||||
''' VERSION: 0.0.0.4
|
||||
'''
|
||||
''' DATE: 18.12.2018
|
||||
'''
|
||||
''' DESCRIPTION:
|
||||
'''
|
||||
''' DEPENDENCIES: NLog, >= 4.5.10
|
||||
'''
|
||||
''' EntityFramework.Firebird, >= 6.4.0
|
||||
'''
|
||||
''' FirebirdSql.Data.FirebirdClient, >= 6.4.0
|
||||
'''
|
||||
''' PARAMETERS: LogConfig, DigitalData.Modules.Logging.LogConfig
|
||||
''' The LogFactory containing the current log config. Used to instanciate the class logger for this and any dependent class
|
||||
'''
|
||||
''' DataSource, String
|
||||
''' The server where the database lives, for example 127.0.0.1 or dd-vmx09-vm03
|
||||
'''
|
||||
''' Database, String
|
||||
''' The location of the Database in the format `127.0.0.1:E:\Path\To\Database.FDB`
|
||||
'''
|
||||
''' User, String
|
||||
''' The user name to connect as
|
||||
'''
|
||||
''' Password, String
|
||||
''' The user's password
|
||||
'''
|
||||
''' PROPERTIES: ConnectionEstablished, Boolean
|
||||
''' If the last opened connection was successful
|
||||
'''
|
||||
''' ConnectionFailed, Boolean
|
||||
''' If the last opened connection failed
|
||||
'''
|
||||
''' ConnectionString, String
|
||||
''' The used connectionstring
|
||||
'''
|
||||
''' EXAMPLES:
|
||||
'''
|
||||
''' REMARKS: If the connection fails due to "wrong username or password", the cause might be that the server harddrive is full..
|
||||
''' </summary>
|
||||
Public Class Firebird
|
||||
Private _Logger As Logger
|
||||
Private _LogConfig As LogConfig
|
||||
Private _connectionServer As String
|
||||
Private _connectionDatabase As String
|
||||
Private _connectionUsername As String
|
||||
Private _connectionPassword As String
|
||||
Private _connectionString As String
|
||||
Public _DBInitialized As Boolean = False
|
||||
|
||||
Public Const MAX_POOL_SIZE = 1000
|
||||
|
||||
Public Enum TransactionMode
|
||||
<Description("Use no transaction, neither internal nor external")>
|
||||
NoTransaction
|
||||
<Description("Use the transaction supplied in the Transaction Parameter")>
|
||||
ExternalTransaction
|
||||
<Description("Create an internal transaction on the fly")>
|
||||
WithTransaction
|
||||
End Enum
|
||||
|
||||
Public ReadOnly Property ConnectionString As String
|
||||
Get
|
||||
Return _connectionString
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public ReadOnly Property DatabaseName As String
|
||||
Get
|
||||
Dim oRegex As New Regex("^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:")
|
||||
Dim oPath As String = oRegex.Replace(_connectionDatabase, "")
|
||||
Dim oFileInfo As New IO.FileInfo(oPath)
|
||||
Return oFileInfo.Name
|
||||
End Get
|
||||
End Property
|
||||
|
||||
''' <summary>
|
||||
'''
|
||||
''' </summary>
|
||||
''' <param name="LogConfig">The LogFactory containing the current log config. Used to instanciate the class logger for this and any dependent class</param>
|
||||
''' <param name="Datasource">The server where the database lives, for example 127.0.0.1 or dd-vmx09-vm03</param>
|
||||
''' <param name="Database">The location of the Database in the format `127.0.0.1:E:\Path\To\Database.FDB`</param>
|
||||
''' <param name="User">The user name to connect as</param>
|
||||
''' <param name="Password">The user's password</param>
|
||||
''' <exception cref="Exceptions.DatabaseException"></exception>
|
||||
Public Sub New(LogConfig As LogConfig, Datasource As String, Database As String, User As String, Password As String)
|
||||
Try
|
||||
_LogConfig = LogConfig
|
||||
_Logger = _LogConfig.GetLogger()
|
||||
Dim oConnectionString = GetConnectionString(Datasource, Database, User, Password)
|
||||
|
||||
_connectionServer = Datasource
|
||||
_connectionDatabase = Database
|
||||
_connectionUsername = User
|
||||
_connectionPassword = Password
|
||||
_connectionString = oConnectionString
|
||||
|
||||
_Logger.Debug("Connecting to database..")
|
||||
|
||||
' Test the connection
|
||||
Dim oConnection = GetConnection()
|
||||
' If initial connection was successfully, close it
|
||||
oConnection.Close()
|
||||
|
||||
If oConnection Is Nothing Then
|
||||
Throw New Exceptions.DatabaseException()
|
||||
Else
|
||||
_DBInitialized = True
|
||||
End If
|
||||
|
||||
_Logger.Debug("Connection sucessfully established!")
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
End Try
|
||||
|
||||
End Sub
|
||||
|
||||
Public Function GetConnection() As FbConnection
|
||||
Try
|
||||
Dim oConnection = New FbConnection(_connectionString)
|
||||
oConnection.Open()
|
||||
|
||||
Return oConnection
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Builds a connectionstring from the provided arguments.
|
||||
''' </summary>
|
||||
''' <param name="DataSource">The database server where to connect to</param>
|
||||
''' <param name="Database">The datasource, eg. the path of the FDB-file</param>
|
||||
''' <param name="User">The user used to connect to the database</param>
|
||||
''' <param name="Password">The password of the connecting user</param>
|
||||
''' <returns>A connectionstring</returns>
|
||||
Private Function GetConnectionString(DataSource As String, Database As String, User As String, Password As String) As String
|
||||
Return New FbConnectionStringBuilder With {
|
||||
.DataSource = DataSource,
|
||||
.Database = Database,
|
||||
.UserID = User,
|
||||
.Password = Password,
|
||||
.Charset = "UTF8",
|
||||
.MaxPoolSize = MAX_POOL_SIZE
|
||||
}.ToString()
|
||||
End Function
|
||||
|
||||
Private Function MaybeGetTransaction(Connection As FbConnection, Mode As TransactionMode, Transaction As FbTransaction) As FbTransaction
|
||||
If Mode = TransactionMode.NoTransaction Then
|
||||
Return Nothing
|
||||
ElseIf Mode = TransactionMode.ExternalTransaction Then
|
||||
Return Transaction
|
||||
Else
|
||||
Return Connection.BeginTransaction()
|
||||
End If
|
||||
End Function
|
||||
|
||||
Private Function MaybeCommitTransaction(Transaction As FbTransaction, TransactionMode As TransactionMode) As Boolean
|
||||
Select Case TransactionMode
|
||||
Case TransactionMode.NoTransaction
|
||||
Return True
|
||||
Case TransactionMode.ExternalTransaction
|
||||
Return True
|
||||
Case TransactionMode.WithTransaction
|
||||
Try
|
||||
Transaction.Commit()
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
Case Else
|
||||
Return True
|
||||
End Select
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Executes a non-query command.
|
||||
''' </summary>
|
||||
''' <param name="SqlCommand">The command to execute</param>
|
||||
''' <param name="Connection">The Firebird connection to use</param>
|
||||
''' <returns>True, if command was executed sucessfully. Otherwise false.</returns>
|
||||
Public Function ExecuteNonQueryWithConnection(SqlCommand As String, Connection As FbConnection, Optional TransactionMode As TransactionMode = TransactionMode.WithTransaction, Optional Transaction As FbTransaction = Nothing) As Boolean
|
||||
_Logger.Debug("Executing Non-Query: {0}", SqlCommand)
|
||||
|
||||
If Connection Is Nothing Then
|
||||
_Logger.Warn("Connection is nothing!")
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Dim oTransaction = MaybeGetTransaction(Connection, TransactionMode, Transaction)
|
||||
|
||||
Try
|
||||
Dim oCommand As New FbCommand With {
|
||||
.CommandText = SqlCommand,
|
||||
.Connection = Connection
|
||||
}
|
||||
|
||||
If Not IsNothing(oTransaction) Then
|
||||
oCommand.Transaction = oTransaction
|
||||
End If
|
||||
|
||||
oCommand.ExecuteNonQuery()
|
||||
_Logger.Debug("Command executed!")
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex, $"Error in ExecuteNonQuery while executing command: [{SqlCommand}]")
|
||||
_Logger.Warn($"Unexpected error in ExecuteNonQueryWithConnection: [{SqlCommand}]")
|
||||
Throw ex
|
||||
Finally
|
||||
MaybeCommitTransaction(oTransaction, TransactionMode)
|
||||
End Try
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Executes a non-query command.
|
||||
''' </summary>
|
||||
''' <param name="SqlCommand">The command to execute</param>
|
||||
''' <returns>True, if command was executed sucessfully. Otherwise false.</returns>
|
||||
Public Function ExecuteNonQuery(SqlCommand As String) As Boolean
|
||||
Using oConnection As FbConnection = GetConnection()
|
||||
Return ExecuteNonQueryWithConnection(SqlCommand, oConnection)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Executes a non-query command inside the specified transaction.
|
||||
''' </summary>
|
||||
''' <param name="SqlCommand">The command to execute</param>
|
||||
''' <returns>True, if command was executed sucessfully. Otherwise false.</returns>
|
||||
Public Function ExecuteNonQuery(SqlCommand As String, Transaction As FbTransaction) As Boolean
|
||||
Using oConnection As FbConnection = GetConnection()
|
||||
Return ExecuteNonQueryWithConnection(SqlCommand, oConnection, TransactionMode.ExternalTransaction, Transaction)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Executes a sql query resulting in a scalar value.
|
||||
''' </summary>
|
||||
''' <param name="SqlQuery">The query to execute</param>
|
||||
''' <param name="Connection">The Firebird connection to use</param>
|
||||
''' <returns>The scalar value if the command was executed successfully. Nothing otherwise.</returns>
|
||||
Public Function GetScalarValueWithConnection(SqlQuery As String, Connection As FbConnection, Optional TransactionMode As TransactionMode = TransactionMode.WithTransaction, Optional Transaction As FbTransaction = Nothing) As Object
|
||||
_Logger.Debug("Fetching Scalar-Value: {0}", SqlQuery)
|
||||
|
||||
If Connection Is Nothing Then
|
||||
_Logger.Warn("Connection is nothing!")
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Dim oTransaction = MaybeGetTransaction(Connection, TransactionMode, Transaction)
|
||||
Dim oResult As Object
|
||||
|
||||
Try
|
||||
Dim oCommand As New FbCommand With {
|
||||
.CommandText = SqlQuery,
|
||||
.Connection = Connection,
|
||||
.Transaction = oTransaction
|
||||
}
|
||||
oResult = oCommand.ExecuteScalar()
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex, $"Error in ReturnScalar while executing command: [{SqlQuery}]")
|
||||
Throw ex
|
||||
Finally
|
||||
MaybeCommitTransaction(oTransaction, TransactionMode)
|
||||
End Try
|
||||
|
||||
Return oResult
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Executes a sql query resulting in a scalar value.
|
||||
''' </summary>
|
||||
''' <param name="SqlQuery">The query to execute</param>
|
||||
''' <returns>The scalar value if the command was executed successfully. Nothing otherwise.</returns>
|
||||
Public Function GetScalarValue(SqlQuery As String) As Object
|
||||
Dim oConnection As FbConnection = GetConnection()
|
||||
Dim oScalarValue As Object = GetScalarValueWithConnection(SqlQuery, oConnection)
|
||||
oConnection.Close()
|
||||
|
||||
Return oScalarValue
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Executes a sql query resulting in a table of values.
|
||||
''' </summary>
|
||||
''' <param name="SqlQuery">The query to execute</param>
|
||||
''' <param name="Connection">The Firebird connection to use</param>
|
||||
''' <returns>A datatable containing the results if the command was executed successfully. Nothing otherwise.</returns>
|
||||
Public Function GetDatatableWithConnection(SqlQuery As String, Connection As FbConnection, Optional TransactionMode As TransactionMode = TransactionMode.NoTransaction, Optional Transaction As FbTransaction = Nothing) As DataTable
|
||||
_Logger.Debug("Fetching Datatable: {0}", SqlQuery)
|
||||
|
||||
If Connection Is Nothing Then
|
||||
_Logger.Warn("Connection is nothing!")
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Dim oTransaction = MaybeGetTransaction(Connection, TransactionMode, Transaction)
|
||||
Dim oDatatable As New DataTable() With {
|
||||
.TableName = "DDRESULT"
|
||||
}
|
||||
|
||||
Try
|
||||
Dim oAdapter As New FbDataAdapter(New FbCommand With {
|
||||
.CommandText = SqlQuery,
|
||||
.Connection = Connection,
|
||||
.Transaction = oTransaction
|
||||
})
|
||||
|
||||
oAdapter.Fill(oDatatable)
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
_Logger.Warn("Error in GetDatatableWithConnection while executing command: [{0}]", SqlQuery)
|
||||
Throw ex
|
||||
Finally
|
||||
MaybeCommitTransaction(oTransaction, TransactionMode)
|
||||
End Try
|
||||
|
||||
Return oDatatable
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Executes a sql query resulting in a table of values.
|
||||
''' </summary>
|
||||
''' <param name="SqlQuery">The query to execute</param>
|
||||
''' <returns>A datatable containing the results if the command was executed successfully. Nothing otherwise.</returns>
|
||||
Public Function GetDatatable(SqlQuery As String, Optional TransactionMode As TransactionMode = TransactionMode.NoTransaction, Optional Transaction As FbTransaction = Nothing) As DataTable
|
||||
Try
|
||||
Dim oConnection As FbConnection = GetConnection()
|
||||
Dim oDatatable As DataTable = GetDatatableWithConnection(SqlQuery, oConnection, TransactionMode, Transaction)
|
||||
oConnection.Close()
|
||||
|
||||
Return oDatatable
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
_Logger.Warn("Error in GetDatatable while executing command: '{0}'", SqlQuery)
|
||||
Throw ex
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
||||
518
Database/Adapters/MSSQLServer.vb
Normal file
518
Database/Adapters/MSSQLServer.vb
Normal file
@@ -0,0 +1,518 @@
|
||||
Imports System.ComponentModel
|
||||
Imports System.Data.Common
|
||||
Imports System.Data.SqlClient
|
||||
Imports DigitalData.Modules.Encryption
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Base
|
||||
|
||||
Public Class MSSQLServer
|
||||
Implements IDatabase
|
||||
|
||||
Public Property DBInitialized As Boolean = False Implements IDatabase.DBInitialized
|
||||
Public Property CurrentConnectionString As String = "" Implements IDatabase.CurrentConnectionString
|
||||
|
||||
Private ReadOnly QueryTimeout As Integer
|
||||
Private ReadOnly Logger As Logger
|
||||
|
||||
Public Enum TransactionMode
|
||||
<Description("Use no transaction, neither internal nor external")>
|
||||
NoTransaction
|
||||
<Description("Use the transaction supplied in the Transaction Parameter")>
|
||||
ExternalTransaction
|
||||
<Description("Create an internal transaction on the fly")>
|
||||
WithTransaction
|
||||
End Enum
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pConnectionString As String, Optional pTimeout As Integer = Constants.DEFAULT_TIMEOUT)
|
||||
Logger = pLogConfig.GetLogger()
|
||||
QueryTimeout = pTimeout
|
||||
|
||||
Try
|
||||
CurrentConnectionString = pConnectionString
|
||||
DBInitialized = TestCanConnect(CurrentConnectionString)
|
||||
Catch ex As Exception
|
||||
DBInitialized = False
|
||||
Logger.Error(ex)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, Server As String, Database As String, UserId As String, Password As String, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT)
|
||||
Logger = pLogConfig.GetLogger()
|
||||
QueryTimeout = Timeout
|
||||
|
||||
Try
|
||||
CurrentConnectionString = GetConnectionString(Server, Database, UserId, Password)
|
||||
DBInitialized = TestCanConnect(CurrentConnectionString)
|
||||
Catch ex As Exception
|
||||
DBInitialized = False
|
||||
Logger.Error(ex)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Encrypts a connection string password.
|
||||
''' </summary>
|
||||
''' <param name="pConnectionString">A connection string with a plain-text password</param>
|
||||
''' <returns>The connection string with the password encrypted.</returns>
|
||||
<DebuggerStepThrough()>
|
||||
Public Shared Function EncryptConnectionString(pConnectionString As String) As String
|
||||
Dim oEncryption As New EncryptionLegacy()
|
||||
Dim oBuilder As New SqlConnectionStringBuilder() With {.ConnectionString = pConnectionString}
|
||||
Dim oEncryptedPassword = oEncryption.EncryptData(oBuilder.Password)
|
||||
oBuilder.Password = oEncryptedPassword
|
||||
|
||||
Return oBuilder.ToString()
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Decrypts a connection string password.
|
||||
''' </summary>
|
||||
''' <param name="pConnectionString">A connection string with a encrypted password</param>
|
||||
''' <returns>The connection string with the password decrypted.</returns>
|
||||
<DebuggerStepThrough()>
|
||||
Public Shared Function DecryptConnectionString(pConnectionString As String) As String
|
||||
Dim oEncryption As New EncryptionLegacy()
|
||||
Dim oBuilder As New SqlConnectionStringBuilder() With {.ConnectionString = pConnectionString}
|
||||
Dim oDecryptedPassword = oEncryption.DecryptData(oBuilder.Password)
|
||||
oBuilder.Password = oDecryptedPassword
|
||||
|
||||
Return oBuilder.ToString()
|
||||
End Function
|
||||
|
||||
<DebuggerStepThrough()>
|
||||
Public Function GetConnectionString(Server As String, Database As String, UserId As String, Password As String) As String
|
||||
Dim oConnectionStringBuilder As New SqlConnectionStringBuilder() With {
|
||||
.DataSource = Server,
|
||||
.InitialCatalog = Database,
|
||||
.UserID = UserId,
|
||||
.Password = Password
|
||||
}
|
||||
|
||||
Return oConnectionStringBuilder.ToString
|
||||
End Function
|
||||
|
||||
<DebuggerStepThrough()>
|
||||
Public Function GetConnection() As SqlConnection
|
||||
Try
|
||||
Dim oConnection = GetSQLConnection()
|
||||
Return oConnection
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
<DebuggerStepThrough()>
|
||||
Private Function MaybeGetTransaction(Connection As SqlConnection, Mode As TransactionMode, Transaction As SqlTransaction) As SqlTransaction
|
||||
If Connection Is Nothing Then
|
||||
Throw New ArgumentNullException("Connection")
|
||||
End If
|
||||
|
||||
If Mode = TransactionMode.NoTransaction Then
|
||||
Return Nothing
|
||||
ElseIf Mode = TransactionMode.ExternalTransaction Then
|
||||
Return Transaction
|
||||
Else
|
||||
Return Connection.BeginTransaction()
|
||||
End If
|
||||
End Function
|
||||
|
||||
<DebuggerStepThrough()>
|
||||
Private Function MaybeCommitTransaction(Transaction As SqlTransaction, TransactionMode As TransactionMode) As Boolean
|
||||
Select Case TransactionMode
|
||||
Case TransactionMode.NoTransaction
|
||||
Return True
|
||||
Case TransactionMode.ExternalTransaction
|
||||
Return True
|
||||
Case TransactionMode.WithTransaction
|
||||
Try
|
||||
Transaction.Commit()
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
Case Else
|
||||
Return True
|
||||
End Select
|
||||
End Function
|
||||
|
||||
Public Function GetConnectionStringForId(pConnectionId As Integer) As String
|
||||
Return Get_ConnectionStringforID(pConnectionId)
|
||||
End Function
|
||||
|
||||
Public Function Get_ConnectionStringforID(pConnectionId As Integer) As String
|
||||
Dim oConnectionString As String = String.Empty
|
||||
|
||||
Logger.Debug("Getting ConnectionString for ConnectionId [{0}]", pConnectionId)
|
||||
|
||||
If pConnectionId = 0 Then
|
||||
Logger.Warn("ConnectionId was 0. Falling back to default connection.")
|
||||
Return String.Empty
|
||||
End If
|
||||
|
||||
Try
|
||||
Dim oTable As DataTable = GetDatatable($"SELECT * FROM TBDD_CONNECTION WHERE GUID = {pConnectionId}")
|
||||
If oTable.Rows.Count = 1 Then
|
||||
Dim oRow As DataRow = oTable.Rows(0)
|
||||
Dim oProvider = oRow.Item("SQL_PROVIDER").ToString.ToUpper
|
||||
Dim oServer = oRow.Item("SERVER")
|
||||
Dim oDatabase = oRow.Item("DATENBANK")
|
||||
Dim oUser = oRow.Item("USERNAME")
|
||||
Dim oPassword = oRow.Item("PASSWORD")
|
||||
|
||||
Select Case oProvider
|
||||
Case "MS-SQL"
|
||||
If oUser = "WINAUTH" Then
|
||||
oConnectionString = $"Server={oServer};Database={oDatabase};Trusted_Connection=True;"
|
||||
Else
|
||||
oConnectionString = $"Server={oServer};Database={oDatabase};User Id={oUser};Password={oPassword};"
|
||||
End If
|
||||
|
||||
Case "ORACLE"
|
||||
If oRow.Item("BEMERKUNG").ToString.Contains("without tnsnames") Then
|
||||
oConnectionString = $"Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={oServer})(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME={oDatabase})));User Id={oUser};Password={oPassword};"
|
||||
Else
|
||||
oConnectionString = $"Data Source={oServer};Persist Security Info=True;User Id={oUser};Password={oPassword};Unicode=True"
|
||||
End If
|
||||
|
||||
Case Else
|
||||
Logger.Warn("Provider [{0}] not supported!", oProvider)
|
||||
|
||||
End Select
|
||||
|
||||
Else
|
||||
Logger.Warn("No entry for Connection-ID: [{0}] ", pConnectionId.ToString)
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Logger.Warn("Error in Get_ConnectionStringforID")
|
||||
End Try
|
||||
|
||||
Return DecryptConnectionString(oConnectionString)
|
||||
End Function
|
||||
|
||||
<DebuggerStepThrough()>
|
||||
Private Function TestCanConnect() As Boolean
|
||||
Return TestCanConnect(CurrentConnectionString)
|
||||
End Function
|
||||
|
||||
Private Function TestCanConnect(pConnectionString As String) As Boolean
|
||||
Try
|
||||
Logger.Debug("Testing connection to [{0}]", MaskConnectionString(pConnectionString))
|
||||
|
||||
Dim oDecryptedConnectionString = DecryptConnectionString(pConnectionString)
|
||||
Dim oConnection As New SqlConnection(oDecryptedConnectionString)
|
||||
OpenSQLConnection(oConnection)
|
||||
oConnection.Close()
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' This Function intentionally has no try..catch block to have any errors caught outside
|
||||
''' </summary>
|
||||
''' <param name="Connection"></param>
|
||||
''' <returns></returns>
|
||||
Private Function OpenSQLConnection(Connection As SqlConnection) As SqlConnection
|
||||
If Connection.State = ConnectionState.Closed Then
|
||||
Connection.Open()
|
||||
End If
|
||||
|
||||
Return Connection
|
||||
End Function
|
||||
|
||||
<DebuggerStepThrough()>
|
||||
Private Function GetSQLConnection() As SqlConnection
|
||||
Return GetConnection(CurrentConnectionString)
|
||||
End Function
|
||||
|
||||
Private Function GetConnection(pConnectionString As String) As SqlConnection
|
||||
Try
|
||||
Dim oConnection As New SqlConnection(pConnectionString)
|
||||
oConnection = OpenSQLConnection(oConnection)
|
||||
|
||||
Dim oMaskedConnectionString = MaskConnectionString(pConnectionString)
|
||||
Logger.Debug("The Following Connection is open: {0}", oMaskedConnectionString)
|
||||
|
||||
Return oConnection
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
<DebuggerStepThrough()>
|
||||
Private Function MaskConnectionString(pConnectionString As String) As String
|
||||
Try
|
||||
If pConnectionString Is Nothing OrElse pConnectionString.Length = 0 Then
|
||||
Logger.Warn("Connection String is empty!")
|
||||
Throw New ArgumentNullException("pConnectionString")
|
||||
End If
|
||||
|
||||
Dim oBuilder As New SqlConnectionStringBuilder() With {.ConnectionString = pConnectionString}
|
||||
Dim oConnectionString = pConnectionString.Replace(oBuilder.Password, "XXXXX")
|
||||
Return oConnectionString
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return "Invalid ConnectionString"
|
||||
End Try
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Function GetDatatable(SqlCommand As String) As DataTable Implements IDatabase.GetDatatable
|
||||
Return GetDatatable(SqlCommand, QueryTimeout)
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Returns a datatable for a sql-statement
|
||||
''' </summary>
|
||||
''' <param name="SqlCommand">sqlcommand for datatable (select XYZ from TableORView)</param>
|
||||
''' <returns>Returns a datatable</returns>
|
||||
Public Function GetDatatable(SqlCommand As String, Timeout As Integer) As DataTable Implements IDatabase.GetDatatable
|
||||
Using oSqlConnection = GetSQLConnection()
|
||||
Return GetDatatableWithConnectionObject(SqlCommand, oSqlConnection, TransactionMode.WithTransaction, Nothing, Timeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Function GetDatatable(SqlCommand As String, Transaction As SqlTransaction, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As DataTable
|
||||
Using oSqlConnection = GetSQLConnection()
|
||||
Return GetDatatableWithConnectionObject(SqlCommand, oSqlConnection, TransactionMode.ExternalTransaction, Transaction, Timeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Async Function GetDatatableAsync(SqlCommand As String, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As Task(Of DataTable)
|
||||
Return Await Task.Run(Function() GetDatatable(SqlCommand, Timeout))
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Function GetDatatableWithConnection(SqlCommand As String, pConnectionString As String, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As DataTable
|
||||
Using oConnection = GetConnection(pConnectionString)
|
||||
Return GetDatatableWithConnectionObject(SqlCommand, oConnection, Timeout:=Timeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
Public Function GetDatatableWithConnectionObject(SqlCommand As String, SqlConnection As SqlConnection,
|
||||
Optional TransactionMode As TransactionMode = TransactionMode.WithTransaction,
|
||||
Optional Transaction As SqlTransaction = Nothing,
|
||||
Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As DataTable
|
||||
Dim oTransaction As SqlTransaction = MaybeGetTransaction(SqlConnection, TransactionMode, Transaction)
|
||||
Dim oTable As New DataTable() With {.TableName = Constants.DEFAULT_TABLE}
|
||||
|
||||
Try
|
||||
Dim oAdapter As New SqlDataAdapter(New SqlCommand With {
|
||||
.CommandText = SqlCommand,
|
||||
.Connection = SqlConnection,
|
||||
.Transaction = oTransaction,
|
||||
.CommandTimeout = Timeout
|
||||
})
|
||||
|
||||
Logger.Debug("GetDatatableWithConnectionObject: Running Query [{0}]", SqlCommand)
|
||||
|
||||
oAdapter.Fill(oTable)
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Logger.Warn("GetDatatableWithConnectionObject: Error in GetDatatableWithConnection while executing command: [{0}]", SqlCommand)
|
||||
Throw ex
|
||||
Finally
|
||||
MaybeCommitTransaction(oTransaction, TransactionMode)
|
||||
End Try
|
||||
|
||||
Return oTable
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Function ExecuteNonQuery(SQLCommand As String) As Boolean Implements IDatabase.ExecuteNonQuery
|
||||
Using oConnection = GetSQLConnection()
|
||||
Return ExecuteNonQueryWithConnectionObject(SQLCommand, oConnection, TransactionMode.WithTransaction, Nothing, QueryTimeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Function ExecuteNonQuery(SQLCommand As String, Timeout As Integer) As Boolean Implements IDatabase.ExecuteNonQuery
|
||||
Using oConnection = GetSQLConnection()
|
||||
Return ExecuteNonQueryWithConnectionObject(SQLCommand, oConnection, TransactionMode.WithTransaction, Nothing, Timeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Function ExecuteNonQuery(SQLCommand As String, Transaction As SqlTransaction, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As Boolean
|
||||
Using oConnection = GetSQLConnection()
|
||||
Return ExecuteNonQueryWithConnectionObject(SQLCommand, Transaction.Connection, TransactionMode.ExternalTransaction, Transaction, Timeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Async Function ExecuteNonQueryAsync(SQLCommand As String, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As Task(Of Boolean)
|
||||
Return Await Task.Run(Function() ExecuteNonQuery(SQLCommand, Timeout))
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Function ExecuteNonQueryWithConnection(pSQLCommand As String, ConnString As String, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As Boolean
|
||||
Using oConnection = GetConnection(ConnString)
|
||||
Return ExecuteNonQueryWithConnectionObject(pSQLCommand, oConnection, TransactionMode.WithTransaction, Nothing, Timeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
Public Function ExecuteNonQueryWithConnectionObject(SqlCommand As String, SqlConnection As SqlConnection,
|
||||
Optional TransactionMode As TransactionMode = TransactionMode.WithTransaction,
|
||||
Optional Transaction As SqlTransaction = Nothing,
|
||||
Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As Boolean
|
||||
Dim oTransaction As SqlTransaction = MaybeGetTransaction(SqlConnection, TransactionMode, Transaction)
|
||||
|
||||
Try
|
||||
Logger.Debug("ExecuteNonQueryWithConnectionObject: Running Command [{0}]", SqlCommand)
|
||||
|
||||
Using oSQLCOmmand = SqlConnection.CreateCommand()
|
||||
oSQLCOmmand.CommandText = SqlCommand
|
||||
oSQLCOmmand.CommandTimeout = Timeout
|
||||
oSQLCOmmand.Transaction = oTransaction
|
||||
oSQLCOmmand.ExecuteNonQuery()
|
||||
End Using
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Logger.Warn("ExecuteNonQueryWithConnectionObject: Error in ExecuteNonQueryWithConnectionObject while executing command: [{0}]-[{1}]", SqlCommand, SqlConnection.ConnectionString)
|
||||
Return False
|
||||
Finally
|
||||
MaybeCommitTransaction(oTransaction, TransactionMode)
|
||||
End Try
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Function GetScalarValue(SQLQuery As String) As Object Implements IDatabase.GetScalarValue
|
||||
Using oConnection As SqlConnection = GetSQLConnection()
|
||||
Return GetScalarValueWithConnectionObject(SQLQuery, oConnection)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Function GetScalarValue(SQLCommand As String, Timeout As Integer) As Object Implements IDatabase.GetScalarValue
|
||||
Using oConnection = GetSQLConnection()
|
||||
Return GetScalarValueWithConnectionObject(SQLCommand, oConnection, TransactionMode.WithTransaction, Nothing, Timeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Function GetScalarValue(SQLCommand As String, Transaction As SqlTransaction, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As Object
|
||||
Using oConnection = GetSQLConnection()
|
||||
Return GetScalarValueWithConnectionObject(SQLCommand, oConnection, TransactionMode.ExternalTransaction, Transaction, Timeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Async Function GetScalarValueAsync(SQLQuery As String, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As Task(Of Object)
|
||||
Return Await Task.Run(Function() GetScalarValue(SQLQuery, Timeout))
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Function GetScalarValueWithConnection(SQLCommand As String, pConnectionString As String, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As Object
|
||||
Using oConnection = GetConnection(pConnectionString)
|
||||
Return GetScalarValueWithConnectionObject(SQLCommand, oConnection, TransactionMode.WithTransaction, Nothing, Timeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
Public Function GetScalarValueWithConnectionObject(SqlCommand As String, SqlConnection As SqlConnection,
|
||||
Optional TransactionMode As TransactionMode = TransactionMode.WithTransaction,
|
||||
Optional Transaction As SqlTransaction = Nothing,
|
||||
Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As Object
|
||||
|
||||
Dim oTransaction As SqlTransaction = MaybeGetTransaction(SqlConnection, TransactionMode, Transaction)
|
||||
Dim oResult As Object = Nothing
|
||||
|
||||
Try
|
||||
Using oSQLCOmmand = SqlConnection.CreateCommand()
|
||||
oSQLCOmmand.CommandText = SqlCommand
|
||||
oSQLCOmmand.CommandTimeout = Timeout
|
||||
oSQLCOmmand.Transaction = oTransaction
|
||||
|
||||
oResult = oSQLCOmmand.ExecuteScalar()
|
||||
End Using
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Logger.Warn("GetDatatableWithConnectionObject: Error in GetDatatableWithConnection while executing command: [{0}]", SqlCommand)
|
||||
Finally
|
||||
MaybeCommitTransaction(oTransaction, TransactionMode)
|
||||
End Try
|
||||
|
||||
Return oResult
|
||||
End Function
|
||||
|
||||
Public Function GetScalarValue(SQLCommand As SqlCommand, OutputParameter As String, Timeout As Integer) As Object
|
||||
Try
|
||||
If TestCanConnect() = False Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Logger.Debug("GetScalarValue: Running Query [{0}]", SQLCommand)
|
||||
|
||||
If SQLCommand.CommandText.Contains(" ") Then
|
||||
SQLCommand.CommandType = CommandType.Text
|
||||
Else
|
||||
SQLCommand.CommandType = CommandType.StoredProcedure
|
||||
End If
|
||||
|
||||
Using oConnection As SqlConnection = GetSQLConnection()
|
||||
|
||||
SQLCommand.Connection = oConnection
|
||||
SQLCommand.Parameters(OutputParameter).Direction = ParameterDirection.Output
|
||||
SQLCommand.CommandTimeout = Timeout
|
||||
SQLCommand.ExecuteNonQuery()
|
||||
oConnection.Close()
|
||||
|
||||
Return SQLCommand.Parameters(OutputParameter).Value
|
||||
End Using
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Logger.Warn($"GetScalarValue failed SQLCommand [{SQLCommand}]")
|
||||
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Function GetScalarValue(SQLCommand As SqlCommand, OutputParameter As String) As Object
|
||||
Return GetScalarValue(SQLCommand, OutputParameter, QueryTimeout)
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Executes the passed sql-statement in asyncmode
|
||||
''' </summary>
|
||||
''' <param name="SqlCommand">the sql statement</param>
|
||||
''' <param name="commandtimeout">Optional Timeout</param>
|
||||
''' <remarks></remarks>
|
||||
Public Sub NewExecuteNonQueryAsync(SqlCommand As String, Optional commandtimeout As Integer = Constants.DEFAULT_TIMEOUT)
|
||||
Logger.Debug("NewExecuteNonQueryAsync: Running Query [{0}]", SqlCommand)
|
||||
|
||||
Try
|
||||
Dim oCallback As New AsyncCallback(AddressOf NewExecuteNonQueryAsync_Callback)
|
||||
|
||||
Using oConnection As SqlConnection = GetSQLConnection()
|
||||
Using oSQLCOmmand = oConnection.CreateCommand()
|
||||
oSQLCOmmand.CommandText = SqlCommand
|
||||
oSQLCOmmand.CommandTimeout = commandtimeout
|
||||
oSQLCOmmand.BeginExecuteNonQuery(oCallback, oSQLCOmmand)
|
||||
End Using
|
||||
End Using
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Logger.Warn($"NewExecuteNonQueryAsync failed SQLCommand [{SqlCommand}]")
|
||||
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Private Sub NewExecuteNonQueryAsync_Callback(ByVal result As IAsyncResult)
|
||||
Dim command As SqlCommand = CType(result.AsyncState, SqlCommand)
|
||||
Dim res = command.EndExecuteNonQuery(result)
|
||||
Logger.Info("Finished executing Async database operation: {0}", command.CommandText)
|
||||
End Sub
|
||||
End Class
|
||||
179
Database/Adapters/ODBC.vb
Normal file
179
Database/Adapters/ODBC.vb
Normal file
@@ -0,0 +1,179 @@
|
||||
Imports System.Data.Odbc
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Public Class ODBC
|
||||
Private _Logger As Logger
|
||||
Private _LogConfig As LogConfig
|
||||
|
||||
Private _connectionDatasource As String
|
||||
Private _connectionUsername As String
|
||||
Private _connectionPassword As String
|
||||
Private _connectionString As String
|
||||
|
||||
Public Sub New(LogConfig As LogConfig, Datasource As String, User As String, Password As String)
|
||||
Try
|
||||
_LogConfig = LogConfig
|
||||
_Logger = _LogConfig.GetLogger()
|
||||
|
||||
_connectionDatasource = Datasource
|
||||
_connectionPassword = Password
|
||||
_connectionUsername = User
|
||||
_connectionString = GetConnectionString(Datasource, User, Password)
|
||||
|
||||
_Logger.Debug("Connecting to database..")
|
||||
|
||||
' Test the connection
|
||||
Dim oConnection = GetConnection()
|
||||
|
||||
If oConnection Is Nothing Then
|
||||
Throw New Exceptions.DatabaseException()
|
||||
End If
|
||||
|
||||
' If initial connection was successfully, close it
|
||||
oConnection.Close()
|
||||
|
||||
_Logger.Debug("Connection sucessfully established!")
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Public Function GetConnection() As OdbcConnection
|
||||
Try
|
||||
Dim oConnection As New OdbcConnection(_connectionString)
|
||||
oConnection.Open()
|
||||
|
||||
Return oConnection
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function GetConnectionString(Datasource As String, User As String, Password As String) As Object
|
||||
Return $"DSN={Datasource};UID={User};PWD={Password}"
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Executes a non-query command.
|
||||
''' </summary>
|
||||
''' <param name="SqlQuery">The command to execute</param>
|
||||
''' <param name="Connection">The Firebird connection to use</param>
|
||||
''' <returns>True, if command was executed sucessfully. Otherwise false.</returns>
|
||||
Public Function ExecuteNonQueryWithConnection(SqlQuery As String, Connection As OdbcConnection) As Object
|
||||
_Logger.Debug("Fetching Non-Query: {0}", SqlQuery)
|
||||
|
||||
Dim oResult As Object
|
||||
|
||||
If Connection Is Nothing Then
|
||||
_Logger.Warn("Connection is nothing!")
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Try
|
||||
Dim oCommand As New OdbcCommand(SqlQuery, Connection)
|
||||
oResult = oCommand.ExecuteNonQuery()
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex, $"Error in ExecuteNonQueryWithConnection while executing command: '{SqlQuery}'")
|
||||
Throw ex
|
||||
End Try
|
||||
|
||||
Return oResult
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Executes a non-query command.
|
||||
''' </summary>
|
||||
''' <param name="SqlCommand">The command to execute</param>
|
||||
''' <returns>True, if command was executed sucessfully. Otherwise false.</returns>
|
||||
Public Function ExecuteNonQuery(SqlCommand As String) As Boolean
|
||||
Dim oConnection As OdbcConnection = GetConnection()
|
||||
Dim oScalarValue As Object = ExecuteNonQueryWithConnection(SqlCommand, oConnection)
|
||||
oConnection.Close()
|
||||
|
||||
Return oScalarValue
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Executes a sql query resulting in a scalar value.
|
||||
''' </summary>
|
||||
''' <param name="SqlQuery">The query to execute</param>
|
||||
''' <param name="Connection">The Firebird connection to use</param>
|
||||
''' <returns>The scalar value if the command was executed successfully. Nothing otherwise.</returns>
|
||||
Public Function GetScalarValueWithConnection(SqlQuery As String, Connection As OdbcConnection) As Object
|
||||
_Logger.Debug("Fetching Datatable: {0}", SqlQuery)
|
||||
|
||||
Dim oResult As Object
|
||||
|
||||
If Connection Is Nothing Then
|
||||
_Logger.Warn("Connection is nothing!")
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Try
|
||||
Dim oCommand As New OdbcCommand(SqlQuery, Connection)
|
||||
oResult = oCommand.ExecuteScalar()
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex, $"Error in GetDatatableWithConnection while executing command: '{SqlQuery}'")
|
||||
Throw ex
|
||||
End Try
|
||||
|
||||
Return oResult
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Executes a sql query resulting in a table of values.
|
||||
''' </summary>
|
||||
''' <param name="SqlQuery">The query to execute</param>
|
||||
''' <returns>A datatable containing the results if the command was executed successfully. Nothing otherwise.</returns>
|
||||
Public Function GetScalarValue(SqlQuery As String) As Object
|
||||
Dim oConnection As OdbcConnection = GetConnection()
|
||||
Dim oDatatable As DataTable = GetDatatableWithConnection(SqlQuery, oConnection)
|
||||
oConnection.Close()
|
||||
|
||||
Return oDatatable
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Executes a sql query resulting in a table of values.
|
||||
''' </summary>
|
||||
''' <param name="SqlQuery">The query to execute</param>
|
||||
''' <param name="Connection">The Firebird connection to use</param>
|
||||
''' <returns>A datatable containing the results if the command was executed successfully. Nothing otherwise.</returns>
|
||||
Public Function GetDatatableWithConnection(SqlQuery As String, Connection As OdbcConnection) As DataTable
|
||||
_Logger.Debug("Fetching Datatable: {0}", SqlQuery)
|
||||
|
||||
Dim oDatatable As New DataTable() With {
|
||||
.TableName = "DDRESULT"
|
||||
}
|
||||
|
||||
If Connection Is Nothing Then
|
||||
_Logger.Warn("Connection is nothing!")
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Try
|
||||
|
||||
Dim oAdapter As New OdbcDataAdapter(SqlQuery, Connection)
|
||||
oAdapter.Fill(oDatatable)
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex, $"Error in GetDatatableWithConnection while executing command: '{SqlQuery}'")
|
||||
Throw ex
|
||||
End Try
|
||||
|
||||
Return oDatatable
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Executes a sql query resulting in a table of values.
|
||||
''' </summary>
|
||||
''' <param name="SqlQuery">The query to execute</param>
|
||||
''' <returns>A datatable containing the results if the command was executed successfully. Nothing otherwise.</returns>
|
||||
Public Function GetDatatable(SqlQuery As String) As DataTable
|
||||
Dim oConnection As OdbcConnection = GetConnection()
|
||||
Dim oDatatable As DataTable = GetDatatableWithConnection(SqlQuery, oConnection)
|
||||
oConnection.Close()
|
||||
|
||||
Return oDatatable
|
||||
End Function
|
||||
End Class
|
||||
253
Database/Adapters/Oracle.vb
Normal file
253
Database/Adapters/Oracle.vb
Normal file
@@ -0,0 +1,253 @@
|
||||
Imports DigitalData.Modules.Encryption
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports Oracle.ManagedDataAccess.Client
|
||||
|
||||
Public Class Oracle
|
||||
Implements IDatabase
|
||||
|
||||
Public Property DBInitialized As Boolean = False Implements IDatabase.DBInitialized
|
||||
Public Property CurrentConnectionString As String = "" Implements IDatabase.CurrentConnectionString
|
||||
|
||||
Private ReadOnly _Timeout As Integer
|
||||
Private ReadOnly _Logger As Logger
|
||||
|
||||
Public Sub New(LogConfig As LogConfig, ConnectionString As String, Optional Timeout As Integer = 120)
|
||||
_Timeout = Timeout
|
||||
_Logger = LogConfig.GetLogger()
|
||||
|
||||
ConnectionString = ConnectionString
|
||||
DBInitialized = TestCanConnect(ConnectionString)
|
||||
End Sub
|
||||
|
||||
Public Sub New(LogConfig As LogConfig, Server As String, Database As String, UserId As String, Password As String, Optional Timeout As Integer = 120)
|
||||
_Timeout = Timeout
|
||||
_Logger = LogConfig.GetLogger()
|
||||
|
||||
CurrentConnectionString = GetConnectionString(Server, Database, UserId, Password)
|
||||
DBInitialized = TestCanConnect(CurrentConnectionString)
|
||||
End Sub
|
||||
|
||||
Private Function TestCanConnect(ConnectionString As String) As Boolean
|
||||
Try
|
||||
Dim oSQLconnect As New OracleConnection
|
||||
oSQLconnect.ConnectionString = ConnectionString
|
||||
oSQLconnect.Open()
|
||||
oSQLconnect.Close()
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Shared Function GetConnectionString(Server As String, Database As String, UserId As String, Password As String) As String
|
||||
Dim oConnectionString = $"Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={Server})(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME={Database})));User Id={UserId};Password={Password};"
|
||||
Return oConnectionString
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Encrypts a connection string password.
|
||||
''' </summary>
|
||||
''' <param name="ConnectionString">A connection string with a plain-text password</param>
|
||||
''' <returns>The connection string with the password encrypted.</returns>
|
||||
<DebuggerStepThrough()>
|
||||
Public Shared Function EncryptConnectionString(ConnectionString As String) As String
|
||||
Dim oEncryption As New EncryptionLegacy()
|
||||
Dim oBuilder As New OracleConnectionStringBuilder() With {.ConnectionString = ConnectionString}
|
||||
Dim oEncryptedPassword = oEncryption.EncryptData(oBuilder.Password)
|
||||
oBuilder.Password = oEncryptedPassword
|
||||
|
||||
Return oBuilder.ToString()
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Decrypts a connection string password.
|
||||
''' </summary>
|
||||
''' <param name="ConnectionString">A connection string with a encrypted password</param>
|
||||
''' <returns>The connection string with the password decrypted.</returns>
|
||||
<DebuggerStepThrough()>
|
||||
Public Shared Function DecryptConnectionString(ConnectionString As String) As String
|
||||
Dim oEncryption As New EncryptionLegacy()
|
||||
Dim oBuilder As New OracleConnectionStringBuilder() With {.ConnectionString = ConnectionString}
|
||||
Dim oDecryptedPassword = oEncryption.DecryptData(oBuilder.Password)
|
||||
oBuilder.Password = oDecryptedPassword
|
||||
|
||||
Return oBuilder.ToString()
|
||||
End Function
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' Executes the passed sql-statement
|
||||
''' </summary>
|
||||
''' <param name="executeStatement">the sql statement</param>
|
||||
''' <returns>Returns true if properly executed, else false</returns>
|
||||
Public Function NewExecutenonQuery(executeStatement As String) As Boolean
|
||||
Try
|
||||
Dim oSQLconnect As New OracleConnection
|
||||
Dim oSQLCOmmand As OracleCommand
|
||||
oSQLconnect.ConnectionString = CurrentConnectionString
|
||||
oSQLconnect.Open()
|
||||
oSQLCOmmand = oSQLconnect.CreateCommand()
|
||||
oSQLCOmmand.CommandText = executeStatement
|
||||
oSQLCOmmand.CommandTimeout = _Timeout
|
||||
oSQLCOmmand.ExecuteNonQuery()
|
||||
oSQLCOmmand.Dispose()
|
||||
oSQLconnect.Close()
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
_Logger.Debug("executeStatement: " & executeStatement)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Executes the passed sql-statement as Scalar
|
||||
''' </summary>
|
||||
''' <param name="executeStatement">the sql statement</param>
|
||||
''' <returns>Returns the scalarvalue</returns>
|
||||
Public Function NewExecuteScalar(executeStatement As String)
|
||||
Dim result
|
||||
Try
|
||||
Dim oSQLconnect As New OracleConnection
|
||||
Dim oSQLCOmmand As OracleCommand
|
||||
oSQLconnect.ConnectionString = CurrentConnectionString
|
||||
oSQLconnect.Open()
|
||||
oSQLCOmmand = oSQLconnect.CreateCommand()
|
||||
oSQLCOmmand.CommandText = executeStatement
|
||||
oSQLCOmmand.CommandTimeout = _Timeout
|
||||
result = oSQLCOmmand.ExecuteScalar()
|
||||
oSQLCOmmand.Dispose()
|
||||
oSQLconnect.Close()
|
||||
Return result
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
_Logger.Debug("executeStatement: " & executeStatement)
|
||||
Throw ex
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function GetDatatable(pSQLCommand As String, pTimeout As Integer) As DataTable Implements IDatabase.GetDatatable
|
||||
Try
|
||||
Using oConnection = GetConnection(CurrentConnectionString)
|
||||
Dim oSQLCommand As OracleCommand
|
||||
oSQLCommand = oConnection.CreateCommand()
|
||||
oSQLCommand.CommandText = pSQLCommand
|
||||
oSQLCommand.CommandTimeout = pTimeout
|
||||
|
||||
Dim oAdapter As OracleDataAdapter = New OracleDataAdapter(oSQLCommand)
|
||||
Dim oTable As DataTable = New DataTable()
|
||||
|
||||
_Logger.Debug("GetDatatable: Running Query [{0}]", oSQLCommand)
|
||||
|
||||
oAdapter.Fill(oTable)
|
||||
|
||||
Return oTable
|
||||
End Using
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
_Logger.Warn("GetDatatable: Error in GetDatatable while executing command: [{0}]", pSQLCommand)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function GetDatatable(pSQLCommand As String) As DataTable Implements IDatabase.GetDatatable
|
||||
Return GetDatatable(pSQLCommand, _Timeout)
|
||||
End Function
|
||||
|
||||
Public Function ExecuteNonQuery(pSQLCommand As String, pTimeout As Integer) As Boolean Implements IDatabase.ExecuteNonQuery
|
||||
Try
|
||||
Using oConnection = GetConnection(CurrentConnectionString)
|
||||
Dim oSQLCOmmand As OracleCommand
|
||||
oSQLCOmmand = oConnection.CreateCommand()
|
||||
oSQLCOmmand.CommandText = pSQLCommand
|
||||
oSQLCOmmand.CommandTimeout = pTimeout
|
||||
|
||||
|
||||
_Logger.Debug("ExecuteNonQuery: Running Query [{0}]", oSQLCOmmand)
|
||||
oSQLCOmmand.ExecuteNonQuery()
|
||||
oSQLCOmmand.Dispose()
|
||||
Return True
|
||||
End Using
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
_Logger.Warn("ExecuteNonQuery: Error in ExecuteNonQuery while executing command: [{0}]", pSQLCommand)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function ExecuteNonQuery(pSQLCommand As String) As Boolean Implements IDatabase.ExecuteNonQuery
|
||||
Return ExecuteNonQuery(pSQLCommand, _Timeout)
|
||||
End Function
|
||||
|
||||
Public Function GetScalarValue(pSQLCommand As String, pTimeout As Integer) As Object Implements IDatabase.GetScalarValue
|
||||
Dim result
|
||||
Try
|
||||
Using oConnection = GetConnection(CurrentConnectionString)
|
||||
Dim oSQLCOmmand As OracleCommand
|
||||
oSQLCOmmand = oConnection.CreateCommand()
|
||||
oSQLCOmmand.CommandText = pSQLCommand
|
||||
oSQLCOmmand.CommandTimeout = pTimeout
|
||||
|
||||
_Logger.Debug("GetScalarValue: Running Query [{0}]", oSQLCOmmand)
|
||||
result = oSQLCOmmand.ExecuteScalar()
|
||||
|
||||
Return result
|
||||
End Using
|
||||
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
_Logger.Warn("GetScalarValue: Error in GetScalarValue while executing command: [{0}]", pSQLCommand)
|
||||
Throw ex
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function GetScalarValue(pSQLCommand As String) As Object Implements IDatabase.GetScalarValue
|
||||
Return GetScalarValue(pSQLCommand, _Timeout)
|
||||
End Function
|
||||
|
||||
Private Function GetConnection(ConnectionString As String) As OracleConnection
|
||||
Try
|
||||
Dim oConnection As New OracleConnection(ConnectionString)
|
||||
oConnection = OpenSQLConnection(oConnection)
|
||||
|
||||
Dim oMaskedConnectionString = MaskConnectionString(ConnectionString)
|
||||
_Logger.Debug("The Following Connection is open: {0}", oMaskedConnectionString)
|
||||
|
||||
Return oConnection
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' This Function intentionally has no try..catch block to have any errors caught outside
|
||||
''' </summary>
|
||||
''' <param name="Connection"></param>
|
||||
''' <returns></returns>
|
||||
Private Function OpenSQLConnection(Connection As OracleConnection) As OracleConnection
|
||||
If Connection.State = ConnectionState.Closed Then
|
||||
Connection.Open()
|
||||
End If
|
||||
|
||||
Return Connection
|
||||
End Function
|
||||
|
||||
<DebuggerStepThrough()>
|
||||
Private Function MaskConnectionString(ConnectionString As String) As String
|
||||
Try
|
||||
If ConnectionString Is Nothing OrElse ConnectionString.Length = 0 Then
|
||||
Throw New ArgumentNullException("ConnectionString")
|
||||
End If
|
||||
|
||||
Dim oBuilder As New OracleConnectionStringBuilder() With {.ConnectionString = ConnectionString}
|
||||
Dim oConnectionString = ConnectionString.Replace(oBuilder.Password, "XXXXX")
|
||||
Return oConnectionString
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
Return "Invalid ConnectionString"
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
||||
23
Database/App.config
Normal file
23
Database/App.config
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
|
||||
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
||||
</configSections>
|
||||
<entityFramework>
|
||||
<defaultConnectionFactory type="EntityFramework.Firebird.FbConnectionFactory, EntityFramework.Firebird" />
|
||||
<providers>
|
||||
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
|
||||
<provider invariantName="FirebirdSql.Data.FirebirdClient" type="EntityFramework.Firebird.FbProviderServices, EntityFramework.Firebird" />
|
||||
</providers>
|
||||
</entityFramework>
|
||||
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="FirebirdSql.Data.FirebirdClient" publicKeyToken="3750abcc3150b00c" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-7.5.0.0" newVersion="7.5.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
20
Database/ConnectionString.vb
Normal file
20
Database/ConnectionString.vb
Normal file
@@ -0,0 +1,20 @@
|
||||
Public Class ConnectionString
|
||||
Public Enum ConnectionStringType
|
||||
MSSQLServer
|
||||
ODBC
|
||||
Oracle
|
||||
End Enum
|
||||
|
||||
Public Shared Function GetConnectionStringType(pConnectionString As String) As ConnectionStringType
|
||||
' This variable only exists to shorten the if-conditions
|
||||
Dim c = pConnectionString
|
||||
|
||||
If (c.Contains("Server=") Or c.Contains("Data Source=")) And (c.Contains("Database=") Or c.Contains("Initial Catalog=")) Then
|
||||
Return ConnectionStringType.MSSQLServer
|
||||
ElseIf (c.Contains("dsn=")) Then
|
||||
Return ConnectionStringType.ODBC
|
||||
Else
|
||||
Return ConnectionStringType.Oracle
|
||||
End If
|
||||
End Function
|
||||
End Class
|
||||
8
Database/Constants.vb
Normal file
8
Database/Constants.vb
Normal file
@@ -0,0 +1,8 @@
|
||||
Public Class Constants
|
||||
Public Const PROVIDER_MSSQL = "MS-SQL"
|
||||
Public Const PROVIDER_ORACLE = "ORACLE"
|
||||
Public Const PROVIDER_ODBC = "ODBC"
|
||||
|
||||
Public Const DEFAULT_TIMEOUT = 120
|
||||
Public Const DEFAULT_TABLE = "DDRESULT"
|
||||
End Class
|
||||
162
Database/Database.vbproj
Normal file
162
Database/Database.vbproj
Normal file
@@ -0,0 +1,162 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\packages\EntityFramework.6.4.4\build\EntityFramework.props" Condition="Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{EAF0EA75-5FA7-485D-89C7-B2D843B03A96}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>DigitalData.Modules.Database</RootNamespace>
|
||||
<AssemblyName>DigitalData.Modules.Database</AssemblyName>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<MyType>Windows</MyType>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<DefineDebug>true</DefineDebug>
|
||||
<DefineTrace>true</DefineTrace>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DocumentationFile>DigitalData.Modules.Database.xml</DocumentationFile>
|
||||
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<DefineDebug>false</DefineDebug>
|
||||
<DefineTrace>true</DefineTrace>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DocumentationFile>DigitalData.Modules.Database.xml</DocumentationFile>
|
||||
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionExplicit>On</OptionExplicit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionCompare>Binary</OptionCompare>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionStrict>Off</OptionStrict>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionInfer>On</OptionInfer>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="EntityFramework.Firebird, Version=6.4.0.0, Culture=neutral, PublicKeyToken=42d22d092898e5f8, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EntityFramework.Firebird.6.4.0\lib\net452\EntityFramework.Firebird.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FirebirdSql.Data.FirebirdClient, Version=7.5.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FirebirdSql.Data.FirebirdClient.7.5.0\lib\net452\FirebirdSql.Data.FirebirdClient.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.4.7.15\lib\net45\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Oracle.ManagedDataAccess">
|
||||
<HintPath>P:\Visual Studio Projekte\Bibliotheken\Oracle.ManagedDataAccess.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.ServiceModel" />
|
||||
<Reference Include="System.Transactions" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Import Include="Microsoft.VisualBasic" />
|
||||
<Import Include="System" />
|
||||
<Import Include="System.Collections" />
|
||||
<Import Include="System.Collections.Generic" />
|
||||
<Import Include="System.Data" />
|
||||
<Import Include="System.Diagnostics" />
|
||||
<Import Include="System.Linq" />
|
||||
<Import Include="System.Xml.Linq" />
|
||||
<Import Include="System.Threading.Tasks" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ConnectionString.vb" />
|
||||
<Compile Include="Constants.vb" />
|
||||
<Compile Include="Dispatcher.vb" />
|
||||
<Compile Include="Exceptions.vb" />
|
||||
<Compile Include="Adapters\Firebird.vb" />
|
||||
<Compile Include="IDatabase.vb" />
|
||||
<Compile Include="Adapters\ODBC.vb" />
|
||||
<Compile Include="Adapters\Oracle.vb" />
|
||||
<Compile Include="Adapters\MSSQLServer.vb" />
|
||||
<Compile Include="My Project\AssemblyInfo.vb" />
|
||||
<Compile Include="My Project\Application.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Application.myapp</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="My Project\Resources.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="My Project\Settings.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<Compile Include="TableCache.vb" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="My Project\Resources.resx">
|
||||
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.vb</LastGenOutput>
|
||||
<CustomToolNamespace>My.Resources</CustomToolNamespace>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
<None Include="My Project\Application.myapp">
|
||||
<Generator>MyApplicationCodeGenerator</Generator>
|
||||
<LastGenOutput>Application.Designer.vb</LastGenOutput>
|
||||
</None>
|
||||
<None Include="My Project\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<CustomToolNamespace>My</CustomToolNamespace>
|
||||
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
|
||||
</None>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Encryption\Encryption.vbproj">
|
||||
<Project>{8a8f20fc-c46e-41ac-bee7-218366cfff99}</Project>
|
||||
<Name>Encryption</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Logging\Logging.vbproj">
|
||||
<Project>{903b2d7d-3b80-4be9-8713-7447b704e1b0}</Project>
|
||||
<Name>Logging</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}".</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.4.4\build\EntityFramework.props'))" />
|
||||
<Error Condition="!Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.4.4\build\EntityFramework.targets'))" />
|
||||
</Target>
|
||||
<Import Project="..\packages\EntityFramework.6.4.4\build\EntityFramework.targets" Condition="Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.targets')" />
|
||||
</Project>
|
||||
89
Database/Dispatcher.vb
Normal file
89
Database/Dispatcher.vb
Normal file
@@ -0,0 +1,89 @@
|
||||
Imports DigitalData.Modules.Base
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Public Class Dispatcher
|
||||
Public ReadOnly Property Connections As New List(Of DispatcherConnection)
|
||||
|
||||
Public ReadOnly Logger As Logger
|
||||
Public ReadOnly LogConfig As LogConfig
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pConnections As List(Of DispatcherConnection))
|
||||
LogConfig = pLogConfig
|
||||
Logger = pLogConfig.GetLogger()
|
||||
Connections = pConnections
|
||||
End Sub
|
||||
|
||||
Public Function GetDatatable(pSQLCommand As String, pConnectionId As Integer) As DataTable
|
||||
Dim oAdapter As IDatabase = GetAdapterClass(pConnectionId)
|
||||
Return oAdapter.GetDatatable(pSQLCommand)
|
||||
End Function
|
||||
|
||||
Public Function ExectueNonQuery(pSQLCommand As String, pConnectionId As Integer) As Boolean
|
||||
Dim oAdapter As IDatabase = GetAdapterClass(pConnectionId)
|
||||
Return oAdapter.ExecuteNonQuery(pSQLCommand)
|
||||
End Function
|
||||
|
||||
Public Function GetScalarValue(pSQLCommand As String, pConnectionId As Integer) As Object
|
||||
Dim oAdapter As IDatabase = GetAdapterClass(pConnectionId)
|
||||
Return oAdapter.GetScalarValue(pSQLCommand)
|
||||
End Function
|
||||
|
||||
Private Function GetConnection(pConnectionId As Integer) As DispatcherConnection
|
||||
Dim oConnection As DispatcherConnection = Connections.
|
||||
Where(Function(conn) conn.Id = pConnectionId).
|
||||
FirstOrDefault()
|
||||
|
||||
If oConnection IsNot Nothing Then
|
||||
Logger.Debug("Resolved ConnectionId [{0}] into Connection [{1}]", pConnectionId, oConnection.Name)
|
||||
End If
|
||||
|
||||
Return oConnection
|
||||
End Function
|
||||
|
||||
Private Function GetAdapterClass(pConnectionId As Integer) As IDatabase
|
||||
Dim oConnection = GetConnection(pConnectionId)
|
||||
Dim oArgs As New List(Of Object) From {LogConfig, oConnection.ConnectionString, Constants.DEFAULT_TIMEOUT}
|
||||
Logger.Debug("Creating database adapter object for type [{0}]", ConnectionType.MSSQL)
|
||||
|
||||
' TODO: Cache Database instances to avoid constructing them for every call
|
||||
|
||||
Select Case oConnection.ConnectionType
|
||||
Case ConnectionType.MSSQL
|
||||
Return New MSSQLServer(LogConfig, oConnection.ConnectionString, Constants.DEFAULT_TIMEOUT)
|
||||
|
||||
Case ConnectionType.Oracle
|
||||
Return New Oracle(LogConfig, oConnection.ConnectionString, Constants.DEFAULT_TIMEOUT)
|
||||
|
||||
Case ConnectionType.Firebird
|
||||
Dim oBuilder As New FirebirdSql.Data.FirebirdClient.FbConnectionStringBuilder(oConnection.ConnectionString)
|
||||
Return New Firebird(LogConfig, oBuilder.DataSource, oBuilder.Database, oBuilder.UserID, oBuilder.Password)
|
||||
|
||||
Case ConnectionType.ODBC
|
||||
'Dim oBuilder As New Data.Odbc.OdbcConnectionStringBuilder(pConnection.ConnectionString)
|
||||
'Return New ODBC(LogConfig)
|
||||
Return Nothing
|
||||
|
||||
Case Else
|
||||
Return Nothing
|
||||
End Select
|
||||
End Function
|
||||
|
||||
Public Enum ConnectionType
|
||||
MSSQL
|
||||
Oracle
|
||||
ODBC
|
||||
Firebird
|
||||
End Enum
|
||||
|
||||
Public Class DispatcherOptions
|
||||
Public Property QueryTimeout As Integer = Constants.DEFAULT_TIMEOUT
|
||||
End Class
|
||||
|
||||
Public Class DispatcherConnection
|
||||
Public Property Id As Integer
|
||||
Public Property Name As String
|
||||
Public Property ConnectionString As String
|
||||
Public Property ConnectionType As ConnectionType
|
||||
End Class
|
||||
End Class
|
||||
|
||||
18
Database/Exceptions.vb
Normal file
18
Database/Exceptions.vb
Normal file
@@ -0,0 +1,18 @@
|
||||
Public Class Exceptions
|
||||
|
||||
Public Class DatabaseException
|
||||
Inherits Exception
|
||||
|
||||
Public Sub New()
|
||||
End Sub
|
||||
|
||||
Public Sub New(message As String)
|
||||
MyBase.New(message)
|
||||
End Sub
|
||||
|
||||
Public Sub New(message As String, innerException As Exception)
|
||||
MyBase.New(message, innerException)
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
End Class
|
||||
18
Database/IDatabase.vb
Normal file
18
Database/IDatabase.vb
Normal file
@@ -0,0 +1,18 @@
|
||||
Imports System.Data.Common
|
||||
|
||||
Public Interface IDatabase
|
||||
''' <summary>
|
||||
''' Returns true if the initial connection to the configured database was successful.
|
||||
''' </summary>
|
||||
Property DBInitialized As Boolean
|
||||
Property CurrentConnectionString As String
|
||||
|
||||
Function GetDatatable(SqlCommand As String, Timeout As Integer) As DataTable
|
||||
Function GetDatatable(SqlCommand As String) As DataTable
|
||||
|
||||
Function ExecuteNonQuery(SQLCommand As String, Timeout As Integer) As Boolean
|
||||
Function ExecuteNonQuery(SQLCommand As String) As Boolean
|
||||
|
||||
Function GetScalarValue(SQLQuery As String, Timeout As Integer) As Object
|
||||
Function GetScalarValue(SQLQuery As String) As Object
|
||||
End Interface
|
||||
13
Database/My Project/Application.Designer.vb
generated
Normal file
13
Database/My Project/Application.Designer.vb
generated
Normal file
@@ -0,0 +1,13 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' Dieser Code wurde von einem Tool generiert.
|
||||
' Laufzeitversion:4.0.30319.42000
|
||||
'
|
||||
' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
|
||||
' der Code erneut generiert wird.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
10
Database/My Project/Application.myapp
Normal file
10
Database/My Project/Application.myapp
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<MyApplicationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||
<MySubMain>false</MySubMain>
|
||||
<SingleInstance>false</SingleInstance>
|
||||
<ShutdownMode>0</ShutdownMode>
|
||||
<EnableVisualStyles>true</EnableVisualStyles>
|
||||
<AuthenticationMode>0</AuthenticationMode>
|
||||
<ApplicationType>1</ApplicationType>
|
||||
<SaveMySettingsOnExit>true</SaveMySettingsOnExit>
|
||||
</MyApplicationData>
|
||||
35
Database/My Project/AssemblyInfo.vb
Normal file
35
Database/My Project/AssemblyInfo.vb
Normal file
@@ -0,0 +1,35 @@
|
||||
Imports System
|
||||
Imports System.Reflection
|
||||
Imports System.Runtime.InteropServices
|
||||
|
||||
' Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||
' Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||
' die einer Assembly zugeordnet sind.
|
||||
|
||||
' Werte der Assemblyattribute überprüfen
|
||||
|
||||
<Assembly: AssemblyTitle("Modules.Database")>
|
||||
<Assembly: AssemblyDescription("")>
|
||||
<Assembly: AssemblyCompany("Digital Data")>
|
||||
<Assembly: AssemblyProduct("Modules.Database")>
|
||||
<Assembly: AssemblyCopyright("Copyright © 2022")>
|
||||
<Assembly: AssemblyTrademark("2.2.7.3")>
|
||||
|
||||
<Assembly: ComVisible(False)>
|
||||
|
||||
'Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird.
|
||||
<Assembly: Guid("b5cdfd4f-609f-41e1-adf0-663de9636ff5")>
|
||||
|
||||
' Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
||||
'
|
||||
' Hauptversion
|
||||
' Nebenversion
|
||||
' Buildnummer
|
||||
' Revision
|
||||
'
|
||||
' Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
|
||||
' übernehmen, indem Sie "*" eingeben:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("2.2.7.3")>
|
||||
<Assembly: AssemblyFileVersion("2.2.7.3")>
|
||||
63
Database/My Project/Resources.Designer.vb
generated
Normal file
63
Database/My Project/Resources.Designer.vb
generated
Normal file
@@ -0,0 +1,63 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' Dieser Code wurde von einem Tool generiert.
|
||||
' Laufzeitversion:4.0.30319.42000
|
||||
'
|
||||
' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
|
||||
' der Code erneut generiert wird.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
Imports System
|
||||
|
||||
Namespace My.Resources
|
||||
|
||||
'Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert
|
||||
'-Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert.
|
||||
'Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen
|
||||
'mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu.
|
||||
'''<summary>
|
||||
''' Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw.
|
||||
'''</summary>
|
||||
<Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0"), _
|
||||
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||
Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _
|
||||
Friend Module Resources
|
||||
|
||||
Private resourceMan As Global.System.Resources.ResourceManager
|
||||
|
||||
Private resourceCulture As Global.System.Globalization.CultureInfo
|
||||
|
||||
'''<summary>
|
||||
''' Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird.
|
||||
'''</summary>
|
||||
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
|
||||
Get
|
||||
If Object.ReferenceEquals(resourceMan, Nothing) Then
|
||||
Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("DigitalData.Modules.Database.Resources", GetType(Resources).Assembly)
|
||||
resourceMan = temp
|
||||
End If
|
||||
Return resourceMan
|
||||
End Get
|
||||
End Property
|
||||
|
||||
'''<summary>
|
||||
''' Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle
|
||||
''' Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden.
|
||||
'''</summary>
|
||||
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
Friend Property Culture() As Global.System.Globalization.CultureInfo
|
||||
Get
|
||||
Return resourceCulture
|
||||
End Get
|
||||
Set
|
||||
resourceCulture = value
|
||||
End Set
|
||||
End Property
|
||||
End Module
|
||||
End Namespace
|
||||
117
Database/My Project/Resources.resx
Normal file
117
Database/My Project/Resources.resx
Normal file
@@ -0,0 +1,117 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
73
Database/My Project/Settings.Designer.vb
generated
Normal file
73
Database/My Project/Settings.Designer.vb
generated
Normal file
@@ -0,0 +1,73 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' Dieser Code wurde von einem Tool generiert.
|
||||
' Laufzeitversion:4.0.30319.42000
|
||||
'
|
||||
' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
|
||||
' der Code erneut generiert wird.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
|
||||
Namespace My
|
||||
|
||||
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.7.0.0"), _
|
||||
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
Partial Friend NotInheritable Class MySettings
|
||||
Inherits Global.System.Configuration.ApplicationSettingsBase
|
||||
|
||||
Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings)
|
||||
|
||||
#Region "Automatische My.Settings-Speicherfunktion"
|
||||
#If _MyType = "WindowsForms" Then
|
||||
Private Shared addedHandler As Boolean
|
||||
|
||||
Private Shared addedHandlerLockObject As New Object
|
||||
|
||||
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
Private Shared Sub AutoSaveSettings(sender As Global.System.Object, e As Global.System.EventArgs)
|
||||
If My.Application.SaveMySettingsOnExit Then
|
||||
My.Settings.Save()
|
||||
End If
|
||||
End Sub
|
||||
#End If
|
||||
#End Region
|
||||
|
||||
Public Shared ReadOnly Property [Default]() As MySettings
|
||||
Get
|
||||
|
||||
#If _MyType = "WindowsForms" Then
|
||||
If Not addedHandler Then
|
||||
SyncLock addedHandlerLockObject
|
||||
If Not addedHandler Then
|
||||
AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings
|
||||
addedHandler = True
|
||||
End If
|
||||
End SyncLock
|
||||
End If
|
||||
#End If
|
||||
Return defaultInstance
|
||||
End Get
|
||||
End Property
|
||||
End Class
|
||||
End Namespace
|
||||
|
||||
Namespace My
|
||||
|
||||
<Global.Microsoft.VisualBasic.HideModuleNameAttribute(), _
|
||||
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()> _
|
||||
Friend Module MySettingsProperty
|
||||
|
||||
<Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")> _
|
||||
Friend ReadOnly Property Settings() As Global.DigitalData.Modules.Database.My.MySettings
|
||||
Get
|
||||
Return Global.DigitalData.Modules.Database.My.MySettings.Default
|
||||
End Get
|
||||
End Property
|
||||
End Module
|
||||
End Namespace
|
||||
7
Database/My Project/Settings.settings
Normal file
7
Database/My Project/Settings.settings
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" UseMySettingsClassName="true">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)" />
|
||||
</Profiles>
|
||||
<Settings />
|
||||
</SettingsFile>
|
||||
17
Database/TableCache.vb
Normal file
17
Database/TableCache.vb
Normal file
@@ -0,0 +1,17 @@
|
||||
Public Class TableCache
|
||||
Private Items As New Dictionary(Of String, DataTable)
|
||||
|
||||
Public Function [Get](SQLCommand As String)
|
||||
Dim oKey As String = SQLCommand.ToUpper
|
||||
If Items.ContainsKey(oKey) Then
|
||||
Return Items.Item(oKey)
|
||||
Else
|
||||
|
||||
End If
|
||||
End Function
|
||||
|
||||
Private Function SaveTable()
|
||||
|
||||
End Function
|
||||
|
||||
End Class
|
||||
7
Database/packages.config
Normal file
7
Database/packages.config
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="EntityFramework" version="6.4.4" targetFramework="net461" />
|
||||
<package id="EntityFramework.Firebird" version="6.4.0" targetFramework="net461" />
|
||||
<package id="FirebirdSql.Data.FirebirdClient" version="7.5.0" targetFramework="net461" />
|
||||
<package id="NLog" version="4.7.15" targetFramework="net461" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user