WIP: Windream2

This commit is contained in:
Jonathan Jenne 2018-09-03 16:35:20 +02:00
parent 41cd8313a9
commit d2427b191b
3 changed files with 103 additions and 68 deletions

View File

@ -3,7 +3,7 @@
Public Class ConnectionBuilder Public Class ConnectionBuilder
Implements IConnectionBuilder Implements IConnectionBuilder
Private LogFactory As LogFactory Private ReadOnly LogFactory As LogFactory
Private SessionReconnect As Boolean = False Private SessionReconnect As Boolean = False
Private DriveLetter As String = "W" Private DriveLetter As String = "W"
Private Support64Bit As Boolean = False Private Support64Bit As Boolean = False

View File

@ -1,22 +1,37 @@
Public Class Helpers Imports DigitalData.Modules.Windream.Constants
Inherits Constants
Public Class Helpers
Private Shared ReadOnly VectorIndicies As List(Of Integer) = New List(Of Integer) From {
INDEX_TYPE_VECTOR_BOOLEAN,
INDEX_TYPE_VECTOR_CURRENCY,
INDEX_TYPE_VECTOR_DATE,
INDEX_TYPE_VECTOR_DATE_TIME,
INDEX_TYPE_VECTOR_FIXED_POINT,
INDEX_TYPE_VECTOR_FLOAT,
INDEX_TYPE_VECTOR_INTEGER,
INDEX_TYPE_VECTOR_INTEGER_64BIT,
INDEX_TYPE_VECTOR_STRING,
INDEX_TYPE_VECTOR_TIME
}
Friend Shared Function ConvertVectorType(vType As Object, value As String) Friend Shared Function ConvertVectorType(vType As Object, value As String)
Select Case vType Select Case vType
Case INDEX_TYPE_HASH ' 36865 Case INDEX_TYPE_HASH ' 36865
'Umwandeln in String 'Umwandeln in String
Return CStr(value) Return value
Case INDEX_TYPE_VECTOR_STRING '4097 Case INDEX_TYPE_VECTOR_STRING '4097
'Umwandeln in String 'Umwandeln in String
Return CStr(value) Return value
Case INDEX_TYPE_VECTOR_INTEGER '4098 Case INDEX_TYPE_VECTOR_INTEGER '4098
'Umwandeln in Integer 'Umwandeln in Integer
value = value.ToString.Replace(" ", "") value = value.Replace(" ", "")
Return CInt(value) Return CInt(value)
Case INDEX_TYPE_VECTOR_FLOAT '4099 Case INDEX_TYPE_VECTOR_FLOAT '4099
Dim Str As String = value value = value.
Str = Str.ToString.Replace(" ", "") Replace(" ", "").
Replace(".", ",")
'Umwandeln in Double 'Umwandeln in Double
Return CDbl(Str.Replace(".", ",")) Return CDbl(value)
Case INDEX_TYPE_VECTOR_BOOLEAN '4100 Case INDEX_TYPE_VECTOR_BOOLEAN '4100
'Umwandeln in Boolean 'Umwandeln in Boolean
Return CBool(value) Return CBool(value)
@ -30,7 +45,11 @@
Return value Return value
Case Else Case Else
'Umwandeln in String 'Umwandeln in String
Return CStr(value) Return value
End Select End Select
End Function End Function
Friend Shared Function IsVectorIndex(indexType As Integer)
Return VectorIndicies.Contains(indexType)
End Function
End Class End Class

View File

