Language: Add ToBoolean, EMIBenchmark: try blocks

This commit is contained in:
Jonathan Jenne 2020-04-22 14:34:22 +02:00
parent 162485e3f0
commit d2717b9216
2 changed files with 46 additions and 33 deletions

View File

@ -11,16 +11,20 @@ Public Class Form1
Private _Logger As Logger Private _Logger As Logger
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
_LogConfig = New LogConfig(LogConfig.PathType.Temp, Nothing, "EDMIBenschmark") Try
_Logger = _LogConfig.GetLogger() _LogConfig = New LogConfig(LogConfig.PathType.Temp, Nothing, "EDMIBenschmark")
_Logger = _LogConfig.GetLogger()
Dim oChannelFactory As New ChannelFactory(Of EDMIServiceReference.IEDMIServiceChannel)( Dim oChannelFactory As New ChannelFactory(Of EDMIServiceReference.IEDMIServiceChannel)(
Channel.GetBinding(TcpClientCredentialType.Windows), Channel.GetBinding(TcpClientCredentialType.Windows),
"net.tcp://172.24.12.39:9000/DigitalData/Services/Main") "net.tcp://172.24.12.39:9000/DigitalData/Services/Main")
_Channel = oChannelFactory.CreateChannel() _Channel = oChannelFactory.CreateChannel()
_Channel.Open() _Channel.Open()
DocumentViewer1.Init(_LogConfig, "21182889975216572111813147150675976632") DocumentViewer1.Init(_LogConfig, "21182889975216572111813147150675976632")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, Text)
End Try
End Sub End Sub
Private Sub AddLogMessage(Message As String) Private Sub AddLogMessage(Message As String)
@ -44,37 +48,41 @@ Public Class Form1
End Sub End Sub
Private Async Sub ButtonImportFiles_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles ButtonImportFiles.ItemClick Private Async Sub ButtonImportFiles_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles ButtonImportFiles.ItemClick
Dim oFiles As New List(Of String) Try
Dim oSWTotal As New Stopwatch() Dim oFiles As New List(Of String)
oSWTotal.Start() Dim oSWTotal As New Stopwatch()
oSWTotal.Start()
For Each oItem As String In listboxFiles.Items For Each oItem As String In listboxFiles.Items
Dim oSW As New Stopwatch() Dim oSW As New Stopwatch()
oSW.Start() oSW.Start()
Dim oFileName As String = oItem Dim oFileName As String = oItem
Dim oFileInfo As New FileInfo(oFileName) Dim oFileInfo As New FileInfo(oFileName)
AddLogMessage($"Importing {oFileInfo.Name}... ({FormatBytes(oFileInfo.Length)})") AddLogMessage($"Importing {oFileInfo.Name}... ({FormatBytes(oFileInfo.Length)})")
Dim oContents As Byte() = New Byte(oFileInfo.Length) {} Dim oContents As Byte() = New Byte(oFileInfo.Length) {}
Using oStream As New FileStream(oFileName, FileMode.Open) Using oStream As New FileStream(oFileName, FileMode.Open)
Await oStream.ReadAsync(oContents, 0, oFileInfo.Length) Await oStream.ReadAsync(oContents, 0, oFileInfo.Length)
End Using End Using
Dim oResult As EDMIServiceReference.DocumentResult = Await _Channel.ImportFileAsync(oFileInfo.Name, oContents, 1, "WichtigesDokument", 0) Dim oResult As EDMIServiceReference.DocumentResult = Await _Channel.ImportFileAsync(oFileInfo.Name, oContents, 1, "WichtigesDokument", 0)
If oResult.OK Then If oResult.OK Then
AddLogMessage($"File [{oFileInfo.Name}] with Id [{oResult.Document.FileId}] imported!") AddLogMessage($"File [{oFileInfo.Name}] with Id [{oResult.Document.FileId}] imported!")
Else Else
AddLogMessage($"Import Error: {oResult.ErrorMessage}") AddLogMessage($"Import Error: {oResult.ErrorMessage}")
End If End If
oSW.Stop() oSW.Stop()
AddLogMessage($"Import Time: {FormatTime(oSW.ElapsedMilliseconds)}") AddLogMessage($"Import Time: {FormatTime(oSW.ElapsedMilliseconds)}")
AddLogMessage("") AddLogMessage("")
Next Next
oSWTotal.Stop() oSWTotal.Stop()
AddLogMessage($"Total Time: {FormatTime(oSWTotal.ElapsedMilliseconds)}") AddLogMessage($"Total Time: {FormatTime(oSWTotal.ElapsedMilliseconds)}")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, Text)
End Try
End Sub End Sub
Private Sub buttonClearLog_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles buttonClearLog.ItemClick Private Sub buttonClearLog_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles buttonClearLog.ItemClick

View File

@ -22,6 +22,11 @@ Public Class Utils
Return [Enum].Parse(GetType(T), value) Return [Enum].Parse(GetType(T), value)
End Function 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
''' <summary> ''' <summary>
''' Checks a value for three different `null` values, ''' Checks a value for three different `null` values,
''' Nothing, Empty String, DBNull ''' Nothing, Empty String, DBNull