This commit is contained in:
Jonathan Jenne 2022-01-21 15:51:14 +01:00
parent 408dacf1b5
commit 0fa654bda0
6 changed files with 64 additions and 27 deletions

View File

@ -65,7 +65,8 @@
<Import Include="System.Threading.Tasks" />
</ItemGroup>
<ItemGroup>
<Compile Include="NamedDatabase.vb" />
<Compile Include="Database\Enums.vb" />
<Compile Include="IDB\Database.vb" />
<Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Application.Designer.vb">
<AutoGen>True</AutoGen>

View File

@ -0,0 +1,8 @@
Namespace Database
Module Enums
Public Enum NamedDatabase
ECM
IDB
End Enum
End Module
End Namespace

View File

@ -0,0 +1,15 @@

Namespace IDB
''' <summary>
''' This module is intended for often used constants and datastructures
''' Therefor it is important that this module does not have any dependencies on other modules!!
''' </summary>
Module Constants
Public Const OBJECT_STATE_FILE_ADDED = "File added"
Public Const OBJECT_STATE_FILE_VERSIONED = "File versioned"
Public Const OBJECT_STATE_FILE_CHANGED = "File changed"
Public Const OBJECT_STATE_FILE_DELETED = "File deleted"
Public Const OBJECT_STATE_METADATA_CHANGED = "Metadata changed"
Public Const OBJECT_STATE_ATTRIBUTEVALUE_DELETED = "Attributevalue deleted"
End Module
End Namespace

View File

@ -1,10 +0,0 @@
''' <summary>
''' This module is intended for often used constants and datastructures
''' Therefor it is important that this module does not have any dependencies on other modules!!
''' </summary>
Namespace Constants
Public Enum NamedDatabase
ECM
IDB
End Enum
End Namespace

View File

