jj firebird
This commit is contained in:
@@ -20,62 +20,72 @@ Public Class ThreadRunner
|
||||
Private _successDirectory As String
|
||||
Private _errorDirectory As String
|
||||
Private _zugferd As ZUGFeRDInterface
|
||||
Private _jobArguments As WorkerArgs
|
||||
|
||||
Private Const TIMER_INTERVAL = 60_000
|
||||
Private Const TIMER_INTERVAL_MS = 60_000
|
||||
|
||||
Public Sub New(LogConfig As LogConfig, WatchDirectories As List(Of String), SuccessDirectory As String, ErrorDirectory As String)
|
||||
Public Sub New(LogConfig As LogConfig, Firebird As Firebird)
|
||||
_logConfig = LogConfig
|
||||
_logger = _logConfig.GetLogger()
|
||||
_watchDirectories = WatchDirectories
|
||||
_successDirectory = SuccessDirectory
|
||||
_errorDirectory = ErrorDirectory
|
||||
_firebird = Firebird
|
||||
_zugferd = New ZUGFeRDInterface(_logConfig)
|
||||
|
||||
If Not Directory.Exists(SuccessDirectory) Then
|
||||
Throw New DirectoryNotFoundException("SuccessDirectory: " & SuccessDirectory)
|
||||
Dim args As New WorkerArgs()
|
||||
args = LoadFolderConfig(args)
|
||||
args = LoadPropertyMapFor(args, "DEFAULT")
|
||||
_jobArguments = args
|
||||
|
||||
_logger.Info("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
|
||||
|
||||
If Not Directory.Exists(ErrorDirectory) Then
|
||||
Throw New DirectoryNotFoundException("ErrorDirectory: " & ErrorDirectory)
|
||||
_logger.Info("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)
|
||||
End If
|
||||
|
||||
For Each oDirectory In WatchDirectories
|
||||
For Each oDirectory In args.WatchDirectories
|
||||
_logger.Info("Checking WatchDirectory {0}", oDirectory)
|
||||
If Not Directory.Exists(oDirectory) Then
|
||||
Throw New DirectoryNotFoundException("WatchDirectory: " & oDirectory)
|
||||
'Throw New DirectoryNotFoundException("WatchDirectory: " & oDirectory)
|
||||
_logger.Warn("WatchDirectory {0} does not exist!", oDirectory)
|
||||
End If
|
||||
Next
|
||||
|
||||
_workerThread = New BackgroundWorker() With {
|
||||
.WorkerReportsProgress = True,
|
||||
.WorkerReportsProgress = False,
|
||||
.WorkerSupportsCancellation = True
|
||||
}
|
||||
|
||||
_workerTimer = New Timer With {
|
||||
.Interval = TIMER_INTERVAL
|
||||
.Interval = TIMER_INTERVAL_MS
|
||||
}
|
||||
End Sub
|
||||
|
||||
Public Sub Start()
|
||||
_workerTimer.Start()
|
||||
_logger.Info("ThreadRunner started.")
|
||||
_logger.Debug("ThreadRunner started.")
|
||||
End Sub
|
||||
|
||||
Public Sub [Stop]()
|
||||
If _workerThread.IsBusy Then
|
||||
_workerThread.CancelAsync()
|
||||
_logger.Info("Worker cancelled.")
|
||||
End If
|
||||
_workerTimer.Stop()
|
||||
_logger.Info("ThreadRunner stopped.")
|
||||
Try
|
||||
If _workerThread.IsBusy Then
|
||||
_workerThread.CancelAsync()
|
||||
_logger.Debug("Worker cancelled.")
|
||||
End If
|
||||
_workerTimer.Stop()
|
||||
_logger.Debug("ThreadRunner stopped.")
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Sub TimerElapsed(sender As Object, e As ElapsedEventArgs) Handles _workerTimer.Elapsed
|
||||
If Not _workerThread.IsBusy Then
|
||||
_workerThread.RunWorkerAsync(New WorkerArgs() With {
|
||||
.WatchDirectories = _watchDirectories,
|
||||
.SuccessDirectory = _successDirectory,
|
||||
.ErrorDirectory = _errorDirectory
|
||||
})
|
||||
_workerThread.RunWorkerAsync(_jobArguments)
|
||||
Else
|
||||
_logger.Warn("Worker is busy")
|
||||
End If
|
||||
@@ -84,14 +94,59 @@ Public Class ThreadRunner
|
||||
Private Sub DoWork(sender As Object, e As DoWorkEventArgs) Handles _workerThread.DoWork
|
||||
Dim args As WorkerArgs = e.Argument
|
||||
|
||||
_logger.Debug("Background worker running..")
|
||||
|
||||
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()
|
||||
End Sub
|
||||
|
||||
Private Sub WorkCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles _workerThread.RunWorkerCompleted
|
||||
Throw New NotImplementedException()
|
||||
_logger.Debug("Background worker completed!")
|
||||
End Sub
|
||||
|
||||
Private Function LoadFolderConfig(args As WorkerArgs)
|
||||
Dim oSQL As String = "SELECT T1.FOLDER_TYPE, T.FOLDER_PATH FROM TBEDM_FOLDER T, TBEDM_FOLDER_TYPE T1 WHERE T.FOLDER_TYPE_ID = T1.GUID AND T1.""ACTIVE"" = True AND T.""ACTIVE"" = True"
|
||||
Dim oResult As DataTable = _firebird.GetDatatable(oSQL)
|
||||
|
||||
For Each row As DataRow In oResult.Rows
|
||||
Dim oFolderType = row.Item("FOLDER_TYPE")
|
||||
|
||||
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
|
||||
Next
|
||||
|
||||
Return args
|
||||
End Function
|
||||
|
||||
Private Function LoadPropertyMapFor(args As WorkerArgs, specification As String)
|
||||
Dim oSQL As String = $"SELECT * FROM TBEDM_XML_ITEMS WHERE SPECIFICATION = '{specification}' AND ACTIVE = True"
|
||||
Dim oResult As DataTable = _firebird.GetDatatable(oSQL)
|
||||
|
||||
For Each row As DataRow In oResult.Rows
|
||||
Dim xmlPath = row.Item("XML_PATH")
|
||||
Dim tableName = row.Item("TABLE_NAME")
|
||||
Dim description = row.Item("DESCRIPTION")
|
||||
Dim isRequired = row.Item("IS_REQUIRED")
|
||||
|
||||
args.PropertyMap.Add(xmlPath, New XmlItemProperty() With {
|
||||
.Description = description,
|
||||
.TableName = tableName,
|
||||
.IsRequired = isRequired
|
||||
})
|
||||
Next
|
||||
|
||||
Return args
|
||||
End Function
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user