MS Added Stream File
This commit is contained in:
parent
49ee0a9374
commit
abf4020a18
@ -2,6 +2,7 @@
|
||||
Imports WINDREAMLib.WMCOMEvent
|
||||
Imports WINDREAMLib.WMEntity
|
||||
Imports WINDREAMLib.WMObjectEditMode
|
||||
|
||||
Imports WINDREAMLib.WMSearchOperator
|
||||
Imports WINDREAMLib.WMSearchRelation
|
||||
Imports WMOBRWSLib
|
||||
@ -59,6 +60,7 @@ 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
|
||||
@ -266,6 +268,109 @@ Public Class Windream2
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function NewStream_File(ByVal FilenameSource As String, ByVal filenameTarget As String)
|
||||
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"
|
||||
|
||||
_logger.Debug($"Import file from {FilenameSource } to {filenameTarget}")
|
||||
|
||||
Dim WMObject
|
||||
Dim aFileIO
|
||||
Dim aWMStream
|
||||
|
||||
aFileIO = New WMOTOOLLib.WMFileIO
|
||||
_logger.Debug("Try to access file and lock it...")
|
||||
Err.Clear()
|
||||
Const WMCOMEventWMSessionNeedIndex = 1
|
||||
|
||||
'Indexierungsdialog der Session unterdrücken
|
||||
Session.SwitchEvents(WMCOMEventWMSessionNeedIndex, False)
|
||||
'clsWindream.MY_WDSESSION.switchEvents(WMCOMEventWMSessionNeedIndex, 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
|
||||
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
|
||||
Try
|
||||
WMObject.LockFor(EditMode)
|
||||
@ -526,7 +631,112 @@ Public Class Windream2
|
||||
Return oResult
|
||||
End Try
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Gets an array of the actual vektorvalues of index, collated with the passed values
|
||||
''' </summary>
|
||||
''' <param name="WMDoc">windream-file as WMObject</param>
|
||||
''' <param name="IndexName">Indexname as String</param>
|
||||
''' <param name="NewValues">The new values as Array</param>
|
||||
''' <param name="CheckDuplikat">True if duplicates shall be prevented</param>
|
||||
''' <exception cref="Exceptions.SessionException"></exception>
|
||||
Public Function GetVektorData_Combined(ByVal WMDoc As WMObject, IndexName As String, NewValues As Object, CheckDuplikat As Boolean)
|
||||
Try
|
||||
Dim oAnzahl As Integer = 0
|
||||
Dim oValueArray()
|
||||
'Jeden Wert des Vektorfeldes durchlaufen
|
||||
Dim oWMValue = WMDoc.GetVariableValue(IndexName)
|
||||
If oWMValue Is Nothing = False Then
|
||||
'Nochmals prüfen ob wirklich Array
|
||||
If oWMValue.GetType.ToString.Contains("System.Object") Then
|
||||
'Keine Duplikatprüfung also einfach neues Array füllen
|
||||
If CheckDuplikat = False Then
|
||||
For Each ovalue As Object In oWMValue
|
||||
'Das Array anpassen
|
||||
ReDim Preserve oValueArray(oAnzahl)
|
||||
'Den Wert im Array speichern
|
||||
oValueArray(oAnzahl) = ovalue.ToString
|
||||
oAnzahl += 1
|
||||
Next
|
||||
'Und jetzt den/die Neuen Wert(e) anfügen
|
||||
For Each oNewValue As Object In NewValues
|
||||
If oNewValue Is Nothing = False Then
|
||||
'Das Array anpassen
|
||||
ReDim Preserve oValueArray(oAnzahl)
|
||||
'Den Wert im Array speichern
|
||||
oValueArray(oAnzahl) = oNewValue.ToString
|
||||
oAnzahl += 1
|
||||
End If
|
||||
Next
|
||||
Else
|
||||
_logger.Debug("Duplicates shall be checked...")
|
||||
'Duplikat Prüfung an, also nur anhängen wenn Wert <>
|
||||
For Each oValue As Object In oWMValue
|
||||
If oValue Is Nothing = False Then
|
||||
'Erst einmal die ALten Werte schreiben
|
||||
ReDim Preserve oValueArray(oAnzahl)
|
||||
'Den Wert im Array speichern
|
||||
oValueArray(oAnzahl) = oValue.ToString
|
||||
_logger.Debug("Value (" & oAnzahl & ") " & oValue.ToString)
|
||||
oAnzahl += 1
|
||||
End If
|
||||
Next
|
||||
'Jetzt die Neuen Werte auf Duplikate überprüfen
|
||||
For Each NewValue As Object In NewValues
|
||||
If NewValue Is Nothing = False Then
|
||||
If oValueArray.Contains(NewValue) = False Then
|
||||
_logger.Debug("New Value (" & oAnzahl & ") " & NewValue.ToString)
|
||||
'Das Array anpassen
|
||||
ReDim Preserve oValueArray(oAnzahl)
|
||||
'Den Wert im Array speichern
|
||||
oValueArray(oAnzahl) = NewValue.ToString
|
||||
oAnzahl += 1
|
||||
Else
|
||||
_logger.Debug("Value '" & NewValue.ToString & "' bereits in Vektorfeld enthalten")
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
End If
|
||||
Else
|
||||
_logger.Debug("Vektorfeld ist noch leer....")
|
||||
'Den/die Neuen Wert(e) anfügen
|
||||
For Each oNewValue As Object In NewValues
|
||||
If oNewValue Is Nothing = False Then
|
||||
If CheckDuplikat = True Then
|
||||
If oValueArray Is Nothing = False Then
|
||||
If oValueArray.Contains(oNewValue) = False Then
|
||||
'Das Array anpassen
|
||||
ReDim Preserve oValueArray(oAnzahl)
|
||||
'Den Wert im Array speichern
|
||||
oValueArray(oAnzahl) = oNewValue.ToString
|
||||
oAnzahl += 1
|
||||
Else
|
||||
_logger.Debug("Value '" & oNewValue.ToString & "' bereits in Array enthalten")
|
||||
End If
|
||||
Else 'Dererste Wert, also hinzufügen
|
||||
'Das Array anpassen
|
||||
ReDim Preserve oValueArray(oAnzahl)
|
||||
'Den Wert im Array speichern
|
||||
oValueArray(oAnzahl) = oNewValue.ToString
|
||||
oAnzahl += 1
|
||||
End If
|
||||
Else
|
||||
'Das Array anpassen
|
||||
ReDim Preserve oValueArray(oAnzahl)
|
||||
'Den Wert im Array speichern
|
||||
oValueArray(oAnzahl) = oNewValue.ToString
|
||||
oAnzahl += 1
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
_logger.Debug("Return ValueArray: length " & oValueArray.Length)
|
||||
Return oValueArray
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
Public Function SetFolderObjecttype(FolderPath As String, Objecttype As String) As Boolean
|
||||
If TestSessionLoggedIn() = False Then
|
||||
Return False
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user