153 lines
6.8 KiB
VB.net
153 lines
6.8 KiB
VB.net
Imports DigitalData.Modules.Database
|
|
Imports DigitalData.Modules.Logging
|
|
Imports ECM.JobRunner.Common
|
|
Imports ECM.JobRunner.Windows.Scheduler
|
|
|
|
Public Class UpdateProfile
|
|
Public Class UpdateProfileMethod
|
|
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 UpdateProfileRequest) As UpdateProfileResponse
|
|
Dim oResponse As Boolean = False
|
|
Dim oUpdateJob As New UpdateJob.UpdateJobMethod(LogConfig, Database, State, Scheduler)
|
|
|
|
' Active on the profile sets active on the job as well
|
|
pData.ImportProfile.Job.Active = pData.ImportProfile.Active
|
|
|
|
Dim oJobResponse = oUpdateJob.Run(New UpdateJob.UpdateJobRequest With {
|
|
.Job = pData.ImportProfile.Job,
|
|
.Action = pData.Action
|
|
})
|
|
|
|
If oJobResponse.OK = False Then
|
|
Return New UpdateProfileResponse With {.OK = False}
|
|
End If
|
|
|
|
Select Case pData.Action
|
|
Case UpdateProfileRequest.UpdateProfileAction.Update
|
|
oResponse = DoUpdateImportProfile(pData)
|
|
|
|
Case UpdateProfileRequest.UpdateProfileAction.Create
|
|
oResponse = DoCreateImportProfile(pData)
|
|
|
|
Case UpdateProfileRequest.UpdateProfileAction.Delete
|
|
oResponse = DoDeleteImportProfile(pData)
|
|
|
|
End Select
|
|
|
|
If oResponse Then
|
|
Scheduler.Reload()
|
|
Else
|
|
Logger.Warn("Error while updating Profile, data not reloaded!")
|
|
End If
|
|
|
|
Return New UpdateProfileResponse With {.OK = oResponse}
|
|
End Function
|
|
|
|
Private Function DoUpdateImportProfile(pData As UpdateProfileRequest) As Boolean
|
|
Dim oProfile = pData.ImportProfile
|
|
Dim oSQL As String = "UPDATE TBECM_JR_FIW_PROFILE
|
|
SET JR_JOB_ID = @JR_JOB_ID,
|
|
WM_OBJECTTYPE = @WM_OBJECTTYPE,
|
|
SOURCE_FOLDER = @SOURCE_FOLDER,
|
|
TARGET_FOLDER = @TARGET_FOLDER,
|
|
BACKUP_FOLDER = @BACKUP_FOLDER,
|
|
SF_DATE_FORMAT = @SF_DATE_FORMAT,
|
|
DEL_FILE_SUCCESS = @DEL_FILE_SUCCESS,
|
|
INCL_SUBFOLDER = @INCL_SUBFOLDER,
|
|
EXCLUDE_REGEX = @EXCLUDE_REGEX,
|
|
ACTIVE = @ACTIVE
|
|
WHERE GUID = @GUID"
|
|
Dim oCommand As New SqlClient.SqlCommand(oSQL)
|
|
|
|
oCommand.Parameters.Add("JR_JOB_ID", SqlDbType.Int).Value = oProfile.Job.Id
|
|
oCommand.Parameters.Add("WM_OBJECTTYPE", SqlDbType.NVarChar, 100).Value = oProfile.ObjectTypeName
|
|
oCommand.Parameters.Add("SOURCE_FOLDER", SqlDbType.NVarChar, 500).Value = oProfile.SourceFolder
|
|
oCommand.Parameters.Add("TARGET_FOLDER", SqlDbType.NVarChar, 500).Value = oProfile.TargetFolder
|
|
oCommand.Parameters.Add("BACKUP_FOLDER", SqlDbType.NVarChar, 500).Value = oProfile.BackupFolder
|
|
oCommand.Parameters.Add("EXCLUDE_REGEX", SqlDbType.NVarChar, 5000).Value = oProfile.FileExcludeRegex
|
|
oCommand.Parameters.Add("SF_DATE_FORMAT", SqlDbType.NVarChar, 50).Value = oProfile.SubfolderDateFormat
|
|
oCommand.Parameters.Add("DEL_FILE_SUCCESS", SqlDbType.Bit).Value = oProfile.DeleteFiles
|
|
oCommand.Parameters.Add("INCL_SUBFOLDER", SqlDbType.Bit).Value = oProfile.IncludeSubfolders
|
|
oCommand.Parameters.Add("ACTIVE", SqlDbType.Bit).Value = oProfile.Active
|
|
oCommand.Parameters.Add("GUID", SqlDbType.Int).Value = oProfile.Id
|
|
|
|
Return Database.ExecuteNonQuery(oCommand)
|
|
End Function
|
|
|
|
Private Function DoCreateImportProfile(pData As UpdateProfileRequest) As Boolean
|
|
Dim oProfile = pData.ImportProfile
|
|
Dim oSQL As String = "INSERT INTO TBECM_JR_FIW_PROFILE (
|
|
JR_JOB_ID,
|
|
WM_OBJECTTYPE,
|
|
SOURCE_FOLDER,
|
|
TARGET_FOLDER,
|
|
BACKUP_FOLDER,
|
|
SF_DATE_FORMAT,
|
|
DEL_FILE_SUCCESS,
|
|
INCL_SUBFOLDER,
|
|
EXCLUDE_REGEX,
|
|
ACTIVE
|
|
) VALUES (
|
|
@JR_JOB_ID,
|
|
@WM_OBJECTTYPE,
|
|
@SOURCE_FOLDER,
|
|
@TARGET_FOLDER,
|
|
@BACKUP_FOLDER,
|
|
@SF_DATE_FORMAT,
|
|
@DEL_FILE_SUCCESS,
|
|
@INCL_SUBFOLDER,
|
|
@EXCLUDE_REGEX,
|
|
@ACTIVE
|
|
)"
|
|
Dim oCommand As New SqlClient.SqlCommand(oSQL)
|
|
|
|
oCommand.Parameters.Add("JR_JOB_ID", SqlDbType.Int).Value = oProfile.Job.Id
|
|
oCommand.Parameters.Add("WM_OBJECTTYPE", SqlDbType.NVarChar, 100).Value = oProfile.ObjectTypeName
|
|
oCommand.Parameters.Add("SOURCE_FOLDER", SqlDbType.NVarChar, 500).Value = oProfile.SourceFolder
|
|
oCommand.Parameters.Add("TARGET_FOLDER", SqlDbType.NVarChar, 500).Value = oProfile.TargetFolder
|
|
oCommand.Parameters.Add("BACKUP_FOLDER", SqlDbType.NVarChar, 500).Value = oProfile.BackupFolder
|
|
oCommand.Parameters.Add("EXCLUDE_REGEX", SqlDbType.NVarChar, 5000).Value = oProfile.FileExcludeRegex
|
|
oCommand.Parameters.Add("SF_DATE_FORMAT", SqlDbType.NVarChar, 50).Value = oProfile.SubfolderDateFormat
|
|
oCommand.Parameters.Add("DEL_FILE_SUCCESS", SqlDbType.Bit).Value = oProfile.DeleteFiles
|
|
oCommand.Parameters.Add("INCL_SUBFOLDER", SqlDbType.Bit).Value = oProfile.IncludeSubfolders
|
|
oCommand.Parameters.Add("ACTIVE", SqlDbType.Bit).Value = oProfile.Active
|
|
oCommand.Parameters.Add("GUID", SqlDbType.Int).Value = oProfile.Id
|
|
|
|
Return Database.ExecuteNonQuery(oCommand)
|
|
End Function
|
|
|
|
Private Function DoDeleteImportProfile(pData As UpdateProfileRequest) As Boolean
|
|
Dim oProfile = pData.ImportProfile
|
|
Dim oSQL As String = "DELETE FROM TBECM_JR_FIW_PROFILE WHERE GUID = @GUID"
|
|
Dim oCommand As New SqlClient.SqlCommand(oSQL)
|
|
|
|
oCommand.Parameters.Add("GUID", SqlDbType.Int).Value = oProfile.Id
|
|
|
|
Return Database.ExecuteNonQuery(oCommand)
|
|
End Function
|
|
End Class
|
|
|
|
Public Class UpdateProfileRequest
|
|
Public Enum UpdateProfileAction
|
|
Create
|
|
Update
|
|
Delete
|
|
End Enum
|
|
|
|
Public Action As UpdateProfileAction
|
|
Public ImportProfile As ImportProfile
|
|
End Class
|
|
|
|
Public Class UpdateProfileResponse
|
|
Inherits Base.BaseResponse
|
|
End Class
|
|
End Class
|