From d2717b92162f9ea42cc3e5ea9c9482d888a623ba Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Wed, 22 Apr 2020 14:34:22 +0200 Subject: [PATCH] Language: Add ToBoolean, EMIBenchmark: try blocks --- GUIs.Test.EDMIBenchmark/Form1.vb | 82 ++++++++++++++++++-------------- Modules.Language/Utils.vb | 5 ++ 2 files changed, 50 insertions(+), 37 deletions(-) diff --git a/GUIs.Test.EDMIBenchmark/Form1.vb b/GUIs.Test.EDMIBenchmark/Form1.vb index 4dfc542d..a83430ee 100644 --- a/GUIs.Test.EDMIBenchmark/Form1.vb +++ b/GUIs.Test.EDMIBenchmark/Form1.vb @@ -11,16 +11,20 @@ Public Class Form1 Private _Logger As Logger Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load - _LogConfig = New LogConfig(LogConfig.PathType.Temp, Nothing, "EDMIBenschmark") - _Logger = _LogConfig.GetLogger() + Try + _LogConfig = New LogConfig(LogConfig.PathType.Temp, Nothing, "EDMIBenschmark") + _Logger = _LogConfig.GetLogger() - Dim oChannelFactory As New ChannelFactory(Of EDMIServiceReference.IEDMIServiceChannel)( - Channel.GetBinding(TcpClientCredentialType.Windows), - "net.tcp://172.24.12.39:9000/DigitalData/Services/Main") - _Channel = oChannelFactory.CreateChannel() - _Channel.Open() + Dim oChannelFactory As New ChannelFactory(Of EDMIServiceReference.IEDMIServiceChannel)( + Channel.GetBinding(TcpClientCredentialType.Windows), + "net.tcp://172.24.12.39:9000/DigitalData/Services/Main") + _Channel = oChannelFactory.CreateChannel() + _Channel.Open() - DocumentViewer1.Init(_LogConfig, "21182889975216572111813147150675976632") + DocumentViewer1.Init(_LogConfig, "21182889975216572111813147150675976632") + Catch ex As Exception + MsgBox(ex.Message, MsgBoxStyle.Critical, Text) + End Try End Sub Private Sub AddLogMessage(Message As String) @@ -44,37 +48,41 @@ Public Class Form1 End Sub Private Async Sub ButtonImportFiles_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles ButtonImportFiles.ItemClick - Dim oFiles As New List(Of String) - Dim oSWTotal As New Stopwatch() - oSWTotal.Start() - - For Each oItem As String In listboxFiles.Items - Dim oSW As New Stopwatch() - oSW.Start() - Dim oFileName As String = oItem - Dim oFileInfo As New FileInfo(oFileName) - - AddLogMessage($"Importing {oFileInfo.Name}... ({FormatBytes(oFileInfo.Length)})") - - Dim oContents As Byte() = New Byte(oFileInfo.Length) {} - - Using oStream As New FileStream(oFileName, FileMode.Open) - Await oStream.ReadAsync(oContents, 0, oFileInfo.Length) - End Using + Try + Dim oFiles As New List(Of String) + Dim oSWTotal As New Stopwatch() + oSWTotal.Start() - Dim oResult As EDMIServiceReference.DocumentResult = Await _Channel.ImportFileAsync(oFileInfo.Name, oContents, 1, "WichtigesDokument", 0) - If oResult.OK Then - AddLogMessage($"File [{oFileInfo.Name}] with Id [{oResult.Document.FileId}] imported!") - Else - AddLogMessage($"Import Error: {oResult.ErrorMessage}") - End If - oSW.Stop() - AddLogMessage($"Import Time: {FormatTime(oSW.ElapsedMilliseconds)}") - AddLogMessage("") - Next + For Each oItem As String In listboxFiles.Items + Dim oSW As New Stopwatch() + oSW.Start() + Dim oFileName As String = oItem + Dim oFileInfo As New FileInfo(oFileName) + + AddLogMessage($"Importing {oFileInfo.Name}... ({FormatBytes(oFileInfo.Length)})") + + Dim oContents As Byte() = New Byte(oFileInfo.Length) {} + + Using oStream As New FileStream(oFileName, FileMode.Open) + Await oStream.ReadAsync(oContents, 0, oFileInfo.Length) + End Using + + Dim oResult As EDMIServiceReference.DocumentResult = Await _Channel.ImportFileAsync(oFileInfo.Name, oContents, 1, "WichtigesDokument", 0) + If oResult.OK Then + AddLogMessage($"File [{oFileInfo.Name}] with Id [{oResult.Document.FileId}] imported!") + Else + AddLogMessage($"Import Error: {oResult.ErrorMessage}") + End If + oSW.Stop() + AddLogMessage($"Import Time: {FormatTime(oSW.ElapsedMilliseconds)}") + AddLogMessage("") + Next - oSWTotal.Stop() - AddLogMessage($"Total Time: {FormatTime(oSWTotal.ElapsedMilliseconds)}") + oSWTotal.Stop() + AddLogMessage($"Total Time: {FormatTime(oSWTotal.ElapsedMilliseconds)}") + Catch ex As Exception + MsgBox(ex.Message, MsgBoxStyle.Critical, Text) + End Try End Sub Private Sub buttonClearLog_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles buttonClearLog.ItemClick diff --git a/Modules.Language/Utils.vb b/Modules.Language/Utils.vb index 53a7fbe4..c7cda3b6 100644 --- a/Modules.Language/Utils.vb +++ b/Modules.Language/Utils.vb @@ -22,6 +22,11 @@ Public Class Utils Return [Enum].Parse(GetType(T), value) End Function + Public Shared Function ToBoolean(input As String) As Boolean + If String.IsNullOrEmpty(input) Then Return False + Return (input.Trim().ToLower() = "true") OrElse (input.Trim() = "1") + End Function + ''' ''' Checks a value for three different `null` values, ''' Nothing, Empty String, DBNull