jj: Fix reading the server from DCOM settings

This commit is contained in:
Jonathan Jenne 2018-08-21 16:52:20 +02:00
parent 8562450ca8
commit d7f490d298

View File

@ -12,14 +12,12 @@ Public Class Windream
#Region "+++++ Variables +++++" #Region "+++++ Variables +++++"
Private Shared Logger As NLog.Logger = NLog.LogManager.GetCurrentClassLogger Private Shared Logger As NLog.Logger = NLog.LogManager.GetCurrentClassLogger
Private CurrentController As WMOSearchController
Private WMDriveLetter As String = "W"
Private ServerBrowser As IServerBrowser Private ServerBrowser As IServerBrowser
Private CurrentSession As IWMSession6
Private CurrentConnect As IWMConnect2
Private CurrentWMServer As String Private CurrentController As WMOSearchController
Private CurrentSession As WMSession
Private CurrentConnect As WMConnect
Private CurrentServer As String
Private CurrentObjecttypes As WMObjects Private CurrentObjecttypes As WMObjects
Private ReconnectSession As Boolean Private ReconnectSession As Boolean
@ -48,6 +46,7 @@ Public Class Windream
End Try End Try
End Sub End Sub
Private Function GetObjectTypes() As WMObjects Private Function GetObjectTypes() As WMObjects
Dim objectTypes As WMObjects Dim objectTypes As WMObjects
@ -60,6 +59,25 @@ Public Class Windream
End Try End Try
End Function End Function
''' <summary>
''' Returns all Objecttypes of current server as list of strings
''' </summary>
''' <returns>List of String of all objecttypes</returns>
''' <remarks></remarks>
Public Function GetObjecttypeNames() As List(Of String)
Dim objectTypes As New List(Of String)
Try
For i As Integer = 0 To CurrentObjecttypes.Count
objectTypes.Add(CurrentObjecttypes.Item(i).aName)
Next
Return objectTypes
Catch ex As Exception
Logger.Error(ex)
Return Nothing
End Try
End Function
Private Function NormalizePath(path As String) Private Function NormalizePath(path As String)
Dim normalizedPath = path Dim normalizedPath = path
@ -78,6 +96,7 @@ Public Class Windream
Public Function NewSession() As Boolean Public Function NewSession() As Boolean
Try Try
ServerBrowser = New ServerBrowser() ServerBrowser = New ServerBrowser()
CurrentServer = ServerBrowser.GetCurrentServer
Catch ex As Exception Catch ex As Exception
Logger.Error(ex, "Could not create ServerBrowser") Logger.Error(ex, "Could not create ServerBrowser")
Return False Return False
@ -85,16 +104,15 @@ Public Class Windream
Try Try
' Create Connect Object for Session ' Create Connect Object for Session
CurrentConnect = New WMConnect With { CurrentConnect = New WMConnect
.ModuleId = 9
}
Catch ex As Exception Catch ex As Exception
Logger.Error(ex, "Could not create WMConnect") Logger.Error(ex, "Could not create WMConnect")
Return False Return False
End Try End Try
Try Try
CurrentSession = New WMSession() ' Create session object with severname set
CurrentSession = CreateObject("Windream.WMSession", ServerBrowser.GetCurrentServer)
Catch ex As Exception Catch ex As Exception
Logger.Error(ex, "Could not create WMConnect") Logger.Error(ex, "Could not create WMConnect")
Return False Return False
@ -116,7 +134,7 @@ Public Class Windream
Return False Return False
End Try End Try
If Not CurrentSession.aLoggedin Then If TestLoggedInSession() = False Then
Logger.Warn("Session created but user {0} could not be logged in", Environment.UserName) Logger.Warn("Session created but user {0} could not be logged in", Environment.UserName)
Return False Return False
End If End If
@ -133,7 +151,7 @@ Public Class Windream
''' <remarks></remarks> ''' <remarks></remarks>
Public Function NewFolder(ByVal folderpath As String) Public Function NewFolder(ByVal folderpath As String)
Try Try
If CurrentSession.aLoggedin Then If TestLoggedInSession() = False Then
Return False Return False
End If End If
folderpath = NormalizePath(folderpath) folderpath = NormalizePath(folderpath)
@ -167,7 +185,7 @@ Public Class Windream
''' <returns>Returns true when folder was created, false if not</returns> ''' <returns>Returns true when folder was created, false if not</returns>
''' <remarks></remarks> ''' <remarks></remarks>
Public Function NewIndexFile(WMFile As String, ByVal indexname As String, ByVal aValues() As String) As Boolean Public Function NewIndexFile(WMFile As String, ByVal indexname As String, ByVal aValues() As String) As Boolean
If TestSession() = False Then If TestLoggedInSession() = False Then
Return False Return False
End If End If
Dim oWMFile As WMObject = GetWMObjectForFile(WMFile) Dim oWMFile As WMObject = GetWMObjectForFile(WMFile)
@ -196,7 +214,7 @@ Public Class Windream
' das entsprechende Attribut aus windream auslesen ' das entsprechende Attribut aus windream auslesen
Dim oAttribute = CurrentSession.GetWMObjectByName(WINDREAMLib.WMEntity.WMEntityAttribute, indexname) Dim oAttribute = CurrentSession.GetWMObjectByName(WINDREAMLib.WMEntity.WMEntityAttribute, indexname)
' den Variablentyp (String, Integer, ...) auslesen ' den Variablentyp (String, Integer, ...) auslesen
oWMType = oAttribute.getVariableValue("dwAttrType") oWMType = oAttribute.GetVariableValue("dwAttrType")
Catch ex As Exception Catch ex As Exception
Logger.Error(ex) Logger.Error(ex)
Return False Return False
@ -359,7 +377,7 @@ Public Class Windream
''' <remarks></remarks> ''' <remarks></remarks>
Public Function NewObjecttypeForFolder(folderpath As String, folderObjecttype As String) As Boolean Public Function NewObjecttypeForFolder(folderpath As String, folderObjecttype As String) As Boolean
Try Try
If CurrentSession.aLoggedin Then If TestLoggedInSession() = False Then
Return False Return False
End If End If
Dim result As Boolean = False Dim result As Boolean = False
@ -419,14 +437,14 @@ Public Class Windream
''' <remarks></remarks> ''' <remarks></remarks>
Public Function NewVersion(ByVal WMPath As String, ByVal Comment As String) Public Function NewVersion(ByVal WMPath As String, ByVal Comment As String)
Try Try
If CurrentSession.aLoggedin Then If TestLoggedInSession() = False Then
Return False Return False
End If End If
WMPath = NormalizePath(WMPath) WMPath = NormalizePath(WMPath)
Dim WMObject As WINDREAMLib.WMObject '= CreateObject("WINDREAMLib.WMObject") 'New WINDREAMLib.WMObject Dim WMObject As WMObject '= CreateObject("WINDREAMLib.WMObject") 'New WINDREAMLib.WMObject
Try Try
WMObject = CurrentSession.GetWMObjectByPath(WINDREAMLib.WMEntity.WMEntityDocument, WMPath) 'WINDREAMLib.WMEntity.WMEntityDocument WMObject = CurrentSession.GetWMObjectByPath(WMEntityDocument, WMPath) 'WINDREAMLib.WMEntity.WMEntityDocument
Catch ex As Exception Catch ex As Exception
Logger.Warn("Could not create WMObject in Create_Version for file '" & WMPath & "': " & ex.Message) Logger.Warn("Could not create WMObject in Create_Version for file '" & WMPath & "': " & ex.Message)
Return False Return False
@ -443,47 +461,43 @@ Public Class Windream
''' <summary> ''' <summary>
''' Returns all choicelists ''' Returns all choicelists
''' </summary> ''' </summary>
''' <returns>choicelists as String-Array</returns> ''' <returns>Choicelists as List of Strings or empty list if no choice lists are found</returns>
''' <remarks></remarks> Public Function GetChoiceLists() As List(Of String)
Public Function GetChoiceLists() As DataTable Dim items As New List(Of String)
Dim dtresult As New DataTable
dtresult.Columns.Add("RESULT", GetType(String)) If TestLoggedInSession() = False Then
If CurrentSession.aLoggedin Then Return items
Return dtresult
End If End If
Try Try
Dim oChoiceLists As WMObjects Dim choiceLists As WMObjects
Dim oChoiceList As IWMObject2 Dim choiceList As IWMObject2
' den Objekttyp laden 'load list of choicelists
oChoiceLists = CurrentSession.GetAllObjects(WMEntityChoiceList) choiceLists = CurrentSession.GetAllObjects(WMEntityChoiceList)
'Array für Indizes vorbereiten
For Each choiceList In choiceLists
For j As Integer = 0 To oChoiceLists.Count() - 1 items.Add(choiceList.aName)
' aktuellee Liste ausleseb auslesen
oChoiceList = oChoiceLists.Item(j)
dtresult.Rows.Add(oChoiceList.aName)
Next Next
dtresult.AcceptChanges()
Return dtresult
Return items
Catch ex As Exception Catch ex As Exception
Logger.Error(ex) Logger.Error(ex)
Return dtresult Return items
End Try End Try
End Function End Function
''' <summary> ''' <summary>
''' Returns all indices for an objecttype ''' Returns all indices for an objecttype
''' </summary> ''' </summary>
''' <param name="ObjecttypeName">Name of objecttype</param> ''' <param name="ObjecttypeName">Name of objecttype</param>
''' <returns>Name of containing indices as String-Array</returns> ''' <returns>Names of indices as list of String</returns>
''' <remarks></remarks> ''' <remarks></remarks>
Public Function GetIndicesByObjecttype(ByVal ObjecttypeName As String) As String() Public Function GetIndicesByObjecttype(ByVal ObjecttypeName As String) As List(Of String)
Try Try
If CurrentSession.aLoggedin Then If TestLoggedInSession() = False Then
Return Nothing Return Nothing
End If End If
Dim oObjectType As WMObject Dim oObjectType As WMObject
Dim oIndexAttributes As WMObjectRelation Dim oIndexAttributes As WMObjectRelation
Dim oIndexAttribute As WMObject Dim oIndexAttribute As WMObject
@ -497,7 +511,8 @@ Public Class Windream
oIndexAttributes = oObjectType.GetWMObjectRelationByName("TypeAttributes") oIndexAttributes = oObjectType.GetWMObjectRelationByName("TypeAttributes")
' Array für Indizes vorbereiten ' Array für Indizes vorbereiten
Dim aIndexNames(oIndexAttributes.Count - 1) As String 'Dim aIndexNames(oIndexAttributes.Count - 1) As String
Dim indexNames As New List(Of String)
' alle Indizes durchlaufen ' alle Indizes durchlaufen
For j As Integer = 0 To oIndexAttributes.Count - 1 For j As Integer = 0 To oIndexAttributes.Count - 1
@ -512,81 +527,64 @@ Public Class Windream
oIndex = oRelProperties.Item(0) oIndex = oRelProperties.Item(0)
' Indexname speichern ' Indexname speichern
aIndexNames(j) = oIndex.aName 'aIndexNames(j) = oIndex.aName
indexNames.Add(oIndex.aName)
Next Next
' Indexarray zurückgeben ' Indexarray zurückgeben
Return aIndexNames 'Return aIndexNames
Return indexNames
Catch ex As Exception Catch ex As Exception
Logger.Error(ex) Logger.Error(ex)
Return Nothing Return Nothing
End Try End Try
End Function End Function
'''' <summary>
'''' Returns all items of a choicelist
'''' </summary>
'''' <param name="NameChoicelist">name of choicelist</param>
'''' <returns>items as String-Array</returns>
'''' <remarks></remarks>
'Public Function GetChoicelistItems(ByVal NameChoicelist As String) As DataTable
' Dim dtresult As New DataTable
' dtresult.Columns.Add("RESULT", GetType(String))
' Try
' 'Dim oAttribute = Me.oSession.GetWMObjectByName(WINDREAMLib.WMEntity.WMEntityAttribute, indexname)
' 'Dim vType = oAttribute.getVariableValue("vItems")
' 'Return vType
' Dim oChoiceList = CurrentSession.GetWMObjectByName(WMEntityChoiceList, NameChoicelist)
' If Err.Number = 0 And TypeName(oChoiceList) <> "Nothing" Then
' Dim oValues = oChoiceList
' oValues = oChoiceList.GetVariableValue("vItems")
' Dim anz As Integer = 0
' For Each CLItem In oValues
' If oChoiceList.aName IsNot Nothing Then
' anz += 1
' End If
' Next
' Dim strListe(anz - 1)
' Dim zahl As Integer = 0
' For Each CLItem In oValues
' If oChoiceList.aName IsNot Nothing Then
' dtresult.Rows.Add(CLItem)
' strListe(zahl) = CLItem
' zahl += 1
' End If
' dtresult.AcceptChanges()
' Next
' Return dtresult
' Else
' Logger.Warn("WMchoicelist: " & NameChoicelist & " not found!")
' Return dtresult
' End If
' Catch ex As Exception
' Logger.Error(ex)
' Return Nothing
' End Try
'End Function
''' <summary> ''' <summary>
''' Returns all Objecttypes of current server as array of strings ''' Returns all items of a choicelist
''' </summary> ''' </summary>
''' <returns>array(String) of all objecttypes</returns> ''' <param name="NameChoicelist">name of choicelist</param>
''' <returns>Items as list of String</returns>
''' <remarks></remarks> ''' <remarks></remarks>
Public Function GetObjecttypesAsStrings() As DataTable Public Function GetChoicelistItems(ByVal NameChoicelist As String) As List(Of String)
Dim dtresult As New DataTable Dim items As New List(Of String)
dtresult.Columns.Add("RESULT", GetType(String))
If TestLoggedInSession() = False Then
Return Nothing
End If
Dim choiceList As WMObject
' Try to get the choicelist first and abort if an error occurs
Try Try
For i As Integer = 0 To CurrentObjecttypes.Count Dim session As IWMSession2 = DirectCast(CurrentSession, IWMSession2)
dtresult.Rows.Add(CurrentObjecttypes.Item(i).aName) choiceList = session.GetWMObjectByName(WMEntityChoiceList, NameChoicelist)
Next
dtresult.AcceptChanges()
Return dtresult
Catch ex As Exception Catch ex As Exception
Logger.Error(ex) Logger.Error(ex)
Return dtresult Return Nothing
End Try End Try
' Try to get choicelist items
Try
Dim values As Object = choiceList.GetVariableValue("vItems")
' If values is nothing, the list is empty
If values Is Nothing Then
Return items
End If
For Each value In values
items.Add(value)
Next
Catch ex As Exception
Logger.Error(ex)
Return Nothing
End Try
Return items
End Function End Function
''' <summary> ''' <summary>
''' Returns the result of windream-search ''' Returns the result of windream-search
''' </summary> ''' </summary>
@ -598,7 +596,7 @@ Public Class Windream
Dim dtresult As New DataTable Dim dtresult As New DataTable
dtresult.Columns.Add("DOC_ID", GetType(Integer)) dtresult.Columns.Add("DOC_ID", GetType(Integer))
dtresult.Columns.Add("PATH", GetType(String)) dtresult.Columns.Add("PATH", GetType(String))
If Not CurrentSession.aLoggedin Then If Not TestLoggedInSession() = False Then
Return dtresult Return dtresult
End If End If
If TestWMFileExists(wdfLocation) = False Then If TestWMFileExists(wdfLocation) = False Then
@ -623,7 +621,7 @@ Public Class Windream
'' Der öffentliche Member CheckSearchProfile für den Typ IWMQuickSearch7 wurde nicht gefunden. [Microsoft.VisualBasic] => GetSearchDocuments() '' Der öffentliche Member CheckSearchProfile für den Typ IWMQuickSearch7 wurde nicht gefunden. [Microsoft.VisualBasic] => GetSearchDocuments()
Select Case suchTyp.ToString.ToUpper Select Case suchTyp.ToString.ToUpper
Case "WMOSRCH.WMQUICKSEARCH" Case "WMOSRCH.WMQUICKSEARCH"
srchQuick.WMSession = CreateObject("Windream.WMSession", CurrentWMServer) srchQuick.WMSession = CreateObject("Windream.WMSession", CurrentServer)
CurrentConnect.LoginSession(srchQuick.WMSession) CurrentConnect.LoginSession(srchQuick.WMSession)
@ -634,7 +632,7 @@ Public Class Windream
oSearch = srchQuick.GetSearch() oSearch = srchQuick.GetSearch()
Case "WMOSRCH.WMINDEXSEARCH" Case "WMOSRCH.WMINDEXSEARCH"
srchIndex.WMSession = CreateObject("Windream.WMSession", CurrentWMServer) srchIndex.WMSession = CreateObject("Windream.WMSession", CurrentServer)
CurrentConnect.LoginSession(srchIndex.WMSession) CurrentConnect.LoginSession(srchIndex.WMSession)
@ -645,7 +643,7 @@ Public Class Windream
oSearch = srchIndex.GetSearch() oSearch = srchIndex.GetSearch()
Case "WMOSRCH.WMOBJECTTYPESEARCH" Case "WMOSRCH.WMOBJECTTYPESEARCH"
srchObjectType.WMSession = CreateObject("Windream.WMSession", CurrentWMServer) srchObjectType.WMSession = CreateObject("Windream.WMSession", CurrentServer)
CurrentConnect.LoginSession(srchObjectType.WMSession) CurrentConnect.LoginSession(srchObjectType.WMSession)
@ -687,7 +685,7 @@ Public Class Windream
''' <remarks></remarks> ''' <remarks></remarks>
Public Function GetTypeOfIndexAsInt(ByVal indexname As String) As Integer Public Function GetTypeOfIndexAsInt(ByVal indexname As String) As Integer
Try Try
If CurrentSession.aLoggedin Then If TestLoggedInSession() = False Then
Return False Return False
End If End If
Dim oAttribute = CurrentSession.GetWMObjectByName(WINDREAMLib.WMEntity.WMEntityAttribute, indexname) Dim oAttribute = CurrentSession.GetWMObjectByName(WINDREAMLib.WMEntity.WMEntityAttribute, indexname)
@ -707,12 +705,12 @@ Public Class Windream
Public Function GetValueforIndex(ByVal WMFile As String, ByVal NameIndex As String) As DataTable Public Function GetValueforIndex(ByVal WMFile As String, ByVal NameIndex As String) As DataTable
Dim dt As New DataTable Dim dt As New DataTable
dt.Columns.Add("RESULT", GetType(String)) dt.Columns.Add("RESULT", GetType(String))
If TestSession() = False Then If TestLoggedInSession() = False Then
Return dt Return dt
End If End If
Try Try
If Not WMFile.StartsWith("\") And WMFile.ToUpper.StartsWith(WMDriveLetter.ToUpper) Then If Not WMFile.StartsWith("\") And WMFile.ToUpper.StartsWith(DriveLetter.ToUpper) Then
WMFile = WMFile.Substring(2) WMFile = WMFile.Substring(2)
End If End If
Dim WMObject As WINDREAMLib.WMObject '= CreateObject("WINDREAMLib.WMObject") 'New WINDREAMLib.WMObject Dim WMObject As WINDREAMLib.WMObject '= CreateObject("WINDREAMLib.WMObject") 'New WINDREAMLib.WMObject
@ -751,7 +749,7 @@ Public Class Windream
''' <remarks></remarks> ''' <remarks></remarks>
Public Function Return_VektorArray(ByVal oDocument As WMObject, vktIndexName As String, arrIndexwerte As Object, vType As Object) Public Function Return_VektorArray(ByVal oDocument As WMObject, vktIndexName As String, arrIndexwerte As Object, vType As Object)
Try Try
If CurrentSession.aLoggedin Then If TestLoggedInSession() = False Then
Return False Return False
End If End If
Dim missing As Boolean = False Dim missing As Boolean = False
@ -827,7 +825,7 @@ Public Class Windream
''' <remarks></remarks> ''' <remarks></remarks>
Public Function GetWMObjectForFile(ByVal WMPath As String) As WMObject Public Function GetWMObjectForFile(ByVal WMPath As String) As WMObject
Try Try
If CurrentSession.aLoggedin Then If TestLoggedInSession() = False Then
Return Nothing Return Nothing
End If End If
WMPath = NormalizePath(WMPath) WMPath = NormalizePath(WMPath)
@ -854,7 +852,7 @@ Public Class Windream
''' <remarks></remarks> ''' <remarks></remarks>
Public Function TestFolderExists(folderpath As String) Public Function TestFolderExists(folderpath As String)
Try Try
If CurrentSession.aLoggedin Then If TestLoggedInSession() = False Then
Return False Return False
End If End If
folderpath = NormalizePath(folderpath) folderpath = NormalizePath(folderpath)
@ -877,7 +875,7 @@ Public Class Windream
''' <remarks></remarks> ''' <remarks></remarks>
Public Function TestWMFileExists(ByVal WMPath As String) Public Function TestWMFileExists(ByVal WMPath As String)
Try Try
If CurrentSession.aLoggedin Then If TestLoggedInSession() = False Then
Return False Return False
End If End If
WMPath = NormalizePath(WMPath) WMPath = NormalizePath(WMPath)
@ -891,7 +889,9 @@ Public Class Windream
Return False Return False
End Try End Try
End Function End Function
Private Function TestSession() As Boolean
Private Function TestLoggedInSession() As Boolean
Try Try
If CurrentSession.aLoggedin Then If CurrentSession.aLoggedin Then
Return True Return True
@ -911,10 +911,10 @@ Public Class Windream
''' <remarks></remarks> ''' <remarks></remarks>
Public Function TestWMUSerExists(username As String) As Boolean Public Function TestWMUSerExists(username As String) As Boolean
Try Try
If TestSession() = False Then If TestLoggedInSession() = False Then
Return False Return False
End If End If
Return CurrentSession.WMObjectExists(WINDREAMLib.WMEntity.WMEntityUser, username, 0, 0) Return CurrentSession.WMObjectExists(WMEntityUser, username, 0, 0)
Catch ex As Exception Catch ex As Exception
Logger.Error(ex) Logger.Error(ex)
Return False Return False
@ -928,10 +928,10 @@ Public Class Windream
''' <remarks></remarks> ''' <remarks></remarks>
Public Function TestWMGroupExists(groupname As String) Public Function TestWMGroupExists(groupname As String)
Try Try
If TestSession() = False Then If TestLoggedInSession() = False Then
Return False Return False
End If End If
Return CurrentSession.WMObjectExists(WINDREAMLib.WMEntity.WMEntityGroups, groupname, 0, 0) Return CurrentSession.WMObjectExists(WMEntityGroups, groupname, 0, 0)
Catch ex As Exception Catch ex As Exception
Logger.Error(ex) Logger.Error(ex)
Return False Return False
@ -972,7 +972,7 @@ Public Class Windream
Public Function REMOVE_VEKTOR_LINK(ByVal WMPath As String, vktIndexName As String, deleteValue As String) Public Function REMOVE_VEKTOR_LINK(ByVal WMPath As String, vktIndexName As String, deleteValue As String)
Try Try
Logger.Info("Removing Value '" & deleteValue & "' of Index '" & vktIndexName & "' " & WMPath) Logger.Info("Removing Value '" & deleteValue & "' of Index '" & vktIndexName & "' " & WMPath)
Dim oWMFile As WINDREAMLib.WMObject = GetWMObjectForFile(WMPath) Dim oWMFile As WMObject = GetWMObjectForFile(WMPath)
If IsNothing(oWMFile) Then If IsNothing(oWMFile) Then
Logger.Warn("Exit from REMOVE_VEKTOR_LINK...") Logger.Warn("Exit from REMOVE_VEKTOR_LINK...")
Return False Return False
@ -985,7 +985,7 @@ Public Class Windream
'Nochmals prüfen ob wirklich Array 'Nochmals prüfen ob wirklich Array
If WMValue.GetType.ToString.Contains("System.Object") Then If WMValue.GetType.ToString.Contains("System.Object") Then
' das entsprechende Attribut aus windream auslesen ' das entsprechende Attribut aus windream auslesen
Dim oAttribute = CurrentSession.GetWMObjectByName(WINDREAMLib.WMEntity.WMEntityAttribute, vktIndexName) Dim oAttribute = CurrentSession.GetWMObjectByName(WMEntityAttribute, vktIndexName)
' den Variablentyp (String, Integer, ...) auslesen ' den Variablentyp (String, Integer, ...) auslesen
Dim vType = oAttribute.getVariableValue("dwAttrType") Dim vType = oAttribute.getVariableValue("dwAttrType")
Dim Anzahl As Integer = 0 Dim Anzahl As Integer = 0
@ -1043,6 +1043,4 @@ Public Class Windream
End Try End Try
End Function End Function
#End Region #End Region
End Class End Class