work on windream

This commit is contained in:
Jonathan Jenne 2019-09-05 11:58:07 +02:00
parent 81a06966b5
commit 46b11aaf47
3 changed files with 160 additions and 105 deletions

View File

@ -40,11 +40,18 @@
Public Const HISTORY_NEW_FROM_VERSION = "HISTORY_New_From_Version" Public Const HISTORY_NEW_FROM_VERSION = "HISTORY_New_From_Version"
Public Const HISTORY_USER_DEFINED = "HISTORY_User_Defined" Public Const HISTORY_USER_DEFINED = "HISTORY_User_Defined"
' Entity Types
Public Const ENTITY_TYPE_OBJECTTYPE = 10
'Search Types 'Search Types
Public Const SEARCH_TYPE_QUICK_SEARCH = "WMOSRCH.WMQUICKSEARCH" Public Const SEARCH_TYPE_QUICK_SEARCH = "WMOSRCH.WMQUICKSEARCH"
Public Const SEARCH_TYPE_INDEX_SEARCH = "WMOSRCH.WMINDEXSEARCH" Public Const SEARCH_TYPE_INDEX_SEARCH = "WMOSRCH.WMINDEXSEARCH"
Public Const SEARCH_TYPE_OBJECTTYPE_SEARCH = "WMOSRCH.WMOBJECTTYPESEARCH" Public Const SEARCH_TYPE_OBJECTTYPE_SEARCH = "WMOSRCH.WMOBJECTTYPESEARCH"
' Attribute Types
Public Const ATTRIBUTE_TYPE_SYSTEMINDEX = 1
Public Const ATTRIBUTE_TYPE_TYPEINDEX = 2
' Misc ' Misc
Public Const OBJECT_TYPE_DEFAULT = "Standard" Public Const OBJECT_TYPE_DEFAULT = "Standard"

View File

@ -56,10 +56,14 @@ Public Class Helpers
Select Case Type Select Case Type
Case INDEX_TYPE_HASH Case INDEX_TYPE_HASH
Return Value
Case INDEX_TYPE_STRING Case INDEX_TYPE_STRING
Return Value
Case INDEX_TYPE_VECTOR_STRING Case INDEX_TYPE_VECTOR_STRING
Return Value Return Value
Case INDEX_TYPE_INTEGER Case INDEX_TYPE_INTEGER
Value = Value.Replace(" ", String.Empty)
Return Convert.ToInt16(Value)
Case INDEX_TYPE_VECTOR_INTEGER Case INDEX_TYPE_VECTOR_INTEGER
Value = Value.Replace(" ", String.Empty) Value = Value.Replace(" ", String.Empty)
Return Convert.ToInt16(Value) Return Convert.ToInt16(Value)
@ -67,17 +71,25 @@ Public Class Helpers
Value = Value.Replace(" ", String.Empty) Value = Value.Replace(" ", String.Empty)
Return Convert.ToInt64(Value) Return Convert.ToInt64(Value)
Case INDEX_TYPE_VECTOR_BOOLEAN Case INDEX_TYPE_VECTOR_BOOLEAN
Return Convert.ToBoolean(Value)
Case INDEX_TYPE_BOOLEAN Case INDEX_TYPE_BOOLEAN
Return Convert.ToBoolean(Value) Return Convert.ToBoolean(Value)
Case INDEX_TYPE_DATE Case INDEX_TYPE_DATE
Return Convert.ToDateTime(Value)
Case INDEX_TYPE_DATE_TIME Case INDEX_TYPE_DATE_TIME
Return Convert.ToDateTime(Value)
Case INDEX_TYPE_TIME Case INDEX_TYPE_TIME
Return Convert.ToDateTime(Value)
Case INDEX_TYPE_VECTOR_DATE_TIME Case INDEX_TYPE_VECTOR_DATE_TIME
Return Convert.ToDateTime(Value)
Case INDEX_TYPE_VECTOR_DATE Case INDEX_TYPE_VECTOR_DATE
Return Convert.ToDateTime(Value) Return Convert.ToDateTime(Value)
Case INDEX_TYPE_FLOAT Case INDEX_TYPE_FLOAT
Return Convert.ToDouble(Value)
Case INDEX_TYPE_VECTOR_FLOAT Case INDEX_TYPE_VECTOR_FLOAT
Return Convert.ToDouble(Value) Return Convert.ToDouble(Value)
Case Else
Return Value
End Select End Select
End Function End Function

