10 Commits

Author SHA1 Message Date
Jonathan Jenne
e156cc9d88 Interfaces: 1.10.5.1 2023-06-16 09:21:42 +02:00
Jonathan Jenne
cfef91059a Filesystem: 1.5.1.1 2023-06-16 09:21:08 +02:00
Jonathan Jenne
a4916ba25f EDMIAPI: Version 1.6.1.1 2023-06-16 09:20:48 +02:00
Jonathan Jenne
18374ba93d Database: Version 2.3.3.1 2023-06-16 09:20:23 +02:00
Jonathan Jenne
977f79b6a6 Base: Version 1.3.0.0 2023-06-16 09:20:01 +02:00
Jonathan Jenne
8c1a1af140 edmiapi: Improve error logging 2023-06-16 09:19:24 +02:00
Jonathan Jenne
36b38f0bd8 database: improve error loggging 2023-06-16 09:19:10 +02:00
Jonathan Jenne
c9c56ad720 Interfaces: Improve error logging 2023-06-16 09:18:48 +02:00
Jonathan Jenne
ab280ccabe File: attempt to fix GetVersionedFilenameWithFilecheck 2023-06-16 09:18:10 +02:00
Jonathan Jenne
b1114545a7 Add a lot of functions to Base 2023-06-16 09:16:49 +02:00
17 changed files with 384 additions and 19 deletions

View File

@@ -77,7 +77,12 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BaseClass.vb" />
<Compile Include="BaseUtils.vb" />
<Compile Include="DatabaseEx.vb" />
<Compile Include="ECM\ECM.vb" />
<Compile Include="ModuleExtensions.vb" />
<Compile Include="FileEx.vb" />
<Compile Include="ObjectEx.vb" />
<Compile Include="GraphicsEx.vb" />
<Compile Include="IDB\Attributes.vb" />
<Compile Include="IDB\Database.vb" />
@@ -101,6 +106,7 @@
</Compile>
<Compile Include="PerformanceEx.vb" />
<Compile Include="ScreenEx.vb" />
<Compile Include="StringEx.vb" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="My Project\Resources.resx">

7
Base/BaseUtils.vb Normal file
View File

@@ -0,0 +1,7 @@
Friend Class BaseUtils
Friend Shared Function FormatHash(pChecksum)
Return BitConverter.
ToString(pChecksum).
Replace("-", String.Empty)
End Function
End Class

16
Base/DatabaseEx.vb Normal file
View File

@@ -0,0 +1,16 @@
Public Class DatabaseEx
''' <summary>
''' Checks a Row value for three different `null` values,
''' Nothing, Empty String, DBNull
'''
''' Returns the original value if the value is not null, or `defaultValue`
''' </summary>
''' <typeparam name="T">The type of the value</typeparam>
''' <param name="Row">The DataRow that contains the value</param>
''' <param name="Column">The column name</param>
''' <param name="DefaultValue">The default value</param>
''' <returns>The original value or the default value</returns>
Public Shared Function NotNull(Of T)(ByVal Row As DataRow, Column As String, DefaultValue As T) As T
Return ObjectEx.NotNull(Row.Item(Column), DefaultValue)
End Function
End Class

26
Base/FileEx.vb Normal file
View File

@@ -0,0 +1,26 @@
Imports System.IO
Imports System.Security.Cryptography
Public Class FileEx
''' <summary>
''' Reads the file at `FilePath` and computes a SHA256 Hash from its contents
''' </summary>
''' <param name="pFilePath"></param>
''' <returns></returns>
Public Function GetChecksumFromFileContents(pFilePath As String) As String
Try
Using oFileStream = IO.File.OpenRead(pFilePath)
Using oStream As New BufferedStream(oFileStream, 1200000)
Dim oChecksum() As Byte = SHA256.Create.ComputeHash(oStream)
Return BaseUtils.FormatHash(oChecksum)
End Using
End Using
Catch ex As Exception
Return Nothing
End Try
End Function
Public Function GetHashFromFileContents(pFilePath As String) As String
Return GetChecksumFromFileContents(pFilePath)
End Function
End Class

101
Base/ModuleExtensions.vb Normal file
View File

