Class DirectoryScanJob
Inspects a directory and compares whether any files' "last modified dates" have changed since the last time it was inspected. If one or more files have been updated (or created), the job invokes a "call-back" method on an identified IDirectoryScanListener that can be resolved from dependency injection or found in the SchedulerContext.
public class DirectoryScanJob : IJob
- Inheritance
-
DirectoryScanJob
- Implements
- Inherited Members
Remarks
What is scanned is configured through the job data keys below. DirectoryScanOptions names them all, and UsingDirectoryScanOptions<TConfigurator>(TConfigurator, DirectoryScanOptions) writes them, so the settings can be given as a value rather than as string keys; the keys stay the persisted form either way.
The listener can be provided in two ways:
- Via dependency injection (recommended): Register the listener implementation in the DI container and specify its type name using DirectoryScanListenerName.
- Via SchedulerContext (legacy): Store the listener instance in the SchedulerContext with a key matching the value specified in DirectoryScanListenerName.
Constructors
DirectoryScanJob(IServiceProvider, TimeProvider?)
Initializes a new instance of the DirectoryScanJob class that resolves its IDirectoryScanListener from the container.
public DirectoryScanJob(IServiceProvider serviceProvider, TimeProvider? timeProvider = null)
Parameters
serviceProviderIServiceProviderThe container the listener is registered in.
timeProviderTimeProviderThe clock deciding how recently a file must have been written to still count as being written to. null takes System.
DirectoryScanJob(TimeProvider?)
Initializes a new instance of the DirectoryScanJob class.
public DirectoryScanJob(TimeProvider? timeProvider = null)
Parameters
timeProviderTimeProviderThe clock deciding how recently a file must have been written to still count as being written to. null takes System.
Fields
DirectoryName
public const string DirectoryName = "DIRECTORY_NAME"
Field Value
DirectoryNames
public const string DirectoryNames = "DIRECTORY_NAMES"
Field Value
DirectoryProviderName
public const string DirectoryProviderName = "DIRECTORY_PROVIDER_NAME"
Field Value
DirectoryScanListenerName
public const string DirectoryScanListenerName = "DIRECTORY_SCAN_LISTENER_NAME"
Field Value
IncludeSubDirectories
public const string IncludeSubDirectories = "INCLUDE_SUB_DIRECTORIES"
Field Value
MinimumUpdateAge
public const string MinimumUpdateAge = "MINIMUM_UPDATE_AGE"
Field Value
SearchPattern
JobDataMap key with which to specify the search string to match against the
names of files. Can contain a combination of valid literal path and wildcard (* and ?)
characters. Defaults to *, every file.
public const string SearchPattern = "SEARCH_PATTERN"
Field Value
Methods
Execute(IJobExecutionContext, CancellationToken)
This is the main entry point for job execution. The scheduler will call this method on the job once it is triggered.
public ValueTask Execute(IJobExecutionContext context, CancellationToken cancellationToken = default)
Parameters
contextIJobExecutionContextThe IJobExecutionContext that the job will use during execution.
cancellationTokenCancellationTokenThe cancellation instruction.