Add virtual property to field value, improve ui when loading files, improve initial loading
This commit is contained in:
@@ -6,6 +6,7 @@ Imports MultiTool.Common.Exceptions
|
||||
Imports MultiTool.Common.Templates
|
||||
Imports MultiTool.Common.Winline
|
||||
Imports MultiTool.Common.Winline.Entities
|
||||
Imports MultiTool.Common.Constants
|
||||
|
||||
Namespace Documents
|
||||
Public Class DocumentLoader
|
||||
@@ -16,12 +17,32 @@ Namespace Documents
|
||||
Private ReadOnly TemplateConfig As TemplateConfig
|
||||
|
||||
Public Property Files As New List(Of Document)
|
||||
Public Event FileLoadComplete As EventHandler(Of FileLoadInfo)
|
||||
|
||||
Public Structure FileLoadInfo
|
||||
Public Property FilesTotal As Integer = 0
|
||||
Public Property FilesLoaded As Integer = 0
|
||||
|
||||
Public Event FileLoadComplete As EventHandler(Of FileLoadInfo)
|
||||
Public Event FileLoadProgress As EventHandler(Of FileLoadProgressInfo)
|
||||
|
||||
Public Class FileLoadInfo
|
||||
Public FilesLoaded As Integer
|
||||
Public FilesTotal As Integer
|
||||
End Structure
|
||||
|
||||
Public Sub New(pTotal As Integer, pLoaded As Integer)
|
||||
FilesTotal = pTotal
|
||||
FilesLoaded = pLoaded
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Class FileLoadProgressInfo
|
||||
Inherits FileLoadInfo
|
||||
|
||||
Public RunningFunction As String
|
||||
|
||||
Public Sub New(pTotal As Integer, pLoaded As Integer)
|
||||
MyBase.New(pTotal, pLoaded)
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pWinline As WinlineData, pMappingConfig As MappingConfig, pTemplateConfig As TemplateConfig)
|
||||
MyBase.New(pLogConfig)
|
||||
@@ -37,6 +58,7 @@ Namespace Documents
|
||||
Try
|
||||
Dim oDirectory As New DirectoryInfo(pTemplate.InputDirectory)
|
||||
Dim oFiles = oDirectory.GetFiles()
|
||||
FilesTotal = oFiles.Count
|
||||
|
||||
Logger.Debug("Found [{0}] files in directory [{1}]", oFiles.Count, oDirectory)
|
||||
|
||||
@@ -44,11 +66,9 @@ Namespace Documents
|
||||
Try
|
||||
Dim oDocument = Await LoadFile(oFile, pTemplate, pMandator)
|
||||
Files.Add(oDocument)
|
||||
FilesLoaded = Files.Count
|
||||
|
||||
Dim oInfo As FileLoadInfo
|
||||
oInfo.FilesLoaded = Files.Count
|
||||
oInfo.FilesTotal = oFiles.Count
|
||||
|
||||
Dim oInfo As New FileLoadInfo(FilesTotal, FilesLoaded)
|
||||
RaiseEvent FileLoadComplete(Me, oInfo)
|
||||
|
||||
Catch ex As MissingAttributeException
|
||||
@@ -179,17 +199,19 @@ Namespace Documents
|
||||
.Final = oValue,
|
||||
.DataType = oColumn.DataType,
|
||||
.IsRequired = oRequired,
|
||||
.IsVirtual = oColumn.Config.IsVirtual,
|
||||
.SortKey = oColumnSortKey
|
||||
})
|
||||
Else
|
||||
Dim oColumnError = DocumentRow.FieldError.None
|
||||
Dim oColumnError = FieldError.None
|
||||
If oColumn.Config?.IsRequired Then
|
||||
oColumnError = DocumentRow.FieldError.MissingValue
|
||||
oColumnError = FieldError.MissingValue
|
||||
End If
|
||||
|
||||
oFields.Add(oColumn.Name, New DocumentRow.FieldValue With {
|
||||
.[Error] = oColumnError,
|
||||
.SortKey = oColumnSortKey
|
||||
.SortKey = oColumnSortKey,
|
||||
.IsVirtual = oColumn.Config.IsVirtual
|
||||
})
|
||||
End If
|
||||
|
||||
@@ -224,6 +246,9 @@ Namespace Documents
|
||||
OrderBy(Function(m) m.Order).
|
||||
ToList()
|
||||
|
||||
Dim oInfo As New FileLoadProgressInfo(FilesTotal, FilesLoaded) With {.RunningFunction = "Mandant finden"}
|
||||
RaiseEvent FileLoadProgress(Me, oInfo)
|
||||
|
||||
Dim oMandator As Mandator = Nothing
|
||||
If pMandator IsNot Nothing Then
|
||||
oMandator = pMandator
|
||||
@@ -237,12 +262,24 @@ Namespace Documents
|
||||
' Set mandator befor applying any functions that depend on a valid mandator
|
||||
pDocument.Mandator = oMandator
|
||||
|
||||
RaiseEvent FileLoadProgress(Me, New FileLoadProgressInfo(FilesTotal, FilesLoaded) With {
|
||||
.RunningFunction = "Winline-Funktionen"
|
||||
})
|
||||
|
||||
pDocument = ApplyDefinedItemFunctionsForImport(pDocument, oMandator, pTemplate)
|
||||
pDocument = ApplyDynamicItemFunctionsForImport(pDocument, oMandator)
|
||||
|
||||
RaiseEvent FileLoadProgress(Me, New FileLoadProgressInfo(FilesTotal, FilesLoaded) With {
|
||||
.RunningFunction = "Preis-Funktionen"
|
||||
})
|
||||
|
||||
' These functions will only be applied if the document does not have errors
|
||||
pDocument = Await MaybeApplyPriceFunctions(pDocument, oMandator, pTemplate)
|
||||
|
||||
RaiseEvent FileLoadProgress(Me, New FileLoadProgressInfo(FilesTotal, FilesLoaded) With {
|
||||
.RunningFunction = "Feld-Funktionen"
|
||||
})
|
||||
|
||||
' This function needs to be the last one because
|
||||
' it can relate to any previously set value
|
||||
ApplyFieldFunctionForImport(pDocument, oMandator, pTemplate)
|
||||
@@ -449,7 +486,7 @@ Namespace Documents
|
||||
|
||||
Dim oDocumentKindField As String = oFieldMap.GetOrDefault("DocumentKind", Nothing)
|
||||
Dim oDocumentKind As Integer = 0
|
||||
If Integer.TryParse(pDocument.GetFieldValue(oDocumentKindField), oDocumentKind) Then
|
||||
If Integer.TryParse(pDocument.GetFieldValue(oDocumentKindField), oDocumentKind) = False Then
|
||||
Logger.Warn("Value for parameter DocumentKind could not be parsed. Setting to 0.")
|
||||
End If
|
||||
|
||||
@@ -479,7 +516,7 @@ Namespace Documents
|
||||
oNumberItem.External = oArticleNumber
|
||||
oNumberItem.Final = oArticleNumber
|
||||
Else
|
||||
oNumberItem.Error = DocumentRow.FieldError.ArticleNotFound
|
||||
oNumberItem.Error = FieldError.ArticleNotFound
|
||||
End If
|
||||
End Sub
|
||||
|
||||
@@ -513,7 +550,7 @@ Namespace Documents
|
||||
'})
|
||||
End If
|
||||
Else
|
||||
oNumberItem.Error = DocumentRow.FieldError.AccountNotFound
|
||||
oNumberItem.Error = FieldError.AccountNotFound
|
||||
End If
|
||||
End Sub
|
||||
|
||||
|
||||
Reference in New Issue
Block a user