diff --git a/Controls.LookupGrid/frmLookupGrid.Designer.vb b/Controls.LookupGrid/frmLookupGrid.Designer.vb
index b194e30b..d12553f3 100644
--- a/Controls.LookupGrid/frmLookupGrid.Designer.vb
+++ b/Controls.LookupGrid/frmLookupGrid.Designer.vb
@@ -46,6 +46,7 @@ Partial Class frmLookupGrid
'
Me.viewLookup.GridControl = Me.gridLookup
Me.viewLookup.Name = "viewLookup"
+ Me.viewLookup.OptionsView.ShowGroupPanel = False
'
'Panel1
'
diff --git a/GUIs.Test.TestGUI/Form1.vb b/GUIs.Test.TestGUI/Form1.vb
index dcde0760..dc815368 100644
--- a/GUIs.Test.TestGUI/Form1.vb
+++ b/GUIs.Test.TestGUI/Form1.vb
@@ -8,7 +8,7 @@ Public Class Form1
Dim MyLogger As LogConfig
Dim Logger As Logger
- Protected _windream2 As Windream2
+ Protected _windream2 As Windream
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim serverName As String = TextBox1.Text
diff --git a/Modules.Windream/ConnectionBuilder.vb b/Modules.Windream/ConnectionBuilder.vb
index da7e5321..5997db69 100644
--- a/Modules.Windream/ConnectionBuilder.vb
+++ b/Modules.Windream/ConnectionBuilder.vb
@@ -7,12 +7,15 @@ Public Class ConnectionBuilder
Private ReadOnly LogConfig As LogConfig
Private SessionReconnect As Boolean = False
Private DriveLetter As String = "W"
+ Private BasePath As String = BASE_PATH
Private Support64Bit As Boolean = False
Private ServerName As String = Nothing
Private UserName As String = Nothing
Private Password As String = Nothing
Private Domain As String = Nothing
+ Private Const BASE_PATH As String = "\\windream\objects"
+
Public Sub New(LogConfig As LogConfig)
Me.LogConfig = LogConfig
End Sub
@@ -33,9 +36,32 @@ Public Class ConnectionBuilder
''' A IConnectionBuilder instance to allow for chaining
Public Function WithDriveLetter(driveLetter As String) As IConnectionBuilder Implements IConnectionBuilder.WithDriveLetter
Me.DriveLetter = driveLetter
+ BasePath = String.Empty
Return Me
End Function
+ '''
+ ''' Sets the drive letter to String.Empty, use \\windream\objects as Windream base path
+ '''
+ ''' The windream base path, eg. \\windream\objects
+ ''' A IConnectionBuilder instance to allow for chaining
+ Public Function WithWindreamObjects(BasePath As String) As IConnectionBuilder Implements IConnectionBuilder.WithWindreamObjects
+ BasePath = BasePath
+ DriveLetter = String.Empty
+ Return Me
+ End Function
+
+ '''
+ ''' Sets the drive letter to String.Empty, use \\windream\objects as Windream base path
+ '''
+ ''' A IConnectionBuilder instance to allow for chaining
+ Public Function WithWindreamObjects() As IConnectionBuilder Implements IConnectionBuilder.WithWindreamObjects
+ BasePath = BASE_PATH
+ DriveLetter = String.Empty
+ Return Me
+ End Function
+
+
'''
''' Sets flag in Windream class to indicate 64-bit support
'''
@@ -74,8 +100,8 @@ Public Class ConnectionBuilder
'''
''' If there was an error while establishing the connection
''' A Windream Object
- Public Function Connect() As Windream2 Implements IConnectionBuilder.Connect
- Return New Windream2(LogConfig, SessionReconnect, DriveLetter, Support64Bit, ServerName, UserName, Password, Domain)
+ Public Function Connect() As Windream Implements IConnectionBuilder.Connect
+ Return New Windream(LogConfig, SessionReconnect, DriveLetter, BasePath, Support64Bit, ServerName, UserName, Password, Domain)
End Function
End Class
diff --git a/Modules.Windream/Constants.vb b/Modules.Windream/Constants.vb
index 35b27f1d..986844c8 100644
--- a/Modules.Windream/Constants.vb
+++ b/Modules.Windream/Constants.vb
@@ -55,5 +55,6 @@
' COM Events
Public Const COM_EVENT_SESSION_NEED_INDEX = 1
-
+ ' Regexes
+ Public Const REGEX_CLEAN_FILENAME As String = "[?*^""<>|]"
End Class
diff --git a/Modules.Windream/IConnectionBuilder.vb b/Modules.Windream/IConnectionBuilder.vb
index 93b8456a..0dbca2cc 100644
--- a/Modules.Windream/IConnectionBuilder.vb
+++ b/Modules.Windream/IConnectionBuilder.vb
@@ -1,8 +1,10 @@
Public Interface IConnectionBuilder
Function WithSessionReconnect() As IConnectionBuilder
Function WithDriveLetter(driveLetter As String) As IConnectionBuilder
+ Function WithWindreamObjects() As IConnectionBuilder
+ Function WithWindreamObjects(BasePath As String) As IConnectionBuilder
Function With64BitSupport() As IConnectionBuilder
Function WithServerName(serverName As String) As IConnectionBuilder
Function WithImpersonation(userName As String, password As String, domain As String) As IConnectionBuilder
- Function Connect() As Windream2
+ Function Connect() As Windream
End Interface
diff --git a/Modules.Windream/Windream.vb b/Modules.Windream/Windream.vb
index 92f8b98f..b5b134b0 100644
--- a/Modules.Windream/Windream.vb
+++ b/Modules.Windream/Windream.vb
@@ -2,664 +2,291 @@
Imports WINDREAMLib.WMCOMEvent
Imports WINDREAMLib.WMEntity
Imports WINDREAMLib.WMObjectEditMode
-Imports WINDREAMLib.WMSearchOperator
-Imports WINDREAMLib.WMSearchRelation
Imports WMOBRWSLib
Imports WMOSRCHLib
Imports WMCNNCTDLLLib
Imports WMOTOOLLib
+Imports System.IO
+Imports DigitalData.Modules.Logging
+Imports System.Text.RegularExpressions
+
+''' Windream
+''' 0.0.0.2
+''' 23.10.2018
+'''
+''' Module that provides methods to access the Windream ECM
+'''
+'''
+''' NLog, >= 4.5.8
+'''
+'''
+''' 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
+''' Drive Letter of the Windream Drive, should default to `W`
+'''
+''' ClientSupport64Bit, Boolean
+''' Should this session support 64bit methods/functionality?
+'''
+''' SessionReconnect, Boolean
+''' Should the session reconnect automatically when the connection to the server is lost?
+'''
+''' SessionServerName, String
+''' Name of the server used in the connection. If this is `Nothing`, the current server defined in the client is used
+'''
+''' SessionUserName, String
+''' Name of the user that is used in the connection. If this is `Nothing`, the currently signed in user is used
+'''
+''' SessionPassword, String
+''' User-password that is used in the connection. If this is `Nothing`, the currently signed in user is used
+'''
+''' SessionDomain, String
+''' User-domain that is used in the connection. If this is `Nothing`, the currently signed in user is used
+'''
+'''
+''' ClientDriveLetter, String (readonly)
+''' ClientSupports64Bit, Boolean (readonly)
+''' Session, IWMSession2 (readonly)
+''' SessionLoggedin, Boolean (readonly)
+''' SessionReconnect, Boolean (readonly)
+''' SessionServername, String (readonly)
+''' Objecttypes, List(Of String) (readonly)
+'''
+'''
+''' _windream = New ConnectionBuilder(LogConfig).
+''' WithDriveLetter("W").
+''' WithSessionReconnect().
+''' With64BitSupport().
+''' WithServerName("sdd-vmx02-aps01").
+''' Connect()
+'''
+'''
+''' This class should not be instanciated directly. Instead, ConnectionBuilder should be used.
+'''
Public Class Windream
- Inherits Constants
-#Region "+++++ Variables +++++"
- Private Shared Logger As NLog.Logger = NLog.LogManager.GetCurrentClassLogger
- Private ServerBrowser As IServerBrowser
+#Region "Private Properties"
+ Private ReadOnly _logger As Logger
+ Private ReadOnly _logConfig As LogConfig
- Private CurrentController As WMOSearchController
- Private CurrentSession As WMSession
- Private CurrentConnect As WMConnect
- Private CurrentServer As String
- Private CurrentObjecttypes As WMObjects
+ Private ReadOnly Property _sessionDomain As String
+ Private ReadOnly Property _sessionPassword As String
+ Private ReadOnly Property _sessionUsername As String
+
+#End Region
+#Region "Public Properties"
+ Public ReadOnly Property ClientDriveLetter As String
+ Public ReadOnly Property ClientBasePath As String
+ Public ReadOnly Property ClientSupports64Bit As Boolean
+
+ Public ReadOnly Property Session As IWMSession2
+ Public ReadOnly Property SessionLoggedin As Boolean = False
+ Public ReadOnly Property SessionReconnect As Boolean
+ Public ReadOnly Property SessionServername As String
+
+ ''' A list of object types that are available
+ Public ReadOnly Property ObjectTypes As List(Of String)
+ Get
+ Dim types As WMObjects = GetObjectTypes()
+ Dim list As New List(Of String)
+
+ For Each type As WMObject In types
+ list.Add(type.aName)
+ Next
+
+ Return list
+ End Get
+ End Property
- Public ReadOnly Property ReconnectSession As Boolean
- Public ReadOnly Property DriveLetter As String
- Public ReadOnly Property Support64Bit As Boolean
- Public Property LoggedInSession As Boolean = False
#End Region
-#Region "+++++ Init +++++"
'''
- ''' Initializes windream and creates a windream session with the actual user
+ ''' Creates a new Windream object and connects to a server with the provided options and credentials
'''
- '''
- Public Sub New(
- Optional DriveLetter As String = "W",
- Optional ReconnectSession As Boolean = False,
- Optional Support64Bit As Boolean = False,
- Optional ServerName As String = Nothing,
- Optional UserName As String = Nothing,
- Optional UserPass As String = Nothing,
- Optional UserDomain As String = Nothing
- )
- Try
- Me.DriveLetter = DriveLetter
- Me.ReconnectSession = ReconnectSession
- Me.Support64Bit = Support64Bit
+ '''
+ '''
+ '''
+ '''
+ '''
+ '''
+ '''
+ '''
+ '''
+ Public Sub New(LogConfig As LogConfig, SessionReconnect As Boolean, ClientDriveLetter As String, BasePath 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 = LogConfig.GetLogger()
+ _logConfig = LogConfig
- Dim session As WMSession = NewSession(ServerName, UserName, UserPass, UserDomain)
+ ' Create a session
+ Dim oSession As IWMSession2 = NewSession(SessionServerName, SessionUserName, SessionPassword, SessionDomain)
- If session Is Nothing Then
- Throw New Exception("Login failed")
- End If
+ ' If no session could be created, exit
+ If oSession Is Nothing Then
+ Throw New Exceptions.SessionException()
+ End If
- CurrentSession = session
- CurrentServer = ServerName
- CurrentObjecttypes = GetObjectTypes()
+ ' Set properties of currently established session
+ Session = oSession
+ SessionLoggedin = True
- Catch ex As Exception
- Logger.Error(ex)
- End Try
+ Me.SessionReconnect = SessionReconnect
+ Me.ClientDriveLetter = ClientDriveLetter
+ Me.ClientSupports64Bit = ClientSupport64Bit
+ Me.SessionServername = SessionServerName
+ Me.ClientBasePath = BasePath
+
+ _sessionUsername = SessionUserName
+ _sessionPassword = SessionPassword
+ _sessionDomain = SessionDomain
End Sub
- Public Function NewSession(Optional serverName As String = Nothing) As WMSession
- Dim browser As ServerBrowser
- Dim connect As WMConnect
- Dim session As WMSession
- Dim credentials As WMUserIdentity
+ Public Function GetChoiceListItems(ChoiceListName As String) As List(Of String)
+ Dim oItems As New List(Of String)
+ Dim oChoicelist As WMObject
- Try
- browser = New ServerBrowser()
- connect = New WMConnect()
- Logger.Info("Successfully created windream objects")
- Catch ex As Exception
- Logger.Error(ex, "Error while creating windream objects")
- Return Nothing
- End Try
-
- Try
- If serverName Is Nothing OrElse serverName.Length = 0 Then
- serverName = browser.GetCurrentServer()
- End If
- Catch ex As Exception
- Logger.Error(ex, "Error while getting current server")
- Return Nothing
- End Try
-
- Try
- credentials = New WMUserIdentity() With {
- .aServerName = serverName
- }
- Catch ex As Exception
- Logger.Error(ex, "Error while creating user identity")
- Return Nothing
- End Try
-
- Try
- session = connect.Login(credentials)
- 'LoggedInSession = True
- CurrentServer = serverName
-
- Return session
- Catch ex As Exception
- Logger.Error(ex, "Error while logging in")
- 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 WMSession
- Dim browser As ServerBrowser
- Dim connect As WMConnect
- Dim session As WMSession
- Dim credentials As WMUserIdentity
-
- Dim impersonation As Boolean
- Dim serverNameFromClient As Boolean
-
- Try
- browser = New ServerBrowser()
- connect = New WMConnect()
- Logger.Info("Successfully created windream objects")
- Catch ex As Exception
- Logger.Error(ex, "Error while creating windream objects")
- Return Nothing
- End Try
-
- ' If no server was supplied, try to get the current server set in the client
- Try
- If serverName Is Nothing OrElse serverName.Length = 0 Then
- serverName = browser.GetCurrentServer
- serverNameFromClient = True
- Else
- serverNameFromClient = False
- End If
- Catch ex As Exception
- Logger.Error(ex, "Error while getting Servername")
- Return Nothing
- End Try
-
- Logger.Info("Servername: {0}", serverName)
- Logger.Info("Servername aquired from client: {0}", serverNameFromClient)
-
- 'TODO: Test connection to windream server
-
- ' If username, password and domain are set, login with impersonation
- ' Else, login with current credentials
- If userName IsNot Nothing And password IsNot Nothing And domain IsNot Nothing Then
- impersonation = True
- credentials = New WMUserIdentity() With {
- .aServerName = serverName,
- .aUserName = userName,
- .aPassword = password,
- .aDomain = domain
- }
-
- connect.ModuleId = 9
-
- Logger.Info("Impersonated Login: True")
- Logger.Info("Username: {0}", userName)
- Logger.Info("Domain: {0}", domain)
- Else
- impersonation = False
- credentials = New WMUserIdentity() With {
- .aServerName = serverName
- }
-
- Logger.Info("Impersonated Login: False")
- Logger.Info("Username: {0}", Environment.UserName)
- Logger.Info("Domain: {0}", Environment.UserDomainName)
+ If TestSessionLoggedIn() = False Then
+ Return oItems
End If
Try
- session = connect.Login(credentials)
+ oChoicelist = Session.GetWMObjectByName(WMEntityChoiceList, ChoiceListName)
Catch ex As Exception
- Logger.Error(ex, "Error while logging in")
- Return Nothing
+ _logger.Error(ex, "Could not get choice list")
+ Return oItems
End Try
Try
- ' Standardmässig hinterlegen dass abgelegte Dateien keine Indexmaske öffnet
- session.SwitchEvents(WMCOMEventWMSessionNeedIndex, False)
- Catch ex As Exception
- Logger.Error(ex, "Could not SwitchEvents")
- Return Nothing
- End Try
+ Dim oChoiceListItems As Object = oChoicelist.GetVariableValue("vItems")
- If session.aLoggedin = False Then
- Logger.Warn("Session created but user {0} could not be logged in", Environment.UserName)
- Return Nothing
- End If
+ If oChoiceListItems Is Nothing Then
+ Return oItems
+ End If
- Return session
- End Function
-
-
- Private Function GetObjectTypes() As WMObjects
- Dim objectTypes As WMObjects
-
- Try
- objectTypes = CurrentSession.GetWMObjectTypes(WMEntityDocument)
- Return objectTypes
- Catch ex As Exception
- Logger.Error(ex)
- Return Nothing
- End Try
- End Function
-
- '''
- ''' Returns all Objecttypes of current server as list of strings
- '''
- ''' List of String of all objecttypes
- '''
- Public Function GetObjecttypeNames() As List(Of String)
- Dim objectTypes As New List(Of String)
-
- Try
- For i As Integer = 0 To CurrentObjecttypes.Count
- objectTypes.Add(CurrentObjecttypes.Item(i).aName)
+ For Each oChoiceListItem In oChoiceListItems
+ oItems.Add(oChoiceListItem)
Next
- Return objectTypes
+
+ Return oItems
Catch ex As Exception
- Logger.Error(ex)
- Return Nothing
+ _logger.Error(ex, "Could not get choice list items")
+ Return oItems
End Try
End Function
- Private Function NormalizePath(path As String)
- Dim normalizedPath = path
-
- If Not path.StartsWith("\") And path.ToUpper().StartsWith(DriveLetter.ToUpper) Then
- normalizedPath = path.Substring(2)
- End If
-
- Return normalizedPath
- End Function
-
-
- '''
- ''' Creates a windream session with the current user and the current server
- '''
- ''' Returns true when created, false if not
- '''
- 'Public Function NewSession() As Boolean
- ' Try
- ' ServerBrowser = New ServerBrowser()
- ' CurrentServer = ServerBrowser.GetCurrentServer
- ' Catch ex As Exception
- ' Logger.Error(ex, "Could not create ServerBrowser")
- ' Return False
- ' End Try
-
- ' Try
- ' ' Create Connect Object for Session
- ' CurrentConnect = New WMConnect
- ' Catch ex As Exception
- ' Logger.Error(ex, "Could not create WMConnect")
- ' Return False
- ' End Try
-
- ' Try
- ' ' Create session object with severname set
- ' CurrentSession = CreateObject("Windream.WMSession", ServerBrowser.GetCurrentServer)
- ' Catch ex As Exception
- ' Logger.Error(ex, "Could not create WMConnect")
- ' Return False
- ' End Try
-
- ' Try
- ' CurrentConnect.LoginSession(CurrentSession)
- ' LoggedInSession = True
- ' Catch ex As Exception
- ' Logger.Error(ex, "Could not login session")
- ' Return False
- ' End Try
-
- ' Try
- ' ' Standardmässig hinterlegen dass abgelegte Dateien keine Indexmaske öffnet
- ' CurrentSession.SwitchEvents(WMCOMEventWMSessionNeedIndex, False)
- ' Catch ex As Exception
- ' Logger.Error(ex, "Could not SwitchEvents")
- ' Return False
- ' End Try
-
- ' If TestLoggedInSession() = False Then
- ' Logger.Warn("Session created but user {0} could not be logged in", Environment.UserName)
- ' Return False
- ' End If
-
- ' Return True
- 'End Function
-#End Region
-#Region "+++++ New +++++"
- '''
- ''' Creates a folder in windream. All folder-parts will be checked
- '''
- ''' full path of new folder
- ''' Returns true when folder was created, false if not
- '''
- Public Function NewFolder(ByVal folderpath As String)
- Try
- If TestLoggedInSession() = False Then
- Return False
- End If
- folderpath = NormalizePath(folderpath)
- Dim folders() As String = folderpath.Split("\")
- For Each folder As String In folders
- Dim WMObject As WINDREAMLib.WMObject
- If TestFolderExists(folder) = False Then
- Try
- WMObject = CurrentSession.GetNewWMObjectFS(WMEntityFolder, folder, WMObjectEditModeNoEdit)
- Catch ex As Exception
- Logger.Error(ex)
- 'clsLogger.Add("Could not create WMObject for folderpath '" & folder & "': " & ex.Message, True)
- Return False
- End Try
-
- End If
- Next
- Return True
- Catch ex As Exception
- Logger.Error(ex)
- 'clsLogger.Add("Unexpected error in NewFolder: " & ex.Message, True)
- Return False
- End Try
- End Function
- '''
- ''' Indexes the file with the given values
- '''
- ''' full filepath
- ''' Name of the index
- ''' values as array
- ''' Returns true when folder was created, false if not
- '''
- Public Function NewIndexFile(WMFile As String, ByVal indexname As String, ByVal aValues() As String) As Boolean
- If TestLoggedInSession() = False Then
- Return False
- End If
- Dim oWMFile As WMObject = GetWMObjectForFile(WMFile)
- If IsNothing(oWMFile) Then
- Return False
- End If
- Dim vektInsState As Integer = 1
- Try
- If Not oWMFile.aLocked Then
- oWMFile.lock()
- Else
- Logger.Info("WMDoc is locked already!")
- Return False
- End If
-
-
- If aValues.Length = 1 And aValues(0) = "" Then
- Logger.Info("Indexvalue is empty - No indexing")
-
- Return False
- End If
- Logger.Info("Indexing of index '" & indexname)
-
- Dim oWMType
- Try
- ' das entsprechende Attribut aus windream auslesen
- Dim oAttribute = CurrentSession.GetWMObjectByName(WINDREAMLib.WMEntity.WMEntityAttribute, indexname)
- ' den Variablentyp (String, Integer, ...) auslesen
- oWMType = oAttribute.GetVariableValue("dwAttrType")
- Catch ex As Exception
- Logger.Error(ex)
- Return False
- End Try
-
- ' wenn in aValues an Position i ein Wert steht
- Dim i As Integer = 0
- Dim value = aValues(i)
-
- Dim oWMValueConverted = Nothing
-
- Dim vektor As Boolean = False
- 'Den Typ des Index-Feldes auslesen
- Logger.Info("type of windreamIndex: " & oWMType.ToString)
- Select Case (oWMType)
-
- Case INDEX_TYPE_STRING
- oWMValueConverted = CStr(value)
- Case INDEX_TYPE_INTEGER
- value = value.ToString.Replace(" ", "")
- value = value.ToString.Replace(" ", "")
- oWMValueConverted = CInt(value)
- Case INDEX_TYPE_FLOAT
- value = value.ToString.Replace(" ", "")
- oWMValueConverted = CDbl(value)
- Case INDEX_TYPE_FIXED_POINT
- value = value.ToString.Replace(" ", "")
- oWMValueConverted = CDbl(value)
- Case INDEX_TYPE_BOOLEAN
- oWMValueConverted = CBool(value)
- Case INDEX_TYPE_DATE
- 'Dim _date As Date = value
- oWMValueConverted = value
- Case INDEX_TYPE_TIME
- oWMValueConverted = CDbl(value)
- Case INDEX_TYPE_CURRENCY
- 'Wegen currency muß ein eigenes Objekt vom typ Variant erzeugt werden
- Dim aValueWrapper As System.Runtime.InteropServices.CurrencyWrapper = New System.Runtime.InteropServices.CurrencyWrapper(CDec(value))
- oWMValueConverted = aValueWrapper
- Case INDEX_TYPE_TIME
- 'If ((value)) Then
- ' oWMValueConverted = CDate(value)
- 'Else
- ' oWMValueConverted = ""
- 'End If
- 'Dim _date As Date = value
- oWMValueConverted = oWMValueConverted '*_date.ToShortTimeString
- Case INDEX_TYPE_FLOAT
- oWMValueConverted = CStr(value)
- Case INDEX_TYPE_VARIANT
-
- oWMValueConverted = CStr(value)
- Case INDEX_TYPE_FULLTEXT
- oWMValueConverted = CStr(value)
- Case 4097
- 'Vektor alphanumerisch
- vektor = True
- Case 4098
- 'Vektor Numerisch
- vektor = True
- Case 4099
- 'Vektor Kommazahl
- vektor = True
- Case 4100
- 'Vektor Kommazahl
- vektor = True
- Case 4101
- 'Vektor Kommazahl
- vektor = True
- Case 4103
- 'Vektor DateTime
- vektor = True
- Case 4107
- vektor = True
- Case 36865
- 'Vektor Kommazahl
- vektor = True
- Case Else
- oWMValueConverted = ""
- End Select
- If vektor = False Then
- If oWMValueConverted.ToString Is Nothing = False Then
- Logger.Info("Converted value is: " & oWMValueConverted.ToString)
- End If
- End If
- '############################################################################################
- '####################### Der eigentliche Indexierungsvorgang ################################
- '############################################################################################
- If vektor = False Then
- Try
- If oWMValueConverted.ToString Is Nothing = False Then
- Logger.Info("Now: oWMFile.SetVariableValue(" & indexname & ", " & oWMValueConverted & ")")
- oWMFile.SetVariableValue(indexname, oWMValueConverted)
- 'Die Datei speichern
- oWMFile.Save()
- Logger.Info("Index has been written!")
- Else
- Logger.Info("No indexvalue exists!")
- End If
- Catch ex As Exception
- Logger.Error(ex)
- oWMFile.Save()
- oWMFile.unlock()
- Return False
- End Try
-
- Else
- Logger.Info("Vectorfield: Preparing of Array!")
- Dim myArray()
- Dim Anzahl As Integer = aValues.Length
- 'Vektorfeld wird mit EINEM Wert gefüllt
- If Anzahl = 1 Then
- Logger.Info("Vectorfield will be filled with ONE VALUE!")
- ReDim myArray(0)
- myArray(0) = Helpers.ConvertVectorType(oWMType, value)
- 'Jetzt überprüfen ob Werte in Vektorfeld angefügt oder überschrieben werden sollen
- Logger.Info("Converted Value: " & myArray(0).ToString)
- Dim VektorArray()
- VektorArray = Return_VektorArray(oWMFile, indexname, myArray, oWMType)
- If VektorArray Is Nothing = False Then
- ReDim myArray(VektorArray.Length - 1)
- Array.Copy(VektorArray, myArray, VektorArray.Length)
- 'Jetzt die Nachindexierung
- oWMFile.SetVariableValue(indexname, myArray) '
- Logger.Info("Vectorindex has been written!")
- 'Die Änderungen festsschreiben/speichern
- oWMFile.Save()
- End If
-
- End If
-
- End If
- i += 1
-
- oWMFile.unlock()
- Logger.Info("...and unlock")
- Return True
- Catch ex As Exception
- Logger.Error(ex)
- oWMFile.Save()
- oWMFile.unlock()
- Return False
- End Try
- End Function
- Private Function NewLockWMFile(oWMFile As WMObject) As Boolean
- Try
- oWMFile.lock()
- Return True
- Catch ex As Exception
- Logger.Error(ex)
- Return False
- End Try
- End Function
- '''
- ''' Sets the folder-objecttype.
- '''
- ''' full path of folder
- ''' Obcjectype Name
- ''' Returns true when Otype was set, false if not
- '''
- Public Function NewObjecttypeForFolder(folderpath As String, folderObjecttype As String) As Boolean
- Try
- If TestLoggedInSession() = False Then
- Return False
- End If
- Dim result As Boolean = False
- Dim WMFolder As WINDREAMLib.WMObject
- folderpath = NormalizePath(folderpath)
-
- If TestFolderExists(folderpath) = True Then
- WMFolder = CurrentSession.GetWMObjectByPath(WMEntityFolder, folderpath)
- Try
- ' die Datei sperren
- WMFolder.lock()
- Catch ex As Exception
- ' nichts tun (Datei ist bereits gesperrt)
- End Try
-
- ' wenn der Datei noch kein Dokumenttyp zugewiesen wurde
- If WMFolder.aObjectType.aName = "Standard" Then
-
- ' ihr den entsprechenden Dokumenttyp zuweisen
- WMFolder.aObjectType = CurrentSession.GetWMObjectByName(WINDREAMLib.WMEntity.WMEntityObjectType, folderObjecttype)
- ' WMObject.aObjectType = Me.selectedProfile.Dokumenttyp
- Logger.Info("Objecttype has been set")
- result = True
- Else
- If WMFolder.aObjectType.aName <> "Standard" Then
- Logger.Warn("An Objecttype has already been set!")
- End If
- End If
-
- Try
- WMFolder.Save()
- Catch ex As Exception
- ' wenn es einen Fehler beim speichern gab, dann konnte auch kein Dokumenttyp gesetzt werden -> es kann also auch keine
- ' Indexierung stattfinden und die Indexierung muss nicht fortgesetzt werden
- Return False
- End Try
-
- Try
- WMFolder.unlock()
- Catch ex As Exception
- ' wenn das entsperren nicht geklappt hat, dann war die Datei auch nicht gesperrt
- End Try
- End If
- Return result
-
- Catch ex As Exception
- Logger.Error(ex)
- Return False
- End Try
- End Function
- '''
- ''' Creates a new version of the file
- '''
- ''' full path to the file
- ''' Comment
- ''' Returns true when version was created, false if not
- '''
- Public Function NewVersion(ByVal WMPath As String, ByVal Comment As String)
- Try
- If TestLoggedInSession() = False Then
- Return False
- End If
- WMPath = NormalizePath(WMPath)
-
- Dim WMObject As WMObject '= CreateObject("WINDREAMLib.WMObject") 'New WINDREAMLib.WMObject
- Try
- WMObject = CurrentSession.GetWMObjectByPath(WMEntityDocument, WMPath) 'WINDREAMLib.WMEntity.WMEntityDocument
- Catch ex As Exception
- Logger.Warn("Could not create WMObject in Create_Version for file '" & WMPath & "': " & ex.Message)
- Return False
- End Try
- WMObject.CreateVersion2(False, "HISTORY_New_From_Version", Comment)
- Return True
- Catch ex As Exception
- Logger.Error(ex)
- Return False
- End Try
- End Function
-#End Region
-#Region "+++++ Get +++++"
- '''
- ''' Returns all choicelists
- '''
- ''' Choicelists as List of Strings or empty list if no choice lists are found
Public Function GetChoiceLists() As List(Of String)
- Dim items As New List(Of String)
+ Dim oItems As New List(Of String)
- If TestLoggedInSession() = False Then
- Return items
+ If TestSessionLoggedIn() = False Then
+ Return oItems
End If
Try
- Dim choiceLists As WMObjects
- Dim choiceList As IWMObject2
+ Dim oChoiceLists As WMObjects
+ Dim oChoiceList As IWMObject2
'load list of choicelists
- choiceLists = CurrentSession.GetAllObjects(WMEntityChoiceList)
+ oChoiceLists = Session.GetAllObjects(WMEntityChoiceList)
- For Each choiceList In choiceLists
- items.Add(choiceList.aName)
+ For Each oChoiceList In oChoiceLists
+ oItems.Add(oChoiceList.aName)
Next
- Return items
+ Return oItems
Catch ex As Exception
- Logger.Error(ex)
- Return items
+ _logger.Error(ex)
+ Return oItems
End Try
End Function
- '''
- ''' Returns all indices for an objecttype
- '''
- ''' Name of objecttype
- ''' Names of indices as list of String
- '''
- Public Function GetIndicesByObjecttype(ByVal ObjecttypeName As String) As List(Of String)
+ Public Function GetFileByPath(Path As String) As WMObject
+ If TestSessionLoggedIn() = False Then
+ Return Nothing
+ End If
+ Path = GetNormalizedPath(Path)
+ Dim oWMObject As WMObject
+
Try
- If TestLoggedInSession() = False Then
- Return Nothing
+ oWMObject = Session.GetWMObjectByPath(WMEntityDocument, Path)
+ Return oWMObject
+ Catch ex As Exception
+ Return Nothing
+ End Try
+ End Function
+
+ Public Function GetIndexType(IndexName As String) As Integer
+ If TestSessionLoggedIn() = False Then
+ Return Nothing
+ End If
+
+ Try
+ Dim oAttribute = Session.GetWMObjectByName(WMEntityAttribute, IndexName)
+ Dim oType = oAttribute.GetVariableValue("dwAttrType")
+ Return oType
+ Catch ex As Exception
+ _logger.Error(ex)
+ Return Nothing
+ End Try
+ End Function
+
+ Public Function GetIndexValue(Path As String, IndexName As String) As List(Of String)
+ Dim oResult As New List(Of String)
+
+ If TestSessionLoggedIn() = False Then
+ Return oResult
+ End If
+
+ Try
+ Path = GetNormalizedPath(Path)
+ Dim oWMObject As WMObject = Session.GetWMObjectByPath(WMEntityDocument, Path)
+
+ If oWMObject Is Nothing Then
+ Return oResult
End If
- Dim oObjectType As WMObject
- Dim oIndexAttributes As WMObjectRelation
- Dim oIndexAttribute As WMObject
- Dim oIndex As WMObject
- Dim oRelProperties As WMObjectRelation
+ Dim oValues = oWMObject.GetVariableValue(IndexName)
+
+ If oValues Is Nothing Then
+ Return oResult
+ End If
+
+ If TypeOf oValues Is IEnumerable Then
+ For Each oValue In oValues
+ oResult.Add(oValue)
+ Next
+ Else
+ oResult.Add(oValues)
+ End If
+
+ Return oResult
+ Catch ex As Exception
+ _logger.Error(ex)
+ Return oResult
+ End Try
+ End Function
+
+ Public Function GetIndiciesByObjecttype(ObjectTypeName As String) As List(Of String)
+ If TestSessionLoggedIn() = False Then
+ Return Nothing
+ End If
+
+ Dim oObjectType As WMObject
+ Dim oIndexAttributes As WMObjectRelation
+ Dim oIndexAttribute As WMObject
+ Dim oIndex As WMObject
+ Dim oRelProperties As WMObjectRelation
+ Dim oTempSession As IWMSession2
+ Dim oIndicies As New List(Of String)
+
+ Try
' den Objekttyp laden
- oObjectType = CurrentSession.GetWMObjectByName(WMEntityObjectType, ObjecttypeName)
+ oTempSession = DirectCast(Session, IWMSession2)
+ oObjectType = Session.GetWMObjectByName(WMEntityObjectType, ObjectTypeName)
' Beziehung zu Indizes des Objekttyp auslesen
oIndexAttributes = oObjectType.GetWMObjectRelationByName("TypeAttributes")
- ' Array für Indizes vorbereiten
- 'Dim aIndexNames(oIndexAttributes.Count - 1) As String
- Dim indexNames As New List(Of String)
' alle Indizes durchlaufen
For j As Integer = 0 To oIndexAttributes.Count - 1
+
' aktuellen Index auslesen
oIndexAttribute = oIndexAttributes.Item(j)
@@ -671,544 +298,1083 @@ Public Class Windream
' Indexname speichern
'aIndexNames(j) = oIndex.aName
- indexNames.Add(oIndex.aName)
+ oIndicies.Add(oIndex.aName)
Next
' Indexarray zurückgeben
'Return aIndexNames
- Return indexNames
+ Return oIndicies
Catch ex As Exception
- Logger.Error(ex)
- Return Nothing
+ _logger.Error(ex)
+ Return oIndicies
End Try
End Function
- '''
- ''' Returns all items of a choicelist
- '''
- ''' name of choicelist
- ''' Items as list of String
- '''
- Public Function GetChoicelistItems(ByVal NameChoicelist As String) As List(Of String)
- Dim items As New List(Of String)
+ 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 oConnect As IWMConnect2
+ Dim oSession As IWMSession2
+ Dim oCredentials As WMUserIdentity
- If TestLoggedInSession() = False Then
+ Dim oImpersonation As Boolean
+ Dim oServerNameFromClient As Boolean
+
+ ' Create initial windream objects
+ Try
+ oBrowser = New ServerBrowser()
+ oConnect = New WMConnect()
+ _logger.Info("Successfully created windream objects")
+ Catch ex As Exception
+ _logger.Error(ex, "Error while creating windream objects")
+ Return Nothing
+ End Try
+
+ ' If no server was supplied, try to get the current server set in the client
+ Try
+ If ServerName Is Nothing OrElse ServerName.Length = 0 Then
+ ServerName = oBrowser.GetCurrentServer
+ oServerNameFromClient = True
+ Else
+ oServerNameFromClient = False
+ End If
+ Catch ex As Exception
+ _logger.Error(ex, "Error while getting Servername")
+ Return Nothing
+ End Try
+
+ _logger.Info("Servername: {0}", ServerName)
+ _logger.Info("Servername aquired from client: {0}", oServerNameFromClient)
+
+ '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
+ If UserName IsNot Nothing And Password IsNot Nothing And Domain IsNot Nothing Then
+ oImpersonation = True
+ oCredentials = New WMUserIdentity() With {
+ .aServerName = ServerName,
+ .aUserName = UserName,
+ .aPassword = Password,
+ .aDomain = Domain
+ }
+
+ oConnect.ModuleId = 9
+ Else
+ oImpersonation = False
+ oCredentials = New WMUserIdentity() With {
+ .aServerName = ServerName
+ }
+ End If
+
+ _logger.Info("Impersonated Login: {0}", oImpersonation)
+ _logger.Info("Username: {0}", IIf(UserName IsNot Nothing, UserName, Environment.UserName))
+ _logger.Info("Domain: {0}", IIf(Domain IsNot Nothing, Domain, Environment.UserDomainName))
+
+ Try
+ oSession = oConnect.Login(oCredentials)
+ _logger.Info("Connected..Session created")
+ Catch ex As Exception
+ _logger.Error(ex, "Error while logging in")
+ Return Nothing
+ End Try
+
+ Try
+ ' Standardmässig hinterlegen dass abgelegte Dateien keine Indexmaske öffnet
+ oSession.SwitchEvents(WMCOMEventWMSessionNeedIndex, False)
+ Catch ex As Exception
+ _logger.Error(ex, "Could not SwitchEvents")
+ Return Nothing
+ End Try
+
+ If oSession.aLoggedin = False Then
+ _logger.Warn("Session created but user {0} could not be logged in", Environment.UserName)
Return Nothing
End If
- Dim choiceList As WMObject
-
- ' Try to get the choicelist first and abort if an error occurs
- Try
- Dim session As IWMSession2 = DirectCast(CurrentSession, IWMSession2)
- choiceList = session.GetWMObjectByName(WMEntityChoiceList, NameChoicelist)
- Catch ex As Exception
- Logger.Error(ex)
- Return Nothing
- End Try
-
- ' Try to get choicelist items
- Try
- Dim values As Object = choiceList.GetVariableValue("vItems")
-
- ' If values is nothing, the list is empty
- If values Is Nothing Then
- Return items
- End If
-
- For Each value In values
- items.Add(value)
- Next
- Catch ex As Exception
- Logger.Error(ex)
- Return Nothing
- End Try
-
- Return items
+ _logger.Info("Connection to {0} established!", ServerName)
+ Return oSession
End Function
+#Region "Public Methods"
'''
- ''' Returns the result of windream-search
+ ''' changes the archive end date
'''
- ''' filepath of windreamSearch-file
- ''' Name of the Docid Index
- ''' Returns datatable
+ ''' WM Filepath
+ ''' number/count of period (if
+ ''' date_unity (d,m,y or day(s),month(s),years(s)
+ ''' dateFrom_value
+ ''' Returns true when date was set, false if not
'''
- Public Function GetSearchDocuments(ByVal wdfLocation As String, NameIndexDocID As String) As DataTable
- Dim dtresult As New DataTable
- dtresult.Columns.Add("DOC_ID", GetType(Integer))
- dtresult.Columns.Add("PATH", GetType(String))
- If TestLoggedInSession() = False Then
- Return dtresult
- End If
- If TestWMFileExists(wdfLocation) = False Then
- Return dtresult
- End If
+ Public Function NewLifecycle_Period(ByVal wmfilepath As String, ByVal dateFrom_value As Date, ByVal date_period As Double, ByVal date_unit As String)
+ Dim oWMObject As WMObject
Try
- Dim ProfileName = wdfLocation.Substring(wdfLocation.LastIndexOf("\") + 1)
- Dim ProfilePath = wdfLocation.Substring(0, wdfLocation.Length - ProfileName.Length)
-
- CurrentController = New WMOSearchController
- CurrentController.CheckSearchProfile(wdfLocation.ToLower)
- Dim suchTyp = CurrentController.SearchProfileTargetProgID
- Dim ExSettings As Object
- Dim oSearch As Object
- ExSettings = CurrentController.SearchProfileExSettings
- If ExSettings = 0 Then ExSettings = 7
-
- Dim srchQuick As WMOSRCHLib.WMQuickSearch = CreateObject("WMOSrch.WMQuickSearch")
- Dim srchIndex As WMOSRCHLib.WMIndexSearch = CreateObject("WMOSrch.WMIndexSearch")
- Dim srchObjectType As WMOSRCHLib.WMObjectTypeSearch = CreateObject("WMOSrch.WMObjectTypeSearch")
- Dim suchTyp1 = suchTyp.ToString.ToUpper
- '' Der öffentliche Member CheckSearchProfile für den Typ IWMQuickSearch7 wurde nicht gefunden. [Microsoft.VisualBasic] => GetSearchDocuments()
- Select Case suchTyp.ToString.ToUpper
- Case "WMOSRCH.WMQUICKSEARCH"
- srchQuick.WMSession = CreateObject("Windream.WMSession", CurrentServer)
-
- CurrentConnect.LoginSession(srchQuick.WMSession)
-
- srchQuick.ClearSearch()
- srchQuick.SearchProfilePath = ProfilePath
- srchQuick.LoadSearchProfile(ProfileName)
-
- oSearch = srchQuick.GetSearch()
-
- Case "WMOSRCH.WMINDEXSEARCH"
- srchIndex.WMSession = CreateObject("Windream.WMSession", CurrentServer)
-
- CurrentConnect.LoginSession(srchIndex.WMSession)
-
- srchIndex.ClearSearch()
- srchIndex.SearchProfilePath = ProfilePath
- srchIndex.LoadSearchProfile(ProfileName)
-
- oSearch = srchIndex.GetSearch()
-
- Case "WMOSRCH.WMOBJECTTYPESEARCH"
- srchObjectType.WMSession = CreateObject("Windream.WMSession", CurrentServer)
-
- CurrentConnect.LoginSession(srchObjectType.WMSession)
-
- srchObjectType.ClearSearch()
- srchObjectType.SearchProfilePath = ProfilePath
- srchObjectType.LoadSearchProfile(ProfileName)
-
- oSearch = srchObjectType.GetSearch()
-
- Case Else
- Logger.Warn("No valid WM-SearchType")
- Return dtresult
- End Select
- Dim WMObjects As Object
- WMObjects = oSearch.Execute
- 'If returnDT = True Then
- If WMObjects.Count > 0 Then
-
- For Each dok As WMObject In WMObjects
- Dim path As String = dok.aPath
- Dim DOC_ID = dok.GetVariableValue(NameIndexDocID)
- Logger.Info("Adding DocInfo for DocID: " & DOC_ID.ToString)
- dtresult.Rows.Add(DOC_ID, path)
-
- Next
- dtresult.AcceptChanges()
- End If
- Return dtresult
- Catch ex As Exception
- Logger.Error(ex)
- Return dtresult
- End Try
- End Function
- '''
- ''' Returns a windream-type as Integer.
- '''
- ''' Name of indexfield
- ''' Returns integer, which describes the type
- '''
- Public Function GetTypeOfIndexAsInt(ByVal indexname As String) As Integer
- Try
- If TestLoggedInSession() = False Then
- Return False
- End If
- Dim oAttribute = CurrentSession.GetWMObjectByName(WMEntityAttribute, indexname)
- Dim vType = oAttribute.GetVariableValue("dwAttrType")
- Return vType
- Catch ex As Exception
- Return Nothing
- End Try
- End Function
- '''
- ''' Returns the value(s) for an index as a datatable
- '''
- ''' filepath of windream-file
- ''' Name of the index
- ''' Datatable
- '''
- Public Function GetValueforIndex(ByVal WMFile As String, ByVal NameIndex As String) As DataTable
- Dim dt As New DataTable
- dt.Columns.Add("RESULT", GetType(String))
- If TestLoggedInSession() = False Then
- Return dt
- End If
- Try
-
- If Not WMFile.StartsWith("\") And WMFile.ToUpper.StartsWith(DriveLetter.ToUpper) Then
- WMFile = WMFile.Substring(2)
- End If
- Dim WMObject As WINDREAMLib.WMObject '= CreateObject("WINDREAMLib.WMObject") 'New WINDREAMLib.WMObject
+ oWMObject = GetFileByPath(wmfilepath)
+ _logger.Info($"Changing the archive end-date for file '{oWMObject.aName}', Items: {dateFrom_value},{date_period},{date_unit}")
Try
- WMObject = CurrentSession.GetWMObjectByPath(WINDREAMLib.WMEntity.WMEntityDocument, WMFile) 'WINDREAMLib.WMEntity.WMEntityDocument
+ ' die Datei sperren
+ oWMObject.LockFor(WMObjectEditModeLifeCycleEdit)
+ _logger.Debug(">> object locked")
+
Catch ex As Exception
- Logger.Error(ex)
- Return dt
+ _logger.Error(ex)
+ ' nichts tun (Datei ist bereits gesperrt)
End Try
- Dim result = WMObject.GetVariableValue(NameIndex)
- If IsNothing(result) Then
- Return Nothing
- Else
- If result.GetType.ToString.Contains("System.Object") Then
- For Each val As String In result
- dt.Rows.Add(val)
- Next
- dt.AcceptChanges()
- Else
- dt.Rows.Add(result)
+ Dim oObjectLifecycle = oWMObject.aWMLifeCycle
+
+ Dim oIntervalType As DateInterval
+ If date_unit.ToLower = "d" Or date_unit.ToLower = "day(s)" Then
+ oIntervalType = DateInterval.Day
+ ElseIf date_unit.ToLower = "m" Or date_unit.ToLower = "month(s)" Then
+ oIntervalType = DateInterval.Month
+ ElseIf date_unit.ToLower = "y" Or date_unit.ToLower = "year(s)" Then
+ oIntervalType = DateInterval.Year
+ End If
+
+ Dim oArchUntil = DateAdd(oIntervalType, date_period, dateFrom_value)
+ _logger.Debug("New date shall be: " & oArchUntil.ToString)
+
+ oObjectLifecycle.SetPeriodEndDate(2, oArchUntil)
+ _logger.Info("Archive end-date has been changed!")
+ oWMObject.Save()
+ oWMObject.unlock()
+ Return SetArchive_Active(oWMObject)
+
+ Catch ex As Exception
+ _logger.Warn($"Unexpected Error in NewLifecycle_Period {ex.Message}")
+ If Not IsNothing(oWMObject) Then
+ If oWMObject.aLocked = True Then
+ oWMObject.unlock()
End If
End If
- Return dt
- Catch ex As Exception
- Logger.Error(ex)
- Return dt
+ Return False
End Try
End Function
'''
- ''' Returns the values for a vektorfield plus the new ones
+ ''' changes the archive end date
'''
- ''' windream-file as Object
- ''' Name of the index
- ''' Returns value as Datatable
+ ''' WM Filepath
+ ''' number/count of period (if
+ ''' date_unity (d,m,y or day(s),month(s),years(s)
+ ''' dateFrom_value
+ ''' Returns true when date was set, false if not
'''
- Public Function Return_VektorArray(ByVal oDocument As WMObject, vktIndexName As String, arrIndexwerte As Object, vType As Object)
+ Public Function NewLifecycle_PeriodTEST(ByVal wmfilepath As String, ByVal oArchUntil As String)
+ Dim oWMObject As WMObject
Try
- If TestLoggedInSession() = False Then
+ oWMObject = GetFileByPath(wmfilepath)
+ _logger.Info($"Changing the archive end-date for file '{oWMObject.aName}', Items: {oArchUntil}")
+ Try
+ ' die Datei sperren
+ oWMObject.LockFor(WMObjectEditModeLifeCycleEdit)
+ _logger.Debug(">> object locked")
+
+ Catch ex As Exception
+ _logger.Error(ex)
+ ' nichts tun (Datei ist bereits gesperrt)
+ End Try
+
+ Dim oObjectLifecycle = oWMObject.aWMLifeCycle
+ ' Dim oDate = CDate(oArchUntil)
+ ' Dim omMyFormattedDate = oDate.ToString("dd.MM.yyyy")
+
+ If oArchUntil <> String.Empty Then
+ If IsDate(oArchUntil) Then
+ If CDate(oArchUntil) < CDate(Now) Then
+ _logger.Debug("oArchUntil < today so direct move to archivepool")
+ Else
+ _logger.Debug("New date shall be: " & oArchUntil)
+ oObjectLifecycle.SetPeriodEndDate(2, oArchUntil)
+ _logger.Info("Archive end-date has been changed!")
+ End If
+ End If
+ Else
+ _logger.Debug("oArchUntil is empty so direct move to archivepool")
+ End If
+
+ Dim result = SetArchive_Active(oWMObject)
+ oWMObject.Save()
+ oWMObject.unlock()
+ Return result
+
+ Catch ex As Exception
+ _logger.Warn($"Unexpected Error in NewLifecycle_PeriodTEST {ex.Message}")
+ If Not IsNothing(oWMObject) Then
+ If oWMObject.aLocked = True Then
+ oWMObject.unlock()
+ End If
+ End If
+ Return False
+ End Try
+ End Function
+ '''
+ ''' Archives windream object immediately
+ '''
+ ''' Returns true when archiving was set, false if not
+ '''
+ Private Function SetArchive_Active(oWMObject As WMObject)
+ Try
+ oWMObject.MoveToArchivePool()
+ _logger.Info("oWMObject has been archived!")
+ Return True
+ Catch ex As Exception
+ _logger.Warn($"Unexpected Error in SetArchive_Active {ex.Message}")
+ Return False
+ End Try
+ End Function
+
+ Public Function NewFolder(Path As String) As Boolean
+ If Not TestSessionLoggedIn() Then
+ Return False
+ End If
+
+ Try
+ Path = GetNormalizedPath(Path)
+ Dim oFolders As List(Of String) = Path.Split().ToList()
+ Dim oFolderObject As WMObject
+
+ For Each oFolder In oFolders
+ If TestFolderExists(Path) = False Then
+ oFolderObject = Session.GetNewWMObjectFS(WMEntityFolder, oFolder, WMObjectEditModeNoEdit)
+ End If
+ Next
+
+ Return True
+ Catch ex As Exception
+ _logger.Error(ex)
+ Return False
+ End Try
+ End Function
+
+ Public Function NewFileVersion(Path As String, Comment As String) As Boolean
+ If Not TestSessionLoggedIn() Then
+ Return False
+ End If
+
+ Try
+ Path = GetNormalizedPath(Path)
+ Dim oFileObject As IWMObject6
+ oFileObject = GetObjectByPath(Path, WMEntityDocument)
+ oFileObject.CreateVersion2(False, Constants.HISTORY_NEW_FROM_VERSION, Comment)
+ Return True
+ Catch ex As Exception
+ _logger.Error(ex)
+ Return False
+ End Try
+ End Function
+
+ 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)
+
+ _logger.Debug($"Streaming file from {FilenameSource} to {FilenameTarget}")
+
+ Dim oWMObject As IWMObject6 = Nothing
+ Dim oFileIO As WMFileIO
+ Dim oWMStream As WMStream
+
+ '_logger.Debug("Try to access file and lock it...")
+ 'Err.Clear()
+
+ 'Indexierungsdialog der Session unterdrücken
+ Session.SwitchEvents(Constants.COM_EVENT_SESSION_NEED_INDEX, False)
+
+ '==================================================================
+ ' create an object
+ '==================================================================
+
+ Try
+ _logger.Debug("Creating WMObject for file {0}", FilenameTarget)
+ oWMObject = Session.GetNewWMObjectFS(WMEntityDocument, FilenameTarget, WMObjectEditModeObject)
+ Catch ex As Exception
+ _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
+ Try
+ WMObject.LockFor(EditMode)
+ Return True
+ Catch ex As Exception
+ _logger.Error(ex)
+ Return False
+ End Try
+ End Function
+
+ Public Function UnlockObject(WMObject As WMObject) As Boolean
+ Try
+ WMObject.unlock()
+ Return True
+ Catch ex As Exception
+ _logger.Error(ex)
+ Return False
+ End Try
+ End Function
+
+ '''
+ ''' Returns the result of a search file
+ '''
+ ''' Path of a search file (*.wdf)
+ ''' Index containing the Document-ID
+ ''' A datatable of the results with columns PATH and DOCID
+ 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 oDatatable
+ End If
+
+ If TestFileExists(SearchFilePath) = False Then
+ Return oDatatable
+ End If
+
+ Try
+ Dim oFileInfo = New FileInfo(SearchFilePath)
+ Dim oProfileName = oFileInfo.Name
+ Dim oProfilePath = oFileInfo.DirectoryName
+
+ Dim oSearchController As New WMOSearchController()
+ oSearchController.CheckSearchProfile(SearchFilePath)
+
+ Dim oSearchType = oSearchController.SearchProfileTargetProgID
+
+ Dim oSearchProfileExSetttings As Integer = oSearchController.SearchProfileExSettings
+
+ If oSearchProfileExSetttings = 0 Then
+ oSearchProfileExSetttings = 7
+ End If
+
+ Dim oSearch As WMSearch
+
+ Select Case oSearchType.ToUpper()
+ Case Constants.SEARCH_TYPE_QUICK_SEARCH
+ Dim oQuickSearch As New WMQuickSearch With {
+ .WMSession = Session,
+ .SearchProfilePath = oProfilePath
+ }
+ oQuickSearch.ClearSearch()
+ oQuickSearch.LoadSearchProfile(oProfileName)
+
+ oSearch = oQuickSearch.GetSearch()
+ Case Constants.SEARCH_TYPE_INDEX_SEARCH
+ Dim oIndexSearch As New WMIndexSearch With {
+ .WMSession = Session,
+ .SearchProfilePath = oProfilePath
+ }
+ oIndexSearch.ClearSearch()
+ oIndexSearch.LoadSearchProfile(oProfileName)
+
+ oSearch = oIndexSearch.GetSearch()
+ Case Constants.SEARCH_TYPE_OBJECTTYPE_SEARCH
+ Dim oObjecttypeSearch As New WMObjectTypeSearch With {
+ .WMSession = Session,
+ .SearchProfilePath = oProfilePath
+ }
+ oObjecttypeSearch.ClearSearch()
+ oObjecttypeSearch.LoadSearchProfile(oProfileName)
+
+ oSearch = oObjecttypeSearch.GetSearch()
+ Case Else
+ _logger.Warn("{0} is not a valid search type", oSearchType)
+ Return oDatatable
+ End Select
+
+ Dim oSearchResults As WMObjects = oSearch.Execute()
+
+ If oSearchResults.Count = 0 Then
+ Return oDatatable
+ End If
+
+ For Each oSearchResult As WMObject In oSearchResults
+ Dim path As String = oSearchResult.aPath
+ Dim docId As Integer = oSearchResult.GetVariableValue(DocIdIndexName)
+
+ oDatatable.Rows.Add(path, docId)
+ Next
+ oDatatable.AcceptChanges()
+
+ Return oDatatable
+ Catch ex As Exception
+ _logger.Error(ex)
+ Return oDatatable
+ End Try
+ End Function
+
+ '''
+ ''' Gets an array of the actual vektorvalues of index, collated with the passed values
+ '''
+ ''' windream-file as WMObject
+ ''' Indexname as String
+ ''' The new values as Array
+ ''' True if duplicates shall be prevented
+ '''
+ Public Function GetVektorData_Combined(ByVal WindreamObject 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 = WindreamObject.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
+
+ '''
+ ''' Sets objecttype of a folder
+ '''
+ '''
+ '''
+ '''
+ Public Function SetFolderObjecttype(FolderPath As String, Objecttype As String) As Boolean
+ If TestSessionLoggedIn() = False Then
+ Return False
+ End If
+
+ Try
+ FolderPath = GetNormalizedPath(FolderPath)
+
+ If TestFolderExists(FolderPath) = False Then
+ _logger.Warn("Folder {0} does not exist!", FolderPath)
Return False
End If
- Dim missing As Boolean = False
- Dim valueCount As Integer = 0
- Dim ValueArray() = Nothing
- 'Jeden Wert des Vektorfeldes durchlaufen
- Dim DT_RESULT = GetValueforIndex(oDocument.aPath, vktIndexName)
- If DT_RESULT.Rows.Count > 0 Then
- 'Erst die aktuellen Werte speichern und schreiben
- For Each row As DataRow In DT_RESULT.Rows
- ReDim Preserve ValueArray(valueCount)
- 'Den Wert im Array speichern
- ValueArray(valueCount) = Helpers.ConvertVectorType(vType, row.Item(0))
- valueCount += 1
- Next
- 'Jetzt die Neuen Werte auf Duplikate überprüfen
- For Each NewValue As Object In arrIndexwerte
- If NewValue Is Nothing = False Then
- If ValueArray.Contains(NewValue) = False Then
- 'Das Array anpassen
- ReDim Preserve ValueArray(valueCount)
- 'Den Wert im Array speichern
- ValueArray(valueCount) = Helpers.ConvertVectorType(vType, NewValue)
- valueCount += 1
- Else
- Logger.Info("Value '" & NewValue.ToString & "' already existing in vectorfield(1)")
+ Dim oWMFolder As WMObject = GetObjectByPath(FolderPath, WMEntityFolder)
- End If
- End If
- Next
- Else
- Logger.Info(" vectorfield is empty....")
-
- 'Den/die Neuen Wert(e) anfügen
- For Each NewValue As Object In arrIndexwerte
- If NewValue Is Nothing = False Then
- If ValueArray Is Nothing = False Then
- If ValueArray.Contains(NewValue) = False Then
- 'Das Array anpassen
- ReDim Preserve ValueArray(valueCount)
- 'Den Wert im Array speichern
- ValueArray(valueCount) = Helpers.ConvertVectorType(vType, NewValue)
- valueCount += 1
- Else
- Logger.Info("Value '" & NewValue.ToString & "' already existing in vectorfield(2)")
-
- End If
- Else 'Dererste Wert, also hinzufügen
- 'Das Array anpassen
- ReDim Preserve ValueArray(valueCount)
- 'Den Wert im Array speichern
- ValueArray(valueCount) = Helpers.ConvertVectorType(vType, NewValue)
- valueCount += 1
-
- End If
-
-
- End If
- Next
+ If LockObject(oWMFolder) = False Then
+ _logger.Warn("Folder {0} could not be locked", FolderPath)
End If
- Return ValueArray
+ If oWMFolder.aObjectType.aName <> Constants.OBJECT_TYPE_DEFAULT Then
+ _logger.Warn("Objecttype for folder {0} has already been set!", FolderPath)
+ End If
+
+ Dim oObjecttype As WMObject = GetObjectByName(Objecttype, WMEntityObjectType)
+
+ If oObjecttype Is Nothing Then
+ _logger.Warn("Objecttype {0} does not exist!", Objecttype)
+ Return False
+ End If
+
+ oWMFolder.aObjectType = oObjecttype
+ oWMFolder.Save()
+
+ If UnlockObject(oWMFolder) Then
+ _logger.Warn("Folder {0} could not be unlocked", FolderPath)
+ End If
+
+ Return True
Catch ex As Exception
- Logger.Error(ex)
+ _logger.Error(ex)
+ Return False
End Try
End Function
- '''
- ''' Returns a WMObject if file exists
- '''
- ''' full path to the file
- ''' Returns WMObject
- '''
- Public Function GetWMObjectForFile(ByVal WMPath As String) As WMObject
+
+ Public Function RemoveFile(Path As String) As Boolean
+ If TestSessionLoggedIn() = False Then
+ Return Nothing
+ End If
+
Try
- If TestLoggedInSession() = False Then
- Return Nothing
+ Dim oWMObject As WMObject = GetFileByPath(Path)
+
+ If oWMObject Is Nothing Then
+ Return False
End If
- WMPath = NormalizePath(WMPath)
- Dim oWMObject As WINDREAMLib.WMObject
+
+ oWMObject.Delete()
+ _logger.Warn($"file {Path} has been deleted!")
+ Return True
+ Catch ex As Exception
+ _logger.Error(ex)
+ Return False
+ 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
+
+ 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
+
+ Dim oVectorValues = oWMObject.GetVariableValue(IndexName)
+ Dim oType As Integer = GetIndexType(IndexName)
+
+ 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 oNewValues As New List(Of Object)
+ oNewValues = oVectorValues.Except(New List(Of Object) From {ValueToDelete}).ToList()
+
+ ' BEGIN WRITE INDEX
+ If LockObject(oWMObject, WMObjectEditModeIndexEdit) = False Then
+ _logger.Warn("File {0} could not be locked")
+ Return False
+ End If
+
+ oWMObject.SetVariableValue(IndexName, oNewValues.ToArray())
+ oWMObject.Save()
+
+ UnlockObject(oWMObject)
+
+ Return True
+ ' END WRITE INDEX
+ Catch ex As Exception
+ _logger.Error(ex)
+ Return False
+ End Try
+ End Function
+
+ Public Function SetFileIndex(Path As String, IndexName As String, Value As String) As Boolean
+ If TestSessionLoggedIn() = False Then
+ Return False
+ End If
+
+ Dim oWMObject As WMObject = GetFileByPath(Path)
+
+ If LockObject(oWMObject, WMObjectEditModeIndexEdit) = False Then
+ _logger.Warn("File {0} could not be locked")
+ Return False
+ End If
+
+ Try
+ Dim oType As Integer = GetIndexType(IndexName)
+ Dim oConvertedValue As Object = Helpers.ConvertIndexValue(oType, Value)
+ oWMObject.SetVariableValue(IndexName, oConvertedValue)
+ 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
+ Try
+ Dim oWMObject As IWMObject6 = DirectCast(WMObject, IWMObject6)
+
+ Dim oFilenameFull As String = oWMObject.aName
+ Dim oFilenameExport As String
+ Dim oSplitIndex = oFilenameFull.LastIndexOf(".")
+ Dim oVersion = 1
+
+ Dim oFilename = oFilenameFull.Substring(0, oSplitIndex)
+ Dim oExtension = oFilenameFull.Substring(oSplitIndex)
+
+ _logger.Debug("Preparing export of file {0}..", oFilenameFull)
+ _logger.Debug("Filename: {0}", oFilename)
+ _logger.Debug("Extension: {0}", oExtension)
+
+ ' build the file path in case the exported file doesn't already exist
+ oFilenameExport = BuildExportPath(ExportPath, oFilename, oExtension)
+
+ ' Add version until we find the version that does NOT exist
+ Do While File.Exists(oFilenameExport)
+ oVersion += 1
+ oFilenameExport = BuildExportPath(ExportPath, oFilename, oExtension, oVersion)
+ Loop
+
+ _logger.Debug("File will be exported to {0}", oFilenameExport)
+
+ _logger.Debug("Opening file stream..")
+ Dim oStream As WMStream = oWMObject.OpenStream("BinaryObject", WMObjectStreamOpenMode.WMObjectStreamOpenModeRead)
+ Dim oWMFileIO As New WMFileIO() With {
+ .aWMStreamEx = oStream,
+ .aWMStream = oStream,
+ .bstrOriginalFileName = oFilenameExport
+ }
+
+ _logger.Debug("Exporting file..")
+ oWMFileIO.ExportOriginal(True)
+
+ _logger.Debug("Cleaning up..")
+ oStream.Flush()
+ oStream.Close()
+
+ _logger.Debug("File exported to {0}", oFilenameExport)
+ Return True
+ Catch ex As Exception
+ _logger.Error(ex)
+ Return False
+ End Try
+ End Function
+
+ Private Function BuildExportPath(BasePath As String, FilenameWithoutExtension As String, Extension As String, Optional Version As Integer = 1)
+ Dim oFilename
+
+ If Version = 1 Then
+ oFilename = FilenameWithoutExtension & Extension
+ Else
+ oFilename = FilenameWithoutExtension & "_" & Version & Extension
+ End If
+
+ Return Path.Combine(BasePath, oFilename)
+ End Function
+
+ Public Function Export_WMFile(WMPath As String, Exportpath As String)
+ Try
+ If Not Exportpath.EndsWith("\") Then
+ Exportpath &= "\"
+ End If
+
+ Dim oWMObject As WMObject = GetFileByPath(WMPath)
+
+ _logger.Debug("Working on file: " & oWMObject.aName)
+
+
+ Dim ExportFileIO = New WMOTOOLLib.WMFileIO ' CreateObject("WMOTOOLLib.WMFileIO") ' New WMOTOOLLib.WMFileIO
+ _logger.Debug("ExportFileIO created...")
+ ' Stream Interface bereitstellen
+ oWMObject.LockFor(WMObjectEditModeFileSystem)
Try
- oWMObject = CurrentSession.GetWMObjectByPath(WINDREAMLib.WMEntity.WMEntityDocument, WMPath)
+ If Not oWMObject.aLocked Then
+ oWMObject.lock()
+ End If
Catch ex As Exception
- Logger.Warn("Could not create WMObject for file '" & WMPath & "': " & ex.Message)
- Return Nothing
+ _logger.Error(ex)
+ Return False
End Try
+
+ Dim oWMStream = oWMObject.OpenStream("BinaryObject", WMObjectEditModeTypedData)
+ '### VERSIONIERUNG ###
+ Dim version As Integer = 2
+ 'Dim Stammname As String = System.IO.Path.GetFileNameWithoutExtension(Quelle)
+ Dim Filename = oWMObject.aName.Substring(0, oWMObject.aName.LastIndexOf("."))
+ Dim Extension = oWMObject.aName.Substring(oWMObject.aName.LastIndexOf("."))
+ Dim tempFilename As String = Exportpath & Filename & Extension
+ 'Überprüfen ob File existiert
+ Do While IO.File.Exists(tempFilename) = True
+ tempFilename = Exportpath & Filename & "_" & version & Extension
+ version = version + 1
+ Loop
+ _logger.Debug("Exportfilename is: " & tempFilename)
+ ' den Dateiinhalt der neuen Datei zuweisen
+ ExportFileIO.aWMStream = oWMStream
+ ExportFileIO.bstrOriginalFileName = tempFilename
+ 'Das eigentliche kopieren
+ ExportFileIO.ExportOriginal(True)
+ ' close the windream file stream
+ oWMStream.Close()
+ oWMObject.Save()
+ oWMObject.unlock()
+ _logger.Info($"WMFile has been exported to {tempFilename} ")
+
+ Return True
+ Catch ex As Exception
+ _logger.Error(ex)
+ Return False
+ End Try
+ End Function
+ Public Function Export_WMFile_DocID(WMPath As String, Exportpath As String, DocId As Integer)
+ Try
+ If Not Exportpath.EndsWith("\") Then
+ Exportpath &= "\"
+ End If
+
+ Dim oWMObject As WMObject = GetFileByPath(WMPath)
+ Try
+ _logger.Info("Working on file: " & oWMObject.aName)
+ Catch ex As Exception
+ _logger.Error(ex)
+ _logger.Warn("No object created: " & WMPath)
+ Return False
+ End Try
+ Dim ExportFileIO = New WMOTOOLLib.WMFileIO ' CreateObject("WMOTOOLLib.WMFileIO") ' New WMOTOOLLib.WMFileIO
+ _logger.Debug("ExportFileIO created...")
+ Dim oWMStream = oWMObject.OpenStream("BinaryObject", 1)
+ '### VERSIONIERUNG ###
+ Dim version As Integer = 2
+ Dim Extension = oWMObject.aName.Substring(oWMObject.aName.LastIndexOf("."))
+ Dim tempFilename As String = Exportpath & DocId & Extension
+ 'Überprüfen ob File existiert
+ Do While IO.File.Exists(tempFilename) = True
+ tempFilename = Exportpath & DocId & "_" & version & Extension
+ version = version + 1
+ Loop
+ _logger.Debug("Exportfilename is: " & tempFilename)
+ ' den Dateiinhalt der neuen Datei zuweisen
+ ExportFileIO.aWMStream = oWMStream
+ ExportFileIO.bstrOriginalFileName = tempFilename
+ 'Das eigentliche kopieren
+ ExportFileIO.ExportOriginal(True)
+ 'close the windream file stream
+ oWMStream.Close()
+ _logger.Info($"WMFile DocID {DocId} has been exported to {tempFilename} ")
+ Return True
+ Catch ex As Exception
+ _logger.Error(ex)
+ _logger.Info("Unexpected error in Export_WMFile: " & ex.Message)
+ Return False
+ End Try
+ End Function
+ Public Function TestFolderExists(Path As String) As Boolean
+ Return TestObjectExists(GetNormalizedPath(Path), WMEntityFolder)
+ End Function
+
+ Public Function TestFileExists(Path As String) As Boolean
+ Return TestObjectExists(GetNormalizedPath(Path), WMEntityDocument)
+ End Function
+
+ Public Function TestUserExists(Username As String) As Boolean
+ Return TestObjectExists(Username, WMEntityUser)
+ End Function
+
+ Public Function TestGroupExists(Groupname As String) As Boolean
+ Return TestObjectExists(Groupname, WMEntityGroups)
+ End Function
+#End Region
+
+#Region "Private Methods"
+ Private Function GetNormalizedPath(Path As String) As String
+ Dim oNormalizedPath = GetCleanedPath(Path)
+
+ If Not Path.StartsWith("\") And Path.ToUpper().StartsWith(ClientDriveLetter.ToUpper) Then
+ oNormalizedPath = Path.Substring(2)
+ ElseIf Path.ToLower.StartsWith(ClientBasePath) Then
+ oNormalizedPath = Path.Substring(ClientBasePath.Length)
+ End If
+
+ Return oNormalizedPath
+ End Function
+
+ Private Function GetCleanedPath(Path As String) As String
+ Return Regex.Replace(Path, Constants.REGEX_CLEAN_FILENAME, String.Empty)
+ End Function
+
+ Private Function GetObjectTypes() As WMObjects
+ Dim oObjectTypes As WMObjects
+
+ Try
+ oObjectTypes = Session.GetWMObjectTypes(WMEntityDocument)
+ Return oObjectTypes
+ Catch ex As Exception
+ _logger.Error(ex)
+ Return Nothing
+ End Try
+ End Function
+
+ Private Function GetObjectByName(ObjectName As String, ObjectType As WMEntity) As WMObject
+ If TestSessionLoggedIn() = False Then
+ Return Nothing
+ End If
+
+ If TestObjectExists(ObjectName, ObjectType) = False Then
+ Return Nothing
+ End If
+
+ Try
+ Dim oWMObject As WMObject = Session.GetWMObjectByName(ObjectType, ObjectName)
Return oWMObject
Catch ex As Exception
- Logger.Error(ex)
+ _logger.Error(ex)
Return Nothing
End Try
End Function
-#End Region
-#Region "+++++ Test +++++"
- '''
- ''' Checks if the folder exists
- '''
- ''' The path of the folder
- ''' True if exists or false if not or error occured
- '''
- Public Function TestFolderExists(folderpath As String)
+
+ Private Function GetObjectByPath(ObjectName As String, ObjectType As WMEntity) As WMObject
+ If TestSessionLoggedIn() = False Then
+ Return Nothing
+ End If
+
+ If TestObjectExists(ObjectName, ObjectType) = False Then
+ Return Nothing
+ End If
+
Try
- If TestLoggedInSession() = False Then
- Return False
- End If
- folderpath = NormalizePath(folderpath)
- Try
- Dim exists = CurrentSession.WMObjectExists(WMEntityFolder, folderpath, 0, 0)
- Return exists
- Catch ex As Exception
- Logger.Error(ex)
- Return False
- End Try
+ Dim oWMObject As WMObject = Session.GetWMObjectByPath(ObjectType, ObjectName)
+ Return oWMObject
Catch ex As Exception
- Return False
+ _logger.Error(ex)
+ Return Nothing
End Try
End Function
- '''
- ''' Checks wether file exists in windream
- '''
- ''' full path to the file
- ''' Returns true when file was deleted, false if not
- '''
- Public Function TestWMFileExists(ByVal WMPath As String)
+
+ Private Function TestSessionLoggedIn() As Boolean
Try
- If TestLoggedInSession() = False Then
- Return False
- End If
- WMPath = NormalizePath(WMPath)
- If IsNothing(GetWMObjectForFile(WMPath)) Then
- Return False
- Else
+ If Session.aLoggedin Then
Return True
+ Else
+ _logger.Warn("There is no active WM-Session for user {0}", _sessionUsername)
+ Return False
End If
Catch ex As Exception
- Logger.Error(ex)
+ _logger.Error(ex)
Return False
End Try
End Function
-
- Private Function TestLoggedInSession() As Boolean
- Try
- If CurrentSession.aLoggedin Then
- Return True
- Else
- Logger.Warn("There is no active WM-SSession!")
- Return False
- End If
- Catch ex As Exception
+ Private Function TestObjectExists(ObjectName As String, ObjectType As WMEntity) As Boolean
+ If TestSessionLoggedIn() = False Then
Return False
- End Try
- End Function
- '''
- ''' Checks if user exists in windream.
- '''
- ''' test username
- ''' Returns true if exists, false if not
- '''
- Public Function TestWMUSerExists(username As String) As Boolean
+ End If
Try
- If TestLoggedInSession() = False Then
- Return False
- End If
- Return CurrentSession.WMObjectExists(WMEntityUser, username, 0, 0)
- Catch ex As Exception
- Logger.Error(ex)
- Return False
- End Try
- End Function
- '''
- ''' Checks if group exists in windream.
- '''
- ''' test username
- ''' Returns true if exists, false if not
- '''
- Public Function TestWMGroupExists(groupname As String)
- Try
- If TestLoggedInSession() = False Then
- Return False
- End If
- Return CurrentSession.WMObjectExists(WMEntityGroups, groupname, 0, 0)
- Catch ex As Exception
- Logger.Error(ex)
- Return False
- End Try
- End Function
-#End Region
-#Region "+++++ Remove +++++"
- '''
- ''' Deletes a file in windream including all preversions
- '''
- ''' full path to the file
- ''' Returns true when file was deleted, false if not
- '''
- Public Function RemFile(ByVal WMPath As String)
- Try
- Const COL_Document_VersionID = "dwVersionID"
- Const WMObjectPartVersion = 128
- Dim oUnexpected_Error As Boolean = False
- WMPath = NormalizePath(WMPath)
- Dim oWMObject = GetWMObjectForFile(WMPath)
- If IsNothing(oWMObject) = False Then
- Try
- If (oWMObject.aPart And WMObjectPartVersion) Then
- Dim oWMObjects As WMObjects
- Dim oWMVersion As WMObject
- Dim iCount As Integer
- oWMObjects = oWMObject.aVersions
- iCount = oWMObjects.Count
- If iCount > 0 Then
- For Each oWMVersion In oWMObjects
- oWMVersion.Delete()
- Logger.Info($">> Deleted version '{oWMVersion.GetVariableValue(COL_Document_VersionID)}' of file '{oWMVersion.aName}'!")
- Next
- End If
- End If
- Catch ex As Exception
- Logger.Warn($"Unexpected Error in CheckingDeleting Prevesions: {ex.Message}")
- oUnexpected_Error = True
- End Try
- If oUnexpected_Error = False Then
- oWMObject.Delete()
- Logger.Info($">> File '{oWMObject.aName}' has been deleted!")
- Return True
- Else
- Return False
- End If
- Else
- Return False
- End If
- Catch ex As Exception
- Logger.Error(ex)
- Return False
- End Try
- End Function
- '''
- ''' Removes the vektorlink from windream
- '''
- ''' full path to the file
- ''' Indexname of Vektor-Index
- ''' Value which is to be deleted
- ''' Returns true when indexing was successfull, false if not
- '''
- Public Function REMOVE_VEKTOR_LINK(ByVal WMPath As String, vktIndexName As String, deleteValue As String)
- Try
- Logger.Info("Removing Value '" & deleteValue & "' of Index '" & vktIndexName & "' " & WMPath)
- Dim oWMFile As WMObject = GetWMObjectForFile(WMPath)
- If IsNothing(oWMFile) Then
- Logger.Warn("Exit from REMOVE_VEKTOR_LINK...")
- Return False
- End If
- Dim containsvalue As Boolean = False
- Dim ValueArray() = Nothing
- 'Jeden Wert des Vektorfeldes durchlaufen
- Dim WMValue = oWMFile.GetVariableValue(vktIndexName)
- If WMValue Is Nothing = False Then
- 'Nochmals prüfen ob wirklich Array
- If WMValue.GetType.ToString.Contains("System.Object") Then
- ' das entsprechende Attribut aus windream auslesen
- Dim oAttribute = CurrentSession.GetWMObjectByName(WMEntityAttribute, vktIndexName)
- ' den Variablentyp (String, Integer, ...) auslesen
- Dim vType = oAttribute.getVariableValue("dwAttrType")
- Dim Anzahl As Integer = 0
- For Each WDValue As Object In WMValue
- If WDValue Is Nothing = False Then
- If WDValue = deleteValue Then
- containsvalue = True
- Logger.Info("The Index contains the value to be deleted!")
- End If
- If WDValue <> deleteValue Then
- 'Erst die ALten Werte schreiben
- ReDim Preserve ValueArray(Anzahl)
- 'Den Wert im Array speichern
- ValueArray(Anzahl) = Helpers.ConvertVectorType(vType, WDValue)
- Anzahl += 1
- End If
- End If
- Next
- Else
- Logger.Warn("Index is not a vector")
- Return False
- End If
- Else
- Logger.Warn("oWMObject is nothing")
- Return True
- End If
-
- If containsvalue = True Then 'And Not IsNothing(ValueArray)
- If NewLockWMFile(oWMFile) = False Then
- Return False
- End If
- 'Indexiern des Vektorfeldes
- oWMFile.SetVariableValue(vktIndexName, ValueArray)
- ' die Indexinformationen des Dokuments speichern
- oWMFile.Save()
- Logger.Info("The new vectorvalues were saved!")
- ' Unlock in einem unbehandelten Try-Block um Fehler abzufangen,
- Try
- ' die Sperrung des Dokuments aufheben
- oWMFile.unlock()
-
- Catch ex As Exception
- ' nichts tun (Datei war nicht gesperrt)
- End Try
- 'Zurückgeben
- Return True
- Else
- Logger.Info("containsvalue is not true")
- Return True
- End If
+ Dim oObjectId = 0
+ Dim oObjectDbId = 0
+ Return Session.WMObjectExists(ObjectType, ObjectName, oObjectId, oObjectDbId)
Catch ex As Exception
- Logger.Error(ex)
+ _logger.Error(ex, "Error while checking existence of WMObject {0} of type {1}", ObjectName, ObjectType.ToString)
Return False
End Try
End Function
#End Region
End Class
+
+
diff --git a/Modules.Windream/Windream.vbproj b/Modules.Windream/Windream.vbproj
index c86a9f1a..72801a2c 100644
--- a/Modules.Windream/Windream.vbproj
+++ b/Modules.Windream/Windream.vbproj
@@ -112,8 +112,8 @@
Settings.settings
True
+
-
diff --git a/Modules.Windream/Windream2.vb b/Modules.Windream/Windream2.vb
deleted file mode 100644
index 320f605c..00000000
--- a/Modules.Windream/Windream2.vb
+++ /dev/null
@@ -1,1370 +0,0 @@
-Imports WINDREAMLib
-Imports WINDREAMLib.WMCOMEvent
-Imports WINDREAMLib.WMEntity
-Imports WINDREAMLib.WMObjectEditMode
-Imports WMOBRWSLib
-Imports WMOSRCHLib
-Imports WMCNNCTDLLLib
-Imports WMOTOOLLib
-Imports System.IO
-Imports DigitalData.Modules.Logging
-
-''' Windream
-''' 0.0.0.2
-''' 23.10.2018
-'''
-''' Module that provides methods to access the Windream ECM
-'''
-'''
-''' NLog, >= 4.5.8
-'''
-'''
-''' 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
-''' Drive Letter of the Windream Drive, should default to `W`
-'''
-''' ClientSupport64Bit, Boolean
-''' Should this session support 64bit methods/functionality?
-'''
-''' SessionReconnect, Boolean
-''' Should the session reconnect automatically when the connection to the server is lost?
-'''
-''' SessionServerName, String
-''' Name of the server used in the connection. If this is `Nothing`, the current server defined in the client is used
-'''
-''' SessionUserName, String
-''' Name of the user that is used in the connection. If this is `Nothing`, the currently signed in user is used
-'''
-''' SessionPassword, String
-''' User-password that is used in the connection. If this is `Nothing`, the currently signed in user is used
-'''
-''' SessionDomain, String
-''' User-domain that is used in the connection. If this is `Nothing`, the currently signed in user is used
-'''
-'''
-''' ClientDriveLetter, String (readonly)
-''' ClientSupports64Bit, Boolean (readonly)
-''' Session, IWMSession2 (readonly)
-''' SessionLoggedin, Boolean (readonly)
-''' SessionReconnect, Boolean (readonly)
-''' SessionServername, String (readonly)
-''' Objecttypes, List(Of String) (readonly)
-'''
-'''
-''' _windream = New ConnectionBuilder(LogConfig).
-''' WithDriveLetter("W").
-''' WithSessionReconnect().
-''' With64BitSupport().
-''' WithServerName("sdd-vmx02-aps01").
-''' Connect()
-'''
-'''
-''' This class should not be instanciated directly. Instead, ConnectionBuilder should be used.
-'''
-Public Class Windream2
-#Region "Private Properties"
- Private ReadOnly _logger As Logger
- Private ReadOnly _logConfig As LogConfig
-
- Private ReadOnly Property _sessionDomain As String
- Private ReadOnly Property _sessionPassword As String
- Private ReadOnly Property _sessionUsername As String
-
-#End Region
-#Region "Public Properties"
- Public ReadOnly Property ClientDriveLetter As String
- Public ReadOnly Property ClientSupports64Bit As Boolean
-
- Public ReadOnly Property Session As IWMSession2
- Public ReadOnly Property SessionLoggedin As Boolean = False
- Public ReadOnly Property SessionReconnect As Boolean
- Public ReadOnly Property SessionServername As String
-
- ''' A list of object types that are available
- Public ReadOnly Property ObjectTypes As List(Of String)
- Get
- Dim types As WMObjects = GetObjectTypes()
- Dim list As New List(Of String)
-
- For Each type As WMObject In types
- list.Add(type.aName)
- Next
-
- Return list
- End Get
- End Property
-
-#End Region
- '''
- ''' Creates a new Windream object and connects to a server with the provided options and credentials
- '''
- '''
- '''
- '''
- '''
- '''
- '''
- '''
- '''
- '''
- 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 = LogConfig.GetLogger()
- _logConfig = LogConfig
-
- ' Create a session
- Dim oSession As IWMSession2 = NewSession(SessionServerName, SessionUserName, SessionPassword, SessionDomain)
-
- ' If no session could be created, exit
- If oSession Is Nothing Then
- Throw New Exceptions.SessionException()
- End If
-
- ' Set properties of currently established session
- Session = oSession
- SessionLoggedin = True
-
- Me.SessionReconnect = SessionReconnect
- Me.ClientDriveLetter = ClientDriveLetter
- Me.ClientSupports64Bit = ClientSupport64Bit
- Me.SessionServername = SessionServerName
-
- _sessionUsername = SessionUserName
- _sessionPassword = SessionPassword
- _sessionDomain = SessionDomain
- End Sub
-
- Public Function GetChoiceListItems(ChoiceListName As String) As List(Of String)
- Dim oItems As New List(Of String)
- Dim oChoicelist As WMObject
-
- If TestSessionLoggedIn() = False Then
- Return oItems
- End If
-
- Try
- oChoicelist = Session.GetWMObjectByName(WMEntityChoiceList, ChoiceListName)
- Catch ex As Exception
- _logger.Error(ex, "Could not get choice list")
- Return oItems
- End Try
-
- Try
- Dim oChoiceListItems As Object = oChoicelist.GetVariableValue("vItems")
-
- If oChoiceListItems Is Nothing Then
- Return oItems
- End If
-
- For Each oChoiceListItem In oChoiceListItems
- oItems.Add(oChoiceListItem)
- Next
-
- Return oItems
- Catch ex As Exception
- _logger.Error(ex, "Could not get choice list items")
- Return oItems
- End Try
- End Function
-
- Public Function GetChoiceLists() As List(Of String)
- Dim oItems As New List(Of String)
-
- If TestSessionLoggedIn() = False Then
- Return oItems
- End If
-
- Try
- Dim oChoiceLists As WMObjects
- Dim oChoiceList As IWMObject2
- 'load list of choicelists
- oChoiceLists = Session.GetAllObjects(WMEntityChoiceList)
-
- For Each oChoiceList In oChoiceLists
- oItems.Add(oChoiceList.aName)
- Next
-
- Return oItems
- Catch ex As Exception
- _logger.Error(ex)
- Return oItems
- End Try
- End Function
-
- Public Function GetFileByPath(Path As String) As WMObject
- If TestSessionLoggedIn() = False Then
- Return Nothing
- End If
- Path = GetNormalizedPath(Path)
- Dim oWMObject As WMObject
-
- Try
- oWMObject = Session.GetWMObjectByPath(WMEntityDocument, Path)
- Return oWMObject
- Catch ex As Exception
- Return Nothing
- End Try
- End Function
-
- Public Function GetIndexType(IndexName As String) As Integer
- If TestSessionLoggedIn() = False Then
- Return Nothing
- End If
-
- Try
- Dim oAttribute = Session.GetWMObjectByName(WMEntityAttribute, IndexName)
- Dim oType = oAttribute.GetVariableValue("dwAttrType")
- Return oType
- Catch ex As Exception
- _logger.Error(ex)
- Return Nothing
- End Try
- End Function
-
- Public Function GetIndexValue(Path As String, IndexName As String) As List(Of String)
- Dim oResult As New List(Of String)
-
- If TestSessionLoggedIn() = False Then
- Return oResult
- End If
-
- Try
- Path = GetNormalizedPath(Path)
- Dim oWMObject As WMObject = Session.GetWMObjectByPath(WMEntityDocument, Path)
-
- If oWMObject Is Nothing Then
- Return oResult
- End If
-
- Dim oValues = oWMObject.GetVariableValue(IndexName)
-
- If oValues Is Nothing Then
- Return oResult
- End If
-
- If TypeOf oValues Is IEnumerable Then
- For Each oValue In oValues
- oResult.Add(oValue)
- Next
- Else
- oResult.Add(oValues)
- End If
-
- Return oResult
- Catch ex As Exception
- _logger.Error(ex)
- Return oResult
- End Try
- End Function
-
- Public Function GetIndiciesByObjecttype(ObjectTypeName As String) As List(Of String)
- If TestSessionLoggedIn() = False Then
- Return Nothing
- End If
-
- Dim oObjectType As WMObject
- Dim oIndexAttributes As WMObjectRelation
- Dim oIndexAttribute As WMObject
- Dim oIndex As WMObject
- Dim oRelProperties As WMObjectRelation
- Dim oTempSession As IWMSession2
- Dim oIndicies As New List(Of String)
-
- Try
- ' den Objekttyp laden
- oTempSession = DirectCast(Session, IWMSession2)
- oObjectType = Session.GetWMObjectByName(WMEntityObjectType, ObjectTypeName)
-
- ' Beziehung zu Indizes des Objekttyp auslesen
- oIndexAttributes = oObjectType.GetWMObjectRelationByName("TypeAttributes")
-
- ' alle Indizes durchlaufen
- For j As Integer = 0 To oIndexAttributes.Count - 1
-
- ' aktuellen Index auslesen
- oIndexAttribute = oIndexAttributes.Item(j)
-
- ' Eigenschaften des Index auslesen
- oRelProperties = oIndexAttribute.GetWMObjectRelationByName("Attribute")
-
- ' Index aus den Eigenschaften auslesen
- oIndex = oRelProperties.Item(0)
-
- ' Indexname speichern
- 'aIndexNames(j) = oIndex.aName
- oIndicies.Add(oIndex.aName)
- Next
-
- ' Indexarray zurückgeben
- 'Return aIndexNames
- Return oIndicies
-
- Catch ex As Exception
- _logger.Error(ex)
- Return oIndicies
- 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
- Dim oBrowser As ServerBrowser
- Dim oConnect As IWMConnect2
- Dim oSession As IWMSession2
- Dim oCredentials As WMUserIdentity
-
- Dim oImpersonation As Boolean
- Dim oServerNameFromClient As Boolean
-
- ' Create initial windream objects
- Try
- oBrowser = New ServerBrowser()
- oConnect = New WMConnect()
- _logger.Info("Successfully created windream objects")
- Catch ex As Exception
- _logger.Error(ex, "Error while creating windream objects")
- Return Nothing
- End Try
-
- ' If no server was supplied, try to get the current server set in the client
- Try
- If ServerName Is Nothing OrElse ServerName.Length = 0 Then
- ServerName = oBrowser.GetCurrentServer
- oServerNameFromClient = True
- Else
- oServerNameFromClient = False
- End If
- Catch ex As Exception
- _logger.Error(ex, "Error while getting Servername")
- Return Nothing
- End Try
-
- _logger.Info("Servername: {0}", ServerName)
- _logger.Info("Servername aquired from client: {0}", oServerNameFromClient)
-
- '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
- If UserName IsNot Nothing And Password IsNot Nothing And Domain IsNot Nothing Then
- oImpersonation = True
- oCredentials = New WMUserIdentity() With {
- .aServerName = ServerName,
- .aUserName = UserName,
- .aPassword = Password,
- .aDomain = Domain
- }
-
- oConnect.ModuleId = 9
- Else
- oImpersonation = False
- oCredentials = New WMUserIdentity() With {
- .aServerName = ServerName
- }
- End If
-
- _logger.Info("Impersonated Login: {0}", oImpersonation)
- _logger.Info("Username: {0}", IIf(UserName IsNot Nothing, UserName, Environment.UserName))
- _logger.Info("Domain: {0}", IIf(Domain IsNot Nothing, Domain, Environment.UserDomainName))
-
- Try
- oSession = oConnect.Login(oCredentials)
- _logger.Info("Connected..Session created")
- Catch ex As Exception
- _logger.Error(ex, "Error while logging in")
- Return Nothing
- End Try
-
- Try
- ' Standardmässig hinterlegen dass abgelegte Dateien keine Indexmaske öffnet
- oSession.SwitchEvents(WMCOMEventWMSessionNeedIndex, False)
- Catch ex As Exception
- _logger.Error(ex, "Could not SwitchEvents")
- Return Nothing
- End Try
-
- If oSession.aLoggedin = False Then
- _logger.Warn("Session created but user {0} could not be logged in", Environment.UserName)
- Return Nothing
- End If
-
- _logger.Info("Connection to {0} established!", ServerName)
- Return oSession
- End Function
-
-#Region "Public Methods"
- '''
- ''' changes the archive end date
- '''
- ''' WM Filepath
- ''' number/count of period (if
- ''' date_unity (d,m,y or day(s),month(s),years(s)
- ''' dateFrom_value
- ''' Returns true when date was set, false if not
- '''
- Public Function NewLifecycle_Period(ByVal wmfilepath As String, ByVal dateFrom_value As Date, ByVal date_period As Double, ByVal date_unit As String)
- Dim oWMObject As WMObject
- Try
- oWMObject = GetFileByPath(wmfilepath)
- _logger.Info($"Changing the archive end-date for file '{oWMObject.aName}', Items: {dateFrom_value},{date_period},{date_unit}")
- Try
- ' die Datei sperren
- oWMObject.LockFor(WMObjectEditModeLifeCycleEdit)
- _logger.Debug(">> object locked")
-
- Catch ex As Exception
- _logger.Error(ex)
- ' nichts tun (Datei ist bereits gesperrt)
- End Try
-
- Dim oObjectLifecycle = oWMObject.aWMLifeCycle
-
- Dim oIntervalType As DateInterval
- If date_unit.ToLower = "d" Or date_unit.ToLower = "day(s)" Then
- oIntervalType = DateInterval.Day
- ElseIf date_unit.ToLower = "m" Or date_unit.ToLower = "month(s)" Then
- oIntervalType = DateInterval.Month
- ElseIf date_unit.ToLower = "y" Or date_unit.ToLower = "year(s)" Then
- oIntervalType = DateInterval.Year
- End If
-
- Dim oArchUntil = DateAdd(oIntervalType, date_period, dateFrom_value)
- _logger.Debug("New date shall be: " & oArchUntil.ToString)
-
- oObjectLifecycle.SetPeriodEndDate(2, oArchUntil)
- _logger.Info("Archive end-date has been changed!")
- oWMObject.Save()
- oWMObject.unlock()
- Return SetArchive_Active(oWMObject)
-
- Catch ex As Exception
- _logger.Warn($"Unexpected Error in NewLifecycle_Period {ex.Message}")
- If Not IsNothing(oWMObject) Then
- If oWMObject.aLocked = True Then
- oWMObject.unlock()
- End If
- End If
- Return False
- End Try
- End Function
- '''
- ''' changes the archive end date
- '''
- ''' WM Filepath
- ''' number/count of period (if
- ''' date_unity (d,m,y or day(s),month(s),years(s)
- ''' dateFrom_value
- ''' Returns true when date was set, false if not
- '''
- Public Function NewLifecycle_PeriodTEST(ByVal wmfilepath As String, ByVal oArchUntil As String)
- Dim oWMObject As WMObject
- Try
- oWMObject = GetFileByPath(wmfilepath)
- _logger.Info($"Changing the archive end-date for file '{oWMObject.aName}', Items: {oArchUntil}")
- Try
- ' die Datei sperren
- oWMObject.LockFor(WMObjectEditModeLifeCycleEdit)
- _logger.Debug(">> object locked")
-
- Catch ex As Exception
- _logger.Error(ex)
- ' nichts tun (Datei ist bereits gesperrt)
- End Try
-
- Dim oObjectLifecycle = oWMObject.aWMLifeCycle
- ' Dim oDate = CDate(oArchUntil)
- ' Dim omMyFormattedDate = oDate.ToString("dd.MM.yyyy")
-
- If oArchUntil <> String.Empty Then
- If IsDate(oArchUntil) Then
- If CDate(oArchUntil) < CDate(Now) Then
- _logger.Debug("oArchUntil < today so direct move to archivepool")
- Else
- _logger.Debug("New date shall be: " & oArchUntil)
- oObjectLifecycle.SetPeriodEndDate(2, oArchUntil)
- _logger.Info("Archive end-date has been changed!")
- End If
- End If
- Else
- _logger.Debug("oArchUntil is empty so direct move to archivepool")
- End If
-
- Dim result = SetArchive_Active(oWMObject)
- oWMObject.Save()
- oWMObject.unlock()
- Return result
-
- Catch ex As Exception
- _logger.Warn($"Unexpected Error in NewLifecycle_PeriodTEST {ex.Message}")
- If Not IsNothing(oWMObject) Then
- If oWMObject.aLocked = True Then
- oWMObject.unlock()
- End If
- End If
- Return False
- End Try
- End Function
- '''
- ''' Archives windream object immediately
- '''
- ''' Returns true when archiving was set, false if not
- '''
- Private Function SetArchive_Active(oWMObject As WMObject)
- Try
- oWMObject.MoveToArchivePool()
- _logger.Info("oWMObject has been archived!")
- Return True
- Catch ex As Exception
- _logger.Warn($"Unexpected Error in SetArchive_Active {ex.Message}")
- Return False
- End Try
- End Function
-
- Public Function NewFolder(Path As String) As Boolean
- If Not TestSessionLoggedIn() Then
- Return False
- End If
-
- Try
- Path = GetNormalizedPath(Path)
- Dim oFolders As List(Of String) = Path.Split().ToList()
- Dim oFolderObject As WMObject
-
- For Each oFolder In oFolders
- If TestFolderExists(Path) = False Then
- oFolderObject = Session.GetNewWMObjectFS(WMEntityFolder, oFolder, WMObjectEditModeNoEdit)
- End If
- Next
-
- Return True
- Catch ex As Exception
- _logger.Error(ex)
- Return False
- End Try
- End Function
-
- Public Function NewFileVersion(Path As String, Comment As String) As Boolean
- If Not TestSessionLoggedIn() Then
- Return False
- End If
-
- Try
- Path = GetNormalizedPath(Path)
- Dim oFileObject As IWMObject6
- oFileObject = GetObjectByPath(Path, WMEntityDocument)
- oFileObject.CreateVersion2(False, Constants.HISTORY_NEW_FROM_VERSION, Comment)
- Return True
- Catch ex As Exception
- _logger.Error(ex)
- Return False
- End Try
- End Function
-
- 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)
-
- _logger.Debug($"Streaming file from {FilenameSource} to {FilenameTarget}")
-
- Dim oWMObject As IWMObject6 = Nothing
- Dim oFileIO As WMFileIO
- Dim oWMStream As WMStream
-
- '_logger.Debug("Try to access file and lock it...")
- 'Err.Clear()
-
- 'Indexierungsdialog der Session unterdrücken
- Session.SwitchEvents(Constants.COM_EVENT_SESSION_NEED_INDEX, False)
-
- '==================================================================
- ' create an object
- '==================================================================
-
- Try
- _logger.Debug("Creating WMObject for file {0}", FilenameTarget)
- oWMObject = Session.GetNewWMObjectFS(WMEntityDocument, FilenameTarget, WMObjectEditModeObject)
- Catch ex As Exception
- _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
- Try
- WMObject.LockFor(EditMode)
- Return True
- Catch ex As Exception
- _logger.Error(ex)
- Return False
- End Try
- End Function
-
- Public Function UnlockObject(WMObject As WMObject) As Boolean
- Try
- WMObject.unlock()
- Return True
- Catch ex As Exception
- _logger.Error(ex)
- Return False
- End Try
- End Function
-
- '''
- ''' Returns the result of a search file
- '''
- ''' Path of a search file (*.wdf)
- ''' Index containing the Document-ID
- ''' A datatable of the results with columns PATH and DOCID
- 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 oDatatable
- End If
-
- If TestFileExists(SearchFilePath) = False Then
- Return oDatatable
- End If
-
- Try
- Dim oFileInfo = New FileInfo(SearchFilePath)
- Dim oProfileName = oFileInfo.Name
- Dim oProfilePath = oFileInfo.DirectoryName
-
- Dim oSearchController As New WMOSearchController()
- oSearchController.CheckSearchProfile(SearchFilePath)
-
- Dim oSearchType = oSearchController.SearchProfileTargetProgID
-
- Dim oSearchProfileExSetttings As Integer = oSearchController.SearchProfileExSettings
-
- If oSearchProfileExSetttings = 0 Then
- oSearchProfileExSetttings = 7
- End If
-
- Dim oSearch As WMSearch
-
- Select Case oSearchType.ToUpper()
- Case Constants.SEARCH_TYPE_QUICK_SEARCH
- Dim oQuickSearch As New WMQuickSearch With {
- .WMSession = Session,
- .SearchProfilePath = oProfilePath
- }
- oQuickSearch.ClearSearch()
- oQuickSearch.LoadSearchProfile(oProfileName)
-
- oSearch = oQuickSearch.GetSearch()
- Case Constants.SEARCH_TYPE_INDEX_SEARCH
- Dim oIndexSearch As New WMIndexSearch With {
- .WMSession = Session,
- .SearchProfilePath = oProfilePath
- }
- oIndexSearch.ClearSearch()
- oIndexSearch.LoadSearchProfile(oProfileName)
-
- oSearch = oIndexSearch.GetSearch()
- Case Constants.SEARCH_TYPE_OBJECTTYPE_SEARCH
- Dim oObjecttypeSearch As New WMObjectTypeSearch With {
- .WMSession = Session,
- .SearchProfilePath = oProfilePath
- }
- oObjecttypeSearch.ClearSearch()
- oObjecttypeSearch.LoadSearchProfile(oProfileName)
-
- oSearch = oObjecttypeSearch.GetSearch()
- Case Else
- _logger.Warn("{0} is not a valid search type", oSearchType)
- Return oDatatable
- End Select
-
- Dim oSearchResults As WMObjects = oSearch.Execute()
-
- If oSearchResults.Count = 0 Then
- Return oDatatable
- End If
-
- For Each oSearchResult As WMObject In oSearchResults
- Dim path As String = oSearchResult.aPath
- Dim docId As Integer = oSearchResult.GetVariableValue(DocIdIndexName)
-
- oDatatable.Rows.Add(path, docId)
- Next
- oDatatable.AcceptChanges()
-
- Return oDatatable
- Catch ex As Exception
- _logger.Error(ex)
- Return oDatatable
- End Try
- End Function
-
- '''
- ''' Gets an array of the actual vektorvalues of index, collated with the passed values
- '''
- ''' windream-file as WMObject
- ''' Indexname as String
- ''' The new values as Array
- ''' True if duplicates shall be prevented
- '''
- Public Function GetVektorData_Combined(ByVal WindreamObject 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 = WindreamObject.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
-
- '''
- ''' Sets objecttype of a folder
- '''
- '''
- '''
- '''
- Public Function SetFolderObjecttype(FolderPath As String, Objecttype As String) As Boolean
- If TestSessionLoggedIn() = False Then
- Return False
- End If
-
- Try
- FolderPath = GetNormalizedPath(FolderPath)
-
- If TestFolderExists(FolderPath) = False Then
- _logger.Warn("Folder {0} does not exist!", FolderPath)
- Return False
- End If
-
- Dim oWMFolder As WMObject = GetObjectByPath(FolderPath, WMEntityFolder)
-
- If LockObject(oWMFolder) = False Then
- _logger.Warn("Folder {0} could not be locked", FolderPath)
- End If
-
- If oWMFolder.aObjectType.aName <> Constants.OBJECT_TYPE_DEFAULT Then
- _logger.Warn("Objecttype for folder {0} has already been set!", FolderPath)
- End If
-
- Dim oObjecttype As WMObject = GetObjectByName(Objecttype, WMEntityObjectType)
-
- If oObjecttype Is Nothing Then
- _logger.Warn("Objecttype {0} does not exist!", Objecttype)
- Return False
- End If
-
- oWMFolder.aObjectType = oObjecttype
- oWMFolder.Save()
-
- If UnlockObject(oWMFolder) Then
- _logger.Warn("Folder {0} could not be unlocked", FolderPath)
- End If
-
- Return True
- Catch ex As Exception
- _logger.Error(ex)
- Return False
- End Try
- End Function
-
- Public Function RemoveFile(Path As String) As Boolean
- If TestSessionLoggedIn() = False Then
- Return Nothing
- End If
-
- Try
- Dim oWMObject As WMObject = GetFileByPath(Path)
-
- If oWMObject Is Nothing Then
- Return False
- End If
-
- oWMObject.Delete()
- _logger.Warn($"file {Path} has been deleted!")
- Return True
- Catch ex As Exception
- _logger.Error(ex)
- Return False
- 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
-
- 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
-
- Dim oVectorValues = oWMObject.GetVariableValue(IndexName)
- Dim oType As Integer = GetIndexType(IndexName)
-
- 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 oNewValues As New List(Of Object)
- oNewValues = oVectorValues.Except(New List(Of Object) From {ValueToDelete}).ToList()
-
- ' BEGIN WRITE INDEX
- If LockObject(oWMObject, WMObjectEditModeIndexEdit) = False Then
- _logger.Warn("File {0} could not be locked")
- Return False
- End If
-
- oWMObject.SetVariableValue(IndexName, oNewValues.ToArray())
- oWMObject.Save()
-
- UnlockObject(oWMObject)
-
- Return True
- ' END WRITE INDEX
- Catch ex As Exception
- _logger.Error(ex)
- Return False
- End Try
- End Function
-
- Public Function SetFileIndex(Path As String, IndexName As String, Value As String) As Boolean
- If TestSessionLoggedIn() = False Then
- Return False
- End If
-
- Dim oWMObject As WMObject = GetFileByPath(Path)
-
- If LockObject(oWMObject, WMObjectEditModeIndexEdit) = False Then
- _logger.Warn("File {0} could not be locked")
- Return False
- End If
-
- Try
- Dim oType As Integer = GetIndexType(IndexName)
- Dim oConvertedValue As Object = Helpers.ConvertIndexValue(oType, Value)
- oWMObject.SetVariableValue(IndexName, oConvertedValue)
- 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
- Try
- Dim oWMObject As IWMObject6 = DirectCast(WMObject, IWMObject6)
-
- Dim oFilenameFull As String = oWMObject.aName
- Dim oFilenameExport As String
- Dim oSplitIndex = oFilenameFull.LastIndexOf(".")
- Dim oVersion = 1
-
- Dim oFilename = oFilenameFull.Substring(0, oSplitIndex)
- Dim oExtension = oFilenameFull.Substring(oSplitIndex)
-
- _logger.Debug("Preparing export of file {0}..", oFilenameFull)
- _logger.Debug("Filename: {0}", oFilename)
- _logger.Debug("Extension: {0}", oExtension)
-
- ' build the file path in case the exported file doesn't already exist
- oFilenameExport = BuildExportPath(ExportPath, oFilename, oExtension)
-
- ' Add version until we find the version that does NOT exist
- Do While File.Exists(oFilenameExport)
- oVersion += 1
- oFilenameExport = BuildExportPath(ExportPath, oFilename, oExtension, oVersion)
- Loop
-
- _logger.Debug("File will be exported to {0}", oFilenameExport)
-
- _logger.Debug("Opening file stream..")
- Dim oStream As WMStream = oWMObject.OpenStream("BinaryObject", WMObjectStreamOpenMode.WMObjectStreamOpenModeRead)
- Dim oWMFileIO As New WMFileIO() With {
- .aWMStreamEx = oStream,
- .aWMStream = oStream,
- .bstrOriginalFileName = oFilenameExport
- }
-
- _logger.Debug("Exporting file..")
- oWMFileIO.ExportOriginal(True)
-
- _logger.Debug("Cleaning up..")
- oStream.Flush()
- oStream.Close()
-
- _logger.Debug("File exported to {0}", oFilenameExport)
- Return True
- Catch ex As Exception
- _logger.Error(ex)
- Return False
- End Try
- End Function
-
- Private Function BuildExportPath(BasePath As String, FilenameWithoutExtension As String, Extension As String, Optional Version As Integer = 1)
- Dim oFilename
-
- If Version = 1 Then
- oFilename = FilenameWithoutExtension & Extension
- Else
- oFilename = FilenameWithoutExtension & "_" & Version & Extension
- End If
-
- Return Path.Combine(BasePath, oFilename)
- End Function
-
- Public Function Export_WMFile(WMPath As String, Exportpath As String)
- Try
- If Not Exportpath.EndsWith("\") Then
- Exportpath &= "\"
- End If
-
- Dim oWMObject As WMObject = GetFileByPath(WMPath)
-
- _logger.Debug("Working on file: " & oWMObject.aName)
-
-
- Dim ExportFileIO = New WMOTOOLLib.WMFileIO ' CreateObject("WMOTOOLLib.WMFileIO") ' New WMOTOOLLib.WMFileIO
- _logger.Debug("ExportFileIO created...")
- ' Stream Interface bereitstellen
- oWMObject.LockFor(WMObjectEditModeFileSystem)
- Try
- If Not oWMObject.aLocked Then
- oWMObject.lock()
- End If
- Catch ex As Exception
- _logger.Error(ex)
- Return False
- End Try
-
- Dim oWMStream = oWMObject.OpenStream("BinaryObject", WMObjectEditModeTypedData)
- '### VERSIONIERUNG ###
- Dim version As Integer = 2
- 'Dim Stammname As String = System.IO.Path.GetFileNameWithoutExtension(Quelle)
- Dim Filename = oWMObject.aName.Substring(0, oWMObject.aName.LastIndexOf("."))
- Dim Extension = oWMObject.aName.Substring(oWMObject.aName.LastIndexOf("."))
- Dim tempFilename As String = Exportpath & Filename & Extension
- 'Überprüfen ob File existiert
- Do While IO.File.Exists(tempFilename) = True
- tempFilename = Exportpath & Filename & "_" & version & Extension
- version = version + 1
- Loop
- _logger.Debug("Exportfilename is: " & tempFilename)
- ' den Dateiinhalt der neuen Datei zuweisen
- ExportFileIO.aWMStream = oWMStream
- ExportFileIO.bstrOriginalFileName = tempFilename
- 'Das eigentliche kopieren
- ExportFileIO.ExportOriginal(True)
- ' close the windream file stream
- oWMStream.Close()
- oWMObject.Save()
- oWMObject.unlock()
- _logger.Info($"WMFile has been exported to {tempFilename} ")
-
- Return True
- Catch ex As Exception
- _logger.Error(ex)
- Return False
- End Try
- End Function
- Public Function Export_WMFile_DocID(WMPath As String, Exportpath As String, DocId As Integer)
- Try
- If Not Exportpath.EndsWith("\") Then
- Exportpath &= "\"
- End If
-
- Dim oWMObject As WMObject = GetFileByPath(WMPath)
- Try
- _logger.Info("Working on file: " & oWMObject.aName)
- Catch ex As Exception
- _logger.Error(ex)
- _logger.Warn("No object created: " & WMPath)
- Return False
- End Try
- Dim ExportFileIO = New WMOTOOLLib.WMFileIO ' CreateObject("WMOTOOLLib.WMFileIO") ' New WMOTOOLLib.WMFileIO
- _logger.Debug("ExportFileIO created...")
- Dim oWMStream = oWMObject.OpenStream("BinaryObject", 1)
- '### VERSIONIERUNG ###
- Dim version As Integer = 2
- Dim Extension = oWMObject.aName.Substring(oWMObject.aName.LastIndexOf("."))
- Dim tempFilename As String = Exportpath & DocId & Extension
- 'Überprüfen ob File existiert
- Do While IO.File.Exists(tempFilename) = True
- tempFilename = Exportpath & DocId & "_" & version & Extension
- version = version + 1
- Loop
- _logger.Debug("Exportfilename is: " & tempFilename)
- ' den Dateiinhalt der neuen Datei zuweisen
- ExportFileIO.aWMStream = oWMStream
- ExportFileIO.bstrOriginalFileName = tempFilename
- 'Das eigentliche kopieren
- ExportFileIO.ExportOriginal(True)
- 'close the windream file stream
- oWMStream.Close()
- _logger.Info($"WMFile DocID {DocId} has been exported to {tempFilename} ")
- Return True
- Catch ex As Exception
- _logger.Error(ex)
- _logger.Info("Unexpected error in Export_WMFile: " & ex.Message)
- Return False
- End Try
- End Function
- Public Function TestFolderExists(Path As String) As Boolean
- Return TestObjectExists(GetNormalizedPath(Path), WMEntityFolder)
- End Function
-
- Public Function TestFileExists(Path As String) As Boolean
- Return TestObjectExists(GetNormalizedPath(Path), WMEntityDocument)
- End Function
-
- Public Function TestUserExists(Username As String) As Boolean
- Return TestObjectExists(Username, WMEntityUser)
- End Function
-
- Public Function TestGroupExists(Groupname As String) As Boolean
- Return TestObjectExists(Groupname, WMEntityGroups)
- End Function
-#End Region
-
-#Region "Private Methods"
- Private Function GetNormalizedPath(Path As String) As String
- Dim oNormalizedPath = Path
-
- If Not Path.StartsWith("\") And Path.ToUpper().StartsWith(ClientDriveLetter.ToUpper) Then
- oNormalizedPath = Path.Substring(2)
- End If
-
- Return oNormalizedPath
- End Function
-
- Private Function GetObjectTypes() As WMObjects
- Dim oObjectTypes As WMObjects
-
- Try
- oObjectTypes = Session.GetWMObjectTypes(WMEntityDocument)
- Return oObjectTypes
- Catch ex As Exception
- _logger.Error(ex)
- Return Nothing
- End Try
- End Function
-
- Private Function GetObjectByName(ObjectName As String, ObjectType As WMEntity) As WMObject
- If TestSessionLoggedIn() = False Then
- Return Nothing
- End If
-
- If TestObjectExists(ObjectName, ObjectType) = False Then
- Return Nothing
- End If
-
- Try
- Dim oWMObject As WMObject = Session.GetWMObjectByName(ObjectType, ObjectName)
- Return oWMObject
- Catch ex As Exception
- _logger.Error(ex)
- Return Nothing
- End Try
- End Function
-
- Private Function GetObjectByPath(ObjectName As String, ObjectType As WMEntity) As WMObject
- If TestSessionLoggedIn() = False Then
- Return Nothing
- End If
-
- If TestObjectExists(ObjectName, ObjectType) = False Then
- Return Nothing
- End If
-
- Try
- Dim oWMObject As WMObject = Session.GetWMObjectByPath(ObjectType, ObjectName)
- Return oWMObject
- Catch ex As Exception
- _logger.Error(ex)
- Return Nothing
- End Try
- End Function
-
- Private Function TestSessionLoggedIn() As Boolean
- Try
- If Session.aLoggedin Then
- Return True
- Else
- _logger.Warn("There is no active WM-Session for user {0}", _sessionUsername)
- Return False
- End If
- Catch ex As Exception
- _logger.Error(ex)
- Return False
- End Try
- End Function
-
- Private Function TestObjectExists(ObjectName As String, ObjectType As WMEntity) As Boolean
- If TestSessionLoggedIn() = False Then
- Return False
- End If
- Try
- Dim oObjectId = 0
- Dim oObjectDbId = 0
-
- Return Session.WMObjectExists(ObjectType, ObjectName, oObjectId, oObjectDbId)
- Catch ex As Exception
- _logger.Error(ex, "Error while checking existence of WMObject {0} of type {1}", ObjectName, ObjectType.ToString)
- Return False
- End Try
- End Function
-#End Region
-End Class
-
-
diff --git a/Modules.Windream/Windream_alt.vb b/Modules.Windream/Windream_alt.vb
new file mode 100644
index 00000000..14e77697
--- /dev/null
+++ b/Modules.Windream/Windream_alt.vb
@@ -0,0 +1,1214 @@
+Imports WINDREAMLib
+Imports WINDREAMLib.WMCOMEvent
+Imports WINDREAMLib.WMEntity
+Imports WINDREAMLib.WMObjectEditMode
+Imports WINDREAMLib.WMSearchOperator
+Imports WINDREAMLib.WMSearchRelation
+Imports WMOBRWSLib
+Imports WMOSRCHLib
+Imports WMCNNCTDLLLib
+Imports WMOTOOLLib
+Public Class Windream_alt
+ Inherits Constants
+#Region "+++++ Variables +++++"
+ Private Shared Logger As NLog.Logger = NLog.LogManager.GetCurrentClassLogger
+
+ Private ServerBrowser As IServerBrowser
+
+ Private CurrentController As WMOSearchController
+ Private CurrentSession As WMSession
+ Private CurrentConnect As WMConnect
+ Private CurrentServer As String
+ Private CurrentObjecttypes As WMObjects
+
+ Public ReadOnly Property ReconnectSession As Boolean
+ Public ReadOnly Property DriveLetter As String
+ Public ReadOnly Property Support64Bit As Boolean
+ Public Property LoggedInSession As Boolean = False
+#End Region
+#Region "+++++ Init +++++"
+ '''
+ ''' Initializes windream and creates a windream session with the actual user
+ '''
+ '''
+ Public Sub New(
+ Optional DriveLetter As String = "W",
+ Optional ReconnectSession As Boolean = False,
+ Optional Support64Bit As Boolean = False,
+ Optional ServerName As String = Nothing,
+ Optional UserName As String = Nothing,
+ Optional UserPass As String = Nothing,
+ Optional UserDomain As String = Nothing
+ )
+ Try
+ Me.DriveLetter = DriveLetter
+ Me.ReconnectSession = ReconnectSession
+ Me.Support64Bit = Support64Bit
+
+ Dim session As WMSession = NewSession(ServerName, UserName, UserPass, UserDomain)
+
+ If session Is Nothing Then
+ Throw New Exception("Login failed")
+ End If
+
+ CurrentSession = session
+ CurrentServer = ServerName
+ CurrentObjecttypes = GetObjectTypes()
+
+ Catch ex As Exception
+ Logger.Error(ex)
+ End Try
+ End Sub
+
+ Public Function NewSession(Optional serverName As String = Nothing) As WMSession
+ Dim browser As ServerBrowser
+ Dim connect As WMConnect
+ Dim session As WMSession
+ Dim credentials As WMUserIdentity
+
+ Try
+ browser = New ServerBrowser()
+ connect = New WMConnect()
+ Logger.Info("Successfully created windream objects")
+ Catch ex As Exception
+ Logger.Error(ex, "Error while creating windream objects")
+ Return Nothing
+ End Try
+
+ Try
+ If serverName Is Nothing OrElse serverName.Length = 0 Then
+ serverName = browser.GetCurrentServer()
+ End If
+ Catch ex As Exception
+ Logger.Error(ex, "Error while getting current server")
+ Return Nothing
+ End Try
+
+ Try
+ credentials = New WMUserIdentity() With {
+ .aServerName = serverName
+ }
+ Catch ex As Exception
+ Logger.Error(ex, "Error while creating user identity")
+ Return Nothing
+ End Try
+
+ Try
+ session = connect.Login(credentials)
+ 'LoggedInSession = True
+ CurrentServer = serverName
+
+ Return session
+ Catch ex As Exception
+ Logger.Error(ex, "Error while logging in")
+ 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 WMSession
+ Dim browser As ServerBrowser
+ Dim connect As WMConnect
+ Dim session As WMSession
+ Dim credentials As WMUserIdentity
+
+ Dim impersonation As Boolean
+ Dim serverNameFromClient As Boolean
+
+ Try
+ browser = New ServerBrowser()
+ connect = New WMConnect()
+ Logger.Info("Successfully created windream objects")
+ Catch ex As Exception
+ Logger.Error(ex, "Error while creating windream objects")
+ Return Nothing
+ End Try
+
+ ' If no server was supplied, try to get the current server set in the client
+ Try
+ If serverName Is Nothing OrElse serverName.Length = 0 Then
+ serverName = browser.GetCurrentServer
+ serverNameFromClient = True
+ Else
+ serverNameFromClient = False
+ End If
+ Catch ex As Exception
+ Logger.Error(ex, "Error while getting Servername")
+ Return Nothing
+ End Try
+
+ Logger.Info("Servername: {0}", serverName)
+ Logger.Info("Servername aquired from client: {0}", serverNameFromClient)
+
+ 'TODO: Test connection to windream server
+
+ ' If username, password and domain are set, login with impersonation
+ ' Else, login with current credentials
+ If userName IsNot Nothing And password IsNot Nothing And domain IsNot Nothing Then
+ impersonation = True
+ credentials = New WMUserIdentity() With {
+ .aServerName = serverName,
+ .aUserName = userName,
+ .aPassword = password,
+ .aDomain = domain
+ }
+
+ connect.ModuleId = 9
+
+ Logger.Info("Impersonated Login: True")
+ Logger.Info("Username: {0}", userName)
+ Logger.Info("Domain: {0}", domain)
+ Else
+ impersonation = False
+ credentials = New WMUserIdentity() With {
+ .aServerName = serverName
+ }
+
+ Logger.Info("Impersonated Login: False")
+ Logger.Info("Username: {0}", Environment.UserName)
+ Logger.Info("Domain: {0}", Environment.UserDomainName)
+ End If
+
+ Try
+ session = connect.Login(credentials)
+ Catch ex As Exception
+ Logger.Error(ex, "Error while logging in")
+ Return Nothing
+ End Try
+
+ Try
+ ' Standardmässig hinterlegen dass abgelegte Dateien keine Indexmaske öffnet
+ session.SwitchEvents(WMCOMEventWMSessionNeedIndex, False)
+ Catch ex As Exception
+ Logger.Error(ex, "Could not SwitchEvents")
+ Return Nothing
+ End Try
+
+ If session.aLoggedin = False Then
+ Logger.Warn("Session created but user {0} could not be logged in", Environment.UserName)
+ Return Nothing
+ End If
+
+ Return session
+ End Function
+
+
+ Private Function GetObjectTypes() As WMObjects
+ Dim objectTypes As WMObjects
+
+ Try
+ objectTypes = CurrentSession.GetWMObjectTypes(WMEntityDocument)
+ Return objectTypes
+ Catch ex As Exception
+ Logger.Error(ex)
+ Return Nothing
+ End Try
+ End Function
+
+ '''
+ ''' Returns all Objecttypes of current server as list of strings
+ '''
+ ''' List of String of all objecttypes
+ '''
+ Public Function GetObjecttypeNames() As List(Of String)
+ Dim objectTypes As New List(Of String)
+
+ Try
+ For i As Integer = 0 To CurrentObjecttypes.Count
+ objectTypes.Add(CurrentObjecttypes.Item(i).aName)
+ Next
+ Return objectTypes
+ Catch ex As Exception
+ Logger.Error(ex)
+ Return Nothing
+ End Try
+ End Function
+
+ Private Function NormalizePath(path As String)
+ Dim normalizedPath = path
+
+ If Not path.StartsWith("\") And path.ToUpper().StartsWith(DriveLetter.ToUpper) Then
+ normalizedPath = path.Substring(2)
+ End If
+
+ Return normalizedPath
+ End Function
+
+
+ '''
+ ''' Creates a windream session with the current user and the current server
+ '''
+ ''' Returns true when created, false if not
+ '''
+ 'Public Function NewSession() As Boolean
+ ' Try
+ ' ServerBrowser = New ServerBrowser()
+ ' CurrentServer = ServerBrowser.GetCurrentServer
+ ' Catch ex As Exception
+ ' Logger.Error(ex, "Could not create ServerBrowser")
+ ' Return False
+ ' End Try
+
+ ' Try
+ ' ' Create Connect Object for Session
+ ' CurrentConnect = New WMConnect
+ ' Catch ex As Exception
+ ' Logger.Error(ex, "Could not create WMConnect")
+ ' Return False
+ ' End Try
+
+ ' Try
+ ' ' Create session object with severname set
+ ' CurrentSession = CreateObject("Windream.WMSession", ServerBrowser.GetCurrentServer)
+ ' Catch ex As Exception
+ ' Logger.Error(ex, "Could not create WMConnect")
+ ' Return False
+ ' End Try
+
+ ' Try
+ ' CurrentConnect.LoginSession(CurrentSession)
+ ' LoggedInSession = True
+ ' Catch ex As Exception
+ ' Logger.Error(ex, "Could not login session")
+ ' Return False
+ ' End Try
+
+ ' Try
+ ' ' Standardmässig hinterlegen dass abgelegte Dateien keine Indexmaske öffnet
+ ' CurrentSession.SwitchEvents(WMCOMEventWMSessionNeedIndex, False)
+ ' Catch ex As Exception
+ ' Logger.Error(ex, "Could not SwitchEvents")
+ ' Return False
+ ' End Try
+
+ ' If TestLoggedInSession() = False Then
+ ' Logger.Warn("Session created but user {0} could not be logged in", Environment.UserName)
+ ' Return False
+ ' End If
+
+ ' Return True
+ 'End Function
+#End Region
+#Region "+++++ New +++++"
+ '''
+ ''' Creates a folder in windream. All folder-parts will be checked
+ '''
+ ''' full path of new folder
+ ''' Returns true when folder was created, false if not
+ '''
+ Public Function NewFolder(ByVal folderpath As String)
+ Try
+ If TestLoggedInSession() = False Then
+ Return False
+ End If
+ folderpath = NormalizePath(folderpath)
+ Dim folders() As String = folderpath.Split("\")
+ For Each folder As String In folders
+ Dim WMObject As WINDREAMLib.WMObject
+ If TestFolderExists(folder) = False Then
+ Try
+ WMObject = CurrentSession.GetNewWMObjectFS(WMEntityFolder, folder, WMObjectEditModeNoEdit)
+ Catch ex As Exception
+ Logger.Error(ex)
+ 'clsLogger.Add("Could not create WMObject for folderpath '" & folder & "': " & ex.Message, True)
+ Return False
+ End Try
+
+ End If
+ Next
+ Return True
+ Catch ex As Exception
+ Logger.Error(ex)
+ 'clsLogger.Add("Unexpected error in NewFolder: " & ex.Message, True)
+ Return False
+ End Try
+ End Function
+ '''
+ ''' Indexes the file with the given values
+ '''
+ ''' full filepath
+ ''' Name of the index
+ ''' values as array
+ ''' Returns true when folder was created, false if not
+ '''
+ Public Function NewIndexFile(WMFile As String, ByVal indexname As String, ByVal aValues() As String) As Boolean
+ If TestLoggedInSession() = False Then
+ Return False
+ End If
+ Dim oWMFile As WMObject = GetWMObjectForFile(WMFile)
+ If IsNothing(oWMFile) Then
+ Return False
+ End If
+ Dim vektInsState As Integer = 1
+ Try
+ If Not oWMFile.aLocked Then
+ oWMFile.lock()
+ Else
+ Logger.Info("WMDoc is locked already!")
+ Return False
+ End If
+
+
+ If aValues.Length = 1 And aValues(0) = "" Then
+ Logger.Info("Indexvalue is empty - No indexing")
+
+ Return False
+ End If
+ Logger.Info("Indexing of index '" & indexname)
+
+ Dim oWMType
+ Try
+ ' das entsprechende Attribut aus windream auslesen
+ Dim oAttribute = CurrentSession.GetWMObjectByName(WINDREAMLib.WMEntity.WMEntityAttribute, indexname)
+ ' den Variablentyp (String, Integer, ...) auslesen
+ oWMType = oAttribute.GetVariableValue("dwAttrType")
+ Catch ex As Exception
+ Logger.Error(ex)
+ Return False
+ End Try
+
+ ' wenn in aValues an Position i ein Wert steht
+ Dim i As Integer = 0
+ Dim value = aValues(i)
+
+ Dim oWMValueConverted = Nothing
+
+ Dim vektor As Boolean = False
+ 'Den Typ des Index-Feldes auslesen
+ Logger.Info("type of windreamIndex: " & oWMType.ToString)
+ Select Case (oWMType)
+
+ Case INDEX_TYPE_STRING
+ oWMValueConverted = CStr(value)
+ Case INDEX_TYPE_INTEGER
+ value = value.ToString.Replace(" ", "")
+ value = value.ToString.Replace(" ", "")
+ oWMValueConverted = CInt(value)
+ Case INDEX_TYPE_FLOAT
+ value = value.ToString.Replace(" ", "")
+ oWMValueConverted = CDbl(value)
+ Case INDEX_TYPE_FIXED_POINT
+ value = value.ToString.Replace(" ", "")
+ oWMValueConverted = CDbl(value)
+ Case INDEX_TYPE_BOOLEAN
+ oWMValueConverted = CBool(value)
+ Case INDEX_TYPE_DATE
+ 'Dim _date As Date = value
+ oWMValueConverted = value
+ Case INDEX_TYPE_TIME
+ oWMValueConverted = CDbl(value)
+ Case INDEX_TYPE_CURRENCY
+ 'Wegen currency muß ein eigenes Objekt vom typ Variant erzeugt werden
+ Dim aValueWrapper As System.Runtime.InteropServices.CurrencyWrapper = New System.Runtime.InteropServices.CurrencyWrapper(CDec(value))
+ oWMValueConverted = aValueWrapper
+ Case INDEX_TYPE_TIME
+ 'If ((value)) Then
+ ' oWMValueConverted = CDate(value)
+ 'Else
+ ' oWMValueConverted = ""
+ 'End If
+ 'Dim _date As Date = value
+ oWMValueConverted = oWMValueConverted '*_date.ToShortTimeString
+ Case INDEX_TYPE_FLOAT
+ oWMValueConverted = CStr(value)
+ Case INDEX_TYPE_VARIANT
+
+ oWMValueConverted = CStr(value)
+ Case INDEX_TYPE_FULLTEXT
+ oWMValueConverted = CStr(value)
+ Case 4097
+ 'Vektor alphanumerisch
+ vektor = True
+ Case 4098
+ 'Vektor Numerisch
+ vektor = True
+ Case 4099
+ 'Vektor Kommazahl
+ vektor = True
+ Case 4100
+ 'Vektor Kommazahl
+ vektor = True
+ Case 4101
+ 'Vektor Kommazahl
+ vektor = True
+ Case 4103
+ 'Vektor DateTime
+ vektor = True
+ Case 4107
+ vektor = True
+ Case 36865
+ 'Vektor Kommazahl
+ vektor = True
+ Case Else
+ oWMValueConverted = ""
+ End Select
+ If vektor = False Then
+ If oWMValueConverted.ToString Is Nothing = False Then
+ Logger.Info("Converted value is: " & oWMValueConverted.ToString)
+ End If
+ End If
+ '############################################################################################
+ '####################### Der eigentliche Indexierungsvorgang ################################
+ '############################################################################################
+ If vektor = False Then
+ Try
+ If oWMValueConverted.ToString Is Nothing = False Then
+ Logger.Info("Now: oWMFile.SetVariableValue(" & indexname & ", " & oWMValueConverted & ")")
+ oWMFile.SetVariableValue(indexname, oWMValueConverted)
+ 'Die Datei speichern
+ oWMFile.Save()
+ Logger.Info("Index has been written!")
+ Else
+ Logger.Info("No indexvalue exists!")
+ End If
+ Catch ex As Exception
+ Logger.Error(ex)
+ oWMFile.Save()
+ oWMFile.unlock()
+ Return False
+ End Try
+
+ Else
+ Logger.Info("Vectorfield: Preparing of Array!")
+ Dim myArray()
+ Dim Anzahl As Integer = aValues.Length
+ 'Vektorfeld wird mit EINEM Wert gefüllt
+ If Anzahl = 1 Then
+ Logger.Info("Vectorfield will be filled with ONE VALUE!")
+ ReDim myArray(0)
+ myArray(0) = Helpers.ConvertVectorType(oWMType, value)
+ 'Jetzt überprüfen ob Werte in Vektorfeld angefügt oder überschrieben werden sollen
+ Logger.Info("Converted Value: " & myArray(0).ToString)
+ Dim VektorArray()
+ VektorArray = Return_VektorArray(oWMFile, indexname, myArray, oWMType)
+ If VektorArray Is Nothing = False Then
+ ReDim myArray(VektorArray.Length - 1)
+ Array.Copy(VektorArray, myArray, VektorArray.Length)
+ 'Jetzt die Nachindexierung
+ oWMFile.SetVariableValue(indexname, myArray) '
+ Logger.Info("Vectorindex has been written!")
+ 'Die Änderungen festsschreiben/speichern
+ oWMFile.Save()
+ End If
+
+ End If
+
+ End If
+ i += 1
+
+ oWMFile.unlock()
+ Logger.Info("...and unlock")
+ Return True
+ Catch ex As Exception
+ Logger.Error(ex)
+ oWMFile.Save()
+ oWMFile.unlock()
+ Return False
+ End Try
+ End Function
+ Private Function NewLockWMFile(oWMFile As WMObject) As Boolean
+ Try
+ oWMFile.lock()
+ Return True
+ Catch ex As Exception
+ Logger.Error(ex)
+ Return False
+ End Try
+ End Function
+ '''
+ ''' Sets the folder-objecttype.
+ '''
+ ''' full path of folder
+ ''' Obcjectype Name
+ ''' Returns true when Otype was set, false if not
+ '''
+ Public Function NewObjecttypeForFolder(folderpath As String, folderObjecttype As String) As Boolean
+ Try
+ If TestLoggedInSession() = False Then
+ Return False
+ End If
+ Dim result As Boolean = False
+ Dim WMFolder As WINDREAMLib.WMObject
+ folderpath = NormalizePath(folderpath)
+
+ If TestFolderExists(folderpath) = True Then
+ WMFolder = CurrentSession.GetWMObjectByPath(WMEntityFolder, folderpath)
+ Try
+ ' die Datei sperren
+ WMFolder.lock()
+ Catch ex As Exception
+ ' nichts tun (Datei ist bereits gesperrt)
+ End Try
+
+ ' wenn der Datei noch kein Dokumenttyp zugewiesen wurde
+ If WMFolder.aObjectType.aName = "Standard" Then
+
+ ' ihr den entsprechenden Dokumenttyp zuweisen
+ WMFolder.aObjectType = CurrentSession.GetWMObjectByName(WINDREAMLib.WMEntity.WMEntityObjectType, folderObjecttype)
+ ' WMObject.aObjectType = Me.selectedProfile.Dokumenttyp
+ Logger.Info("Objecttype has been set")
+ result = True
+ Else
+ If WMFolder.aObjectType.aName <> "Standard" Then
+ Logger.Warn("An Objecttype has already been set!")
+ End If
+ End If
+
+ Try
+ WMFolder.Save()
+ Catch ex As Exception
+ ' wenn es einen Fehler beim speichern gab, dann konnte auch kein Dokumenttyp gesetzt werden -> es kann also auch keine
+ ' Indexierung stattfinden und die Indexierung muss nicht fortgesetzt werden
+ Return False
+ End Try
+
+ Try
+ WMFolder.unlock()
+ Catch ex As Exception
+ ' wenn das entsperren nicht geklappt hat, dann war die Datei auch nicht gesperrt
+ End Try
+ End If
+ Return result
+
+ Catch ex As Exception
+ Logger.Error(ex)
+ Return False
+ End Try
+ End Function
+ '''
+ ''' Creates a new version of the file
+ '''
+ ''' full path to the file
+ ''' Comment
+ ''' Returns true when version was created, false if not
+ '''
+ Public Function NewVersion(ByVal WMPath As String, ByVal Comment As String)
+ Try
+ If TestLoggedInSession() = False Then
+ Return False
+ End If
+ WMPath = NormalizePath(WMPath)
+
+ Dim WMObject As WMObject '= CreateObject("WINDREAMLib.WMObject") 'New WINDREAMLib.WMObject
+ Try
+ WMObject = CurrentSession.GetWMObjectByPath(WMEntityDocument, WMPath) 'WINDREAMLib.WMEntity.WMEntityDocument
+ Catch ex As Exception
+ Logger.Warn("Could not create WMObject in Create_Version for file '" & WMPath & "': " & ex.Message)
+ Return False
+ End Try
+ WMObject.CreateVersion2(False, "HISTORY_New_From_Version", Comment)
+ Return True
+ Catch ex As Exception
+ Logger.Error(ex)
+ Return False
+ End Try
+ End Function
+#End Region
+#Region "+++++ Get +++++"
+ '''
+ ''' Returns all choicelists
+ '''
+ ''' Choicelists as List of Strings or empty list if no choice lists are found
+ Public Function GetChoiceLists() As List(Of String)
+ Dim items As New List(Of String)
+
+ If TestLoggedInSession() = False Then
+ Return items
+ End If
+
+ Try
+ Dim choiceLists As WMObjects
+ Dim choiceList As IWMObject2
+ 'load list of choicelists
+ choiceLists = CurrentSession.GetAllObjects(WMEntityChoiceList)
+
+ For Each choiceList In choiceLists
+ items.Add(choiceList.aName)
+ Next
+
+ Return items
+ Catch ex As Exception
+ Logger.Error(ex)
+ Return items
+ End Try
+ End Function
+
+ '''
+ ''' Returns all indices for an objecttype
+ '''
+ ''' Name of objecttype
+ ''' Names of indices as list of String
+ '''
+ Public Function GetIndicesByObjecttype(ByVal ObjecttypeName As String) As List(Of String)
+ Try
+ If TestLoggedInSession() = False Then
+ Return Nothing
+ End If
+
+ Dim oObjectType As WMObject
+ Dim oIndexAttributes As WMObjectRelation
+ Dim oIndexAttribute As WMObject
+ Dim oIndex As WMObject
+ Dim oRelProperties As WMObjectRelation
+ ' den Objekttyp laden
+ oObjectType = CurrentSession.GetWMObjectByName(WMEntityObjectType, ObjecttypeName)
+
+ ' Beziehung zu Indizes des Objekttyp auslesen
+ oIndexAttributes = oObjectType.GetWMObjectRelationByName("TypeAttributes")
+
+ ' Array für Indizes vorbereiten
+ 'Dim aIndexNames(oIndexAttributes.Count - 1) As String
+ Dim indexNames As New List(Of String)
+ ' alle Indizes durchlaufen
+ For j As Integer = 0 To oIndexAttributes.Count - 1
+ ' aktuellen Index auslesen
+ oIndexAttribute = oIndexAttributes.Item(j)
+
+ ' Eigenschaften des Index auslesen
+ oRelProperties = oIndexAttribute.GetWMObjectRelationByName("Attribute")
+
+ ' Index aus den Eigenschaften auslesen
+ oIndex = oRelProperties.Item(0)
+
+ ' Indexname speichern
+ 'aIndexNames(j) = oIndex.aName
+ indexNames.Add(oIndex.aName)
+ Next
+
+ ' Indexarray zurückgeben
+ 'Return aIndexNames
+ Return indexNames
+
+ Catch ex As Exception
+ Logger.Error(ex)
+ Return Nothing
+ End Try
+ End Function
+
+ '''
+ ''' Returns all items of a choicelist
+ '''
+ ''' name of choicelist
+ ''' Items as list of String
+ '''
+ Public Function GetChoicelistItems(ByVal NameChoicelist As String) As List(Of String)
+ Dim items As New List(Of String)
+
+ If TestLoggedInSession() = False Then
+ Return Nothing
+ End If
+
+ Dim choiceList As WMObject
+
+ ' Try to get the choicelist first and abort if an error occurs
+ Try
+ Dim session As IWMSession2 = DirectCast(CurrentSession, IWMSession2)
+ choiceList = session.GetWMObjectByName(WMEntityChoiceList, NameChoicelist)
+ Catch ex As Exception
+ Logger.Error(ex)
+ Return Nothing
+ End Try
+
+ ' Try to get choicelist items
+ Try
+ Dim values As Object = choiceList.GetVariableValue("vItems")
+
+ ' If values is nothing, the list is empty
+ If values Is Nothing Then
+ Return items
+ End If
+
+ For Each value In values
+ items.Add(value)
+ Next
+ Catch ex As Exception
+ Logger.Error(ex)
+ Return Nothing
+ End Try
+
+ Return items
+ End Function
+
+ '''
+ ''' Returns the result of windream-search
+ '''
+ ''' filepath of windreamSearch-file
+ ''' Name of the Docid Index
+ ''' Returns datatable
+ '''
+ Public Function GetSearchDocuments(ByVal wdfLocation As String, NameIndexDocID As String) As DataTable
+ Dim dtresult As New DataTable
+ dtresult.Columns.Add("DOC_ID", GetType(Integer))
+ dtresult.Columns.Add("PATH", GetType(String))
+ If TestLoggedInSession() = False Then
+ Return dtresult
+ End If
+ If TestWMFileExists(wdfLocation) = False Then
+ Return dtresult
+ End If
+ Try
+ Dim ProfileName = wdfLocation.Substring(wdfLocation.LastIndexOf("\") + 1)
+ Dim ProfilePath = wdfLocation.Substring(0, wdfLocation.Length - ProfileName.Length)
+
+ CurrentController = New WMOSearchController
+ CurrentController.CheckSearchProfile(wdfLocation.ToLower)
+ Dim suchTyp = CurrentController.SearchProfileTargetProgID
+ Dim ExSettings As Object
+ Dim oSearch As Object
+ ExSettings = CurrentController.SearchProfileExSettings
+ If ExSettings = 0 Then ExSettings = 7
+
+ Dim srchQuick As WMOSRCHLib.WMQuickSearch = CreateObject("WMOSrch.WMQuickSearch")
+ Dim srchIndex As WMOSRCHLib.WMIndexSearch = CreateObject("WMOSrch.WMIndexSearch")
+ Dim srchObjectType As WMOSRCHLib.WMObjectTypeSearch = CreateObject("WMOSrch.WMObjectTypeSearch")
+ Dim suchTyp1 = suchTyp.ToString.ToUpper
+ '' Der öffentliche Member CheckSearchProfile für den Typ IWMQuickSearch7 wurde nicht gefunden. [Microsoft.VisualBasic] => GetSearchDocuments()
+ Select Case suchTyp.ToString.ToUpper
+ Case "WMOSRCH.WMQUICKSEARCH"
+ srchQuick.WMSession = CreateObject("Windream.WMSession", CurrentServer)
+
+ CurrentConnect.LoginSession(srchQuick.WMSession)
+
+ srchQuick.ClearSearch()
+ srchQuick.SearchProfilePath = ProfilePath
+ srchQuick.LoadSearchProfile(ProfileName)
+
+ oSearch = srchQuick.GetSearch()
+
+ Case "WMOSRCH.WMINDEXSEARCH"
+ srchIndex.WMSession = CreateObject("Windream.WMSession", CurrentServer)
+
+ CurrentConnect.LoginSession(srchIndex.WMSession)
+
+ srchIndex.ClearSearch()
+ srchIndex.SearchProfilePath = ProfilePath
+ srchIndex.LoadSearchProfile(ProfileName)
+
+ oSearch = srchIndex.GetSearch()
+
+ Case "WMOSRCH.WMOBJECTTYPESEARCH"
+ srchObjectType.WMSession = CreateObject("Windream.WMSession", CurrentServer)
+
+ CurrentConnect.LoginSession(srchObjectType.WMSession)
+
+ srchObjectType.ClearSearch()
+ srchObjectType.SearchProfilePath = ProfilePath
+ srchObjectType.LoadSearchProfile(ProfileName)
+
+ oSearch = srchObjectType.GetSearch()
+
+ Case Else
+ Logger.Warn("No valid WM-SearchType")
+ Return dtresult
+ End Select
+ Dim WMObjects As Object
+ WMObjects = oSearch.Execute
+ 'If returnDT = True Then
+ If WMObjects.Count > 0 Then
+
+ For Each dok As WMObject In WMObjects
+ Dim path As String = dok.aPath
+ Dim DOC_ID = dok.GetVariableValue(NameIndexDocID)
+ Logger.Info("Adding DocInfo for DocID: " & DOC_ID.ToString)
+ dtresult.Rows.Add(DOC_ID, path)
+
+ Next
+ dtresult.AcceptChanges()
+ End If
+ Return dtresult
+ Catch ex As Exception
+ Logger.Error(ex)
+ Return dtresult
+ End Try
+ End Function
+ '''
+ ''' Returns a windream-type as Integer.
+ '''
+ ''' Name of indexfield
+ ''' Returns integer, which describes the type
+ '''
+ Public Function GetTypeOfIndexAsInt(ByVal indexname As String) As Integer
+ Try
+ If TestLoggedInSession() = False Then
+ Return False
+ End If
+ Dim oAttribute = CurrentSession.GetWMObjectByName(WMEntityAttribute, indexname)
+ Dim vType = oAttribute.GetVariableValue("dwAttrType")
+ Return vType
+ Catch ex As Exception
+ Return Nothing
+ End Try
+ End Function
+ '''
+ ''' Returns the value(s) for an index as a datatable
+ '''
+ ''' filepath of windream-file
+ ''' Name of the index
+ ''' Datatable
+ '''
+ Public Function GetValueforIndex(ByVal WMFile As String, ByVal NameIndex As String) As DataTable
+ Dim dt As New DataTable
+ dt.Columns.Add("RESULT", GetType(String))
+ If TestLoggedInSession() = False Then
+ Return dt
+ End If
+ Try
+
+ If Not WMFile.StartsWith("\") And WMFile.ToUpper.StartsWith(DriveLetter.ToUpper) Then
+ WMFile = WMFile.Substring(2)
+ End If
+ Dim WMObject As WINDREAMLib.WMObject '= CreateObject("WINDREAMLib.WMObject") 'New WINDREAMLib.WMObject
+ Try
+ WMObject = CurrentSession.GetWMObjectByPath(WINDREAMLib.WMEntity.WMEntityDocument, WMFile) 'WINDREAMLib.WMEntity.WMEntityDocument
+ Catch ex As Exception
+ Logger.Error(ex)
+ Return dt
+ End Try
+
+ Dim result = WMObject.GetVariableValue(NameIndex)
+ If IsNothing(result) Then
+ Return Nothing
+ Else
+ If result.GetType.ToString.Contains("System.Object") Then
+ For Each val As String In result
+ dt.Rows.Add(val)
+ Next
+ dt.AcceptChanges()
+ Else
+ dt.Rows.Add(result)
+ End If
+ End If
+ Return dt
+ Catch ex As Exception
+ Logger.Error(ex)
+ Return dt
+ End Try
+ End Function
+ '''
+ ''' Returns the values for a vektorfield plus the new ones
+ '''
+ ''' windream-file as Object
+ ''' Name of the index
+ ''' Returns value as Datatable
+ '''
+ Public Function Return_VektorArray(ByVal oDocument As WMObject, vktIndexName As String, arrIndexwerte As Object, vType As Object)
+ Try
+ If TestLoggedInSession() = False Then
+ Return False
+ End If
+ Dim missing As Boolean = False
+ Dim valueCount As Integer = 0
+ Dim ValueArray() = Nothing
+ 'Jeden Wert des Vektorfeldes durchlaufen
+ Dim DT_RESULT = GetValueforIndex(oDocument.aPath, vktIndexName)
+ If DT_RESULT.Rows.Count > 0 Then
+ 'Erst die aktuellen Werte speichern und schreiben
+ For Each row As DataRow In DT_RESULT.Rows
+
+ ReDim Preserve ValueArray(valueCount)
+ 'Den Wert im Array speichern
+ ValueArray(valueCount) = Helpers.ConvertVectorType(vType, row.Item(0))
+ valueCount += 1
+ Next
+ 'Jetzt die Neuen Werte auf Duplikate überprüfen
+ For Each NewValue As Object In arrIndexwerte
+ If NewValue Is Nothing = False Then
+ If ValueArray.Contains(NewValue) = False Then
+ 'Das Array anpassen
+ ReDim Preserve ValueArray(valueCount)
+ 'Den Wert im Array speichern
+ ValueArray(valueCount) = Helpers.ConvertVectorType(vType, NewValue)
+ valueCount += 1
+ Else
+ Logger.Info("Value '" & NewValue.ToString & "' already existing in vectorfield(1)")
+
+ End If
+ End If
+ Next
+ Else
+ Logger.Info(" vectorfield is empty....")
+
+ 'Den/die Neuen Wert(e) anfügen
+ For Each NewValue As Object In arrIndexwerte
+ If NewValue Is Nothing = False Then
+ If ValueArray Is Nothing = False Then
+ If ValueArray.Contains(NewValue) = False Then
+ 'Das Array anpassen
+ ReDim Preserve ValueArray(valueCount)
+ 'Den Wert im Array speichern
+ ValueArray(valueCount) = Helpers.ConvertVectorType(vType, NewValue)
+ valueCount += 1
+ Else
+ Logger.Info("Value '" & NewValue.ToString & "' already existing in vectorfield(2)")
+
+ End If
+ Else 'Dererste Wert, also hinzufügen
+ 'Das Array anpassen
+ ReDim Preserve ValueArray(valueCount)
+ 'Den Wert im Array speichern
+ ValueArray(valueCount) = Helpers.ConvertVectorType(vType, NewValue)
+ valueCount += 1
+
+ End If
+
+
+ End If
+ Next
+ End If
+
+ Return ValueArray
+ Catch ex As Exception
+ Logger.Error(ex)
+ End Try
+ End Function
+ '''
+ ''' Returns a WMObject if file exists
+ '''
+ ''' full path to the file
+ ''' Returns WMObject
+ '''
+ Public Function GetWMObjectForFile(ByVal WMPath As String) As WMObject
+ Try
+ If TestLoggedInSession() = False Then
+ Return Nothing
+ End If
+ WMPath = NormalizePath(WMPath)
+ Dim oWMObject As WINDREAMLib.WMObject
+ Try
+ oWMObject = CurrentSession.GetWMObjectByPath(WINDREAMLib.WMEntity.WMEntityDocument, WMPath)
+ Catch ex As Exception
+ Logger.Warn("Could not create WMObject for file '" & WMPath & "': " & ex.Message)
+ Return Nothing
+ End Try
+ Return oWMObject
+ Catch ex As Exception
+ Logger.Error(ex)
+ Return Nothing
+ End Try
+ End Function
+#End Region
+#Region "+++++ Test +++++"
+ '''
+ ''' Checks if the folder exists
+ '''
+ ''' The path of the folder
+ ''' True if exists or false if not or error occured
+ '''
+ Public Function TestFolderExists(folderpath As String)
+ Try
+ If TestLoggedInSession() = False Then
+ Return False
+ End If
+ folderpath = NormalizePath(folderpath)
+ Try
+ Dim exists = CurrentSession.WMObjectExists(WMEntityFolder, folderpath, 0, 0)
+ Return exists
+ Catch ex As Exception
+ Logger.Error(ex)
+ Return False
+ End Try
+ Catch ex As Exception
+ Return False
+ End Try
+ End Function
+ '''
+ ''' Checks wether file exists in windream
+ '''
+ ''' full path to the file
+ ''' Returns true when file was deleted, false if not
+ '''
+ Public Function TestWMFileExists(ByVal WMPath As String)
+ Try
+ If TestLoggedInSession() = False Then
+ Return False
+ End If
+ WMPath = NormalizePath(WMPath)
+ If IsNothing(GetWMObjectForFile(WMPath)) Then
+ Return False
+ Else
+ Return True
+ End If
+ Catch ex As Exception
+ Logger.Error(ex)
+ Return False
+ End Try
+ End Function
+
+
+ Private Function TestLoggedInSession() As Boolean
+ Try
+ If CurrentSession.aLoggedin Then
+ Return True
+ Else
+ Logger.Warn("There is no active WM-SSession!")
+ Return False
+ End If
+ Catch ex As Exception
+ Return False
+ End Try
+ End Function
+ '''
+ ''' Checks if user exists in windream.
+ '''
+ ''' test username
+ ''' Returns true if exists, false if not
+ '''
+ Public Function TestWMUSerExists(username As String) As Boolean
+ Try
+ If TestLoggedInSession() = False Then
+ Return False
+ End If
+ Return CurrentSession.WMObjectExists(WMEntityUser, username, 0, 0)
+ Catch ex As Exception
+ Logger.Error(ex)
+ Return False
+ End Try
+ End Function
+ '''
+ ''' Checks if group exists in windream.
+ '''
+ ''' test username
+ ''' Returns true if exists, false if not
+ '''
+ Public Function TestWMGroupExists(groupname As String)
+ Try
+ If TestLoggedInSession() = False Then
+ Return False
+ End If
+ Return CurrentSession.WMObjectExists(WMEntityGroups, groupname, 0, 0)
+ Catch ex As Exception
+ Logger.Error(ex)
+ Return False
+ End Try
+ End Function
+#End Region
+#Region "+++++ Remove +++++"
+ '''
+ ''' Deletes a file in windream including all preversions
+ '''
+ ''' full path to the file
+ ''' Returns true when file was deleted, false if not
+ '''
+ Public Function RemFile(ByVal WMPath As String)
+ Try
+ Const COL_Document_VersionID = "dwVersionID"
+ Const WMObjectPartVersion = 128
+ Dim oUnexpected_Error As Boolean = False
+ WMPath = NormalizePath(WMPath)
+ Dim oWMObject = GetWMObjectForFile(WMPath)
+ If IsNothing(oWMObject) = False Then
+ Try
+ If (oWMObject.aPart And WMObjectPartVersion) Then
+ Dim oWMObjects As WMObjects
+ Dim oWMVersion As WMObject
+ Dim iCount As Integer
+ oWMObjects = oWMObject.aVersions
+ iCount = oWMObjects.Count
+ If iCount > 0 Then
+ For Each oWMVersion In oWMObjects
+ oWMVersion.Delete()
+ Logger.Info($">> Deleted version '{oWMVersion.GetVariableValue(COL_Document_VersionID)}' of file '{oWMVersion.aName}'!")
+ Next
+ End If
+ End If
+ Catch ex As Exception
+ Logger.Warn($"Unexpected Error in CheckingDeleting Prevesions: {ex.Message}")
+ oUnexpected_Error = True
+ End Try
+ If oUnexpected_Error = False Then
+ oWMObject.Delete()
+ Logger.Info($">> File '{oWMObject.aName}' has been deleted!")
+ Return True
+ Else
+ Return False
+ End If
+ Else
+ Return False
+ End If
+ Catch ex As Exception
+ Logger.Error(ex)
+ Return False
+ End Try
+ End Function
+ '''
+ ''' Removes the vektorlink from windream
+ '''
+ ''' full path to the file
+ ''' Indexname of Vektor-Index
+ ''' Value which is to be deleted
+ ''' Returns true when indexing was successfull, false if not
+ '''
+ Public Function REMOVE_VEKTOR_LINK(ByVal WMPath As String, vktIndexName As String, deleteValue As String)
+ Try
+ Logger.Info("Removing Value '" & deleteValue & "' of Index '" & vktIndexName & "' " & WMPath)
+ Dim oWMFile As WMObject = GetWMObjectForFile(WMPath)
+ If IsNothing(oWMFile) Then
+ Logger.Warn("Exit from REMOVE_VEKTOR_LINK...")
+ Return False
+ End If
+ Dim containsvalue As Boolean = False
+ Dim ValueArray() = Nothing
+ 'Jeden Wert des Vektorfeldes durchlaufen
+ Dim WMValue = oWMFile.GetVariableValue(vktIndexName)
+ If WMValue Is Nothing = False Then
+ 'Nochmals prüfen ob wirklich Array
+ If WMValue.GetType.ToString.Contains("System.Object") Then
+ ' das entsprechende Attribut aus windream auslesen
+ Dim oAttribute = CurrentSession.GetWMObjectByName(WMEntityAttribute, vktIndexName)
+ ' den Variablentyp (String, Integer, ...) auslesen
+ Dim vType = oAttribute.getVariableValue("dwAttrType")
+ Dim Anzahl As Integer = 0
+ For Each WDValue As Object In WMValue
+ If WDValue Is Nothing = False Then
+ If WDValue = deleteValue Then
+ containsvalue = True
+ Logger.Info("The Index contains the value to be deleted!")
+ End If
+ If WDValue <> deleteValue Then
+ 'Erst die ALten Werte schreiben
+ ReDim Preserve ValueArray(Anzahl)
+ 'Den Wert im Array speichern
+ ValueArray(Anzahl) = Helpers.ConvertVectorType(vType, WDValue)
+ Anzahl += 1
+ End If
+ End If
+ Next
+ Else
+ Logger.Warn("Index is not a vector")
+ Return False
+ End If
+ Else
+ Logger.Warn("oWMObject is nothing")
+ Return True
+ End If
+
+ If containsvalue = True Then 'And Not IsNothing(ValueArray)
+ If NewLockWMFile(oWMFile) = False Then
+ Return False
+ End If
+ 'Indexiern des Vektorfeldes
+ oWMFile.SetVariableValue(vktIndexName, ValueArray)
+ ' die Indexinformationen des Dokuments speichern
+ oWMFile.Save()
+ Logger.Info("The new vectorvalues were saved!")
+ ' Unlock in einem unbehandelten Try-Block um Fehler abzufangen,
+ Try
+ ' die Sperrung des Dokuments aufheben
+ oWMFile.unlock()
+
+ Catch ex As Exception
+ ' nichts tun (Datei war nicht gesperrt)
+ End Try
+ 'Zurückgeben
+ Return True
+ Else
+ Logger.Info("containsvalue is not true")
+ Return True
+ End If
+
+ Catch ex As Exception
+ Logger.Error(ex)
+ Return False
+ End Try
+ End Function
+#End Region
+End Class