Table of Contents

Class DirectoryScanJob

Namespace
Quartz.Jobs
Assembly
Quartz.Jobs.dll

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:

  1. Via dependency injection (recommended): Register the listener implementation in the DI container and specify its type name using DirectoryScanListenerName.
  2. 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

serviceProvider IServiceProvider

The container the listener is registered in.

timeProvider TimeProvider

The 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

timeProvider TimeProvider

The 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

string

DirectoryNames

public const string DirectoryNames = "DIRECTORY_NAMES"

Field Value

string

DirectoryProviderName

public const string DirectoryProviderName = "DIRECTORY_PROVIDER_NAME"

Field Value

string

DirectoryScanListenerName

public const string DirectoryScanListenerName = "DIRECTORY_SCAN_LISTENER_NAME"

Field Value

string

IncludeSubDirectories

public const string IncludeSubDirectories = "INCLUDE_SUB_DIRECTORIES"

Field Value

string

MinimumUpdateAge

public const string MinimumUpdateAge = "MINIMUM_UPDATE_AGE"

Field Value

string

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

string

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

context IJobExecutionContext

The IJobExecutionContext that the job will use during execution.

cancellationToken CancellationToken

The cancellation instruction.

Returns

ValueTask