94 lines
3.5 KiB
VB.net
94 lines
3.5 KiB
VB.net
Imports DigitalData.Modules.Database
|
|
Imports DigitalData.Modules.Logging
|
|
Imports ECM.JobRunner.Common
|
|
Imports ECM.JobRunner.Windows.Scheduler
|
|
|
|
Public Class UpdateJob
|
|
Public Class UpdateJobMethod
|
|
Inherits Base.BaseMethod
|
|
|
|
Private ReadOnly Scheduler As JobScheduler
|
|
|
|
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pState As State, pScheduler As JobScheduler)
|
|
MyBase.New(pLogConfig, pDatabase, pState)
|
|
Scheduler = pScheduler
|
|
End Sub
|
|
|
|
Public Function Run(pData As UpdateJobRequest) As UpdateJobResponse
|
|
Dim oResponse As Boolean = False
|
|
|
|
Select Case pData.Action
|
|
Case UpdateJobRequest.UpdateJobAction.Update
|
|
oResponse = DoUpdateJob(pData)
|
|
|
|
Case UpdateJobRequest.UpdateJobAction.Create
|
|
oResponse = DoCreateJob(pData)
|
|
|
|
Case UpdateJobRequest.UpdateJobAction.Delete
|
|
oResponse = DoDeleteJob(pData)
|
|
|
|
End Select
|
|
|
|
If oResponse Then
|
|
Scheduler.Reload()
|
|
Else
|
|
Logger.Warn("Error while updating Profile, data not reloaded!")
|
|
End If
|
|
|
|
Return New UpdateJobResponse With {.OK = oResponse}
|
|
End Function
|
|
|
|
Private Function DoUpdateJob(pData As UpdateJobRequest) As Boolean
|
|
Dim oJob = pData.Job
|
|
Dim oSQL As String = "UPDATE TBECM_JR_JOB SET TITLE = @TITLE, QUARTZ_DEF = @CRON, JOB_TYPE_ID = @TYPE_ID, ACTIVE = @ACTIVE WHERE GUID = @GUID"
|
|
Dim oCommand As New SqlClient.SqlCommand(oSQL)
|
|
|
|
oCommand.Parameters.Add("TITLE", SqlDbType.NVarChar, 250).Value = oJob.Name
|
|
oCommand.Parameters.Add("CRON", SqlDbType.NVarChar, 250).Value = oJob.CronSchedule
|
|
oCommand.Parameters.Add("TYPE_ID", SqlDbType.Int).Value = oJob.TypeId
|
|
oCommand.Parameters.Add("ACTIVE", SqlDbType.Bit).Value = oJob.Active
|
|
oCommand.Parameters.Add("GUID", SqlDbType.Int).Value = oJob.Id
|
|
|
|
Return Database.ExecuteNonQuery(oCommand)
|
|
End Function
|
|
|
|
Private Function DoCreateJob(pData As UpdateJobRequest) As Boolean
|
|
Dim oJob = pData.Job
|
|
Dim oSQL As String = "INSERT INTO TBECM_JR_JOB (TITLE, QUARTZ_DEF, JOB_TYPE_ID, ACTIVE) VALUES (@TITLE, @CRON, @TYPE_ID, @ACTIVE)"
|
|
Dim oCommand As New SqlClient.SqlCommand(oSQL)
|
|
|
|
oCommand.Parameters.Add("TITLE", SqlDbType.NVarChar, 250).Value = oJob.Name
|
|
oCommand.Parameters.Add("CRON", SqlDbType.NVarChar, 250).Value = oJob.CronSchedule
|
|
oCommand.Parameters.Add("TYPE_ID", SqlDbType.Int).Value = oJob.TypeId
|
|
oCommand.Parameters.Add("ACTIVE", SqlDbType.Bit).Value = oJob.Active
|
|
|
|
Return Database.ExecuteNonQuery(oCommand)
|
|
End Function
|
|
|
|
Private Function DoDeleteJob(pData As UpdateJobRequest) As Boolean
|
|
Dim oJob = pData.Job
|
|
Dim oSQL As String = "DELETE FROM TBECM_JR_JOB WHERE GUID = @GUID"
|
|
Dim oCommand As New SqlClient.SqlCommand(oSQL)
|
|
|
|
oCommand.Parameters.Add("GUID", SqlDbType.Int).Value = oJob.Id
|
|
|
|
Return Database.ExecuteNonQuery(oCommand)
|
|
End Function
|
|
End Class
|
|
|
|
Public Class UpdateJobRequest
|
|
Public Enum UpdateJobAction
|
|
Create
|
|
Update
|
|
Delete
|
|
End Enum
|
|
|
|
Public Action As UpdateJobAction
|
|
Public Job As JobDefinition
|
|
End Class
|
|
|
|
Public Class UpdateJobResponse
|
|
Inherits Base.BaseResponse
|
|
End Class
|
|
End Class
|