jj: oh my god /o\
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
Imports System.ComponentModel
|
||||
Imports System.IO
|
||||
Imports System.Timers
|
||||
Imports System.Xml.XPath
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Interfaces
|
||||
Imports DigitalData.Modules.Jobs
|
||||
Imports DigitalData.Modules.Jobs.ImportZUGFeRDFiles
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Public Class ThreadRunner
|
||||
@@ -11,14 +15,35 @@ Public Class ThreadRunner
|
||||
|
||||
Private _logConfig As LogConfig
|
||||
Private _logger As Logger
|
||||
Private _directories As List(Of String)
|
||||
Private _firebird As Firebird
|
||||
Private _watchDirectories As List(Of String)
|
||||
Private _successDirectory As String
|
||||
Private _errorDirectory As String
|
||||
Private _zugferd As ZUGFeRDInterface
|
||||
|
||||
Private Const TIMER_INTERVAL = 60_000
|
||||
|
||||
Public Sub New(LogConfig As LogConfig, Directories As List(Of String))
|
||||
Public Sub New(LogConfig As LogConfig, WatchDirectories As List(Of String), SuccessDirectory As String, ErrorDirectory As String)
|
||||
_logConfig = LogConfig
|
||||
_logger = _logConfig.GetLogger()
|
||||
_directories = Directories
|
||||
_watchDirectories = WatchDirectories
|
||||
_successDirectory = SuccessDirectory
|
||||
_errorDirectory = ErrorDirectory
|
||||
_zugferd = New ZUGFeRDInterface(_logConfig)
|
||||
|
||||
If Not Directory.Exists(SuccessDirectory) Then
|
||||
Throw New DirectoryNotFoundException("SuccessDirectory: " & SuccessDirectory)
|
||||
End If
|
||||
|
||||
If Not Directory.Exists(ErrorDirectory) Then
|
||||
Throw New DirectoryNotFoundException("ErrorDirectory: " & ErrorDirectory)
|
||||
End If
|
||||
|
||||
For Each oDirectory In WatchDirectories
|
||||
If Not Directory.Exists(oDirectory) Then
|
||||
Throw New DirectoryNotFoundException("WatchDirectory: " & oDirectory)
|
||||
End If
|
||||
Next
|
||||
|
||||
_workerThread = New BackgroundWorker() With {
|
||||
.WorkerReportsProgress = True,
|
||||
@@ -46,33 +71,21 @@ Public Class ThreadRunner
|
||||
|
||||
Private Sub TimerElapsed(sender As Object, e As ElapsedEventArgs) Handles _workerTimer.Elapsed
|
||||
If Not _workerThread.IsBusy Then
|
||||
_workerThread.RunWorkerAsync(_directories)
|
||||
_workerThread.RunWorkerAsync(New WorkerArgs() With {
|
||||
.WatchDirectories = _watchDirectories,
|
||||
.SuccessDirectory = _successDirectory,
|
||||
.ErrorDirectory = _errorDirectory
|
||||
})
|
||||
Else
|
||||
_logger.Warn("Worker is busy")
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub DoWork(sender As Object, e As DoWorkEventArgs) Handles _workerThread.DoWork
|
||||
Dim oDirectories As List(Of String) = e.Argument
|
||||
Dim args As WorkerArgs = e.Argument
|
||||
|
||||
For Each oPath As String In oDirectories
|
||||
Dim oDirInfo As New DirectoryInfo(oPath)
|
||||
|
||||
_logger.Info($"Processing directory {oDirInfo.FullName}..")
|
||||
|
||||
If oDirInfo.Exists Then
|
||||
Dim oFiles As List(Of FileInfo) = oDirInfo.GetFiles().ToList()
|
||||
Dim oFileCount = oFiles.Count
|
||||
Dim oCurrentFileCount = 0
|
||||
|
||||
For Each oFile In oFiles
|
||||
oCurrentFileCount += 1
|
||||
_logger.Info($"Processing file {oFile.FullName} (${oCurrentFileCount}/{oFileCount})")
|
||||
|
||||
ZUGFeRDInterface.ExtractXMLFile(oFile.FullName)
|
||||
Next
|
||||
End If
|
||||
Next
|
||||
Dim job As New ImportZUGFeRDFiles(_logConfig, _firebird)
|
||||
job.Start(args)
|
||||
End Sub
|
||||
Private Sub WorkProgress(sender As Object, e As ProgressChangedEventArgs) Handles _workerThread.ProgressChanged
|
||||
Throw New NotImplementedException()
|
||||
|
||||
Reference in New Issue
Block a user