jj: Windream Version 0.0.0.2

This commit is contained in:
Jonathan Jenne 2018-10-08 16:43:45 +02:00
parent 46c65eb464
commit bad26b316a
4 changed files with 202 additions and 128 deletions

View File

@ -1,9 +1,10 @@
Imports NLog
Imports DigitalData.Modules.Logging
Public Class ConnectionBuilder
Implements IConnectionBuilder
Private ReadOnly LogFactory As LogFactory
Private ReadOnly LogConfig As LogConfig
Private SessionReconnect As Boolean = False
Private DriveLetter As String = "W"
Private Support64Bit As Boolean = False
@ -12,8 +13,8 @@ Public Class ConnectionBuilder
Private Password As String = Nothing
Private Domain As String = Nothing
Public Sub New(LogFactory As LogFactory)
Me.LogFactory = LogFactory
Public Sub New(LogConfig As LogConfig)
Me.LogConfig = LogConfig
End Sub
Public Function WithSessionReconnect() As IConnectionBuilder Implements IConnectionBuilder.WithSessionReconnect
@ -44,7 +45,7 @@ Public Class ConnectionBuilder
End Function
Public Function Connect() As Windream2 Implements IConnectionBuilder.Connect
Return New Windream2(LogFactory, SessionReconnect, DriveLetter, Support64Bit, ServerName, UserName, Password, Domain)
Return New Windream2(LogConfig, SessionReconnect, DriveLetter, Support64Bit, ServerName, UserName, Password, Domain)
End Function
End Class

View File

@ -48,4 +48,12 @@
' Misc
Public Const OBJECT_TYPE_DEFAULT = "Standard"
' File Stream
Public Const STREAM_BINARY_OBJECT = "BinaryObject"
Public Const STREAM_OPEN_MODE_READ_WRITE = 2
' COM Events
Public Const COM_EVENT_SESSION_NEED_INDEX = 1
End Class

View File

@ -136,5 +136,11 @@
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Modules.Logging\Logging.vbproj">
<Project>{903b2d7d-3b80-4be9-8713-7447b704e1b0}</Project>
<Name>Logging</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
</Project>

View File