@@ -0,0 +1,101 @@
Imports System.Runtime.CompilerServices
Public Module ModuleExtensions
Const UnixEraStartTicks As Long = 621355968000000000
' ======================================================
' === DATETIME
' ======================================================
<Extension()>
Public Function GetUnixTimestamp(pDate As Date) As Long
Dim UnixEraTicks = pDate.Ticks - UnixEraStartTicks
Return UnixEraTicks \ 10000
End Function
<Extension()>
Public Function DateFromUnix(pTimestamp As Long) As Date
Return New Date(UnixEraStartTicks + pTimestamp * 10000)
End Function
' ======================================================
' === STRING
' ======================================================
''' <summary>
''' Truncates a string to the specified length if it exceeds that length.
''' </summary>
''' <param name="pString">The string</param>
''' <param name="pLength">The maximum string length</param>
''' <returns>The truncated string</returns>
<Extension()>
Public Function Truncate(pString As String, pLength As Integer) As String
If String.IsNullOrEmpty(pString) Then Return pString
Return pString.Substring(0, Math.Min(pLength, pString.Length))
End Function
''' <summary>
''' Replaces single quotes in text for SQL Commands.
''' </summary>
''' <param name="pString">The string</param>
''' <returns>The escaped string.</returns>
<Extension()>
Public Function EscapeForSQL(pString As String) As String
Return ObjectEx.NotNull(pString, String.Empty).Replace("'", "''")
End Function
''' <summary>
''' Converts a string to boolean. Accepts true and 1 as truthy values
''' </summary>
''' <param name="pString">The input string</param>
''' <returns>True if input is true or 1, otherwise false.</returns>
<Extension()>
Public Function ToBoolean(pString As String) As Boolean
If String.IsNullOrEmpty(pString) Then Return False
Return (pString.Trim().ToLower() = "true") OrElse (pString.Trim() = "1")
End Function
' ======================================================
' === DATATABLE
' ======================================================
<Extension()>
Public Function ItemEx(Of T)(pRow As DataRow, pFieldName As String, Optional pDefaultValue As T = Nothing) As T
Try
Return ObjectEx.NotNull(pRow.Item(pFieldName), pDefaultValue)
Catch ex As Exception
Return Nothing
End Try
End Function
<Extension()>
Public Function ItemEx(Of T)(pRow As DataRow, pFieldIndex As Integer, Optional pDefaultValue As T = Nothing) As T
Try
Return ObjectEx.NotNull(pRow.Item(pFieldIndex), pDefaultValue)
Catch ex As Exception
Return Nothing
End Try
End Function
<Extension()>
Public Function FieldOrDefault(Of T)(pRow As DataRow, pFieldName As String, Optional pDefaultValue As T = Nothing) As T
Return ItemEx(pRow, pFieldName, pDefaultValue)
End Function
<Extension()>
Public Function FieldOrDefault(Of T)(pRow As DataRow, pFieldIndex As Integer, Optional pDefaultValue As T = Nothing) As T
Return ItemEx(pRow, pFieldIndex, pDefaultValue)
End Function
<Extension()>
Public Function First(pTable As DataTable) As DataRow
Try
If pTable Is Nothing OrElse pTable.Rows.Count = 0 Then
Return Nothing
End If
Return pTable.Rows.Item(0)
Catch ex As Exception
Return Nothing
End Try
End Function
End Module

View File

@@ -13,7 +13,7 @@ Imports System.Runtime.InteropServices
<Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("Base")>
<Assembly: AssemblyCopyright("Copyright © 2023")>
<Assembly: AssemblyTrademark("1.2.1.0")>
<Assembly: AssemblyTrademark("1.3.0.0")>
<Assembly: ComVisible(False)>
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' indem Sie "*" wie unten gezeigt eingeben:
' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.2.1.0")>
<Assembly: AssemblyFileVersion("1.2.1.0")>
<Assembly: AssemblyVersion("1.3.0.0")>
<Assembly: AssemblyFileVersion("1.3.0.0")>

46
Base/ObjectEx.vb Normal file
View File

