WIP
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
Imports System.IO
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports ImporterShared.Schemas
|
||||
Imports ImporterShared.Winline
|
||||
|
||||
Namespace Documents
|
||||
Public Class DocumentLoader
|
||||
@@ -17,7 +18,7 @@ Namespace Documents
|
||||
End Sub
|
||||
|
||||
|
||||
Public Function LoadFiles(pInputDirectory As String, pSchema As Schema) As Boolean
|
||||
Public Function LoadFiles(pInputDirectory As String, pSchema As Schema, pMandator As Mandator) As Boolean
|
||||
If pInputDirectory = String.Empty Then
|
||||
Throw New ArgumentNullException("InputDirectory")
|
||||
End If
|
||||
@@ -32,7 +33,8 @@ Namespace Documents
|
||||
Logger.Debug("Found [{0}] files in directory [{1}]", oFiles.Count, oDirectory)
|
||||
|
||||
For Each oFile In oFiles
|
||||
Dim oDocument = LoadFile(oFile, pSchema)
|
||||
' TODO: Supply currently selected mandator when the mandator selection works
|
||||
Dim oDocument = LoadFile(oFile, pSchema, pMandator)
|
||||
Files.Add(oDocument)
|
||||
Next
|
||||
|
||||
@@ -40,12 +42,12 @@ Namespace Documents
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Throw New IOException($"Could not load files from directory {pInputDirectory}", ex)
|
||||
Throw ex
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function LoadFile(pFileInfo As FileInfo, pSchema As Schema) As Document
|
||||
Public Function LoadFile(pFileInfo As FileInfo, pSchema As Schema, pMandator As Mandator) As Document
|
||||
Dim oFileList As New List(Of FileInfo) From {pFileInfo}
|
||||
Logger.Info("Loading file [{0}]", pFileInfo.Name)
|
||||
|
||||
@@ -54,11 +56,11 @@ Namespace Documents
|
||||
Select(AddressOf WrapFileInfo).
|
||||
Select(Function(d) IncludeSchema(d, pSchema)).
|
||||
Select(Function(d) LoadDocumentData(d, pSchema)).
|
||||
Select(Function(d) MatchDataFromWinLine(d, Winline.Mandators)).
|
||||
Select(Function(d) MatchDataFromWinLine(d, Winline.Mandators, pMandator)).
|
||||
SingleOrDefault()
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
Throw ex
|
||||
End Try
|
||||
End Function
|
||||
|
||||
@@ -154,20 +156,26 @@ Namespace Documents
|
||||
End Function
|
||||
|
||||
|
||||
Private Function MatchDataFromWinLine(pDocument As Document, pMandators As List(Of Winline.Mandator)) As Document
|
||||
Private Function MatchDataFromWinLine(pDocument As Document, pMandators As List(Of Mandator), pMandator As Mandator) As Document
|
||||
Dim oMandators As List(Of Winline.Mandator) = pMandators.
|
||||
Where(Function(m) m.IsWhitelisted = True).
|
||||
OrderBy(Function(m) m.Order).
|
||||
ToList()
|
||||
|
||||
Dim oMandator = Winline.FindMatchingMandatorFromOrder(pDocument)
|
||||
Dim oMandator As Mandator = Nothing
|
||||
If pMandator IsNot Nothing Then
|
||||
oMandator = pMandator
|
||||
Else
|
||||
oMandator = Winline.FindMatchingMandatorFromOrder(pDocument)
|
||||
End If
|
||||
|
||||
If oMandator Is Nothing Then
|
||||
Logger.Warn("Mandator not found for File [{0}]", pDocument.File.Name)
|
||||
Throw New Exceptions.NoMandatorException($"Mandator not found for file [{pDocument.File.Name}]")
|
||||
End If
|
||||
|
||||
pDocument = MatchDocumentData(pDocument, oMandator)
|
||||
pDocument.Mandator = oMandator.Id
|
||||
pDocument.Mandator = oMandator
|
||||
|
||||
Return pDocument
|
||||
End Function
|
||||
|
||||
Reference in New Issue
Block a user