Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Logging.LogConfig
Imports DigitalData.Modules.Database
Imports DigitalData.Services.JobRunner

Public Class JobRunnerService
    Private _logConfig As LogConfig
    Private _logger As Logger
    Private _mssql As MSSQLServer
    Private _firebird As Firebird
    Private _jobrunner As JobRunner

    Protected Overrides Sub OnStart(ByVal args() As String)
        _logConfig = New LogConfig(PathType.CustomPath, My.Settings.LOG_PATH) With {
            .Debug = My.Settings.LOG_DEBUG
        }
        _logger = _logConfig.GetLogger()
        _logger.Info("Starting Service {0}", ServiceName)

        Try
            _mssql = New MSSQLServer(_logConfig, My.Settings.SQL_CONNECTIONSTRING)
            _firebird = New Firebird(_logConfig, My.Settings.FIREBIRD_SERVER, My.Settings.FIREBIRD_DATABASE, My.Settings.FIREBIRD_USER, My.Settings.FIREBIRD_PASSWORD)
        Catch ex As Exception
            _logger.Error(ex)
        End Try

        Try
            _jobrunner = New JobRunner(_logConfig, _mssql, _firebird)
            _jobrunner.Start()
        Catch ex As Exception
            _logger.Error(ex)
        End Try
    End Sub

    Protected Overrides Sub OnStop()
        _jobrunner.Stop()
        _logger.Info("Stopping Service {0}", ServiceName)
    End Sub
End Class
