Imports IntraSell_DLL

Imports Microsoft.VisualBasic.ApplicationServices

Namespace My

    ' The following events are available for MyApplication:
    ' 
    ' Startup: Raised when the application starts, before the startup form is created.
    ' Shutdown: Raised after all application forms are closed.  This event is not raised if the application terminates abnormally.
    ' UnhandledException: Raised if the application encounters an unhandled exception.
    ' StartupNextInstance: Raised when launching a single-instance application and the application is already active. 
    ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
    Partial Friend Class MyApplication

        ''' <summary>
        ''' 
        ''' </summary>
        ''' <param name="sender"></param>
        ''' <param name="e"></param>
        ''' <remarks></remarks>
        Public Sub Me_Startup( _
           sender As Object, _
           e As StartupEventArgs _
        ) Handles Me.Startup

            Try
                PrintCommandHelp()
                LoadConfig()
                CopyVorlagenUndConfig()
                SpracheFestlegen(Settings.language, updateSettings:=False)
                'IntraSell_Net_Base.ModuleGlobal.SetConnection(connString:=Settings.intrasell_daten_2_ConnectionString)
                ModuleReports.ConfigureLeaseTime()
            Catch ex As Exception
                'MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Kritischer Fehler!")
                HandleAppError(ex, Silent:=False, Hilfe:="Rufen Sie Tel 0676-6063036")
            End Try

        End Sub

        Sub PrintCommandHelp()
            Console.WriteLine("data=c:\IntraSell_Net\")
            Console.WriteLine("configfile=c:\IntraSell_Net\IntraSell_Net_Settings.xml")
            Console.WriteLine("localconfig")
            Console.WriteLine("user_name=ej")
            Console.WriteLine("pass_word=ej")
        End Sub

        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Protected Sub Me_Shutdown() Handles MyBase.Shutdown
            'Dispose Payment Provider 
            Try
                UnregisterPaymentProvider()
            Catch ex As Exception
                WriteLog("Fehler in UnregisterPaymentProvider() " + ex.Message)
            End Try
            Try
                ClassCleanUp.CleanUpOnShutDown()
            Catch ex As Exception
                WriteLog("Fehler in ClassCleanUp.CleanUpOnShutDown() " + ex.Message)
            End Try

            WriteLog("GOOD BYE!")
        End Sub

        Public Sub UnregisterPaymentProvider() ' Handles MyBase.Disposed 
            Try
                WriteLog("UnregisterPaymentProvider")
                If PaymentProviderRegistry.registeredProviders Is Nothing Then Exit Sub

                For Each prov In PaymentProviderRegistry.registeredProviders
                    WriteLog("Unregister PaymentProvider " & prov.ToString)
                    ' DisposeProvider wird beim Beenden des Plugins aufgerufen
                    If prov IsNot Nothing Then
                        prov.DisposeProvider()
                        WriteLog("DONE Unregister PaymentProvider " + prov.ToString)
                    End If
                Next
            Catch ex As Exception
                WriteLog("Error: " & ex.Message)
                WriteLog("Stacktrace: " & ex.StackTrace)
            End Try
        End Sub

    End Class

End Namespace

