TaskFlow/app/DD_PM_WINDREAM/ClassFinalIndex.vb
2019-04-16 14:01:35 +02:00

115 lines
4.1 KiB
VB.net

Public Class ClassFinalIndex
Public Const INDEX_TYPE_STRING = 1
Public Const INDEX_TYPE_INTEGER = 2
Public Const INDEX_TYPE_FLOAT = 3
Public Const INDEX_TYPE_BOOLEAN = 4
Public Const INDEX_TYPE_DATE = 5
Public Const INDEX_TYPE_VECTOR_INTEGER = 4107
Public Const INDEX_TYPE_VECTOR_STRING = 4097
Public Const INDEX_TYPE_VECTOR_BOOLEAN = 4100
Public Const INDEX_TYPE_VECTOR_DATE = 4101
Public Const PREFIX_VECTOR = "[%VKT"
Public Shared Function GetValue(obj As Object, indexName As String, indcies As List(Of String), types As List(Of Integer), isVector As Boolean)
Try
Dim props As FinalIndexProperties = obj
Dim i As Integer = indcies.IndexOf(indexName)
Dim type As Integer = types.Item(i)
Dim value As String = ""
If type = INDEX_TYPE_STRING Or type = INDEX_TYPE_VECTOR_STRING Then
value = props.StringValue
ElseIf type = INDEX_TYPE_INTEGER Or type = INDEX_TYPE_VECTOR_INTEGER Then
value = props.IntegerValue.ToString
ElseIf type = INDEX_TYPE_FLOAT Then
value = props.FloatValue.ToString
ElseIf type = INDEX_TYPE_BOOLEAN Or type = INDEX_TYPE_VECTOR_BOOLEAN Then
value = IIf(props.BoolValue, "1", "0")
End If
Return value
'If isVector Then
' Return $"{PREFIX_VECTOR}{value}"
'Else
' Return value
'End If
Catch ex As Exception
LOGGER.Error(ex)
MsgBox($"Error in GetValue: {ex.Message}", MsgBoxStyle.Critical)
End Try
End Function
Public Shared Function SetValue(value As String, obj As Object, indexName As String, indcies As List(Of String), types As List(Of Integer))
Try
Dim props As FinalIndexProperties = obj
Dim i As Integer = indcies.IndexOf(indexName)
If Not indcies.Contains(indexName) Then
Return obj
End If
Dim type As Integer = types.Item(i)
Dim isVector = value.StartsWith(PREFIX_VECTOR)
If isVector Then
value = value.Replace(PREFIX_VECTOR, String.Empty)
End If
props.VectorIndex = isVector
If type = INDEX_TYPE_STRING Or type = INDEX_TYPE_VECTOR_STRING Then
value = NotNull(value, "")
props.StringValue = value
ElseIf type = INDEX_TYPE_INTEGER Or type = INDEX_TYPE_VECTOR_INTEGER Then
value = NotNull(Of Integer)(value, 0)
If value = String.Empty Then
props.IntegerValue = 0
Else
props.IntegerValue = Integer.Parse(value)
End If
ElseIf type = INDEX_TYPE_FLOAT Then
value = NotNull(Of Double)(value, 0)
If value = String.Empty Then
props.FloatValue = 0
Else
props.FloatValue = Double.Parse(value)
End If
ElseIf type = INDEX_TYPE_BOOLEAN Or type = INDEX_TYPE_VECTOR_BOOLEAN Then
value = NotNull(value, "False")
If value = "1" Or value.ToLower = "true" Then
props.BoolValue = True
Else
props.BoolValue = False
End If
End If
Return props
Catch ex As Exception
LOGGER.Error(ex)
MsgBox($"Error in SetValue: {ex.Message}", MsgBoxStyle.Critical)
End Try
End Function
Public Shared Function IsVectorIndex(type As Integer) As Boolean
If type = INDEX_TYPE_VECTOR_BOOLEAN Or type = INDEX_TYPE_VECTOR_DATE Or type = INDEX_TYPE_VECTOR_INTEGER Or type = INDEX_TYPE_VECTOR_STRING Then
Return True
Else
Return False
End If
End Function
Public Shared Function GetIndexType(indexName As String, indicies As List(Of String), types As List(Of Integer))
Dim position As Integer = indicies.IndexOf(indexName)
Dim type As Integer = types.Item(position)
Return type
End Function
End Class