213 lines
9.2 KiB
VB.net
213 lines
9.2 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.Logging
|
|
Imports DigitalData.Modules.ZooFlow.State
|
|
Imports DigitalData.Services.EDMIService
|
|
Imports DigitalData.Services.EDMIService.GlobalState
|
|
Imports DigitalData.Services.EDMIService.Methods.GlobalIndexer.ImportFile
|
|
Imports DigitalData.Services.EDMIService.Methods.IDB
|
|
|
|
Public Class frmFilesystem
|
|
Private EDMIClient 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 _globalState As GlobalState
|
|
|
|
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_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)
|
|
Catch
|
|
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)
|
|
If SaveFileDialog1.ShowDialog = DialogResult.OK Then
|
|
System.IO.File.WriteAllText(SaveFileDialog1.FileName, "Some text data")
|
|
End If
|
|
End Sub
|
|
|
|
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)
|
|
|
|
EDMIClient = New Client(LogConfig, oIPAddress, oPort)
|
|
|
|
txtStatus.Text = STATUS_CONNECTING
|
|
Dim oResult = EDMIClient.Connect()
|
|
|
|
If oResult Then
|
|
ServiceAddress = $"{oIPAddress}:{oPort}"
|
|
ServiceOnline = True
|
|
txtStatus.Text = STATUS_CONNECTED
|
|
txtStatus.BackColor = Color.LightGreen
|
|
My.Application.Service.Client = EDMIClient
|
|
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(LogConfig, oECMConnectionString)
|
|
Logger.Debug("Establishing IDB connection..")
|
|
Dim oIDBConnectionString = oClientConfig.ConnectionStringIDB
|
|
My.DatabaseIDB = New MSSQLServer(LogConfig, oIDBConnectionString)
|
|
|
|
Logger.Debug("Establishing Database connection with fallback..")
|
|
My.Database = New DatabaseWithFallback(LogConfig, My.Application.Service.Client, My.DatabaseECM, My.DatabaseIDB)
|
|
|
|
InitializeGlobalState()
|
|
Else
|
|
ServiceAddress = ""
|
|
ServiceOnline = True
|
|
txtStatus.Text = STATUS_FAILED
|
|
txtStatus.BackColor = Color.LightCoral
|
|
_globalState = Nothing
|
|
End If
|
|
Catch ex As Exception
|
|
_globalState = Nothing
|
|
If Logger IsNot Nothing Then Logger.Error(ex)
|
|
MsgBox("Fehler beim Verbindungsaufbau", MsgBoxStyle.Critical, Text)
|
|
End Try
|
|
End Sub
|
|
|
|
Private Sub btnStreamSimpleFile_ClickAsync(sender As Object, e As EventArgs) Handles btnStreamSimpleFile.Click
|
|
Try
|
|
If EDMIClient Is Nothing OrElse ServiceOnline = False Then
|
|
MsgBox("Bitte zuerst Verbindung zum EDMI Service herstellen.", MsgBoxStyle.Exclamation, Text)
|
|
Return
|
|
End If
|
|
|
|
If My.DatabaseIDB Is Nothing OrElse My.DatabaseECM Is Nothing Then
|
|
MsgBox("Bitte zuerst die Datenbankverbindungen herstellen.", MsgBoxStyle.Exclamation, Text)
|
|
Return
|
|
End If
|
|
|
|
If _globalState Is Nothing Then
|
|
MsgBox("GlobalState konnte nicht initialisiert werden.", 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)
|
|
|
|
Dim oUser As New UserState With {
|
|
.UserName = Environment.UserName,
|
|
.Language = "de-DE",
|
|
.LanguageId = 1031
|
|
}
|
|
|
|
Dim oObjectStore As String = "WORK"
|
|
Dim oIDBDoctypeId As Long = 1
|
|
Dim oObjectKind As String = "DOC"
|
|
Dim oProfileId As Integer = 1
|
|
Dim oAttributes As New List(Of UserAttributeValue)
|
|
|
|
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)
|
|
|
|
Dim oChecksum As String
|
|
Using oSha256 As SHA256 = SHA256.Create()
|
|
oChecksum = BitConverter.ToString(oSha256.ComputeHash(fileBytes)).Replace("-", String.Empty)
|
|
End Using
|
|
|
|
Dim oFileProperties As New FileProperties With {
|
|
.FileName = fi.FullName,
|
|
.FileCreatedAt = fi.CreationTimeUtc.ToString("O"),
|
|
.FileChangedAt = fi.LastWriteTimeUtc.ToString("O"),
|
|
.FileImportedAt = DateTime.UtcNow,
|
|
.FileContents = fileBytes,
|
|
.FileChecksum = oChecksum,
|
|
.FileInfoRaw = fi
|
|
}
|
|
|
|
Dim oRequest As New Globix_ImportFileRequest With {
|
|
.File = oFileProperties,
|
|
.ProfileId = oProfileId,
|
|
.IDBDoctypeId = oIDBDoctypeId,
|
|
.KindType = oObjectKind,
|
|
.StoreName = oObjectStore,
|
|
.AttributeValues = oAttributes,
|
|
.User = oUser
|
|
}
|
|
|
|
Dim oImportMethod = New ImportFileMethod(LogConfig, My.DatabaseIDB, My.DatabaseECM, _globalState)
|
|
Dim oResponse = oImportMethod.Run(oRequest)
|
|
|
|
If oResponse IsNot Nothing AndAlso oResponse.ObjectId > 0 Then
|
|
Logger.Info("Import erfolgreich abgeschlossen. ObjectId [{0}]", oResponse.ObjectId)
|
|
MsgBox($"Import erfolgreich. ObjectId: {oResponse.ObjectId}", MsgBoxStyle.Information, Text)
|
|
Else
|
|
Logger.Warn("ImportFile lieferte kein erfolgreiches Ergebnis.")
|
|
MsgBox("Import konnte nicht durchgeführt werden.", MsgBoxStyle.Exclamation, Text)
|
|
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 Sub
|
|
|
|
Private Sub InitializeGlobalState()
|
|
Try
|
|
_globalState = New GlobalState(LogConfig, My.DatabaseIDB, My.DatabaseECM)
|
|
_globalState.LoadObjectStores()
|
|
_globalState.LoadConnections()
|
|
_globalState.LoadDoctypes()
|
|
|
|
Dim oConfig As New Config With {
|
|
.ClientConfig = New Config.ClientConfiguration With {
|
|
.ForceDirectDatabaseAccess = True
|
|
}
|
|
}
|
|
|
|
_globalState.LoadClientConfig(oConfig)
|
|
|
|
Logger.Info("GlobalState init: ObjectStores [{0}], Connections [{1}], Doctypes [{2}]",
|
|
_globalState.ObjectStores.Count,
|
|
_globalState.Connections.Count,
|
|
_globalState.Doctypes.Count)
|
|
Catch ex As Exception
|
|
_globalState = Nothing
|
|
Logger.Error(ex)
|
|
MsgBox("GlobalState konnte nicht initialisiert werden.", MsgBoxStyle.Exclamation, Text)
|
|
End Try
|
|
End Sub
|
|
End Class |