09-08-2023
This commit is contained in:
114
Connectors.Form/Modules/BaseModule.vb
Normal file
114
Connectors.Form/Modules/BaseModule.vb
Normal file
@@ -0,0 +1,114 @@
|
||||
Imports System.IO
|
||||
Imports System.Threading.Tasks
|
||||
Imports DevExpress.DocumentView
|
||||
Imports DigitalData.Modules.Base
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Public MustInherit Class BaseModule
|
||||
Inherits BaseClass
|
||||
Implements ISync
|
||||
|
||||
Friend ReadOnly Config As Config
|
||||
Friend ReadOnly Database As MSSQLServer
|
||||
|
||||
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 Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pConfig As Config)
|
||||
MyBase.New(pLogConfig)
|
||||
|
||||
Database = pDatabase
|
||||
Config = pConfig
|
||||
End Sub
|
||||
|
||||
Friend Async Function FetchDocIds() As Task(Of List(Of String))
|
||||
If Config.SQLQueryFetch = "" Then
|
||||
Logger.Warn("Fetch Query is not configured. Exiting.")
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Dim oTable As DataTable = Await Database.GetDatatableAsync(Config.SQLQueryFetch)
|
||||
|
||||
If oTable Is Nothing Then
|
||||
Logger.Warn("Error while fetching DocIds. Exiting")
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Dim oDocIds = oTable.Rows.
|
||||
Cast(Of DataRow).
|
||||
Select(Function(r) r.Item(0).ToString()).
|
||||
ToList()
|
||||
|
||||
AddInfoEntry("Found [{0}] files.", oDocIds.Count)
|
||||
Return oDocIds
|
||||
End Function
|
||||
|
||||
Friend Sub EnsureOutputDirectoryExists()
|
||||
Dim oOutputDirectory As String = Config.OutputDirectory
|
||||
|
||||
If Directory.Exists(oOutputDirectory) = False Then
|
||||
Throw New DirectoryNotFoundException($"Directory '{oOutputDirectory}' does not exist.")
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Friend Function CopyFileToOutputPath(pFileContents As Byte(), pFilePath As String) As Boolean
|
||||
Try
|
||||
Using oStream As New MemoryStream(pFileContents)
|
||||
Using oWriter As New FileStream(pFilePath, FileMode.Create)
|
||||
oStream.CopyTo(oWriter)
|
||||
Logger.Debug("File copied to document path [{0}]", pFilePath)
|
||||
End Using
|
||||
End Using
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function TestConfigIsCompleteBase() As Boolean
|
||||
Dim oComplete = True
|
||||
|
||||
If Config.ConnectionString = String.Empty Then
|
||||
AddWarnEntry("Configuration for 'ConnectionString' is empty.")
|
||||
oComplete = False
|
||||
End If
|
||||
|
||||
If Config.SQLQueryFetch = String.Empty Then
|
||||
AddWarnEntry("Configuration for 'SQLQueryFetch' is empty.")
|
||||
oComplete = False
|
||||
End If
|
||||
|
||||
If Config.SQLQueryExport = String.Empty Then
|
||||
AddWarnEntry("Configuration for 'SQLQueryExport' is empty.")
|
||||
oComplete = False
|
||||
End If
|
||||
|
||||
If Config.OutputDirectory = String.Empty Then
|
||||
AddWarnEntry("Configuration for 'OutputDirectory' is empty.")
|
||||
oComplete = False
|
||||
End If
|
||||
|
||||
Return oComplete
|
||||
End Function
|
||||
|
||||
Friend Sub AddInfoEntry(pMessage As String, ParamArray pArgs As Object())
|
||||
RaiseEvent OnLogEntry(Me, String.Format(pMessage, pArgs))
|
||||
End Sub
|
||||
|
||||
Friend Sub AddWarnEntry(pMessage As String, ParamArray pArgs As Object())
|
||||
RaiseEvent OnLogEntry(Me, String.Format(pMessage, pArgs))
|
||||
End Sub
|
||||
|
||||
Friend Sub AddDivider()
|
||||
RaiseEvent OnLogEntry(Me, "---")
|
||||
End Sub
|
||||
End Class
|
||||
Reference in New Issue
Block a user