Monorepo/GUIs.Test.TestGUI/frmFilesystem.vb
2025-11-28 09:23:48 +01:00

193 lines
8.3 KiB
VB.net

Imports System.Collections.Generic
Imports System.IO
Imports System.Numerics ' Verweis auf System.Numerics assembly hinzufügen!
Imports System.Security.Cryptography
Imports DigitalData.GUIs.Common
Imports DigitalData.Modules.Base.IDB.Constants
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.EDMI.API
Imports DigitalData.Modules.EDMI.API.EDMIServiceReference
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.ZooFlow.State
Public Class frmFilesystem
Private Client As Client
Private Logger As Logger
Private Const STATUS_CONNECTED = "Connection Established"
Private Const STATUS_CONNECTING = "Trying to create connection..."
Private Const STATUS_FAILED = "Connection Failed!"
Private ConnectionChanged As Boolean = False
Public Property ServiceAddress As String = ""
Public Property ServiceOnline As Boolean = False
Private LogConfig As LogConfig
Private MYDD_Filesystem As DigitalData.Modules.Filesystem.File
Private ShortName As String = "E:\some_test_file.txt"
Private LongName As String = "E:\some_test_file_with_some_more_data_and_with_some_more_data_and_with_some_more_data_and_with_some_more_data_and_with_some_more_data_and_with_some_more_data_and_with_some_more_data_and_with_some_more_data_and_with_some_more_data_and_with_some_more.txt"
Private Sub frmFilesystem_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
LogConfig = New LogConfig(LogConfig.PathType.Temp)
Logger = LogConfig.GetLogger()
MYDD_Filesystem = New DigitalData.Modules.Filesystem.File(LogConfig)
'Using oWriter = IO.File.CreateText("E:\some_test_file.txt")
' oWriter.WriteLine("bla bla bla")
'End Using
'IO.File.Copy(ShortName, LongName)
'Dim oVersion1 = Filesystem.GetVersionedFilename(LongName)
'IO.File.Copy(ShortName, oVersion1)
'Dim oVersion2 = Filesystem.GetVersionedFilename(LongName)
'IO.File.Copy(ShortName, oVersion2)
Catch ex As Exception
Finally
'IO.File.Delete(ShortName)
'IO.File.Delete(LongName)
End Try
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim oDateString = MYDD_Filesystem.CreateDateDirectory("E:\")
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
If SaveFileDialog1.ShowDialog = DialogResult.OK Then
' Fallback: einfache Textdatei schreiben
System.IO.File.WriteAllText(SaveFileDialog1.FileName, "Some text data")
End If
End Sub
Private Async Function Button2_ClickAsync(sender As Object, e As EventArgs) As Task Handles Button2.Click
' Import a file via EDMI Globix ImportFile API to test Service.EDMIService ImportFileMethod
Try
If Client Is Nothing OrElse ServiceOnline = False Then
MsgBox("Bitte zuerst Verbindung zum EDMI Service herstellen.", MsgBoxStyle.Exclamation, Text)
Return
End If
Using ofd As New OpenFileDialog()
ofd.Title = "Datei für Import wählen"
ofd.Filter = "Alle Dateien (*.*)|*.*"
If ofd.ShowDialog() <> DialogResult.OK Then
Return
End If
Dim oFilePath = ofd.FileName
Dim fi As New FileInfo(oFilePath)
Dim fileBytes As Byte() = IO.File.ReadAllBytes(oFilePath)
' Basic user context for testing
Dim user As New DigitalData.Modules.ZooFlow.State.UserState() With {
.UserName = Environment.UserName,
.Language = "de-DE",
.LanguageId = 1031
}
Dim oObjectStore As String = "SelectedDocType.ObjectStore"
Dim oIDBDoctypeId As Long = 1
Dim oObjectKind As String = "DOC"
Dim oProfileId As Integer = 1
Dim oAttributes As List(Of UserAttributeValue) = Nothing
Dim oOptions As New Options.ImportFileOptions
Logger.Debug("FilePath: [{0}]", oFilePath)
Logger.Debug("ObjectStore: [{0}]", oObjectStore)
Logger.Debug("ObjectKind: [{0}]", oObjectKind)
Logger.Debug("ProfileId: [{0}]", oProfileId)
Logger.Debug("IDB DoctypeId: [{0}]", oIDBDoctypeId)
Logger.Info("Running Import")
Dim oResult = Await My.Application.Service.Client.Globix_ImportFileAsync(
oFilePath, oProfileId, oAttributes, oObjectStore, oObjectKind, oIDBDoctypeId, oOptions)
Logger.Info("Import result: [{0}]", oResult.OK)
Logger.Info("Imported file got ObjectId [{0}]", oResult.ObjectId)
If oResult.OK Then
MsgBox("Alles OK")
Else
Logger.Warn("Import failed with message: [{0}] and details [{1}]", oResult.ErrorMessage, oResult.ErrorDetails)
Dim oMsg As String, oTitle As String
If My.Application.User.Language = "de-DE" Then
oMsg = $"Die Datei wurde nicht verarbeitet.{vbNewLine}{vbNewLine}Fehler: {oResult.ErrorMessage}"
oTitle = "Achtung"
Else
oMsg = $"Unexpected Error in FileFlow{vbNewLine}{vbNewLine}Fehler: {oResult.ErrorMessage}"
oTitle = "Attention"
End If
MsgBox("Fehler")
End If
End Using
Catch ex As Exception
If Logger IsNot Nothing Then Logger.Error(ex)
MsgBox("Fehler beim Datei-Import.", MsgBoxStyle.Critical, Text)
End Try
End Function
Public Class SecureStorageHandler
End Class
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Try
Dim oIPAddress = txtServiceAddress.Text
Dim oPort = Integer.Parse(txtServicePort.Text)
Client = New Client(LogConfig, oIPAddress, oPort)
txtStatus.Text = STATUS_CONNECTING
Dim oResult = Client.Connect()
If oResult = True Then
ServiceAddress = $"{oIPAddress}:{oPort}"
ServiceOnline = True
txtStatus.Text = STATUS_CONNECTED
My.Application.Service.Client = Client
Logger.Debug("Loading client config..")
Dim oClientConfig = My.Application.Service.Client.ClientConfig
Logger.Debug("Establishing ECM connection..")
Dim oECMConnectionString = oClientConfig.ConnectionStringECM
My.DatabaseECM = New MSSQLServer(My.LogConfig, oECMConnectionString)
Logger.Debug("Establishing IDB connection..")
Dim oIDBConnectionString = oClientConfig.ConnectionStringIDB
My.DatabaseIDB = New MSSQLServer(My.LogConfig, oIDBConnectionString)
Logger.Debug("Establishing Database connection with fallback..")
My.Database = New DatabaseWithFallback(LogConfig, My.Application.Service.Client, My.DatabaseECM, My.DatabaseIDB)
Else
ServiceAddress = ""
ServiceOnline = True
txtStatus.Text = STATUS_FAILED
' TODO: Make a connection test that is as elaborate as this one :D
'Select Case oResult
' Case ClassService.ConnectionTestResult.NotFound
' lblStatus.Text = "Dienst konnte nicht gefunden werden. Bitte überprüfen sie Addresse und Port."
' Case ClassService.ConnectionTestResult.EmptyURI
' lblStatus.Text = "Bitte tragen Sie eine gültige Dienst Adresse ein."
' Case ClassService.ConnectionTestResult.Authentication
' lblStatus.Text = "Authentifizierungsfehler. Prüfen Sie, ob sich Ihr Gerät in der korrekten Domäne befindet."
' Case Else
' lblStatus.Text = "Unbekannter Fehler."
'End Select
End If
Catch ex As Exception
If Logger IsNot Nothing Then Logger.Error(ex)
MsgBox("Fehler beim Verbindungsaufbau", MsgBoxStyle.Critical, Text)
End Try
End Sub
End Class