08-12-2022

This commit is contained in:
Jonathan Jenne
2022-12-08 16:43:22 +01:00
parent 7b7147eeee
commit 0a25b0925c
43 changed files with 1740 additions and 378 deletions

View File

@@ -80,6 +80,7 @@
<HintPath>..\packages\Quartz.3.5.0\lib\net462\Quartz.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Data" />
@@ -117,6 +118,14 @@
<Compile Include="Config.vb" />
<Compile Include="Constants.vb" />
<Compile Include="LogProvider.vb" />
<Compile Include="Models\Jobs\JobDefinition.vb" />
<Compile Include="Models\Jobs\JobType.vb" />
<Compile Include="Models\Jobs\HistoryItem.vb" />
<Compile Include="Models\Jobs\StatusItem.vb" />
<Compile Include="Models\Profiles\BaseProfile.vb" />
<Compile Include="Models\Profiles\ImportProfile.vb" />
<Compile Include="Models\Profiles\ImportProfileStep.vb" />
<Compile Include="Models\Windream\ObjectType.vb" />
<Compile Include="My Project\Application.Designer.vb">
<AutoGen>True</AutoGen>
<DependentUpon>Application.myapp</DependentUpon>
@@ -160,6 +169,7 @@
<Compile Include="WCF\Methods\Base.vb" />
<Compile Include="WCF\Methods\GetJobConfig.vb" />
<Compile Include="WCF\Methods\UpdateJob.vb" />
<Compile Include="WCF\Methods\UpdateProfile.vb" />
<Compile Include="WCF\Methods\GetJobStatus.vb" />
<Compile Include="WCF\ServiceHost.vb" />
</ItemGroup>

View File

@@ -0,0 +1,7 @@
Public Class HistoryItem
Public Property JobName As String
Public Property CreatedAt As DateTime
Public Property Successful As Boolean
Public Property ErrorMessage As String
Public Property Message As String
End Class

View File

@@ -0,0 +1,20 @@
Imports System.ComponentModel.DataAnnotations
Public Class JobDefinition
<Required>
Public Id As Integer = -1
<Required>
Public TypeId As Integer
Public Type As JobType
<Required>
<StringLength(250)>
Public Name As String
<Required>
<StringLength(250)>
Public CronSchedule As String
Public Active As Boolean
End Class

View File

@@ -0,0 +1,5 @@
Public Class JobType
Public Id As Integer
Public Name As String
Public Active As Boolean
End Class

View File

@@ -0,0 +1,14 @@
Public Class StatusItem
Public Const PROGRESS_CURRENT = "__Progress_Current"
Public Const PROGRESS_TOTAL = "__Progress_Total"
Public Id As String
Public Name As String
Public ExecutionTime As TimeSpan
Public ProgressCurrent As Integer
Public ProgressTotal As Integer
Public Executing As Boolean = False
Public StartTime As Date
Public CompleteTime As Date
End Class

View File

@@ -0,0 +1,3 @@
Public Class BaseProfile
Public Property Job As New JobDefinition
End Class

View File

@@ -0,0 +1,36 @@
Imports System.ComponentModel.DataAnnotations
Public Class ImportProfile
Inherits BaseProfile
Public Property Active As Boolean
<Required>
Public Property Id As Integer
<Required>
Public Property JobId As Integer
<Required>
Public Property ObjectTypeName As String
<Required>
<StringLength(500)>
Public Property SourceFolder As String
<Required>
<StringLength(500)>
Public Property TargetFolder As String
<StringLength(500)>
Public Property BackupFolder As String
<StringLength(50)>
Public Property SubfolderDateFormat As String
<StringLength(5000)>
Public Property FileExcludeRegex As String
Public Property DeleteFiles As Boolean
Public Property IncludeSubfolders As Boolean
Public Property Steps As New List(Of ImportProfileStep)
End Class

View File

@@ -0,0 +1,26 @@
Public Class ImportProfileStep
Public Property Active As Boolean
Public Property Id As Integer
Public Property ProfileId As Integer
Public Property IndexName As String
Public Property Scope As StepScope
Public Property Method As StepMethod
Public Property Argument1 As String
Public Property Argument2 As String
Public Property Argument3 As String
Public Enum StepMethod
SUBSTRING
REGEX
SPLIT
ALL
VALUE
End Enum
Public Enum StepScope
FILE
FOLDER
End Enum
End Class

View File

@@ -0,0 +1,4 @@
Public Class ObjectType
Public Name As String
Public Indexes As New List(Of String)
End Class

View File

@@ -67,6 +67,8 @@ Namespace Scheduler.Jobs
Return Task.FromResult(True)
End If
Logger.Info("[0] files found in source directory [{1}]", oFiles.Count, oSourceDirectory)
'Dim oMax = 100
'For index = 1 To oMax
' UpdateProgress(index, oMax)

