You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
180 lines
4.7 KiB
180 lines
4.7 KiB
|
|
#Region "Includes"
|
|
|
|
Imports System.Data.SqlClient
|
|
Imports Common.Common
|
|
|
|
#End Region
|
|
|
|
Public Class Job
|
|
|
|
#Region "Members"
|
|
|
|
Private m_JobId As Integer
|
|
Private m_Description As String
|
|
Private m_ProgrammId As Integer
|
|
Private m_JobType As JobType
|
|
Private m_JobStartType As JobStartType
|
|
Private m_Common As Common.Common
|
|
|
|
#End Region
|
|
|
|
#Region "Constructor"
|
|
|
|
Public Sub New(ByVal common As Common.Common, ByVal jobId As Integer, ByVal description As String, ByVal programmId As Integer, ByVal jobType As JobType, ByVal jobStartType As JobStartType)
|
|
m_Common = common
|
|
|
|
m_JobId = jobId
|
|
m_Description = description
|
|
m_ProgrammId = programmId
|
|
m_JobType = jobType
|
|
m_JobStartType = jobStartType
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
#Region "Properties"
|
|
|
|
Public ReadOnly Property JobId() As Integer
|
|
Get
|
|
Return m_JobId
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property Description() As String
|
|
Get
|
|
Return m_Description
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property ProgrammId() As Integer
|
|
Get
|
|
Return m_ProgrammId
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property JobType() As JobType
|
|
Get
|
|
Return m_JobType
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property JobStartType() As JobStartType
|
|
Get
|
|
Return m_JobStartType
|
|
End Get
|
|
End Property
|
|
|
|
#End Region
|
|
|
|
#Region "Public Methods"
|
|
|
|
'Launches a start or a watch job'
|
|
Public Sub Launch(ByVal isRunJob As Boolean, ByVal isNachLetzterAusfuerung As Boolean)
|
|
Try
|
|
'insert start datetime into db, used to check, if the job really started
|
|
'batch has to call bmsDll.Start() method...
|
|
DataAccess.Job.SetJobLastRun(m_Common.DSN, m_JobId, LastRun.Start)
|
|
|
|
'log some infos into eventlog
|
|
'm_Common.Log(SERVICE_DISPLAY_NAME, "Starter launched Job " + m_JobId.ToString() + " (" + m_Description + ")")
|
|
|
|
'reset calculated bit
|
|
DataAccess.Job.SetNextStartDateCalculated(m_Common.DSN, m_JobId, True)
|
|
|
|
If Not isRunJob And Not isNachLetzterAusfuerung Then
|
|
'just calculate next start time if its not a runjob (job that has to execute as fast as possible)
|
|
DataAccess.Job.SetNextExecDateTime(m_Common.DSN, m_JobId)
|
|
End If
|
|
|
|
Select Case m_JobType
|
|
Case JobType.StartJob
|
|
Select Case m_JobStartType
|
|
Case JobStartType.Executable
|
|
StartExe()
|
|
Case JobStartType.SqlQuery
|
|
StartSqlQuery()
|
|
Case JobStartType.WindowsService
|
|
StartService()
|
|
Case Else
|
|
Throw New Exception("Unbekannter Job Start Typ """ & m_JobStartType.ToString() & """ ist unbekannt")
|
|
End Select
|
|
Case Else
|
|
Throw New Exception("Unbekannter Job Typ """ & m_JobType.ToString() & """")
|
|
End Select
|
|
|
|
Catch ex As Exception
|
|
Dim exModified As New Exception("Der Job JobId: " + m_JobId.ToString() + " (" + m_Description + ") konnte nicht gestartet werden." + Environment.NewLine + ex.Message, ex)
|
|
Throw exModified
|
|
End Try
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
#Region "private Methods"
|
|
|
|
'Starts an executable. But before, it gets all start parameters from db it needs
|
|
Private Sub StartExe()
|
|
Try
|
|
Dim programmPath As String = ""
|
|
|
|
DataAccess.Job.GetStartParameter(m_Common.DSN, m_JobId, StartParameterType.FilePath, programmPath)
|
|
process.Start(programmPath)
|
|
|
|
Catch ex As Exception
|
|
Throw ex
|
|
End Try
|
|
End Sub
|
|
|
|
'Starts a service. But before, it gets all start parameters from db it needs
|
|
Private Sub StartService()
|
|
Try
|
|
Dim serviceName As String = "", machineName As String = ""
|
|
|
|
DataAccess.Job.GetStartParameter(m_Common.DSN, m_JobId, StartParameterType.ServiceName, serviceName)
|
|
DataAccess.Job.GetStartParameter(m_Common.DSN, m_JobId, StartParameterType.ServerName, machineName)
|
|
|
|
Dim serviceController As New System.ServiceProcess.ServiceController(serviceName, machineName)
|
|
|
|
If Not serviceController.Status = ServiceProcess.ServiceControllerStatus.Running Then
|
|
serviceController.Start()
|
|
End If
|
|
|
|
Catch ex As Exception
|
|
Throw ex
|
|
End Try
|
|
End Sub
|
|
|
|
'Starts a sql query. But before, it gets all start parameters from db it needs
|
|
Private Sub StartSqlQuery()
|
|
Dim sqlConn As New SqlConnection
|
|
Try
|
|
Dim connectionString As String = "", sqlQuery As String = ""
|
|
|
|
DataAccess.Job.GetStartParameter(m_Common.DSN, m_JobId, StartParameterType.ConnectionString, connectionString)
|
|
DataAccess.Job.GetStartParameter(m_Common.DSN, m_JobId, StartParameterType.SQLQuery, sqlQuery)
|
|
|
|
Dim sqlCom As New SqlCommand
|
|
|
|
sqlConn.ConnectionString = connectionString
|
|
sqlConn.Open()
|
|
|
|
sqlCom.CommandType = CommandType.Text
|
|
sqlCom.Connection = sqlConn
|
|
|
|
sqlCom.CommandText = sqlQuery
|
|
sqlCom.ExecuteNonQuery()
|
|
|
|
sqlConn.Close()
|
|
Catch ex As Exception
|
|
If sqlConn.State = ConnectionState.Open Then
|
|
sqlConn.Close()
|
|
End If
|
|
Throw ex
|
|
End Try
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
End Class
|