@@ -0,0 +1,46 @@
Public Class ObjectEx
''' <summary>
''' Checks a value for three different `null` values,
''' Nothing, Empty String, DBNull
'''
''' Returns the original value if the value is not null, or `defaultValue`
''' </summary>
''' <typeparam name="T">The type of the value</typeparam>
''' <param name="value">The value</param>
''' <param name="defaultValue">The default Value</param>
''' <returns>The original value or the default value</returns>
Public Shared Function NotNull(Of T)(ByVal value As T, ByVal defaultValue As T) As T
If IsNothing(value) OrElse String.IsNullOrEmpty(value.ToString) OrElse IsDBNull(value) Then
Return defaultValue
Else
Return value
End If
End Function
''' <summary>
''' Converts a String value to the given Enum
''' </summary>
''' <typeparam name="T">The Enum Type</typeparam>
''' <param name="value">The string value to convert</param>
Public Shared Function ToEnum(Of T)(value As String) As T
Return [Enum].Parse(GetType(T), value)
End Function
''' <summary>
''' Converts an Integer value to the given Enum
''' </summary>
''' <typeparam name="T">The Enum Type</typeparam>
''' <param name="value">The integer value to convert</param>
Public Shared Function ToEnum(Of T)(value As Integer) As T
Return [Enum].ToObject(GetType(T), value)
End Function
''' <summary>
''' Converts a Long value to the given Enum
''' </summary>
''' <typeparam name="T">The Enum Type</typeparam>
''' <param name="value">The long value to convert</param>
Public Shared Function ToEnum(Of T)(value As Long) As T
Return [Enum].ToObject(GetType(T), value)
End Function
End Class

View File

@@ -45,4 +45,45 @@ Public Class ScreenEx
RestoreFormState(pForm, oFormState)
End Sub
''' <summary>
''' Checks if a point is Visible on any screen
''' </summary>
Public Shared Function IsVisibleOnAnyScreen(Location As Point) As Boolean
Try
Dim oRect As New Rectangle(Location, New Size(0, 0))
For Each oScreen In Screen.AllScreens
If oScreen.WorkingArea.IntersectsWith(oRect) Then
Return True
End If
Next
Return False
Catch ex As Exception
Return False
End Try
End Function
''' <summary>
''' Checks if Size is not negative
''' </summary>
Public Shared Function SizeIsVisible(Size As Size) As Boolean
If Size.Width >= 0 And Size.Height >= 0 Then
Return True
End If
Return False
End Function
''' <summary>
''' Checks if Location is not negative
''' </summary>
Public Shared Function LocationIsVisible(Location As Point) As Boolean
If Location.X >= 0 And Location.Y >= 0 Then
Return True
End If
Return False
End Function
End Class

116
Base/StringEx.vb Normal file

File diff suppressed because one or more lines are too long

View File

@@ -100,7 +100,6 @@ Public Class MSSQLServer
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")
@@ -115,7 +114,6 @@ Public Class MSSQLServer
End If
End Function
<DebuggerStepThrough()>
Private Function MaybeCommitTransaction(Transaction As SqlTransaction, TransactionMode As TransactionMode) As Boolean
Select Case TransactionMode
Case TransactionMode.NoTransaction
@@ -127,6 +125,7 @@ Public Class MSSQLServer
Transaction.Commit()
Return True
Catch ex As Exception
Logger.Warn("Error while committing transaction!")
Logger.Error(ex)
Return False
End Try

View File

@@ -13,7 +13,7 @@ Imports System.Runtime.InteropServices
<Assembly: AssemblyCompany("Digital Data")>
<Assembly: AssemblyProduct("Modules.Database")>
<Assembly: AssemblyCopyright("Copyright © 2023")>
<Assembly: AssemblyTrademark("2.3.3.0")>
<Assembly: AssemblyTrademark("2.3.3.1")>
<Assembly: ComVisible(False)>
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("2.3.3.0")>
<Assembly: AssemblyFileVersion("2.3.3.0")>
<Assembly: AssemblyVersion("2.3.3.1")>
<Assembly: AssemblyFileVersion("2.3.3.1")>

View File