View File

@ -7,6 +7,7 @@ Imports WMOSRCHLib
Imports WMCNNCTDLLLib Imports WMCNNCTDLLLib
Imports WMOTOOLLib Imports WMOTOOLLib
Imports System.IO Imports System.IO
Imports System.IO.Path
Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Logging
Imports System.Text.RegularExpressions Imports System.Text.RegularExpressions
@ -69,10 +70,9 @@ Public Class Windream
#Region "Private Properties" #Region "Private Properties"
Private ReadOnly _logger As Logger Private ReadOnly _logger As Logger
Private ReadOnly _logConfig As LogConfig Private ReadOnly _logConfig As LogConfig
Private ReadOnly _sessionDomain As String
Private ReadOnly Property _sessionDomain As String Private ReadOnly _sessionPassword As String
Private ReadOnly Property _sessionPassword As String Private ReadOnly _sessionUsername As String
Private ReadOnly Property _sessionUsername As String
#End Region #End Region
#Region "Public Properties" #Region "Public Properties"
@ -85,6 +85,8 @@ Public Class Windream
Public ReadOnly Property SessionReconnect As Boolean Public ReadOnly Property SessionReconnect As Boolean
Public ReadOnly Property SessionServername As String Public ReadOnly Property SessionServername As String
Public ReadOnly Property UsesDriveLetter As Boolean = True
''' <returns>A list of object types that are available</returns> ''' <returns>A list of object types that are available</returns>
Public ReadOnly Property ObjectTypes As List(Of String) Public ReadOnly Property ObjectTypes As List(Of String)
Get Get
@ -135,6 +137,10 @@ Public Class Windream
Me.SessionServername = SessionServerName Me.SessionServername = SessionServerName
Me.ClientBasePath = GetNormalizedBasePath(BasePath) Me.ClientBasePath = GetNormalizedBasePath(BasePath)
If ClientDriveLetter = String.Empty Then
UsesDriveLetter = False
End If
_sessionUsername = SessionUserName _sessionUsername = SessionUserName
_sessionPassword = SessionPassword _sessionPassword = SessionPassword
_sessionDomain = SessionDomain _sessionDomain = SessionDomain
@ -311,6 +317,41 @@ Public Class Windream
End Try End Try
End Function End Function
Public Function GetTypeIndiciesByObjecttype(ObjectTypeName As String, Optional SystemIndicies As Boolean = False) As List(Of String)
If TestSessionLoggedIn() = False Then
Return Nothing
End If
Dim oObjectType As IWMObject6
Dim oTempSession As IWMSession2
Dim oIndicies As New List(Of String)
Dim oAttributeFlag As Integer = 0
Try
' den Objekttyp laden
oTempSession = DirectCast(Session, IWMSession2)
oObjectType = Session.GetWMObjectByName(WMEntityObjectType, ObjectTypeName)
If SystemIndicies = True Then
oAttributeFlag = Constants.ATTRIBUTE_TYPE_SYSTEMINDEX
Else
oAttributeFlag = Constants.ATTRIBUTE_TYPE_TYPEINDEX
End If
Dim oVariableNames As WMObjectVariableNames = oObjectType.GetVariableNames(oAttributeFlag, False)
For oIndex = 0 To oVariableNames.Count - 1
oIndicies.Add(oVariableNames.Item(oIndex))
Next
Return oIndicies
Catch ex As Exception
_logger.Warn("Type Indicies could not be read")
_logger.Error(ex)
Return Nothing
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 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 oBrowser As ServerBrowser
Dim oConnect As IWMConnect2 Dim oConnect As IWMConnect2
@ -541,12 +582,16 @@ Public Class Windream
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 oFolderObject As WMObject Dim oFolderObject As WMObject
Dim oCurrentPath As String = String.Empty
For Each oFolder In oFolders For Each oFolder In oFolders
If TestFolderExists(Path) = False Then oCurrentPath = Combine(oCurrentPath, oFolder)
oFolderObject = Session.GetNewWMObjectFS(WMEntityFolder, oFolder, WMObjectEditModeNoEdit)
If TestFolderExists(oCurrentPath) = False Then
oFolderObject = Session.GetNewWMObjectFS(WMEntityFolder, oCurrentPath, WMObjectEditModeNoEdit)
End If End If
Next Next
@ -575,9 +620,8 @@ Public Class Windream
End Function End Function
Public Function NewFileStream(ByVal FilenameSource As String, ByVal FilenameTarget As String) As Boolean Public Function NewFileStream(ByVal FilenameSource As String, ByVal FilenameTarget As String) As Boolean
'Try
Dim oExtension As String = Path.GetExtension(FilenameSource) Dim oExtension As String = Path.GetExtension(FilenameSource)
_logger.Debug("Stream_File was started...")
If Not TestSessionLoggedIn() Then If Not TestSessionLoggedIn() Then
Return False Return False
End If End If
@ -585,23 +629,18 @@ Public Class Windream
Dim oTargetDrive As String = Path.GetDirectoryName(FilenameTarget) Dim oTargetDrive As String = Path.GetDirectoryName(FilenameTarget)
FilenameTarget = GetNormalizedPath(FilenameTarget) FilenameTarget = GetNormalizedPath(FilenameTarget)
_logger.Debug($"Streaming file from {FilenameSource} to {FilenameTarget}") _logger.NewBlock("File Stream")
_logger.Debug($"Preparing to stream file from {FilenameSource} to {FilenameTarget}")
Dim oWMObject As IWMObject6 = Nothing Dim oWMObject As IWMObject6 = Nothing
Dim oFileIO As WMFileIO Dim oFileIO As WMFileIO
Dim oWMStream As WMStream Dim oWMStream As WMStream
'_logger.Debug("Try to access file and lock it...")
'Err.Clear()
'Indexierungsdialog der Session unterdrücken 'Indexierungsdialog der Session unterdrücken
Session.SwitchEvents(Constants.COM_EVENT_SESSION_NEED_INDEX, False) Session.SwitchEvents(Constants.COM_EVENT_SESSION_NEED_INDEX, False)
'==================================================================
' create an object
'==================================================================
Try Try
' GetNewWMObjectFS already locks the WMObject
_logger.Debug("Creating WMObject for file {0}", FilenameTarget) _logger.Debug("Creating WMObject for file {0}", FilenameTarget)
oWMObject = Session.GetNewWMObjectFS(WMEntityDocument, FilenameTarget, WMObjectEditModeObject) oWMObject = Session.GetNewWMObjectFS(WMEntityDocument, FilenameTarget, WMObjectEditModeObject)
Catch ex As Exception Catch ex As Exception
@ -614,12 +653,6 @@ Public Class Windream
Return False Return False
End If End If
_logger.Debug("Locking object for {0}", FilenameTarget)
If LockObject(oWMObject) = False Then
_logger.Warn("Document {0} could not be locked", FilenameTarget)
Return False
End If
Try Try
_logger.Debug("Opening stream for {0}", FilenameTarget) _logger.Debug("Opening stream for {0}", FilenameTarget)
oWMStream = oWMObject.OpenStream(Constants.STREAM_BINARY_OBJECT, Constants.STREAM_OPEN_MODE_READ_WRITE) oWMStream = oWMObject.OpenStream(Constants.STREAM_BINARY_OBJECT, Constants.STREAM_OPEN_MODE_READ_WRITE)
@ -633,9 +666,9 @@ Public Class Windream
_logger.Debug("Creating FileIO", FilenameTarget) _logger.Debug("Creating FileIO", FilenameTarget)
oFileIO = New WMFileIO With { oFileIO = New WMFileIO With {
.bstrOriginalFileName = FilenameSource, .bstrOriginalFileName = FilenameSource,
.aWMStream = oWMStream .aWMStream = oWMStream
} }
Catch ex As Exception Catch ex As Exception
If UnlockObject(oWMObject) Then RemoveFile(FilenameTarget) If UnlockObject(oWMObject) Then RemoveFile(FilenameTarget)
_logger.Error(ex, "Error while creating FileIO object") _logger.Error(ex, "Error while creating FileIO object")
@ -664,80 +697,10 @@ Public Class Windream
Return False Return False
End Try End Try
_logger.Info($"File '{FilenameTarget}' was imported.") _logger.Info($"File '{FilenameTarget}' was streamed.")
_logger.EndBlock()
Return True Return True
'If Err.Number > 0 Then
' _logger.Warn($"WMObject could not be created - Error: ' {Err.Description}'")
'End If
' If oWMObject IsNot Nothing Then
' ' lock object for file system access (to change the file itself)
' LockObject(oWMObject)
' ' set fileIO the local source file
' oFileIO.bstrOriginalFileName = FilenameSource
' If Err.Number > 0 Then
' 'MsgBox(Err.Number.ToString)
' _logger.Warn($"fileIO could not be set - Error: '{Err.Description}'")
' If UnlockObject(oWMObject) Then RemoveFile(FilenameTarget)
' Return False
' End If
' ' open the windream object's file stream for writing
' oWMStream = oWMObject.OpenStream(Constants.STREAM_BINARY_OBJECT, Constants.STREAM_OPEN_MODE_READ_WRITE)
' If Err.Number > 0 Then
' _logger.Warn($"Error whhile creating stream - Error: '{Err.Description}'")
' If UnlockObject(oWMObject) Then RemoveFile(FilenameTarget)
' Return False
' End If
' _logger.Debug("oWMStream created!")
' ' give fileIO helper object the windream stream
' oFileIO.aWMStream = oWMStream
' If Err.Number > 0 Then
' _logger.Warn($"Error while adding aWMStream to aFileIO - Error: '{Err.Description}'")
' If UnlockObject(oWMObject) Then RemoveFile(FilenameTarget)
' Return False
' End If
' ' let fileIO object import the original file into windream
' oFileIO.ImportOriginal(True)
' If Err.Number > 0 Then
' _logger.Warn($"Error while FileIO.ImportOriginal(True) Error: '{Err.Description}'")
' If UnlockObject(oWMObject) Then RemoveFile(FilenameTarget)
' Return False
' End If
' _logger.Debug("Content of file was transferred!")
' ' close the windream file stream
' oWMStream.Close()
' If Err.Number > 0 Then
' _logger.Warn($"Error in aWMStream.Close() - Error: '{Err.Description}'")
' If UnlockObject(oWMObject) Then RemoveFile(FilenameTarget)
' Return False
' 'MsgBox(Err.Description)
' End If
' ' save new windream object
' oWMObject.Save()
' If Err.Number > 0 Then
' _logger.Warn($"Error while WMObject.save() - Error: '{Err.Description}'")
' If UnlockObject(oWMObject) Then RemoveFile(FilenameTarget)
' Return False
' 'MsgBox(Err.Description)
' End If
' _logger.Debug("File was saved correctly.")
' ' unlock the windream object
' If oWMObject.unlock() = False Then
' RemoveFile(FilenameTarget)
' Return False
' End If
' _logger.Info($"File '{FilenameTarget}' was imported.")
' Return True
' Else
' _logger.Warn($"WMObject could not be created!")
' Return False
' End If
'Catch ex As Exception
' _logger.Warn("Unexpected Error in NewStream_File:")
' _logger.Error(ex)
' Return False
'End Try
End Function End Function
Public Function LockObject(WMObject As WMObject, Optional EditMode As WMObjectEditMode = WMObjectEditModeNoEdit) As Boolean Public Function LockObject(WMObject As WMObject, Optional EditMode As WMObjectEditMode = WMObjectEditModeNoEdit) As Boolean
@ -763,12 +726,20 @@ Public Class Windream
Public Function GetNormalizedPath(Path As String) As String Public Function GetNormalizedPath(Path As String) As String
Dim oNormalizedPath = GetCleanedPath(Path) Dim oNormalizedPath = GetCleanedPath(Path)
If ClientDriveLetter <> String.Empty And Path.ToUpper().StartsWith(ClientDriveLetter.ToUpper) Then If UsesDriveLetter Then
oNormalizedPath = Path.Substring(2) ' Remove Driveletter eg. W:\
ElseIf Path.ToLower.StartsWith(ClientBasePath) Then If oNormalizedPath.StartsWith($"{ClientDriveLetter}:\") Then
oNormalizedPath = Path.Substring(ClientBasePath.Length) oNormalizedPath = oNormalizedPath.Substring(ClientDriveLetter + 2)
End If
Else
If oNormalizedPath.ToLower.StartsWith(ClientBasePath.ToLower) Then
' Remove Windream Base Path eg. \\windream\objects\
oNormalizedPath = oNormalizedPath.Substring(ClientBasePath.Length)
End If
End If End If
oNormalizedPath = oNormalizedPath.Replace("\\", "\")
Return oNormalizedPath Return oNormalizedPath
End Function End Function
@ -1089,18 +1060,27 @@ Public Class Windream
End Try End Try
End Function End Function
Public Function SetFileIndex(Path As String, IndexName As String, Value As String) As Boolean Public Function SetFileIndex(Path As String, IndexName As String, Value As String, ObjectType As String) As Boolean
If TestSessionLoggedIn() = False Then If TestSessionLoggedIn() = False Then
Return False Return False
End If End If
Dim oWMObject As WMObject = GetFileByPath(Path) If TestFileExists(Path) = False Then
_logger.Warn("File '{0}' does not exist", Path)
Return False
End If
Dim oWMObject As IWMObject6 = GetFileByPath(Path)
If LockObject(oWMObject, WMObjectEditModeIndexEdit) = False Then If LockObject(oWMObject, WMObjectEditModeIndexEdit) = False Then
_logger.Warn("File {0} could not be locked") _logger.Warn("File {0} could not be locked")
Return False Return False
End If End If
If oWMObject.aObjectType.aName = Constants.OBJECT_TYPE_DEFAULT Then
oWMObject.aObjectType = GetObjectByName(ObjectType, WMEntityObjectType)
End If
Try Try
Dim oType As Integer = GetIndexType(IndexName) Dim oType As Integer = GetIndexType(IndexName)
Dim oConvertedValue As Object = Helpers.ConvertIndexValue(oType, Value) Dim oConvertedValue As Object = Helpers.ConvertIndexValue(oType, Value)
@ -1118,6 +1098,53 @@ Public Class Windream
End Try End Try
End Function End Function
Public Function SetFileIndex(Path As String, IndexName As String, Values As List(Of String), ObjectType As String) As Boolean
If TestSessionLoggedIn() = False Then
Return False
End If
If TestFileExists(Path) = False Then
_logger.Warn("File '{0}' does not exist", Path)
Return False
End If
Dim oWMObject As IWMObject6 = GetFileByPath(Path)
If LockObject(oWMObject, WMObjectEditModeIndexEdit) = False Then
_logger.Warn("File {0} could not be locked")
Return False
End If
If oWMObject.aObjectType.aName = Constants.OBJECT_TYPE_DEFAULT Then
oWMObject.aObjectType = GetObjectByName(ObjectType, WMEntityObjectType)
End If
Try
Dim oType As Integer = GetIndexType(IndexName)
Dim oConvertedValues As New List(Of String)
Dim oArray As Object
ReDim oArray(Values.Count - 1)
For oIndex = 0 To Values.Count - 1
Dim oValue As Object = Helpers.ConvertIndexValue(oType, Values.Item(oIndex))
oArray(oIndex) = oValue
Next
oWMObject.SetVariableValue(IndexName, oArray)
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
End Try
End Function
Public Function ExportFile(WMObject As WMObject, ExportPath As String) As Boolean Public Function ExportFile(WMObject As WMObject, ExportPath As String) As Boolean
Try Try
Dim oWMObject As IWMObject6 = DirectCast(WMObject, IWMObject6) Dim oWMObject As IWMObject6 = DirectCast(WMObject, IWMObject6)
@ -1291,6 +1318,15 @@ Public Class Windream
Public Function TestGroupExists(Groupname As String) As Boolean Public Function TestGroupExists(Groupname As String) As Boolean
Return TestObjectExists(Groupname, WMEntityGroups) Return TestObjectExists(Groupname, WMEntityGroups)
End Function End Function
Public Function TestIndexTypeIsVectorIndex(IndexType As Integer) As Boolean
Return Helpers.IsVectorIndex(IndexType)
End Function
Public Function TestIndexNameIsVectorIndex(IndexName As String) As Boolean
Dim oIndexType As Integer = GetIndexType(IndexName)
Return Helpers.IsVectorIndex(oIndexType)
End Function
#End Region #End Region
#Region "Private Methods" #Region "Private Methods"