View File

@@ -2,7 +2,6 @@
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Language
Imports ECM.JobRunner.Common
Imports ECM.JobRunner.Windows.Scheduler
Imports DigitalData.Modules.Windream
@@ -17,13 +16,12 @@ Public Class State
Public ReadOnly Property JobTypes As New List(Of JobType)
Public ReadOnly Property ObjectTypes As New List(Of ObjectType)
Public ReadOnly Property JobDefinitions As New List(Of JobDefinition)
Public ReadOnly Property ProfileDefintions As New ProfileDefinitions
Public Class ProfileDefinitions
Public Property ImportProfiles As New List(Of ImportProfile)
Public Property ImportProfileSteps As New List(Of ImportProfileStep)
End Class
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pWindream As Windream)
@@ -45,6 +43,7 @@ Public Class State
_ObjectTypes = GetObjectTypes()
_JobDefinitions = GetJobDefinitions(_JobTypes)
_ProfileDefintions.ImportProfileSteps = GetImportProfileSteps()
_ProfileDefintions.ImportProfiles = GetImportProfiles()
End Sub
@@ -89,7 +88,7 @@ Public Class State
Try
Logger.Info("Loading Job Types..")
Dim oSQL As String = "SELECT * FROM TBECM_JR_TYPE WHERE ACTIVE = 1"
Dim oSQL As String = "SELECT * FROM TBECM_JR_TYPE"
Dim oTable As DataTable = Database.GetDatatable(oSQL)
If oTable Is Nothing Then
@@ -119,33 +118,113 @@ Public Class State
End Try
End Function
Private Function GetImportProfileSteps() As List(Of ImportProfileStep)
Dim oSteps As New List(Of ImportProfileStep)
Try
Logger.Info("Loading Import Profiles Steps..")
Dim oSQL As String = "SELECT * FROM TBECM_JR_FIW_STEP"
Dim oTable As DataTable = Database.GetDatatable(oSQL)
If oTable Is Nothing Then
Logger.Warn("Database Error while loading Import Profile Steps!")
Return oSteps
End If
Logger.Info("[{0}] Import Profile Steps loaded!", oTable.Rows.Count)
For Each oRow As DataRow In oTable.Rows
Dim oTypeId = oRow.ItemEx("PROFILE_ID", 0)
Dim oScope As ImportProfileStep.StepScope
Select Case oRow.ItemEx("SCOPE", "FILE")
Case "FOLDER"
oScope = ImportProfileStep.StepScope.FOLDER
Case "FILE"
oScope = ImportProfileStep.StepScope.FILE
End Select
Dim oMethod As ImportProfileStep.StepMethod
Select Case oRow.ItemEx("METHOD", "ALL")
Case "SUBSTRING"
oScope = ImportProfileStep.StepMethod.SUBSTRING
Case "SPLIT"
oScope = ImportProfileStep.StepMethod.SPLIT
Case "REGEX"
oScope = ImportProfileStep.StepMethod.REGEX
Case "STATIC"
oScope = ImportProfileStep.StepMethod.VALUE
Case Else
oScope = ImportProfileStep.StepMethod.ALL
End Select
Dim oStep As New ImportProfileStep With {
.Id = oRow.ItemEx("GUID", 0),
.ProfileId = oRow.ItemEx("PROFILE_ID", 0),
.IndexName = oRow.Item("IDX_NAME"),
.Method = oMethod,
.Argument1 = oRow.ItemEx("ARGUMENT1", ""),
.Argument2 = oRow.ItemEx("ARGUMENT2", ""),
.Argument3 = oRow.ItemEx("ARGUMENT3", ""),
.Scope = oScope,
.Active = oRow.ItemEx("ACTIVE", 0)
}
oSteps.Add(oStep)
Logger.Debug("Adding Import Profile Step for Index [{0}]", oStep.IndexName)
Next
Return oSteps
Catch ex As Exception
Logger.Error(ex)
Return oSteps
End Try
End Function
Private Function GetImportProfiles() As List(Of ImportProfile)
Dim oProfiles As New List(Of ImportProfile)
Try
Logger.Info("Loading Profiles..")
Logger.Info("Loading Import Profiles..")
Dim oSQL As String = "SELECT * FROM TBECM_JR_FIW_PROFILE"
Dim oTable As DataTable = Database.GetDatatable(oSQL)
If oTable Is Nothing Then
Logger.Warn("Database Error while loading Profiles!")
Logger.Warn("Database Error while loading Import Profiles!")
Return oProfiles
End If
Logger.Info("[{0}] Profiles loaded!", oTable.Rows.Count)
Logger.Info("[{0}] Import Profiles loaded!", oTable.Rows.Count)
For Each oRow As DataRow In oTable.Rows
Dim oTypeId = oRow.ItemEx("JOB_TYPE_ID", 0)
Dim oProfile As New ImportProfile With {
.Id = oRow.ItemEx("GUID", 0),
.JobId = oRow.ItemEx("JR_JOB_ID", 0),
.SourceFolder = oRow.ItemEx("SOURCE_FOLDER", "")
.ObjectTypeName = oRow.Item("WM_OBJECTTYPE"),
.SourceFolder = oRow.ItemEx("SOURCE_FOLDER", ""),
.TargetFolder = oRow.ItemEx("TARGET_FOLDER", ""),
.BackupFolder = oRow.ItemEx("BACKUP_FOLDER", ""),
.SubfolderDateFormat = oRow.ItemEx("SF_DATE_FORMAT", ""),
.DeleteFiles = oRow.ItemEx("DEL_FILE_SUCCESS", 0),
.FileExcludeRegex = oRow.ItemEx("EXCLUDE_REGEX", ""),
.IncludeSubfolders = oRow.ItemEx("INCL_SUBFOLDER", 0),
.Active = oRow.ItemEx("ACTIVE", 0)
}
oProfiles.Add(oProfile)
Logger.Debug("Adding Profile for Folder [{0}]", oProfile.SourceFolder)
Logger.Debug("Adding Import Profile for Folder [{0}]", oProfile.SourceFolder)
Next
Return oProfiles

