Imports DigitalData.Modules.Logging Imports MultiTool.Common.Exceptions Public Class FormHelper Private ReadOnly Logger As Logger Private ReadOnly Form As Windows.Forms.Form Public Sub New(pLogConfig As LogConfig, pForm As Windows.Forms.Form) Logger = pLogConfig.GetLogger() Form = pForm End Sub Public Sub ShowError(pException As Exception, pFunction As String, Optional pDetails As String = "") Dim oMessage = String.Format(My.Resources.frmShared.In_der_Funktion___0___ist_folgender_Fehler_aufgetreten___1_, pFunction, vbNewLine & vbNewLine & pException.Message) If pDetails <> String.Empty Then oMessage &= $"{vbNewLine}{pDetails}" End If If TypeOf pException Is MultiToolException Then oMessage &= $"{vbNewLine}" Select Case pException.GetType() Case GetType(MissingAttributeException) oMessage &= $"Fehlendes Attribut: '{pException.Message}'" End Select End If Logger.Error(pException) MsgBox(oMessage, MsgBoxStyle.Critical, Form.Text) End Sub Public Sub ShowWarning(pMessage As String, Optional pDetails As String = "") Dim oMessage As String = pMessage If pDetails <> String.Empty Then oMessage &= $"{vbNewLine}{pDetails}" End If Logger.Info(oMessage) MsgBox(oMessage, MsgBoxStyle.Exclamation, Form.Text) End Sub Public Sub TryOpenDirectory(pPath As String, pDisplayName As String) If IO.Directory.Exists(pPath) Then Process.Start(pPath) Else Dim oMessage = String.Format(My.Resources.frmImportMainExtra._0__nicht_konfiguriert_oder_nicht_gefunden, pDisplayName) MsgBox(oMessage, MsgBoxStyle.Exclamation, Form.Text) End If End Sub Public Sub TryOpenFile(pPath As String, pDisplayName As String) If IO.File.Exists(pPath) Then Process.Start(pPath) Else Dim oMessage = String.Format(My.Resources.frmImportMainExtra._0__nicht_konfiguriert_oder_nicht_gefunden, pDisplayName) MsgBox(oMessage, MsgBoxStyle.Exclamation, Form.Text) End If End Sub End Class