110 lines
3.0 KiB
VB.net
110 lines
3.0 KiB
VB.net
Imports ECM.JobRunner.Windows.Scheduler.Jobs
|
|
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)
|
|
|
|
Try
|
|
Logger.Info("Running File Import [{0}]", Name)
|
|
|
|
Dim oProfile = State.ProfileDefintions.ImportProfiles.Where(Function(p) p.JobId = Id).SingleOrDefault()
|
|
|
|
Dim oSourceDirectory As String = oProfile.SourceFolder
|
|
Dim oRecursive As Boolean = oProfile.IncludeSubfolders
|
|
Dim oFiles = GetFiles(oSourceDirectory, oRecursive)
|
|
|
|
If oFiles.Count = 0 Then
|
|
Logger.Info("No Files for Profile [{0}]", Name)
|
|
Return Task.FromResult(True)
|
|
End If
|
|
|
|
'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
|
|
|
|
End Namespace
|