View File

@@ -1,6 +1,7 @@
Imports System.ServiceModel
Imports ECM.JobRunner.Common
Imports ECM.JobRunner.Windows.UpdateJob
Imports ECM.JobRunner.Windows.UpdateProfile
Imports ECM.JobRunner.Windows.GetJobStatus
Imports ECM.JobRunner.Windows.GetJobConfig
@@ -17,6 +18,9 @@ Namespace WCF
<OperationContract>
Function UpdateJob(pData As UpdateJobRequest) As UpdateJobResponse
<OperationContract>
Function UpdateProfile(pData As UpdateProfileRequest) As UpdateProfileResponse
<OperationContract>
Function GetJobConfig() As GetJobConfigResponse
End Interface

View File

@@ -50,6 +50,11 @@ Namespace WCF
Dim oMethod As New UpdateJob.UpdateJobMethod(LogConfig, Database, State, Scheduler)
Return oMethod.Run(pData)
End Function
Public Function UpdateProfile(pData As UpdateProfile.UpdateProfileRequest) As UpdateProfile.UpdateProfileResponse Implements IJobRunner.UpdateProfile
Dim oMethod As New UpdateProfile.UpdateProfileMethod(LogConfig, Database, State, Scheduler)
Return oMethod.Run(pData)
End Function
End Class
End Namespace

View File

@@ -17,11 +17,32 @@ Public Class GetJobConfig
.JobTypes = State.JobTypes,
.JobDefinitions = State.JobDefinitions,
.ProfileDefinitions = New GetJobConfigResponse.ProfileDefinitionConfig With {
.ImportProfiles = State.ProfileDefintions.ImportProfiles
.ImportProfiles = State.ProfileDefintions.ImportProfiles.
Select(AddressOf FillJobForProfile).
Select(AddressOf FillStepsForProfile).
ToList()
},
.WindreamObjectTypes = State.ObjectTypes
}
End Function
Private Function FillJobForProfile(pProfile As ImportProfile) As ImportProfile
Dim oJob = State.JobDefinitions.
Where(Function(job) job.Id = pProfile.JobId).
FirstOrDefault()
pProfile.Job = oJob
Return pProfile
End Function
Private Function FillStepsForProfile(pProfile As ImportProfile) As ImportProfile
Dim oSteps = State.ProfileDefintions.ImportProfileSteps.
Where(Function(s) s.ProfileId = pProfile.Id).
ToList()
pProfile.Steps = oSteps
Return pProfile
End Function
End Class
Public Class GetJobConfigResponse

View File

@@ -31,6 +31,8 @@ Public Class UpdateJob
If oResponse Then
Scheduler.Reload()
Else
Logger.Warn("Error while updating Profile, data not reloaded!")
End If
Return New UpdateJobResponse With {.OK = oResponse}
@@ -74,8 +76,6 @@ Public Class UpdateJob
End Function
End Class
Public Class UpdateJobRequest
Public Enum UpdateJobAction
Create
@@ -84,7 +84,7 @@ Public Class UpdateJob
End Enum
Public Action As UpdateJobAction
Public Job As JobRunnerReference.JobDefinition
Public Job As JobDefinition
End Class
Public Class UpdateJobResponse

View File

@@ -0,0 +1,152 @@
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