@@ -203,15 +203,18 @@ Public Class DatabaseWithFallback
' If the table is not cached, we try going through the service
If Not IsTableCached(pDataTableName) Then
_Logger.Debug("Datatable is not chached, fetching data from service.")
Return GetDatatableFromService(pFallbackSQL, pFallbackType, pConnectionId)
End If
' If there is a proper ConnectionId, we try going through the service
If pConnectionId > 0 Then
_Logger.Debug("ConnectionId is set, fetching data from service.")
Return GetDatatableFromService(pFallbackSQL, pFallbackType, pConnectionId)
End If
Try
_Logger.Debug("Datatable is chached, fetching data from cache.")
oTableResult = _Client.GetDatatableByName(pDataTableName, pFilterExpression, pSortByColumn)
Catch ex As Exception
_Logger.Error(ex)

View File

@@ -13,7 +13,7 @@ Imports System.Runtime.InteropServices
<Assembly: AssemblyCompany("Digital Data")>
<Assembly: AssemblyProduct("EDMIAPI")>
<Assembly: AssemblyCopyright("Copyright © 2023")>
<Assembly: AssemblyTrademark("1.6.1.0")>
<Assembly: AssemblyTrademark("1.6.1.1")>
<Assembly: ComVisible(False)>
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.6.1.0")>
<Assembly: AssemblyFileVersion("1.6.1.0")>
<Assembly: AssemblyVersion("1.6.1.1")>
<Assembly: AssemblyFileVersion("1.6.1.1")>

View File

@@ -155,7 +155,7 @@ Public Class File
If pFilePath.Length > MAX_FILE_PATH_LENGTH Then
_Logger.Info("Filename is too long. Filename will be cut to prevent further errors.")
_Logger.Info("Original Filename is: {0}", oFileNameWithoutExtension)
Dim oNewLength As Integer = Math.Round(oFileNameWithoutExtension.Length / 2)
Dim oNewLength As Integer = CInt(Math.Floor(oFileNameWithoutExtension.Length / 2.0))
Dim oNewFileNameWithoutExtension = oFileNameWithoutExtension.Substring(0, oNewLength)
_Logger.Info("New Filename will be: {0}", oNewFileNameWithoutExtension)

View File

@@ -13,7 +13,7 @@ Imports System.Runtime.InteropServices
<Assembly: AssemblyCompany("Digital Data")>
<Assembly: AssemblyProduct("Modules.Filesystem")>
<Assembly: AssemblyCopyright("Copyright © 2023")>
<Assembly: AssemblyTrademark("1.5.1.0")>
<Assembly: AssemblyTrademark("1.5.1.1")>
<Assembly: ComVisible(False)>
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.5.1.0")>
<Assembly: AssemblyFileVersion("1.5.1.0")>
<Assembly: AssemblyVersion("1.5.1.1")>
<Assembly: AssemblyFileVersion("1.5.1.1")>

View File

@@ -13,7 +13,7 @@ Imports System.Runtime.InteropServices
<Assembly: AssemblyCompany("Digital Data")>
<Assembly: AssemblyProduct("Modules.Interfaces")>
<Assembly: AssemblyCopyright("Copyright © 2023")>
<Assembly: AssemblyTrademark("1.10.5.0")>
<Assembly: AssemblyTrademark("1.10.5.1")>
<Assembly: ComVisible(False)>
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.10.5.0")>
<Assembly: AssemblyFileVersion("1.10.5.0")>
<Assembly: AssemblyVersion("1.10.5.1")>
<Assembly: AssemblyFileVersion("1.10.5.1")>

View File

@@ -182,6 +182,7 @@ Public Class ZUGFeRDInterface
Throw ex
Catch ex As Exception
_logger.Warn("Error while validating ZUGFeRD file with GDPicture")
_logger.Error(ex)
Throw ex
End Try
@@ -210,6 +211,7 @@ Public Class ZUGFeRDInterface
Throw ex
Catch ex As Exception
_logger.Warn("Error while validating ZUGFeRD file with GDPicture")
_logger.Error(ex)
Throw ex
End Try
@@ -383,7 +385,9 @@ Public Class ZUGFeRDInterface
Catch ex As Exception
_logger.Debug("Serializing with type [{0}] failed", oTypeName)
_logger.Debug(ex.Message)
_logger.Error(ex.InnerException?.Message)
If IsNothing(ex.InnerException) = False Then
_logger.Debug(ex.InnerException.Message)
End If
End Try
Next