jj: WIP: Rework Windream Module

This commit is contained in:
Jonathan Jenne 2018-08-24 17:03:13 +02:00
parent 2f71d46638
commit 8b9de4d0f8
7 changed files with 783 additions and 51 deletions

View File

@ -0,0 +1,48 @@
Public Class ConnectionBuilder
Implements IConnectionBuilder
Private LogFactory As NLog.LogFactory
Private SessionReconnect As Boolean = False
Private DriveLetter As String = "W"
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
Public Sub New(LogFactory As NLog.LogFactory)
Me.LogFactory = LogFactory
End Sub
Public Function WithSessionReconnect() As IConnectionBuilder Implements IConnectionBuilder.WithSessionReconnect
SessionReconnect = True
Return Me
End Function
Public Function WithDriveLetter(driveLetter As String) As IConnectionBuilder Implements IConnectionBuilder.WithDriveLetter
Me.DriveLetter = driveLetter
Return Me
End Function
Public Function With64BitSupport() As IConnectionBuilder Implements IConnectionBuilder.With64BitSupport
Support64Bit = True
Return Me
End Function
Public Function WithServerName(serverName As String) As IConnectionBuilder Implements IConnectionBuilder.WithServerName
Me.ServerName = serverName
Return Me
End Function
Public Function WithImpersonation(userName As String, password As String, domain As String) As IConnectionBuilder Implements IConnectionBuilder.WithImpersonation
Me.UserName = userName
Me.Password = password
Me.Domain = domain
Return Me
End Function
Public Function Connect() As Windream2 Implements IConnectionBuilder.Connect
Return New Windream2(LogFactory, SessionReconnect, DriveLetter, Support64Bit, ServerName, UserName, Password, Domain)
End Function
End Class

View File

@ -36,4 +36,8 @@
'Single Index Types
Public Const WMObjectVariableValueTypeUndefined = 0
'History Tags
Public Const HISTORY_NEW_FROM_VERSION = "HISTORY_New_From_Version"
Public Const HISTORY_USER_DEFINED = "HISTORY_User_Defined"
End Class

View File

@ -0,0 +1,18 @@
Imports System.Runtime.InteropServices
Public Class Exceptions
Public Class SessionException
Inherits Exception
Public Sub New()
End Sub
Public Sub New(message As String)
MyBase.New(message)
End Sub
Public Sub New(message As String, innerException As Exception)
MyBase.New(message, innerException)
End Sub
End Class
End Class

View File

