07-12-2022
This commit is contained in:
@@ -8,4 +8,13 @@ Public Class Config
|
||||
Public Property Host As String = "localhost"
|
||||
Public Property Port As Integer = 9000
|
||||
Public Property Name As String = "JobRunner"
|
||||
Public Property Windream As New WindreamConfig
|
||||
|
||||
Public Class WindreamConfig
|
||||
Public Server As String = "localhost"
|
||||
Public Username As String = "DD_ECM"
|
||||
Public Password As String = "DD_ECM"
|
||||
Public Domain As String = "dd-gan"
|
||||
Public DriveLetter As String = "W"
|
||||
End Class
|
||||
End Class
|
||||
|
||||
@@ -8,4 +8,9 @@
|
||||
Public Const JOB_CONFIG_DATABASE = "__Database"
|
||||
Public Const JOB_CONFIG_STATE = "__State"
|
||||
End Class
|
||||
|
||||
Public Class Jobs
|
||||
Public Const JOB_TYPE_IMPORT = 1
|
||||
Public Const JOB_TYPE_INDEX = 2
|
||||
End Class
|
||||
End Class
|
||||
|
||||
@@ -67,6 +67,9 @@
|
||||
<Reference Include="DigitalData.Modules.Messaging">
|
||||
<HintPath>..\..\DDModules\Messaging\bin\Debug\DigitalData.Modules.Messaging.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="DigitalData.Modules.Windream">
|
||||
<HintPath>..\..\DDModules\Windream\bin\Debug\DigitalData.Modules.Windream.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.Logging.Abstractions.2.1.1\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}]."
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
Imports DigitalData.Modules.Config
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Messaging.WCF
|
||||
Imports DigitalData.Modules.Windream
|
||||
|
||||
Public Class Service
|
||||
|
||||
@@ -16,6 +17,7 @@ Public Class Service
|
||||
Private Scheduler As Scheduler.JobScheduler
|
||||
Private Database As MSSQLServer
|
||||
Private State As State
|
||||
Private Windream As Windream
|
||||
|
||||
Protected Overrides Async Sub OnStart(ByVal args() As String)
|
||||
' Code zum Starten des Dienstes hier einfügen. Diese Methode sollte Vorgänge
|
||||
@@ -37,8 +39,13 @@ Public Class Service
|
||||
' set logging debug flag from config
|
||||
LogConfig.Debug = Config.Debug
|
||||
|
||||
' Initialize Windream
|
||||
Dim oWindream = Config.Windream
|
||||
Windream = New Windream(LogConfig, True, oWindream.DriveLetter, "/", True,
|
||||
oWindream.Server, oWindream.Username, oWindream.Password, oWindream.Domain)
|
||||
|
||||
' initialize global state
|
||||
State = New State(LogConfig, Database)
|
||||
State = New State(LogConfig, Database, Windream)
|
||||
|
||||
' start the scheduler
|
||||
Scheduler = New Scheduler.JobScheduler(LogConfig, Database, State)
|
||||
|
||||
@@ -4,34 +4,86 @@ Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Language
|
||||
Imports ECM.JobRunner.Common
|
||||
Imports ECM.JobRunner.Windows.Scheduler
|
||||
Imports System.Runtime.InteropServices
|
||||
Imports DigitalData.Modules.Windream
|
||||
|
||||
Public Class State
|
||||
Inherits BaseClass
|
||||
|
||||
Private ReadOnly Database As MSSQLServer
|
||||
Private ReadOnly Windream As Windream
|
||||
|
||||
Public ReadOnly JobHistory As JobHistory
|
||||
Public ReadOnly JobStatus As JobStatus
|
||||
|
||||
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 Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer)
|
||||
Public ReadOnly Property ProfileDefintions As New ProfileDefinitions
|
||||
|
||||
Public Class ProfileDefinitions
|
||||
Public Property ImportProfiles As New List(Of ImportProfile)
|
||||
End Class
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pWindream As Windream)
|
||||
MyBase.New(pLogConfig)
|
||||
Database = pDatabase
|
||||
Windream = pWindream
|
||||
JobHistory = New JobHistory(pLogConfig)
|
||||
JobStatus = New JobStatus(pLogConfig)
|
||||
|
||||
_JobTypes = GetJobTypes()
|
||||
_JobDefinitions = GetJobDefinitions(_JobTypes)
|
||||
LoadData()
|
||||
End Sub
|
||||
|
||||
Public Sub Reload()
|
||||
_JobTypes = GetJobTypes()
|
||||
_JobDefinitions = GetJobDefinitions(_JobTypes)
|
||||
LoadData()
|
||||
End Sub
|
||||
|
||||
Private Sub LoadData()
|
||||
_JobTypes = GetJobTypes()
|
||||
_ObjectTypes = GetObjectTypes()
|
||||
|
||||
_JobDefinitions = GetJobDefinitions(_JobTypes)
|
||||
_ProfileDefintions.ImportProfiles = GetImportProfiles()
|
||||
End Sub
|
||||
|
||||
Private Function GetObjectTypes() As List(Of ObjectType)
|
||||
Dim oObjectTypes As New List(Of ObjectType)
|
||||
Try
|
||||
Logger.Info("Loading Windream Object Types..")
|
||||
Dim oObjectTypesNames = Windream.ObjectTypes
|
||||
Logger.Info("[{0}] Windream Object Types loaded!", oObjectTypes.Count)
|
||||
|
||||
For Each oObjectTypeName In oObjectTypesNames
|
||||
Dim oObjectType = New ObjectType With {
|
||||
.Name = oObjectTypeName,
|
||||
.Indexes = GetIndexesFor(oObjectTypeName)
|
||||
}
|
||||
oObjectTypes.Add(oObjectType)
|
||||
Next
|
||||
|
||||
Return oObjectTypes
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return oObjectTypes
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function GetIndexesFor(pObjectType As String) As List(Of String)
|
||||
Dim oIndexes As New List(Of String)
|
||||
Try
|
||||
Logger.Info("Loading Windream Indexes for [{0}]..", pObjectType)
|
||||
oIndexes = Windream.GetIndiciesByObjecttype(pObjectType)
|
||||
Logger.Info("[{0}] Windream Indexes loaded!", oIndexes.Count)
|
||||
|
||||
Return oIndexes
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return oIndexes
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function GetJobTypes() As List(Of JobType)
|
||||
Dim oTypes As New List(Of JobType)
|
||||
Try
|
||||
@@ -67,6 +119,44 @@ Public Class State
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function GetImportProfiles() As List(Of ImportProfile)
|
||||
Dim oProfiles As New List(Of ImportProfile)
|
||||
|
||||
Try
|
||||
Logger.Info("Loading 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!")
|
||||
Return oProfiles
|
||||
End If
|
||||
|
||||
Logger.Info("[{0}] 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", "")
|
||||
}
|
||||
|
||||
oProfiles.Add(oProfile)
|
||||
|
||||
Logger.Debug("Adding Profile for Folder [{0}]", oProfile.SourceFolder)
|
||||
Next
|
||||
|
||||
Return oProfiles
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return oProfiles
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function GetJobDefinitions(pJobTypes As List(Of JobType)) As List(Of JobDefinition)
|
||||
Dim oJobs As New List(Of JobDefinition)
|
||||
|
||||
@@ -92,7 +182,8 @@ Public Class State
|
||||
.Name = oRow.ItemEx("TITLE", ""),
|
||||
.Active = oRow.ItemEx("ACTIVE", 0),
|
||||
.CronSchedule = oRow.ItemEx("QUARTZ_DEF", "")
|
||||
}
|
||||
}
|
||||
|
||||
oJobs.Add(oJob)
|
||||
|
||||
Logger.Debug("Adding Job [{0}]", oJob.Name)
|
||||
|
||||
@@ -15,7 +15,11 @@ Public Class GetJobConfig
|
||||
Public Function Run() As GetJobConfigResponse
|
||||
Return New GetJobConfigResponse With {
|
||||
.JobTypes = State.JobTypes,
|
||||
.JobDefinitions = State.JobDefinitions
|
||||
.JobDefinitions = State.JobDefinitions,
|
||||
.ProfileDefinitions = New GetJobConfigResponse.ProfileDefinitionConfig With {
|
||||
.ImportProfiles = State.ProfileDefintions.ImportProfiles
|
||||
},
|
||||
.WindreamObjectTypes = State.ObjectTypes
|
||||
}
|
||||
End Function
|
||||
End Class
|
||||
@@ -26,8 +30,18 @@ Public Class GetJobConfig
|
||||
<DataMember>
|
||||
Public Property JobTypes As List(Of JobType)
|
||||
|
||||
<DataMember>
|
||||
Public Property WindreamObjectTypes As List(Of ObjectType)
|
||||
|
||||
<DataMember>
|
||||
Public Property JobDefinitions As List(Of JobDefinition)
|
||||
|
||||
<DataMember>
|
||||
Public Property ProfileDefinitions As New ProfileDefinitionConfig
|
||||
|
||||
Public Class ProfileDefinitionConfig
|
||||
Public Property ImportProfiles As List(Of ImportProfile)
|
||||
End Class
|
||||
End Class
|
||||
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user