@ -2,28 +2,25 @@
Imports WINDREAMLib.WMCOMEvent
Imports WINDREAMLib.WMEntity
Imports WINDREAMLib.WMObjectEditMode
Imports WINDREAMLib.WMSearchOperator
Imports WINDREAMLib.WMSearchRelation
Imports WMOBRWSLib
Imports WMOSRCHLib
Imports WMCNNCTDLLLib
Imports WMOTOOLLib
Imports NLog
Imports System.IO
Imports DigitalData.Modules.Logging
''' <summary>
''' MODULE: Windream
'''
''' VERSION: 0.0.0.1
''' VERSION: 0.0.0.2
'''
''' DATE: 27.08.2018
''' DATE: 08.10.2018
'''
''' DESCRIPTION:
'''
''' DEPENDENCIES: NLog, >= 4.5.8
'''
''' PARAMETERS: LogFactory, NLog.LogFactory
''' PARAMETERS: LogConfig, DigitalData.Modules.Logging.LogConfig
''' The LogFactory containing the current log config. Used to instanciate the class logger for this and any dependent class
'''
''' ClientDriveLetter, String
@ -60,10 +57,9 @@ Imports System.IO
''' REMARKS: This class should not be instanciated directly. Instead, ConnectionBuilder should be used.
''' </summary>
Public Class Windream2
Const WMObjectStreamOpenModeReadWrite = 2
#Region "Private Properties"
Private ReadOnly _logger As Logger
Private ReadOnly _loggerFactory As LogFactory
Private ReadOnly _logConfig As LogConfig
Private ReadOnly Property _sessionDomain As String
Private ReadOnly Property _sessionPassword As String
@ -97,7 +93,7 @@ Public Class Windream2
''' <summary>
''' Creates a new Windream object and connects to a server with the provided options and credentials
''' </summary>
''' <param name="LogFactory"></param>
''' <param name="LogConfig"></param>
''' <param name="SessionReconnect"></param>
''' <param name="ClientDriveLetter"></param>
''' <param name="ClientSupport64Bit"></param>
@ -106,10 +102,10 @@ Public Class Windream2
''' <param name="SessionPassword"></param>
''' <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)
Public Sub New(LogConfig As LogConfig, 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
_logger = LogConfig.GetLogger()
_logConfig = LogConfig
' Create a session
Dim oSession As IWMSession2 = NewSession(SessionServerName, SessionUserName, SessionPassword, SessionDomain)
@ -268,107 +264,170 @@ Public Class Windream2
End Try
End Function
Public Function NewStream_File(ByVal FilenameSource As String, ByVal filenameTarget As String)
Try
Public Function NewFileStream(ByVal FilenameSource As String, ByVal FilenameTarget As String) As Boolean
'Try
Dim oExtension As String = Path.GetExtension(FilenameSource)
_logger.Debug("Stream_File was started...")
If Not TestSessionLoggedIn() Then
Return False
End If
Dim oTargetDrive As String = Path.GetDirectoryName(filenameTarget)
filenameTarget = GetNormalizedPath(filenameTarget)
Const STREAM_BinaryObject = "BinaryObject"
Dim oTargetDrive As String = Path.GetDirectoryName(FilenameTarget)
FilenameTarget = GetNormalizedPath(FilenameTarget)
_logger.Debug($"Import file from {FilenameSource } to {filenameTarget}")
_logger.Debug($"Streaming file from {FilenameSource} to {FilenameTarget}")
Dim WMObject
Dim aFileIO
Dim aWMStream
Dim oWMObject As IWMObject6 = Nothing
Dim oFileIO As WMFileIO
Dim oWMStream As WMStream
aFileIO = New WMOTOOLLib.WMFileIO
_logger.Debug("Try to access file and lock it...")
Err.Clear()
Const WMCOMEventWMSessionNeedIndex = 1
'_logger.Debug("Try to access file and lock it...")
'Err.Clear()
'Indexierungsdialog der Session unterdrücken
Session.SwitchEvents(WMCOMEventWMSessionNeedIndex, False)
'clsWindream.MY_WDSESSION.switchEvents(WMCOMEventWMSessionNeedIndex, False)
Session.SwitchEvents(Constants.COM_EVENT_SESSION_NEED_INDEX, False)
'==================================================================
' create an object
'==================================================================
WMObject = Session.GetNewWMObjectFS(WMEntity.WMEntityDocument, filenameTarget, WMObjectEditModeObject)
If Err.Number > 0 Then
_logger.Warn($"WMObject could not be created - Error: ' {Err.Description}'")
End If
If WMObject IsNot Nothing Then
' lock object for file system access (to change the file itself)
LockObject(WMObject)
' set fileIO the local source file
aFileIO.bstrOriginalFileName = FilenameSource
If Err.Number > 0 Then
'MsgBox(Err.Number.ToString)
_logger.Warn($"fileIO could not be set - Error: '{Err.Description}'")
If UnlockObject(WMObject) Then RemoveFile(filenameTarget)
Return False
End If
' open the windream object's file stream for writing
aWMStream = WMObject.OpenStream(STREAM_BinaryObject, WMObjectStreamOpenModeReadWrite)
If Err.Number > 0 Then
_logger.Warn($"Error whhile creating stream - Error: '{Err.Description}'")
If UnlockObject(WMObject) Then RemoveFile(filenameTarget)
Return False
End If
_logger.Debug("oWMStream created!")
' give fileIO helper object the windream stream
aFileIO.aWMStream = aWMStream
If Err.Number > 0 Then
_logger.Warn($"Error while adding aWMStream to aFileIO - Error: '{Err.Description}'")
If UnlockObject(WMObject) Then RemoveFile(filenameTarget)
Return False
End If
' let fileIO object import the original file into windream
aFileIO.ImportOriginal(True)
If Err.Number > 0 Then
_logger.Warn($"Error while FileIO.ImportOriginal(True) Error: '{Err.Description}'")
If UnlockObject(WMObject) Then RemoveFile(filenameTarget)
Return False
End If
_logger.Debug("Content of file was transferred!")
' close the windream file stream
aWMStream.Close()
If Err.Number > 0 Then
_logger.Warn($"Error in aWMStream.Close() - Error: '{Err.Description}'")
If UnlockObject(WMObject) Then RemoveFile(filenameTarget)
Return False
'MsgBox(Err.Description)
End If
' save new windream object
WMObject.save()
If Err.Number > 0 Then
_logger.Warn($"Error while WMObject.save() - Error: '{Err.Description}'")
If UnlockObject(WMObject) Then RemoveFile(filenameTarget)
Return False
'MsgBox(Err.Description)
End If
_logger.Debug("File was saved correctly.")
' unlock the windream object
If WMObject.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
Try
_logger.Debug("Creating WMObject for file {0}", FilenameTarget)
oWMObject = Session.GetNewWMObjectFS(WMEntityDocument, FilenameTarget, WMObjectEditModeObject)
Catch ex As Exception
_logger.Warn("Unexpected Error in NewStream_File:")
_logger.Error(ex)
_logger.Error(ex, "WMObject could not be created")
Return False
End Try
If oWMObject Is Nothing Then
_logger.Warn("Document {0} could not be found", FilenameTarget)
Return False
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
_logger.Debug("Opening stream for {0}", FilenameTarget)
oWMStream = oWMObject.OpenStream(Constants.STREAM_BINARY_OBJECT, Constants.STREAM_OPEN_MODE_READ_WRITE)
Catch ex As Exception
_logger.Error(ex)
If UnlockObject(oWMObject) Then RemoveFile(FilenameTarget)
Return False
End Try
Try
_logger.Debug("Creating FileIO", FilenameTarget)
oFileIO = New WMFileIO With {
.bstrOriginalFileName = FilenameSource,
.aWMStream = oWMStream
}
Catch ex As Exception
If UnlockObject(oWMObject) Then RemoveFile(FilenameTarget)
_logger.Error(ex, "Error while creating FileIO object")
Return False
End Try
Try
_logger.Debug("Streaming file...")
oFileIO.ImportOriginal(True)
_logger.Debug("Content of file was transferred!")
Catch ex As Exception
If UnlockObject(oWMObject) Then RemoveFile(FilenameTarget)
_logger.Error(ex, "Error while streaming file")
Return False
End Try
Try
_logger.Debug("Closing Stream")
oWMStream.Close()
_logger.Debug("Saving new object")
oWMObject.Save()
_logger.Debug("Unlocking new object")
oWMObject.unlock()
Catch ex As Exception
RemoveFile(FilenameTarget)
Return False
End Try
_logger.Info($"File '{FilenameTarget}' was imported.")
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
Public Function LockObject(WMObject As WMObject, Optional EditMode As WMObjectEditMode = WMObjectEditModeNoEdit) As Boolean
@ -391,15 +450,17 @@ 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)
Public Function GetSearchDocuments(SearchFilePath As String, DocIdIndexName As String) As DataTable
Dim oDatatable As New DataTable
oDatatable.Columns.Add("PATH", GetType(String))
oDatatable.Columns.Add("DOCID", GetType(Integer))
If TestSessionLoggedIn() = False Then
Return oResult
Return oDatatable
End If
If TestFileExists(SearchFilePath) = False Then
Return oResult
Return oDatatable
End If
Try
@ -450,27 +511,27 @@ Public Class Windream2
oSearch = oObjecttypeSearch.GetSearch()
Case Else
_logger.Warn("{0} is not a valid search type", oSearchType)
Return oResult
Return oDatatable
End Select
Dim oSearchResults As WMObjects = oSearch.Execute()
If oSearchResults.Count = 0 Then
Return oResult
Return oDatatable
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)
oDatatable.Rows.Add(path, docId)
Next
oDatatable.AcceptChanges()
Return oResult
Return oDatatable
Catch ex As Exception
_logger.Error(ex)
Return oResult
Return oDatatable
End Try
End Function
@ -507,8 +568,7 @@ Public Class Windream2
End If
Try
Dim oTempSession As IWMSession2 = DirectCast(Session, IWMSession2)
oChoicelist = oTempSession.GetWMObjectByName(WMEntityChoiceList, ChoiceListName)
oChoicelist = Session.GetWMObjectByName(WMEntityChoiceList, ChoiceListName)
Catch ex As Exception
_logger.Error(ex, "Could not get choice list")
Return oItems
@ -586,8 +646,7 @@ Public Class Windream2
End If
Try
Dim oTempSession As IWMSession2 = DirectCast(Session, IWMSession2)
Dim oAttribute = oTempSession.GetWMObjectByName(WMEntityAttribute, IndexName)
Dim oAttribute = Session.GetWMObjectByName(WMEntityAttribute, IndexName)
Dim oType = oAttribute.GetVariableValue("dwAttrType")
Return oType
Catch ex As Exception