This commit is contained in:
Digital Data - Marlon Schreiber
2018-08-27 14:17:03 +02:00
8 changed files with 858 additions and 72 deletions

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>
@@ -685,7 +831,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