WIP: Windream2

This commit is contained in:
Jonathan Jenne 2018-08-27 15:03:54 +02:00
parent b294eaddf9
commit 3ac94c40e6
2 changed files with 212 additions and 6 deletions

View File

@ -40,4 +40,12 @@
Public Const HISTORY_NEW_FROM_VERSION = "HISTORY_New_From_Version"
Public Const HISTORY_USER_DEFINED = "HISTORY_User_Defined"
'Search Types
Public Const SEARCH_TYPE_QUICK_SEARCH = "WMOSRCH.WMQUICKSEARCH"
Public Const SEARCH_TYPE_INDEX_SEARCH = "WMOSRCH.WMINDEXSEARCH"
Public Const SEARCH_TYPE_OBJECTTYPE_SEARCH = "WMOSRCH.WMOBJECTTYPESEARCH"
' Misc
Public Const OBJECT_TYPE_DEFAULT = "Standard"
End Class

View File

@ -9,6 +9,7 @@ Imports WMOSRCHLib
Imports WMCNNCTDLLLib
Imports WMOTOOLLib
Imports NLog
Imports System.IO
''' <summary>
''' MODULE: Windream
@ -42,7 +43,7 @@ Public Class Windream2
Public ReadOnly Property ClientDriveLetter As String
Public ReadOnly Property ClientSupport64Bit As Boolean
Public ReadOnly Property Session As WMSession
Public ReadOnly Property Session As IWMSession2
Public ReadOnly Property SessionLoggedin As Boolean
Public ReadOnly Property SessionReconnect As Boolean
Public ReadOnly Property SessionServername As String
@ -76,15 +77,22 @@ Public Class Windream2
''' <param name="SessionDomain"></param>
''' <exception cref="Exceptions.SessionException"></exception>
Public Sub New(LogFactory As LogFactory, SessionReconnect As Boolean, ClientDriveLetter As String, ClientSupport64Bit As Boolean, SessionServerName As String, SessionUserName As String, SessionPassword As String, SessionDomain As String)
' Create logger and save LogFactory for dependent classes
_logger = LogFactory.GetCurrentClassLogger()
_loggerFactory = LogFactory
Dim oSession As WMSession = NewSession(SessionServerName, SessionUserName, SessionPassword, SessionDomain)
' Create a session
Dim oSession As IWMSession2 = NewSession(SessionServerName, SessionUserName, SessionPassword, SessionDomain)
' If no session could be created, exit
If oSession Is Nothing Then
Throw New Exceptions.SessionException()
End If
' Set properties of currently established session
Session = oSession
SessionLoggedin = True
Me.SessionReconnect = SessionReconnect
@ -97,10 +105,10 @@ Public Class Windream2
_sessionDomain = SessionDomain
End Sub
Public Function NewSession(Optional ServerName As String = Nothing, Optional UserName As String = Nothing, Optional Password As String = Nothing, Optional Domain As String = Nothing) As WMSession
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 WMConnect
Dim oSession As WMSession
Dim oConnect As IWMConnect2
Dim oSession As IWMSession2
Dim oCredentials As WMUserIdentity
Dim oImpersonation As Boolean
@ -241,6 +249,86 @@ Public Class Windream2
End Try
End Function
Public Function GetSearchDocuments(SearchFilePath As String, DocIdIndexName As String) As Dictionary(Of Integer, String)
Dim oResult As New Dictionary(Of Integer, String)
If TestSessionLoggedIn() = False Then
Return oResult
End If
If TestFileExists(SearchFilePath) = False Then
Return oResult
End If
Try
Dim oFileInfo = New FileInfo(SearchFilePath)
Dim oProfileName = oFileInfo.Name
Dim oProfilePath = oFileInfo.DirectoryName
Dim oSearchController As New WMOSearchController()
oSearchController.CheckSearchProfile(SearchFilePath)
Dim oSearchType = oSearchController.SearchProfileTargetProgID
Dim oSearchProfileExSetttings As Integer = oSearchController.SearchProfileExSettings
If oSearchProfileExSetttings = 0 Then
oSearchProfileExSetttings = 7
End If
Dim oSearch As WMSearch
Select Case oSearchType.ToUpper()
Case Constants.SEARCH_TYPE_QUICK_SEARCH
Dim oQuickSearch As New WMQuickSearch()
oQuickSearch.WMSession = Session
oQuickSearch.ClearSearch()
oQuickSearch.SearchProfilePath = SearchFilePath
oQuickSearch.LoadSearchProfile(oProfileName)
oSearch = oQuickSearch.GetSearch()
Case Constants.SEARCH_TYPE_INDEX_SEARCH
Dim oIndexSearch As New WMIndexSearch()
oIndexSearch.WMSession = Session
oIndexSearch.ClearSearch()
oIndexSearch.SearchProfilePath = SearchFilePath
oIndexSearch.LoadSearchProfile(oProfileName)
oSearch = oIndexSearch.GetSearch()
Case Constants.SEARCH_TYPE_OBJECTTYPE_SEARCH
Dim oObjecttypeSearch As New WMObjectTypeSearch()
oObjecttypeSearch.WMSession = Session
oObjecttypeSearch.ClearSearch()
oObjecttypeSearch.SearchProfilePath = SearchFilePath
oObjecttypeSearch.LoadSearchProfile(oProfileName)
oSearch = oObjecttypeSearch.GetSearch()
Case Else
_logger.Warn("{0} is not a valid search type", oSearchType)
Return oResult
End Select
Dim oSearchResults As WMObjects = oSearch.Execute()
If oSearchResults.Count = 0 Then
Return oResult
End If
For Each oSearchResult As WMObject In oSearchResults
Dim path As String = oSearchResult.aPath
Dim docId As Integer = oSearchResult.GetVariableValue(DocIdIndexName)
oResult.Add(docId, path)
Next
Return oResult
Catch ex As Exception
_logger.Error(ex)
Return oResult
End Try
End Function
Public Function GetChoiceLists() As List(Of String)
Dim oItems As New List(Of String)
@ -363,6 +451,78 @@ Public Class Windream2
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 Object 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 SetFolderObjecttype(FolderPath As String, Objecttype As String) As Boolean
If TestSessionLoggedIn() = False Then
Return False
End If
Try
FolderPath = GetNormalizedPath(FolderPath)
If TestFolderExists(FolderPath) = False Then
Return False
End If
Dim oWMFolder As WMObject = GetObjectByPath(FolderPath, WMEntityFolder)
If LockFile(oWMFolder) = False Then
' Nichts tun, Ordner ist bereits gesperrt.
End If
If oWMFolder.aObjectType.aName <> Constants.OBJECT_TYPE_DEFAULT Then
_logger.Warn("Objecttype for folder {0} has already been set!", FolderPath)
End If
Dim oObjecttype As WMObject = GetObjectByName(Objecttype, WMEntityObjectType)
If oObjecttype Is Nothing Then
_logger.Warn("Objecttype {0} does not exist!", Objecttype)
Return False
End If
oWMFolder.aObjectType = oObjecttype
Catch ex As Exception
End Try
End Function
Public Function RemoveFile(Path As String) As Boolean
If TestSessionLoggedIn() = False Then
Return Nothing
@ -469,6 +629,44 @@ Public Class Windream2
End Try
End Function
Private Function GetObjectByName(ObjectName As String, ObjectType As WMEntity) As WMObject
If TestSessionLoggedIn() = False Then
Return Nothing
End If
If TestObjectExists(ObjectName, ObjectType) = False Then
Return Nothing
End If
Try
Dim oTempSession As IWMSession2 = DirectCast(Session, IWMSession2)
Dim oWMObject As WMObject = oTempSession.GetWMObjectByName(ObjectType, ObjectName)
Return oWMObject
Catch ex As Exception
_logger.Error(ex)
Return Nothing
End Try
End Function
Private Function GetObjectByPath(ObjectName As String, ObjectType As WMEntity) As WMObject
If TestSessionLoggedIn() = False Then
Return Nothing
End If
If TestObjectExists(ObjectName, ObjectType) = False Then
Return Nothing
End If
Try
Dim oTempSession As IWMSession2 = DirectCast(Session, IWMSession2)
Dim oWMObject As WMObject = oTempSession.GetWMObjectByPath(ObjectType, ObjectName)
Return oWMObject
Catch ex As Exception
_logger.Error(ex)
Return Nothing
End Try
End Function
Private Function TestSessionLoggedIn() As Boolean
Try
If Session.aLoggedin Then
@ -483,7 +681,7 @@ Public Class Windream2
End Try
End Function
Public Function TestObjectExists(ObjectName As String, ObjectType As WMEntity) As Boolean
Private Function TestObjectExists(ObjectName As String, ObjectType As WMEntity) As Boolean
If TestSessionLoggedIn() = False Then
Return False
End If