07-12-2022

This commit is contained in:
Jonathan Jenne
2022-12-07 16:45:31 +01:00
parent 248be23804
commit 7b7147eeee
28 changed files with 781 additions and 385 deletions

View File

@@ -97,6 +97,7 @@ Namespace Scheduler
.Name = pJob.Name,
.Enabled = pJob.Active,
.Arguments = New Dictionary(Of String, String) From {
{"Id", pJob.Id},
{"Name", pJob.Name}
},
.CronSchedule = pJob.CronSchedule

View File

@@ -10,17 +10,24 @@ Namespace Scheduler.Jobs
Friend Database As MSSQLServer
Friend State As State
Friend Id As Integer
Friend Name As String
Private ctx As IJobExecutionContext
Public Function InitializeJob(context As IJobExecutionContext) As Dictionary(Of String, String)
ctx = context
Dim oJobData = context.MergedJobDataMap
Dim oArgs As Dictionary(Of String, String) = oJobData.Item(Constants.Scheduler.JOB_CONFIG_ARGUMENTS)
LogConfig = oJobData.Item(Constants.Scheduler.JOB_CONFIG_LOGCONFIG)
Database = oJobData.Item(Constants.Scheduler.JOB_CONFIG_DATABASE)
State = oJobData.Item(Constants.Scheduler.JOB_CONFIG_STATE)
Logger = LogConfig.GetLogger()
Id = Integer.Parse(oArgs.Item("Id"))
Name = oArgs.Item("Name")
State.JobStatus.Start(ctx)
Return oJobData.Item(Constants.Scheduler.JOB_CONFIG_ARGUMENTS)
End Function

View File

@@ -8,10 +8,9 @@ Namespace Scheduler.Jobs
Private Function IJob_Execute(context As IJobExecutionContext) As Task Implements IJob.Execute
Dim oArgs = MyBase.InitializeJob(context)
Dim oArg1 = oArgs.Item("Arg1")
Logger.Info("I'm a debug Job!")
Logger.Info("Arg1: [{0}]", oArg1)
Logger.Info("Name: [{0}]", Name)
Dim oResult = New JobResult() With {
.Description = $"I'm a debug job and my result was [{Guid.NewGuid}]."

View File

@@ -2,31 +2,107 @@
Imports Quartz
Namespace Scheduler.Jobs
''' <summary>
'''
''' Parameters / Properties
''' =======================
'''
''' - SourceDirectory
''' - TargetDirectory
''' - Include Subdirectories
''' - Delete Subdirectories
''' - Backup
''' - BackupFolder
''' - Overwrite
''' - Windream DocType
''' - Delete Files
''' - Delete Directory
''' - Delay
'''
''' Rules
''' ======
'''
''' - TargetIndex
''' - Active
''' - Index From
''' - Static
''' - Static Value
''' - File
''' - Folder
''' - Index Type
''' - Separator
''' - Current Date
''' - Current Short Date
''' - KOMPLETT
''' - BEREICH
''' - REST
''' - TRENNZEICHEN
''' - Separator
''' - Remove Zeroes
''' - Include Extension
''' - OrderKey
'''
''' </summary>
Public Class FileImportJob
Inherits BaseJob
Implements IJob
Public Function Execute(context As IJobExecutionContext) As Task Implements IJob.Execute
Dim oArgs = MyBase.InitializeJob(context)
Dim oName = oArgs.Item("Name")
Logger.Info("Running File Import [{0}]", oName)
Try
Logger.Info("Running File Import [{0}]", Name)
Dim oMax = 100
For index = 1 To oMax
UpdateProgress(index, oMax)
Threading.Thread.Sleep(100)
Next
Dim oProfile = State.ProfileDefintions.ImportProfiles.Where(Function(p) p.JobId = Id).SingleOrDefault()
Dim oResult = New JobResult() With {
.Description = $"File Import Job [{oName}] completed!"
}
Dim oSourceDirectory As String = oProfile.SourceFolder
Dim oRecursive As Boolean = oProfile.IncludeSubfolders
Dim oFiles = GetFiles(oSourceDirectory, oRecursive)
context.Result = oResult
If oFiles.Count = 0 Then
Logger.Info("No Files for Profile [{0}]", Name)
Return Task.FromResult(True)
End If
CompleteJob()
Return Task.FromResult(True)
'Dim oMax = 100
'For index = 1 To oMax
' UpdateProgress(index, oMax)
' Threading.Thread.Sleep(100)
'Next
Dim oResult = New JobResult() With {
.Description = $"File Import Job [{Name}] completed!"
}
context.Result = oResult
Return Task.FromResult(True)
Catch ex As Exception
Logger.Error(ex)
Return Task.FromResult(False)
Finally
CompleteJob()
End Try
End Function
Private Function GetFiles(pDirectory As String, pRecursive As Boolean) As String()
Dim oFiles As String()
If pRecursive Then
oFiles = IO.Directory.GetFiles(pDirectory, "*.*", IO.SearchOption.AllDirectories)
Logger.Info("Found [{0}] files in Folder [{1}] (and subdirectories)", oFiles.Count, pDirectory)
Else
oFiles = IO.Directory.GetFiles(pDirectory, "*.*", IO.SearchOption.TopDirectoryOnly)
Logger.Info("Found [{0}] files in Folder [{1}]", oFiles.Count, pDirectory)
End If
Return oFiles
End Function
End Class

View File

@@ -8,12 +8,11 @@ Namespace Scheduler.Jobs
Public Function Execute(context As IJobExecutionContext) As Task Implements IJob.Execute
Dim oArgs = MyBase.InitializeJob(context)
Dim oName = oArgs.Item("Name")
Logger.Info("Running File Index [{0}]", oName)
Logger.Info("Running File Index [{0}]", Name)
Dim oResult = New JobResult() With {
.Description = $"File Index Job [{oName}] completed!"
.Description = $"File Index Job [{Name}] completed!"
}
context.Result = oResult