@ -56,16 +56,17 @@ Imports System.IO
''' '''
''' EXAMPLES: ''' EXAMPLES:
''' '''
''' REMARKS: ''' REMARKS: This class should not be instanciated directly. Instead, ConnectionBuilder should be used.
''' </summary> ''' </summary>
Public Class Windream2 Public Class Windream2
#Region "Private Properties" #Region "Private Properties"
Private _logger As Logger Private ReadOnly _logger As Logger
Private _loggerFactory As LogFactory Private ReadOnly _loggerFactory As LogFactory
Private ReadOnly Property _sessionDomain As String
Private ReadOnly Property _sessionPassword As String
Private ReadOnly Property _sessionUsername As String
Private ReadOnly _sessionDomain As String
Private ReadOnly _sessionPassword As String
Private ReadOnly _sessionUsername As String
#End Region #End Region
#Region "Public Properties" #Region "Public Properties"
Public ReadOnly Property ClientDriveLetter As String Public ReadOnly Property ClientDriveLetter As String
@ -116,8 +117,6 @@ Public Class Windream2
Throw New Exceptions.SessionException() Throw New Exceptions.SessionException()
End If End If
' Set properties of currently established session ' Set properties of currently established session
Session = oSession Session = oSession
SessionLoggedin = True SessionLoggedin = True
@ -141,6 +140,7 @@ Public Class Windream2
Dim oImpersonation As Boolean Dim oImpersonation As Boolean
Dim oServerNameFromClient As Boolean Dim oServerNameFromClient As Boolean
' Create initial windream objects
Try Try
oBrowser = New ServerBrowser() oBrowser = New ServerBrowser()
oConnect = New WMConnect() oConnect = New WMConnect()
@ -166,7 +166,17 @@ Public Class Windream2
_logger.Info("Servername: {0}", ServerName) _logger.Info("Servername: {0}", ServerName)
_logger.Info("Servername aquired from client: {0}", oServerNameFromClient) _logger.Info("Servername aquired from client: {0}", oServerNameFromClient)
'TODO: Test connection to windream server 'Test connection to windream server
Try
Dim response = My.Computer.Network.Ping(ServerName)
If response = False Then
_logger.Warn("Windream Server {0} refused connection", ServerName)
Return Nothing
End If
Catch ex As Exception
_logger.Error(ex)
Return Nothing
End Try
' If username, password and domain are set, login with impersonation ' If username, password and domain are set, login with impersonation
' Else, login with current credentials ' Else, login with current credentials
@ -211,6 +221,7 @@ Public Class Windream2
Return Nothing Return Nothing
End If End If
_logger.Info("Connection to {0} established!", ServerName)
Return oSession Return oSession
End Function End Function
@ -223,12 +234,11 @@ Public Class Windream2
Try Try
Path = GetNormalizedPath(Path) Path = GetNormalizedPath(Path)
Dim oFolders As List(Of String) = Path.Split().ToList() Dim oFolders As List(Of String) = Path.Split().ToList()
Dim oTempSession As IWMSession2 = DirectCast(Session, IWMSession2)
Dim oFolderObject As WMObject Dim oFolderObject As WMObject
For Each oFolder In oFolders For Each oFolder In oFolders
If TestFolderExists(Path) = False Then If TestFolderExists(Path) = False Then
oFolderObject = oTempSession.GetNewWMObjectFS(WMEntityFolder, oFolder, WMObjectEditModeNoEdit) oFolderObject = Session.GetNewWMObjectFS(WMEntityFolder, oFolder, WMObjectEditModeNoEdit)
End If End If
Next Next
@ -247,7 +257,7 @@ Public Class Windream2
Try Try
Path = GetNormalizedPath(Path) Path = GetNormalizedPath(Path)
Dim oFileObject As IWMObject6 Dim oFileObject As IWMObject6
oFileObject = Session.GetWMObjectByPath(WMEntityDocument, Path) oFileObject = GetObjectByPath(Path, WMEntityDocument)
oFileObject.CreateVersion2(False, Constants.HISTORY_NEW_FROM_VERSION, Comment) oFileObject.CreateVersion2(False, Constants.HISTORY_NEW_FROM_VERSION, Comment)
Return True Return True
Catch ex As Exception Catch ex As Exception
@ -256,9 +266,9 @@ Public Class Windream2
End Try End Try
End Function End Function
Public Function LockObject(WMObject As WMObject) As Boolean Public Function LockObject(WMObject As WMObject, Optional EditMode As WMObjectEditMode = WMObjectEditModeNoEdit) As Boolean
Try Try
WMObject.lock() WMObject.LockFor(EditMode)
Return True Return True
Catch ex As Exception Catch ex As Exception
_logger.Error(ex) _logger.Error(ex)
@ -307,26 +317,29 @@ Public Class Windream2
Select Case oSearchType.ToUpper() Select Case oSearchType.ToUpper()
Case Constants.SEARCH_TYPE_QUICK_SEARCH Case Constants.SEARCH_TYPE_QUICK_SEARCH
Dim oQuickSearch As New WMQuickSearch() Dim oQuickSearch As New WMQuickSearch With {
oQuickSearch.WMSession = Session .WMSession = Session,
.SearchProfilePath = SearchFilePath
}
oQuickSearch.ClearSearch() oQuickSearch.ClearSearch()
oQuickSearch.SearchProfilePath = SearchFilePath
oQuickSearch.LoadSearchProfile(oProfileName) oQuickSearch.LoadSearchProfile(oProfileName)
oSearch = oQuickSearch.GetSearch() oSearch = oQuickSearch.GetSearch()
Case Constants.SEARCH_TYPE_INDEX_SEARCH Case Constants.SEARCH_TYPE_INDEX_SEARCH
Dim oIndexSearch As New WMIndexSearch() Dim oIndexSearch As New WMIndexSearch With {
oIndexSearch.WMSession = Session .WMSession = Session,
.SearchProfilePath = SearchFilePath
}
oIndexSearch.ClearSearch() oIndexSearch.ClearSearch()
oIndexSearch.SearchProfilePath = SearchFilePath
oIndexSearch.LoadSearchProfile(oProfileName) oIndexSearch.LoadSearchProfile(oProfileName)
oSearch = oIndexSearch.GetSearch() oSearch = oIndexSearch.GetSearch()
Case Constants.SEARCH_TYPE_OBJECTTYPE_SEARCH Case Constants.SEARCH_TYPE_OBJECTTYPE_SEARCH
Dim oObjecttypeSearch As New WMObjectTypeSearch() Dim oObjecttypeSearch As New WMObjectTypeSearch With {
oObjecttypeSearch.WMSession = Session .WMSession = Session,
.SearchProfilePath = SearchFilePath
}
oObjecttypeSearch.ClearSearch() oObjecttypeSearch.ClearSearch()
oObjecttypeSearch.SearchProfilePath = SearchFilePath
oObjecttypeSearch.LoadSearchProfile(oProfileName) oObjecttypeSearch.LoadSearchProfile(oProfileName)
oSearch = oObjecttypeSearch.GetSearch() oSearch = oObjecttypeSearch.GetSearch()
@ -579,50 +592,53 @@ Public Class Windream2
End Try End Try
End Function End Function
'Public Function RemoveVectorIndexValue(Path As String, IndexName As String, ValueToDelete As String) As Boolean Public Function RemoveVectorIndexValue(Path As String, IndexName As String, ValueToDelete As String) As Boolean
' If TestSessionLoggedIn() = False Then If TestSessionLoggedIn() = False Then
' Return False Return False
' End If End If
' Try Try
' Dim oTempSession As IWMSession2 = DirectCast(Session, IWMSession2) Dim oWMObject As WMObject = Session.GetWMObjectByName(WMEntityAttribute, Path)
' Dim oWMObject As WMObject = oTempSession.GetWMObjectByName(WMEntityAttribute, Path)
' If oWMObject Is Nothing Then If oWMObject Is Nothing Then
' _logger.Warn("Could not find document {0}", Path) _logger.Warn("Could not find document {0}", Path)
' Return False Return False
' End If End If
' Dim oVectorValues = oWMObject.GetVariableValue(IndexName) Dim oVectorValues = oWMObject.GetVariableValue(IndexName)
' Dim oType As Integer = GetIndexType(IndexName) Dim oType As Integer = GetIndexType(IndexName)
' If oVectorValues Is Nothing Then If Helpers.IsVectorIndex(oType) = False Then
' _logger.Warn("Could not values of index {0}", IndexName) _logger.Warn("Index {0} is not a vector index", IndexName)
' Return False Return False
' End If End If
If oVectorValues Is Nothing Then
_logger.Warn("Could not values of index {0}", IndexName)
Return False
End If
' Dim oValueFound As Boolean = False Dim oNewValues As New List(Of Object)
oNewValues = oVectorValues.Except(New List(Of Object) From {ValueToDelete}).ToList()
' For Each oVectorValue In oVectorValues ''' BEGIN WRITE INDEX
' If oVectorValue = ValueToDelete Then If LockObject(oWMObject, WMObjectEditModeIndexEdit) = False Then
' oValueFound = True _logger.Warn("File {0} could not be locked")
' End If Return False
' Next End If
' Dim oNewValues As New List(Of Object) oWMObject.SetVariableValue(IndexName, oNewValues.ToArray())
oWMObject.Save()
' If oValueFound Then UnlockObject(oWMObject)
' oNewValues = oVectorValues
' oNewValues = oNewValues.Except(New List(Of Object) From {ValueToDelete}).ToList()
' End If
Return True
' Catch ex As Exception ''' END WRITE INDEX
' _logger.Error(ex) Catch ex As Exception
' Return Nothing _logger.Error(ex)
' End Try Return False
'End Function End Try
End Function
Public Function TestFolderExists(Path As String) As Boolean Public Function TestFolderExists(Path As String) As Boolean
Return TestObjectExists(GetNormalizedPath(Path), WMEntityFolder) Return TestObjectExists(GetNormalizedPath(Path), WMEntityFolder)
@ -705,7 +721,7 @@ Public Class Windream2
If Session.aLoggedin Then If Session.aLoggedin Then
Return True Return True
Else Else
_logger.Warn("There is no active WM-Session!") _logger.Warn("There is no active WM-Session for user {0}", _sessionUsername)
Return False Return False
End If End If
Catch ex As Exception Catch ex As Exception