This commit is contained in:
Jonathan Jenne
2023-08-15 13:27:50 +02:00
parent 775418fb7a
commit ea8ed48d25
7 changed files with 101 additions and 18 deletions

View File

@@ -1,4 +1,5 @@
Imports System.IO
Imports System.Runtime.Remoting.Messaging
Imports System.Threading.Tasks
Imports DevExpress.DocumentView
Imports DigitalData.Modules.Base
@@ -12,14 +13,23 @@ Public MustInherit Class BaseModule
Friend ReadOnly Config As Config
Friend ReadOnly Database As MSSQLServer
Public Const DIVIDER_TEXT = "-------------------------------------"
Public Enum LogLevel
Info
Warn
[Error]
End Enum
Public MustOverride Property Name As String Implements ISync.Name
Public MustOverride Property IsLoggedIn As Boolean Implements ISync.IsLoggedIn
Public MustOverride Async Function Run() As Task Implements ISync.Run
Public MustOverride Function Cleanup() As Task Implements ISync.Cleanup
Public MustOverride Function TestConfigIsComplete() As Boolean Implements ISync.TestConfigIsComplete
Public Event OnLogEntry As EventHandler(Of String) Implements ISync.OnLogEntry
Public Event OnLogEntry As EventHandler(Of Tuple(Of String, LogLevel)) Implements ISync.OnLogEntry
Public Event OnFileProcessed As EventHandler(Of String) Implements ISync.OnFileProcessed
Public Event OnFileError As EventHandler(Of String) Implements ISync.OnFileError
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pConfig As Config)
MyBase.New(pLogConfig)
@@ -127,18 +137,25 @@ Public MustInherit Class BaseModule
End Function
Friend Sub AddInfoEntry(pMessage As String, ParamArray pArgs As Object())
RaiseEvent OnLogEntry(Me, String.Format(pMessage, pArgs))
RaiseEvent OnLogEntry(Me, New Tuple(Of String, LogLevel)(String.Format(pMessage, pArgs), LogLevel.Info))
End Sub
Friend Sub AddWarnEntry(pMessage As String, ParamArray pArgs As Object())
RaiseEvent OnLogEntry(Me, String.Format(pMessage, pArgs))
RaiseEvent OnLogEntry(Me, New Tuple(Of String, LogLevel)(String.Format(pMessage, pArgs), LogLevel.Warn))
End Sub
Friend Sub AddErrorEntry(pMessage As String, ParamArray pArgs As Object())
RaiseEvent OnLogEntry(Me, New Tuple(Of String, LogLevel)(String.Format(pMessage, pArgs), LogLevel.Error))
End Sub
Friend Sub AddDivider()
RaiseEvent OnLogEntry(Me, "---")
RaiseEvent OnLogEntry(Me, New Tuple(Of String, LogLevel)(DIVIDER_TEXT, LogLevel.Info))
End Sub
Friend Sub RaiseFileProcessed(pFilePath As String)
RaiseEvent OnFileProcessed(Me, pFilePath)
End Sub
Friend Sub RaiseFileError(pFilePath As String)
RaiseEvent OnFileError(Me, pFilePath)
End Sub
End Class

View File

@@ -7,6 +7,7 @@ Public Interface ISync
Function Cleanup() As Task
Function TestConfigIsComplete() As Boolean
Event OnLogEntry As EventHandler(Of String)
Event OnLogEntry As EventHandler(Of Tuple(Of String, BaseModule.LogLevel))
Event OnFileProcessed As EventHandler(Of String)
Event OnFileError As EventHandler(Of String)
End Interface

View File

@@ -51,11 +51,15 @@ Namespace Sharepoint
End If
Dim oSQL = String.Format(Config.SQLQueryExport, oDocument.Id, oFileName)
Await Database.ExecuteNonQueryAsync(oSQL)
RaiseFileProcessed(oFilePath)
If Await Database.ExecuteNonQueryAsync(oSQL) = True Then
RaiseFileProcessed(oFilePath)
Else
Throw New ApplicationException("Database entry could not be written!")
End If
Catch ex As Exception
RaiseFileError(oDocId)
Logger.Error(ex)
AddWarnEntry("Error while running Sync: " & ex.Message)
End Try

View File

@@ -63,11 +63,15 @@ Namespace slt
End If
Dim oSQL = String.Format(Config.SQLQueryExport, oDocument.ExtDocId, oFileName)
Await Database.ExecuteNonQueryAsync(oSQL)
RaiseFileProcessed(oFilePath)
If Await Database.ExecuteNonQueryAsync(oSQL) = True Then
RaiseFileProcessed(oFilePath)
Else
Throw New ApplicationException("Database entry could not be written!")
End If
Catch ex As Exception
RaiseFileError(oDocId)
Logger.Error(ex)
AddWarnEntry("Error while running Sync: " & ex.Message)
End Try