This commit is contained in:
Jonathan Jenne
2018-12-18 17:32:51 +01:00
parent d33624c66c
commit 56fcedc309
6 changed files with 143 additions and 44 deletions

View File

@@ -22,7 +22,7 @@ Public Class ThreadRunner
Private _zugferd As ZUGFeRDInterface
Private _jobArguments As WorkerArgs
Private Const TIMER_INTERVAL_MS = 60_000
Private Const TIMER_INTERVAL_MS = 10_000
Public Sub New(LogConfig As LogConfig, Firebird As Firebird)
_logConfig = LogConfig
@@ -35,23 +35,23 @@ Public Class ThreadRunner
args = LoadPropertyMapFor(args, "DEFAULT")
_jobArguments = args
_logger.Info("Checking SuccessDirectory {0}", args.SuccessDirectory)
_logger.Debug("Checking SuccessDirectory {0}", args.SuccessDirectory)
If Not Directory.Exists(args.SuccessDirectory) Then
_logger.Warn("SuccessDirectory {0} does not exist!", args.SuccessDirectory)
'Throw New DirectoryNotFoundException("SuccessDirectory: " & args.SuccessDirectory)
End If
_logger.Info("Checking ErrorDirectory {0}", args.ErrorDirectory)
_logger.Debug("Checking ErrorDirectory {0}", args.ErrorDirectory)
If Not Directory.Exists(args.ErrorDirectory) Then
'Throw New DirectoryNotFoundException("ErrorDirectory: " & args.ErrorDirectory)
_logger.Warn("ErrorDirectory {0} does not exist!", args.ErrorDirectory)
'Throw New DirectoryNotFoundException("ErrorDirectory: " & args.ErrorDirectory)
End If
For Each oDirectory In args.WatchDirectories
_logger.Info("Checking WatchDirectory {0}", oDirectory)
_logger.Debug("Checking WatchDirectory {0}", oDirectory)
If Not Directory.Exists(oDirectory) Then
'Throw New DirectoryNotFoundException("WatchDirectory: " & oDirectory)
_logger.Warn("WatchDirectory {0} does not exist!", oDirectory)
'Throw New DirectoryNotFoundException("WatchDirectory: " & oDirectory)
End If
Next
@@ -60,14 +60,13 @@ Public Class ThreadRunner
.WorkerSupportsCancellation = True
}
_workerTimer = New Timer With {
.Interval = TIMER_INTERVAL_MS
}
_workerTimer = New Timer()
End Sub
Public Sub Start()
Public Sub Start(Interval As Integer)
_workerTimer.Interval = Interval * 1000
_workerTimer.Start()
_logger.Debug("ThreadRunner started.")
_logger.Debug("ThreadRunner started with {0}s Interval.", Interval)
End Sub
Public Sub [Stop]()
@@ -92,12 +91,17 @@ Public Class ThreadRunner
End Sub
Private Sub DoWork(sender As Object, e As DoWorkEventArgs) Handles _workerThread.DoWork
Dim args As WorkerArgs = e.Argument
Try
Dim args As WorkerArgs = e.Argument
_logger.Debug("Background worker running..")
_logger.Debug("Background worker running..")
Dim job As New ImportZUGFeRDFiles(_logConfig, _firebird)
job.Start(args)
Dim job As New ImportZUGFeRDFiles(_logConfig, _firebird)
job.Start(args)
Catch ex As Exception
_logger.Warn("Background worker failed!")
_logger.Error(ex)
End Try
End Sub
Private Sub WorkCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles _workerThread.RunWorkerCompleted
@@ -113,15 +117,12 @@ Public Class ThreadRunner
Select Case oFolderType
Case ZUGFERD_IN
_logger.Debug("Setting WatchDirectory: {0}", row.Item("FOLDER_PATH"))
args.WatchDirectories.Add(row.Item("FOLDER_PATH"))
Case ZUGFERD_SUCCESS
_logger.Debug("Setting SuccessDirectory: {0}", row.Item("FOLDER_PATH"))
args.SuccessDirectory = row.Item("FOLDER_PATH")
Case ZUGFERD_ERROR
_logger.Debug("Setting ErrorDirectory: {0}", row.Item("FOLDER_PATH"))
args.ErrorDirectory = row.Item("FOLDER_PATH")
End Select