
Imports DevExpress.XtraEditors
Imports DigitalData.Modules.Logging

Namespace Base
    Public Class BaseForm
        Inherits XtraForm

        Private ReadOnly _Logger As Logger
        Private ReadOnly _ErrorHandler As BaseErrorHandler

        Protected ReadOnly Property Logger As Logger
            Get
                Return _Logger
            End Get
        End Property

        Public Sub New()
        End Sub

        Public Sub New(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)
            _ErrorHandler.ShowErrorMessage(ErrorMessage)
        End Sub
    End Class
End Namespace

