Add RegexEditor, Improve Database Add Language

This commit is contained in:
Jonathan Jenne
2019-08-08 16:42:38 +02:00
parent f418074011
commit c9e0d8cec1
33 changed files with 1384 additions and 124 deletions

View File

@@ -1,35 +1,53 @@
Imports Oracle.ManagedDataAccess.Client
Imports DigitalData.Modules.Logging
Imports Oracle.ManagedDataAccess.Client
Public Class Oracle
Private Shared Logger As NLog.Logger = NLog.LogManager.GetCurrentClassLogger
Public DBInitialized As Boolean = False
Public CurrentOracleConnectionString As String = ""
Public Sub New(CONSTRING As String)
Init(CONSTRING)
Private _Timeout As Integer
Private _Logger As Logger
Public Sub New(LogConfig As LogConfig, ConnectionString As String, Optional Timeout As Integer = 120)
_Timeout = Timeout
_Logger = LogConfig.GetLogger()
CurrentOracleConnectionString = ConnectionString
DBInitialized = TestCanConnect(CurrentOracleConnectionString)
End Sub
Public Function Init(CONSTRING As String)
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()
CurrentOracleConnectionString = GetConnectionString(Server, Database, UserId, Password)
DBInitialized = TestCanConnect(CurrentOracleConnectionString)
End Sub
Private Function TestCanConnect(ConnectionString As String) As Boolean
Try
Dim oSQLconnect As New OracleConnection
oSQLconnect.ConnectionString = CONSTRING
oSQLconnect.ConnectionString = ConnectionString
oSQLconnect.Open()
oSQLconnect.Close()
CurrentOracleConnectionString = CONSTRING
DBInitialized = True
Return True
Catch ex As Exception
DBInitialized = False
Logger.Error(ex)
'clsLogger.Add("Error in DatabaseInit: " & ex.Message, True)
_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>
''' Returns a datatable for a sql-statement
''' </summary>
''' <param name="sqlcommand">sqlcommand for datatable (select XYZ from TableORView)</param>
''' <param name="commandtimeout">Optional Timeout</param>
''' <returns>Returns a datatable</returns>
''' <remarks></remarks>
Public Function GetDatatable(sqlcommand As String, Optional commandtimeout As Integer = 120) As DataTable
Public Function GetDatatable(sqlcommand As String) As DataTable
Try
Dim oSQLconnect As New OracleConnection
Dim oSQLCOmmand As OracleCommand
@@ -37,15 +55,15 @@ Public Class Oracle
oSQLconnect.Open()
oSQLCOmmand = oSQLconnect.CreateCommand()
oSQLCOmmand.CommandText = sqlcommand
oSQLCOmmand.CommandTimeout = commandtimeout
oSQLCOmmand.CommandTimeout = _Timeout
Dim adapter1 As OracleDataAdapter = New OracleDataAdapter(oSQLCOmmand)
Dim dt As DataTable = New DataTable()
adapter1.Fill(dt)
oSQLconnect.Close()
Return dt
Catch ex As Exception
Logger.Error(ex)
Logger.Debug("sqlcommand: " & sqlcommand)
_Logger.Error(ex)
_Logger.Debug("sqlcommand: " & sqlcommand)
Return Nothing
End Try
End Function
@@ -53,10 +71,8 @@ Public Class Oracle
''' Executes the passed sql-statement
''' </summary>
''' <param name="executeStatement">the sql statement</param>
''' <param name="commandtimeout">Optional Timeout</param>
''' <returns>Returns true if properly executed, else false</returns>
''' <remarks></remarks>
Public Function NewExecutenonQuery(executeStatement As String, Optional commandtimeout As Integer = 120) As Boolean
Public Function NewExecutenonQuery(executeStatement As String) As Boolean
Try
Dim oSQLconnect As New OracleConnection
Dim oSQLCOmmand As OracleCommand
@@ -64,55 +80,24 @@ Public Class Oracle
oSQLconnect.Open()
oSQLCOmmand = oSQLconnect.CreateCommand()
oSQLCOmmand.CommandText = executeStatement
oSQLCOmmand.CommandTimeout = commandtimeout
oSQLCOmmand.CommandTimeout = _Timeout
oSQLCOmmand.ExecuteNonQuery()
oSQLCOmmand.Dispose()
oSQLconnect.Close()
Return True
Catch ex As Exception
Logger.Error(ex)
Logger.Debug("executeStatement: " & executeStatement)
_Logger.Error(ex)
_Logger.Debug("executeStatement: " & executeStatement)
Return False
End Try
End Function
''' <summary>
''' Executes the passed sql-statement in asyncmode
''' </summary>
''' <param name="executeStatement">the sql statement</param>
''' <param name="commandtimeout">Optional Timeout</param>
''' <remarks></remarks>
Public Sub NewExecuteNonQueryAsync(executeStatement As String, Optional commandtimeout As Integer = 120)
Dim oSQLconnect As New OracleConnection
Dim oSQLCOmmand As OracleCommand
Dim callback As New AsyncCallback(AddressOf Execute_non_Query_Async_Callback)
Try
oSQLconnect.ConnectionString = CurrentOracleConnectionString
oSQLconnect.Open()
oSQLCOmmand = oSQLconnect.CreateCommand()
oSQLCOmmand.CommandText = executeStatement
oSQLCOmmand.CommandTimeout = commandtimeout
oSQLCOmmand.ExecuteNonQuery()
oSQLCOmmand.Dispose()
oSQLconnect.Close()
Catch ex As Exception
Logger.Error(ex)
Logger.Debug("executeStatement: " & executeStatement)
End Try
End Sub
Private Sub Execute_non_Query_Async_Callback(ByVal result As IAsyncResult)
Dim command As OracleCommand = CType(result.AsyncState, OracleCommand)
Dim res = command.ExecuteNonQuery
Logger.Info(String.Format("Finished executing Async database operation: {0}", command.CommandText))
End Sub
''' <summary>
''' Executes the passed sql-statement as Scalar
''' </summary>
''' <param name="executeStatement">the sql statement</param>
''' <param name="commandtimeout">Optional Timeout</param>
''' <returns>Returns true if properly executed, else false</returns>
''' <remarks></remarks>
Public Function NewExecuteScalar(executeStatement As String, Optional commandtimeout As Integer = 120)
''' <returns>Returns the scalarvalue</returns>
Public Function NewExecuteScalar(executeStatement As String)
Dim result
Try
Dim oSQLconnect As New OracleConnection
@@ -121,15 +106,15 @@ Public Class Oracle
oSQLconnect.Open()
oSQLCOmmand = oSQLconnect.CreateCommand()
oSQLCOmmand.CommandText = executeStatement
oSQLCOmmand.CommandTimeout = commandtimeout
oSQLCOmmand.CommandTimeout = _Timeout
result = oSQLCOmmand.ExecuteScalar()
oSQLCOmmand.Dispose()
oSQLconnect.Close()
Return result
Catch ex As Exception
Logger.Error(ex)
Logger.Debug("executeStatement: " & executeStatement)
Return Nothing
_Logger.Error(ex)
_Logger.Debug("executeStatement: " & executeStatement)
Throw ex
End Try
End Function
End Class