Monorepo/GUIs.Common/Base/BaseRibbonForm.vb

63 lines
2.1 KiB
VB.net

Imports DevExpress.XtraBars.Docking
Imports DevExpress.XtraBars.Ribbon
Imports DigitalData.Modules.Logging
Namespace Base
''' <summary>
''' This BaseClass is used to provide common functionality like the Logger or ErrorHandler to all Forms
''' </summary>
''' <example>
''' To use it, create a form and change the `Inherits` statement in FormName.Designer.vb to this form.
'''
''' Partial Class frmExample
''' Inherits BaseRibbonForm
'''
''' ...
''' End Class
''' </example>
Public Class BaseRibbonForm
Inherits RibbonForm
Private _Logger As Logger
Private _ErrorHandler As BaseErrorHandler
Protected ReadOnly Property Logger As Logger
Get
Return _Logger
End Get
End Property
Public Sub New()
End Sub
Public Sub InitializeBaseForm(LogConfig As LogConfig)
' Get the full name of the inheriting form
' so the log messages have the right classname
Dim oClassName = [GetType]().FullName
' My.LogConfig is undefined in the designer
_Logger = LogConfig?.GetLogger(oClassName)
_ErrorHandler = New BaseErrorHandler(LogConfig, _Logger, Me)
' When you add something, be careful if it
' depends on a global var like My.LogConfig
' you might need to check for its existence with ?
End Sub
''' ============== PUBLIC METHODS ==============
Public Sub ShowInfoMessage(Message As String)
_ErrorHandler.ShowInfoMessage(Message)
End Sub
Public Sub ShowErrorMessage(Exception As Exception)
Dim oCallingClass = LogConfig.GetClassFullName(IncludeMethodNames:=True, Parts:=2)
_ErrorHandler.ShowErrorMessage(Exception, oCallingClass)
End Sub
Public Sub ShowErrorMessage(ErrorMessage As String)
Dim oCallingClass = LogConfig.GetClassFullName(IncludeMethodNames:=True, Parts:=2)
_ErrorHandler.ShowErrorMessage(New ApplicationException(ErrorMessage), oCallingClass)
End Sub
End Class
End Namespace