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
Implements IConnectionBuilder
Private LogFactory As LogFactory
Private ReadOnly LogFactory As LogFactory
Private SessionReconnect As Boolean = False
Private DriveLetter As String = "W"
Private Support64Bit As Boolean = False

View File

@ -1,22 +1,37 @@
Public Class Helpers
Inherits Constants
Imports DigitalData.Modules.Windream.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)
Select Case vType
Case INDEX_TYPE_HASH ' 36865
'Umwandeln in String
Return CStr(value)
Return value
Case INDEX_TYPE_VECTOR_STRING '4097
'Umwandeln in String
Return CStr(value)
Return value
Case INDEX_TYPE_VECTOR_INTEGER '4098
'Umwandeln in Integer
value = value.ToString.Replace(" ", "")
value = value.Replace(" ", "")
Return CInt(value)
Case INDEX_TYPE_VECTOR_FLOAT '4099
Dim Str As String = value
Str = Str.ToString.Replace(" ", "")
value = value.
Replace(" ", "").
Replace(".", ",")
'Umwandeln in Double
Return CDbl(Str.Replace(".", ","))
Return CDbl(value)
Case INDEX_TYPE_VECTOR_BOOLEAN '4100
'Umwandeln in Boolean
Return CBool(value)
@ -30,7 +45,11 @@
Return value
Case Else
'Umwandeln in String
Return CStr(value)
Return value
End Select
End Function
Friend Shared Function IsVectorIndex(indexType As Integer)
Return VectorIndicies.Contains(indexType)
End Function
End Class

View File

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