@ -0,0 +1,8 @@
Public Interface IConnectionBuilder
Function WithSessionReconnect() As IConnectionBuilder
Function WithDriveLetter(driveLetter 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
End Interface

View File

@ -7,6 +7,7 @@ Imports WINDREAMLib.WMSearchRelation
Imports WMOBRWSLib
Imports WMOSRCHLib
Imports WMCNNCTDLLLib
Imports WMOTOOLLib
Public Class Windream
Inherits Constants
#Region "+++++ Variables +++++"
@ -20,25 +21,38 @@ Public Class Windream
Private CurrentServer As String
Private CurrentObjecttypes As WMObjects
Private ReconnectSession As Boolean
Private DriveLetter As String
Public LoggedInSession As Boolean = False
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 +++++"
''' <summary>
''' Initializes windream and creates a windream session with the actual user
''' </summary>
''' <remarks></remarks>
Public Sub New(Optional DriveLetter As String = "W", Optional ReconnectSession As Boolean = False)
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
If Not NewSession() Then
Logger.Warn("Session could not be created")
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
@ -46,6 +60,137 @@ Public Class Windream
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
@ -88,59 +233,60 @@ Public Class Windream
Return normalizedPath
End Function
''' <summary>
''' Creates a windream session with the actual user
''' Creates a windream session with the current user and the current server
''' </summary>
''' <returns>Returns true when created, false if not</returns>
''' <remarks></remarks>
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
'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 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
' ' 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
' 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
' 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
' 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
' Return True
'End Function
#End Region
#Region "+++++ New +++++"
''' <summary>
@ -688,7 +834,7 @@ Public Class Windream
If TestLoggedInSession() = False Then
Return False
End If
Dim oAttribute = CurrentSession.GetWMObjectByName(WINDREAMLib.WMEntity.WMEntityAttribute, indexname)
Dim oAttribute = CurrentSession.GetWMObjectByName(WMEntityAttribute, indexname)
Dim vType = oAttribute.GetVariableValue("dwAttrType")
Return vType
Catch ex As Exception

View File

@ -93,8 +93,11 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ClassHelper.vb" />
<Compile Include="ConnectionBuilder.vb" />
<Compile Include="Constants.vb" />
<Compile Include="Exceptions.vb" />
<Compile Include="Helpers.vb" />
<Compile Include="IConnectionBuilder.vb" />
<Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Application.Designer.vb">
<AutoGen>True</AutoGen>
@ -111,6 +114,7 @@
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="Windream.vb" />
<Compile Include="Windream2.vb" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="My Project\Resources.resx">

View File

@ -0,0 +1,504 @@
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
Imports NLog
''' <summary>
''' MODULE: Windream
'''
''' VERSION: 0.0.0.1
'''
''' DATE: 24.08.2018
'''
''' DESCRIPTION:
'''
''' DEPENDENCIES: NLog, >= 4.5.8
'''
''' PARAMETERS:
'''
''' PROPERTIES:
'''
''' EXAMPLES:
'''
''' REMARKS:
''' </summary>
Public Class Windream2
#Region "Private Properties"
Private _logger As Logger
Private _loggerFactory As LogFactory
Private ReadOnly _sessionDomain As String
Private ReadOnly _sessionPassword As String
Private ReadOnly _sessionUsername As String
#End Region
#Region "Public Properties"
Public ReadOnly Property ClientDriveLetter As String
Public ReadOnly Property ClientSupport64Bit As Boolean
Public ReadOnly Property Session As WMSession
Public ReadOnly Property SessionLoggedin As Boolean
Public ReadOnly Property SessionReconnect As Boolean
Public ReadOnly Property SessionServername As String
''' <returns>A list of object types that are available</returns>
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
''' <summary>
''' Creates a new Windream object and connects to a server with the provided options and credentials
''' </summary>
''' <param name="LogFactory"></param>
''' <param name="SessionReconnect"></param>
''' <param name="ClientDriveLetter"></param>
''' <param name="ClientSupport64Bit"></param>
''' <param name="SessionServerName"></param>
''' <param name="SessionUserName"></param>
''' <param name="SessionPassword"></param>
''' <param name="SessionDomain"></param>
''' <exception cref="Exceptions.SessionException"></exception>
Public Sub New(LogFactory As LogFactory, SessionReconnect As Boolean, ClientDriveLetter As String, ClientSupport64Bit As Boolean, SessionServerName As String, SessionUserName As String, SessionPassword As String, SessionDomain As String)
_logger = LogFactory.GetCurrentClassLogger()
_loggerFactory = LogFactory
Dim oSession As WMSession = NewSession(SessionServerName, SessionUserName, SessionPassword, SessionDomain)
If oSession Is Nothing Then
Throw New Exceptions.SessionException()
End If
SessionLoggedin = True
Me.SessionReconnect = SessionReconnect
Me.ClientDriveLetter = ClientDriveLetter
Me.ClientSupport64Bit = ClientSupport64Bit
Me.SessionServername = SessionServerName
_sessionUsername = SessionUserName
_sessionPassword = SessionPassword
_sessionDomain = SessionDomain
End Sub
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 oBrowser As ServerBrowser
Dim oConnect As WMConnect
Dim oSession As WMSession
Dim oCredentials As WMUserIdentity
Dim oImpersonation As Boolean
Dim oServerNameFromClient As Boolean
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)
'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
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)
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
Return oSession
End Function
#Region "Public Methods"
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 oTempSession As IWMSession2 = DirectCast(Session, IWMSession2)
Dim oFolderObject As WMObject
For Each oFolder In oFolders
If TestFolderExists(Path) = False Then
oFolderObject = oTempSession.GetNewWMObjectFS(WMEntityFolder, oFolder, WMObjectEditModeNoEdit)
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 = Session.GetWMObjectByPath(WMEntityDocument, Path)
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 LockFile(FileObject As WMObject) As Boolean
Try
FileObject.lock()
Return True
Catch ex As Exception
_logger.Error(ex)
Return False
End Try
End Function
Public Function UnlockFile(FileObject As WMObject) As Boolean
Try
FileObject.unlock()
Return True
Catch ex As Exception
_logger.Error(ex)
Return False
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 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
Dim oTempSession As IWMSession2 = DirectCast(Session, IWMSession2)
oChoicelist = oTempSession.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 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 GetIndexType(IndexName As String) As Integer
If TestSessionLoggedIn() = False Then
Return Nothing
End If
Try
Dim oTempSession As IWMSession2 = DirectCast(Session, IWMSession2)
Dim oAttribute = oTempSession.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 RemoveFile(Path As String) As Boolean
If TestSessionLoggedIn() = False Then
Return Nothing
End If
Try
Dim oTempSession As IWMSession2 = DirectCast(Session, IWMSession2)
Dim oWMObject As WMObject = oTempSession.GetWMObjectByName(WMEntityAttribute, Path)
If oWMObject Is Nothing Then
Return False
End If
oWMObject.Delete()
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 oTempSession As IWMSession2 = DirectCast(Session, IWMSession2)
' Dim oWMObject As WMObject = oTempSession.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 oVectorValues Is Nothing Then
' _logger.Warn("Could not values of index {0}", IndexName)
' Return False
' End If
' Dim oValueFound As Boolean = False
' For Each oVectorValue In oVectorValues
' If oVectorValue = ValueToDelete Then
' oValueFound = True
' End If
' Next
' Dim oNewValues As New List(Of Object)
' If oValueFound Then
' oNewValues = oVectorValues
' oNewValues = oNewValues.Except(New List(Of Object) From {ValueToDelete}).ToList()
' End If
' Catch ex As Exception
' _logger.Error(ex)
' Return Nothing
' 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 TestSessionLoggedIn() As Boolean
Try
If Session.aLoggedin Then
Return True
Else
_logger.Warn("There is no active WM-Session!")
Return False
End If
Catch ex As Exception
_logger.Error(ex)
Return False
End Try
End Function
Public Function TestObjectExists(ObjectName As String, ObjectType As WMEntity) As Boolean
If TestSessionLoggedIn() = False Then
Return False
End If
Try
Dim oTempSession = DirectCast(Session, IWMSession2)
Dim oObjectId = 0
Dim oObjectDbId = 0
Return oTempSession.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