@ -278,7 +278,7 @@ Public Class MSSQLServer
End Try
End Function
<DebuggerStepThrough()>
'<DebuggerStepThrough()>
Public Function GetDatatable(SqlCommand As String) As DataTable Implements IDatabase.GetDatatable
Return GetDatatable(SqlCommand, _Timeout)
End Function
@ -294,19 +294,19 @@ Public Class MSSQLServer
End Using
End Function
<DebuggerStepThrough()>
'<DebuggerStepThrough()>
Public Function GetDatatable(SqlCommand As String, Transaction As SqlTransaction, Optional Timeout As Integer = 120) As DataTable
Using oSqlConnection = GetSQLConnection()
Return GetDatatableWithConnectionObject(SqlCommand, oSqlConnection, TransactionMode.ExternalTransaction, Transaction, Timeout)
End Using
End Function
<DebuggerStepThrough()>
'<DebuggerStepThrough()>
Public Async Function GetDatatableAsync(SqlCommand As String, Optional Timeout As Integer = 120) As Task(Of DataTable)
Return Await Task.Run(Function() GetDatatable(SqlCommand, Timeout))
End Function
<DebuggerStepThrough()>
'<DebuggerStepThrough()>
Public Function GetDatatableWithConnection(SqlCommand As String, ConnectionString As String, Optional Timeout As Integer = 120) As DataTable
Using oConnection = GetConnection(ConnectionString)
Return GetDatatableWithConnectionObject(SqlCommand, oConnection, Timeout:=Timeout)
@ -342,33 +342,33 @@ Public Class MSSQLServer
Return oTable
End Function
<DebuggerStepThrough()>
'<DebuggerStepThrough()>
Public Function ExecuteNonQuery(SQLCommand As String) As Boolean Implements IDatabase.ExecuteNonQuery
Using oConnection = GetSQLConnection()
Return ExecuteNonQueryWithConnectionObject(SQLCommand, oConnection, TransactionMode.WithTransaction, Nothing, _Timeout)
End Using
End Function
<DebuggerStepThrough()>
'<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()>
'<DebuggerStepThrough()>
Public Function ExecuteNonQuery(SQLCommand As String, Transaction As SqlTransaction, Optional Timeout As Integer = 120) As Boolean
Using oConnection = GetSQLConnection()
Return ExecuteNonQueryWithConnectionObject(SQLCommand, Transaction.Connection, TransactionMode.ExternalTransaction, Transaction, Timeout)
End Using
End Function
<DebuggerStepThrough()>
'<DebuggerStepThrough()>
Public Async Function ExecuteNonQueryAsync(SQLCommand As String, Optional Timeout As Integer = 120) As Task(Of Boolean)
Return Await Task.Run(Function() ExecuteNonQuery(SQLCommand, Timeout))
End Function
<DebuggerStepThrough()>
'<DebuggerStepThrough()>
Public Function ExecuteNonQueryWithConnection(pSQLCommand As String, ConnString As String, Optional Timeout As Integer = 120) As Boolean
Using oConnection = GetConnection(ConnString)
Return ExecuteNonQueryWithConnectionObject(pSQLCommand, oConnection, TransactionMode.WithTransaction, Nothing, Timeout)
@ -399,33 +399,33 @@ Public Class MSSQLServer
End Try
End Function
<DebuggerStepThrough()>
'<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()>
'<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()>
'<DebuggerStepThrough()>
Public Function GetScalarValue(SQLCommand As String, Transaction As SqlTransaction, Optional Timeout As Integer = 120) As Object
Using oConnection = GetSQLConnection()
Return GetScalarValueWithConnectionObject(SQLCommand, oConnection, TransactionMode.ExternalTransaction, Transaction, Timeout)
End Using
End Function
<DebuggerStepThrough()>
'<DebuggerStepThrough()>
Public Async Function GetScalarValueAsync(SQLQuery As String, Optional Timeout As Integer = 120) As Task(Of Object)
Return Await Task.Run(Function() GetScalarValue(SQLQuery, Timeout))
End Function
<DebuggerStepThrough()>
'<DebuggerStepThrough()>
Public Function GetScalarValueWithConnection(SQLCommand As String, ConnectionString As String, Optional Timeout As Integer = 120) As Object
Using oConnection = GetConnection(ConnectionString)
Return GetScalarValueWithConnectionObject(SQLCommand, oConnection, TransactionMode.WithTransaction, Nothing, Timeout)
@ -490,7 +490,7 @@ Public Class MSSQLServer
End Try
End Function
<DebuggerStepThrough()>
'<DebuggerStepThrough()>
Public Function GetScalarValue(SQLCommand As SqlCommand, OutputParameter As String) As Object
Return GetScalarValue(SQLCommand, OutputParameter, _Timeout)
End Function
@ -521,7 +521,7 @@ Public Class MSSQLServer
End Try
End Sub
<DebuggerStepThrough()>
'<DebuggerStepThrough()>
Private Sub NewExecuteNonQueryAsync_Callback(ByVal result As IAsyncResult)
Dim command As SqlCommand = CType(result.AsyncState, SqlCommand)
Dim res = command.EndExecuteNonQuery(result)

View File

@ -75,6 +75,11 @@ Public Class File
Return oCleanName
End Function
''' <summary>
''' Reads the file at `FilePath` and computes a SHA256 Hash from its contents
''' </summary>
''' <param name="FilePath"></param>
''' <returns></returns>
Public Function GetChecksum(FilePath As String) As String
Try
Using oFileStream = IO.File.OpenRead(FilePath)
@ -339,6 +344,24 @@ Public Class File
End Try
End Function
''' <summary>
''' Checks if a file is locked, ie. in use by another process.
''' </summary>
''' <remarks>
''' https://docs.microsoft.com/en-us/dotnet/standard/io/handling-io-errors
''' </remarks>
Public Function TestFileIsLocked(pFilePath As String) As Boolean
Try
Using stream As FileStream = IO.File.Open(FileMode.Open, FileAccess.Read, FileShare.None)
stream.Close()
End Using
Catch ex As Exception When ((ex.HResult And &HFFFF) = 32)
Return True
End Try
Return False
End Function
Public Function TestPathIsDirectory(Path As String) As Boolean
If Not Directory.Exists(Path) Then
Return False