improve logging of missing/incorrectly configured properties
This commit is contained in:
parent
f5febac0e1
commit
9b17c1fbcb
@ -185,6 +185,7 @@ Public Class ImportZUGFeRDFiles
|
|||||||
|
|
||||||
Public Sub Start(Arguments As Object) Implements IJob.Start
|
Public Sub Start(Arguments As Object) Implements IJob.Start
|
||||||
Dim args As WorkerArgs = Arguments
|
Dim args As WorkerArgs = Arguments
|
||||||
|
Dim oPropertyExtractor = New PropertyValues(_logConfig)
|
||||||
|
|
||||||
_logger.Info("Starting Job {0}", [GetType].Name)
|
_logger.Info("Starting Job {0}", [GetType].Name)
|
||||||
|
|
||||||
@ -308,7 +309,7 @@ Public Class ImportZUGFeRDFiles
|
|||||||
|
|
||||||
' get properties as a nested object, see `oPropertyList`
|
' get properties as a nested object, see `oPropertyList`
|
||||||
For Each oProperty As KeyValuePair(Of String, XmlItemProperty) In oGroup
|
For Each oProperty As KeyValuePair(Of String, XmlItemProperty) In oGroup
|
||||||
Dim oPropertyValues As List(Of Object) = PropertyValues.GetPropValue(oDocument, oProperty.Key)
|
Dim oPropertyValues As List(Of Object) = oPropertyExtractor.GetPropValue(oDocument, oProperty.Key)
|
||||||
|
|
||||||
oPropertyList.Add(oProperty.Value, oPropertyValues)
|
oPropertyList.Add(oProperty.Value, oPropertyValues)
|
||||||
|
|
||||||
@ -328,7 +329,8 @@ Public Class ImportZUGFeRDFiles
|
|||||||
Dim oColumnIsEmpty = False
|
Dim oColumnIsEmpty = False
|
||||||
|
|
||||||
For Each oRow In oPropertyList
|
For Each oRow In oPropertyList
|
||||||
Dim oValue As List(Of Object) = oRow.Value.Item(oRowIndex)
|
Dim oValue As List(Of Object) = oRow.Value
|
||||||
|
'Dim oValue As List(Of Object) = oRow.Value.Item(oRowIndex)
|
||||||
oColumnIsEmpty = oValue.Count = 0
|
oColumnIsEmpty = oValue.Count = 0
|
||||||
Next
|
Next
|
||||||
|
|
||||||
@ -416,7 +418,7 @@ Public Class ImportZUGFeRDFiles
|
|||||||
|
|
||||||
' Iterate through default properties
|
' Iterate through default properties
|
||||||
For Each Item As KeyValuePair(Of String, XmlItemProperty) In oDefaultProperties
|
For Each Item As KeyValuePair(Of String, XmlItemProperty) In oDefaultProperties
|
||||||
Dim oPropertyValueList As List(Of Object) = PropertyValues.GetPropValue(oDocument, Item.Key)
|
Dim oPropertyValueList As List(Of Object) = oPropertyExtractor.GetPropValue(oDocument, Item.Key)
|
||||||
Dim oPropertyDescription As String = Item.Value.Description
|
Dim oPropertyDescription As String = Item.Value.Description
|
||||||
Dim oPropertyValue As Object = Nothing
|
Dim oPropertyValue As Object = Nothing
|
||||||
|
|
||||||
@ -428,6 +430,12 @@ Public Class ImportZUGFeRDFiles
|
|||||||
oPropertyValue = Nothing
|
oPropertyValue = Nothing
|
||||||
Case Else
|
Case Else
|
||||||
oPropertyValue = oPropertyValueList.First()
|
oPropertyValue = oPropertyValueList.First()
|
||||||
|
|
||||||
|
' This should hopefully show config errors
|
||||||
|
If TypeOf oPropertyValue Is List(Of Object) Then
|
||||||
|
_logger.Warn("Property with Description {0} may be configured incorrectly", oPropertyDescription)
|
||||||
|
oPropertyValue = Nothing
|
||||||
|
End If
|
||||||
End Select
|
End Select
|
||||||
End If
|
End If
|
||||||
|
|
||||||
|
|||||||
@ -1,20 +1,36 @@
|
|||||||
Imports System.Collections.Generic
|
Imports System.Collections.Generic
|
||||||
Imports System.Reflection
|
Imports System.Reflection
|
||||||
Imports System.Text.RegularExpressions
|
Imports System.Text.RegularExpressions
|
||||||
|
Imports DigitalData.Modules.Logging
|
||||||
|
|
||||||
Public Class PropertyValues
|
Public Class PropertyValues
|
||||||
Private Shared _indexPattern = "\((\d+)\)"
|
Private _indexPattern = "\((\d+)\)"
|
||||||
Private Shared _indexRegex As New Regex(_indexPattern)
|
Private _indexRegex As New Regex(_indexPattern)
|
||||||
|
Private _Logger As Logger
|
||||||
|
|
||||||
Public Shared Function GetPropValue(Obj As Object, PropertyName As String) As List(Of Object)
|
Public Sub New(LogConfig As LogConfig)
|
||||||
|
_Logger = LogConfig.GetLogger()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Public Function GetPropValue(Obj As Object, PropertyName As String) As List(Of Object)
|
||||||
Dim oNameParts As String() = PropertyName.Split("."c)
|
Dim oNameParts As String() = PropertyName.Split("."c)
|
||||||
|
|
||||||
If IsNothing(Obj) Then
|
If IsNothing(Obj) Then
|
||||||
|
_Logger.Debug("`Obj` is Nothing. Exiting.")
|
||||||
Return New List(Of Object)
|
Return New List(Of Object)
|
||||||
End If
|
End If
|
||||||
|
|
||||||
|
|
||||||
If oNameParts.Length = 1 Then
|
If oNameParts.Length = 1 Then
|
||||||
Return Obj.GetType().GetProperty(PropertyName).GetValue(Obj, Nothing)
|
Dim oPropInfo As PropertyInfo = Obj.GetType().GetProperty(PropertyName)
|
||||||
|
|
||||||
|
If IsNothing(oPropInfo) Then
|
||||||
|
_Logger.Debug("Property {0} does not exist.", PropertyName)
|
||||||
|
Return New List(Of Object)
|
||||||
|
Else
|
||||||
|
Dim oPropValue = oPropInfo.GetValue(Obj, Nothing)
|
||||||
|
Return New List(Of Object) From {oPropValue}
|
||||||
|
End If
|
||||||
End If
|
End If
|
||||||
|
|
||||||
For Each oPart As String In oNameParts
|
For Each oPart As String In oNameParts
|
||||||
@ -30,11 +46,8 @@ Public Class PropertyValues
|
|||||||
|
|
||||||
Dim oInfo As PropertyInfo = oType.GetProperty(oPartName)
|
Dim oInfo As PropertyInfo = oType.GetProperty(oPartName)
|
||||||
|
|
||||||
If IsNothing(oInfo) Then
|
If IsNothing(oInfo) OrElse IsNothing(oInfo.GetValue(Obj, Nothing)) Then
|
||||||
Return New List(Of Object)
|
_Logger.Debug("Property {0} does not exist.", oPartName)
|
||||||
End If
|
|
||||||
|
|
||||||
If IsNothing(oInfo.GetValue(Obj, Nothing)) Then
|
|
||||||
Return New List(Of Object)
|
Return New List(Of Object)
|
||||||
End If
|
End If
|
||||||
|
|
||||||
@ -56,7 +69,11 @@ Public Class PropertyValues
|
|||||||
End If
|
End If
|
||||||
|
|
||||||
For Each oArrayItem In Obj
|
For Each oArrayItem In Obj
|
||||||
Dim oResult = GetPropValue(oArrayItem, oPathFragments(1))
|
Dim oResult As List(Of Object) = GetPropValue(oArrayItem, oPathFragments(1))
|
||||||
|
|
||||||
|
'If Not IsNothing(oResult) AndAlso oResult.Count > 0 Then
|
||||||
|
' oResults.Add(oResult.Item(0))
|
||||||
|
'End If
|
||||||
|
|
||||||
If Not IsNothing(oResult) Then
|
If Not IsNothing(oResult) Then
|
||||||
oResults.Add(oResult)
|
oResults.Add(oResult)
|
||||||
@ -70,7 +87,7 @@ Public Class PropertyValues
|
|||||||
Return New List(Of Object) From {Obj}
|
Return New List(Of Object) From {Obj}
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Shared Function GetIndex(Prop As String) As Integer
|
Private Function GetIndex(Prop As String) As Integer
|
||||||
If Regex.IsMatch(Prop, _indexPattern) Then
|
If Regex.IsMatch(Prop, _indexPattern) Then
|
||||||
Dim oMatch = _indexRegex.Match(Prop)
|
Dim oMatch = _indexRegex.Match(Prop)
|
||||||
Dim oGroup = oMatch.Groups.Item(1)
|
Dim oGroup = oMatch.Groups.Item(1)
|
||||||
@ -82,11 +99,11 @@ Public Class PropertyValues
|
|||||||
Return Nothing
|
Return Nothing
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Shared Function StripIndex(Prop As String) As String
|
Private Function StripIndex(Prop As String) As String
|
||||||
Return Regex.Replace(Prop, _indexPattern, "")
|
Return Regex.Replace(Prop, _indexPattern, "")
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Shared Function HasIndex(Prop As String) As Boolean
|
Private Function HasIndex(Prop As String) As Boolean
|
||||||
Return Regex.IsMatch(Prop, _indexPattern)
|
Return Regex.IsMatch(Prop, _indexPattern)
|
||||||
End Function
|
End Function
|
||||||
End Class
|
End Class
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user