jj: add SetFileIndex, Convert Index Value
This commit is contained in:
@@ -129,6 +129,177 @@ Public Class Windream2
|
||||
_sessionDomain = SessionDomain
|
||||
End Sub
|
||||
|
||||
Public Function GetChoiceListItems(ChoiceListName As String) As List(Of String)
|
||||
Dim oItems As New List(Of String)
|
||||
Dim oChoicelist As WMObject
|
||||
|
||||
If TestSessionLoggedIn() = False Then
|
||||
Return oItems
|
||||
End If
|
||||
|
||||
Try
|
||||
oChoicelist = Session.GetWMObjectByName(WMEntityChoiceList, ChoiceListName)
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex, "Could not get choice list")
|
||||
Return oItems
|
||||
End Try
|
||||
|
||||
Try
|
||||
Dim oChoiceListItems As Object = oChoicelist.GetVariableValue("vItems")
|
||||
|
||||
If oChoiceListItems Is Nothing Then
|
||||
Return oItems
|
||||
End If
|
||||
|
||||
For Each oChoiceListItem In oChoiceListItems
|
||||
oItems.Add(oChoiceListItem)
|
||||
Next
|
||||
|
||||
Return oItems
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex, "Could not get choice list items")
|
||||
Return oItems
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function GetChoiceLists() As List(Of String)
|
||||
Dim oItems As New List(Of String)
|
||||
|
||||
If TestSessionLoggedIn() = False Then
|
||||
Return oItems
|
||||
End If
|
||||
|
||||
Try
|
||||
Dim oChoiceLists As WMObjects
|
||||
Dim oChoiceList As IWMObject2
|
||||
'load list of choicelists
|
||||
oChoiceLists = Session.GetAllObjects(WMEntityChoiceList)
|
||||
|
||||
For Each oChoiceList In oChoiceLists
|
||||
oItems.Add(oChoiceList.aName)
|
||||
Next
|
||||
|
||||
Return oItems
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return oItems
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function GetFileByPath(Path As String) As WMObject
|
||||
If TestSessionLoggedIn() = False Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Dim oWMObject As WMObject
|
||||
|
||||
Try
|
||||
oWMObject = Session.GetWMObjectByPath(WMEntityDocument, Path)
|
||||
Return oWMObject
|
||||
Catch ex As Exception
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function GetIndexType(IndexName As String) As Integer
|
||||
If TestSessionLoggedIn() = False Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Try
|
||||
Dim oAttribute = Session.GetWMObjectByName(WMEntityAttribute, IndexName)
|
||||
Dim oType = oAttribute.GetVariableValue("dwAttrType")
|
||||
Return oType
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function GetIndexValue(Path As String, IndexName As String) As List(Of String)
|
||||
Dim oResult As New List(Of String)
|
||||
|
||||
If TestSessionLoggedIn() = False Then
|
||||
Return oResult
|
||||
End If
|
||||
|
||||
Try
|
||||
Path = GetNormalizedPath(Path)
|
||||
Dim oWMObject As WMObject = Session.GetWMObjectByPath(WMEntityDocument, Path)
|
||||
|
||||
If oWMObject Is Nothing Then
|
||||
Return oResult
|
||||
End If
|
||||
|
||||
Dim oValues = oWMObject.GetVariableValue(IndexName)
|
||||
|
||||
If oValues Is Nothing Then
|
||||
Return oResult
|
||||
End If
|
||||
|
||||
If TypeOf oValues Is IEnumerable Then
|
||||
For Each oValue In oValues
|
||||
oResult.Add(oValue)
|
||||
Next
|
||||
Else
|
||||
oResult.Add(oValues)
|
||||
End If
|
||||
|
||||
Return oResult
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return oResult
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function GetIndiciesByObjecttype(ObjectTypeName As String) As List(Of String)
|
||||
If TestSessionLoggedIn() = False Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Dim oObjectType As WMObject
|
||||
Dim oIndexAttributes As WMObjectRelation
|
||||
Dim oIndexAttribute As WMObject
|
||||
Dim oIndex As WMObject
|
||||
Dim oRelProperties As WMObjectRelation
|
||||
Dim oTempSession As IWMSession2
|
||||
Dim oIndicies As New List(Of String)
|
||||
|
||||
Try
|
||||
' den Objekttyp laden
|
||||
oTempSession = DirectCast(Session, IWMSession2)
|
||||
oObjectType = Session.GetWMObjectByName(WMEntityObjectType, ObjectTypeName)
|
||||
|
||||
' Beziehung zu Indizes des Objekttyp auslesen
|
||||
oIndexAttributes = oObjectType.GetWMObjectRelationByName("TypeAttributes")
|
||||
|
||||
' alle Indizes durchlaufen
|
||||
For j As Integer = 0 To oIndexAttributes.Count - 1
|
||||
|
||||
' aktuellen Index auslesen
|
||||
oIndexAttribute = oIndexAttributes.Item(j)
|
||||
|
||||
' Eigenschaften des Index auslesen
|
||||
oRelProperties = oIndexAttribute.GetWMObjectRelationByName("Attribute")
|
||||
|
||||
' Index aus den Eigenschaften auslesen
|
||||
oIndex = oRelProperties.Item(0)
|
||||
|
||||
' Indexname speichern
|
||||
'aIndexNames(j) = oIndex.aName
|
||||
oIndicies.Add(oIndex.aName)
|
||||
Next
|
||||
|
||||
' Indexarray zurückgeben
|
||||
'Return aIndexNames
|
||||
Return oIndicies
|
||||
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return oIndicies
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function NewSession(Optional ServerName As String = Nothing, Optional UserName As String = Nothing, Optional Password As String = Nothing, Optional Domain As String = Nothing) As IWMSession2
|
||||
Dim oBrowser As ServerBrowser
|
||||
Dim oConnect As IWMConnect2
|
||||
@@ -535,161 +706,13 @@ Public Class Windream2
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function GetChoiceLists() As List(Of String)
|
||||
Dim oItems As New List(Of String)
|
||||
|
||||
If TestSessionLoggedIn() = False Then
|
||||
Return oItems
|
||||
End If
|
||||
|
||||
Try
|
||||
Dim oChoiceLists As WMObjects
|
||||
Dim oChoiceList As IWMObject2
|
||||
'load list of choicelists
|
||||
oChoiceLists = Session.GetAllObjects(WMEntityChoiceList)
|
||||
|
||||
For Each oChoiceList In oChoiceLists
|
||||
oItems.Add(oChoiceList.aName)
|
||||
Next
|
||||
|
||||
Return oItems
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return oItems
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function GetChoiceListItems(ChoiceListName As String) As List(Of String)
|
||||
Dim oItems As New List(Of String)
|
||||
Dim oChoicelist As WMObject
|
||||
|
||||
If TestSessionLoggedIn() = False Then
|
||||
Return oItems
|
||||
End If
|
||||
|
||||
Try
|
||||
oChoicelist = Session.GetWMObjectByName(WMEntityChoiceList, ChoiceListName)
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex, "Could not get choice list")
|
||||
Return oItems
|
||||
End Try
|
||||
|
||||
Try
|
||||
Dim oChoiceListItems As Object = oChoicelist.GetVariableValue("vItems")
|
||||
|
||||
If oChoiceListItems Is Nothing Then
|
||||
Return oItems
|
||||
End If
|
||||
|
||||
For Each oChoiceListItem In oChoiceListItems
|
||||
oItems.Add(oChoiceListItem)
|
||||
Next
|
||||
|
||||
Return oItems
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex, "Could not get choice list items")
|
||||
Return oItems
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function GetIndiciesByObjecttype(ObjectTypeName As String) As List(Of String)
|
||||
If TestSessionLoggedIn() = False Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Dim oObjectType As WMObject
|
||||
Dim oIndexAttributes As WMObjectRelation
|
||||
Dim oIndexAttribute As WMObject
|
||||
Dim oIndex As WMObject
|
||||
Dim oRelProperties As WMObjectRelation
|
||||
Dim oTempSession As IWMSession2
|
||||
Dim oIndicies As New List(Of String)
|
||||
|
||||
Try
|
||||
' den Objekttyp laden
|
||||
oTempSession = DirectCast(Session, IWMSession2)
|
||||
oObjectType = Session.GetWMObjectByName(WMEntityObjectType, ObjectTypeName)
|
||||
|
||||
' Beziehung zu Indizes des Objekttyp auslesen
|
||||
oIndexAttributes = oObjectType.GetWMObjectRelationByName("TypeAttributes")
|
||||
|
||||
' alle Indizes durchlaufen
|
||||
For j As Integer = 0 To oIndexAttributes.Count - 1
|
||||
|
||||
' aktuellen Index auslesen
|
||||
oIndexAttribute = oIndexAttributes.Item(j)
|
||||
|
||||
' Eigenschaften des Index auslesen
|
||||
oRelProperties = oIndexAttribute.GetWMObjectRelationByName("Attribute")
|
||||
|
||||
' Index aus den Eigenschaften auslesen
|
||||
oIndex = oRelProperties.Item(0)
|
||||
|
||||
' Indexname speichern
|
||||
'aIndexNames(j) = oIndex.aName
|
||||
oIndicies.Add(oIndex.aName)
|
||||
Next
|
||||
|
||||
' Indexarray zurückgeben
|
||||
'Return aIndexNames
|
||||
Return oIndicies
|
||||
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return oIndicies
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function GetIndexType(IndexName As String) As Integer
|
||||
If TestSessionLoggedIn() = False Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Try
|
||||
Dim oAttribute = Session.GetWMObjectByName(WMEntityAttribute, IndexName)
|
||||
Dim oType = oAttribute.GetVariableValue("dwAttrType")
|
||||
Return oType
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function GetIndexValue(Path As String, IndexName As String) As List(Of String)
|
||||
Dim oResult As New List(Of String)
|
||||
|
||||
If TestSessionLoggedIn() = False Then
|
||||
Return oResult
|
||||
End If
|
||||
|
||||
Try
|
||||
Path = GetNormalizedPath(Path)
|
||||
Dim oWMObject As WMObject = Session.GetWMObjectByPath(WMEntityDocument, Path)
|
||||
|
||||
If oWMObject Is Nothing Then
|
||||
Return oResult
|
||||
End If
|
||||
|
||||
Dim oValues = oWMObject.GetVariableValue(IndexName)
|
||||
|
||||
If oValues Is Nothing Then
|
||||
Return oResult
|
||||
End If
|
||||
|
||||
If TypeOf oValues Is IEnumerable Then
|
||||
For Each oValue In oValues
|
||||
oResult.Add(oValue)
|
||||
Next
|
||||
Else
|
||||
oResult.Add(oValues)
|
||||
End If
|
||||
|
||||
Return oResult
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return oResult
|
||||
End Try
|
||||
End Function
|
||||
''' <summary>
|
||||
''' Gets an array of the actual vektorvalues of index, collated with the passed values
|
||||
''' </summary>
|
||||
@@ -890,7 +913,7 @@ Public Class Windream2
|
||||
Dim oNewValues As New List(Of Object)
|
||||
oNewValues = oVectorValues.Except(New List(Of Object) From {ValueToDelete}).ToList()
|
||||
|
||||
''' BEGIN WRITE INDEX
|
||||
' BEGIN WRITE INDEX
|
||||
If LockObject(oWMObject, WMObjectEditModeIndexEdit) = False Then
|
||||
_logger.Warn("File {0} could not be locked")
|
||||
Return False
|
||||
@@ -902,7 +925,36 @@ Public Class Windream2
|
||||
UnlockObject(oWMObject)
|
||||
|
||||
Return True
|
||||
''' END WRITE INDEX
|
||||
' END WRITE INDEX
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function SetFileIndex(Path As String, IndexName As String, Value As String) As Boolean
|
||||
If TestSessionLoggedIn() = False Then
|
||||
Return False
|
||||
End If
|
||||
|
||||
Dim oWMObject As WMObject = GetFileByPath(Path)
|
||||
|
||||
If LockObject(oWMObject, WMObjectEditModeIndexEdit) = False Then
|
||||
_logger.Warn("File {0} could not be locked")
|
||||
Return False
|
||||
End If
|
||||
|
||||
Try
|
||||
Dim oType As Integer = GetIndexType(IndexName)
|
||||
Dim oConvertedValue As Object = Helpers.ConvertIndexValue(oType, Value)
|
||||
oWMObject.SetVariableValue(IndexName, oConvertedValue)
|
||||
oWMObject.Save()
|
||||
|
||||
If UnlockObject(oWMObject) = False Then
|
||||
_logger.Warn("File {0} could not be unlocked", Path)
|
||||
End If
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return False
|
||||
|
||||
Reference in New Issue
Block a user