Passa al contenuto principale

Class Orchestrator

Namespace: TecnoPack.Scheduler
Assembly: CO0002_Templ_FlowpackHMI_V00_26_M.dll

Provides a high-level interface for scheduling and managing jobs using Quartz.NET, including database persistence with SQLite, initialization, and event retrieval.

public static class Orchestrator

Inheritance

object ← Orchestrator

Remarks

This class manages the lifecycle of a single Quartz.NET scheduler instance, ensures platform-specific SQLite libraries are available, and provides helper methods for querying scheduled events within a time range.

Properties

Scheduler

Gets the active Quartz.NET scheduler instance.

public static IScheduler Scheduler { get; }

Property Value

IScheduler

Methods

EnsureInitilization()

Ensures that the scheduler has been initialized and throws an exception if it has not.

public static void EnsureInitilization()

Exceptions

InvalidOperationException

Thrown if has not been called before using the scheduler.

GetEventsByTimeRangeSql(DateTime, DateTime)

Retrieves all scheduled events within a specified time range from the Quartz.NET SQLite database.

public static Task<EventModelDTO[]> GetEventsByTimeRangeSql(DateTime startDate, DateTime endDate)

Parameters

startDate DateTime

The start of the time range for which events should be retrieved. Times are converted to UTC internally.

endDate DateTime

The end of the time range for which events should be retrieved. Times are converted to UTC internally.

Returns

Task<EventModelDTO[]>

An array of representing all events that start, end, or span any portion of the given time range.
If no events are found, an empty array is returned.

Examples

DateTime start = new DateTime(2026, 1, 12, 0, 0, 0);
DateTime end = new DateTime(2026, 1, 12, 23, 59, 59);
EventModelDTO[] events = await Orchestrator.GetEventsByTimeRangeSql(start, end);
foreach (var ev in events)
{
Console.WriteLine($"Event {ev.Id} from {ev.StartTime} to {ev.EndTime}");
}

Remarks

The method executes a SQL query against the Quartz.NET tables QRTZ_TRIGGERS and QRTZ_JOB_DETAILS, filtering events whose start or end times intersect the specified range. Job data is stored in a binary blob and is deserialized into a dictionary to extract the eventModel JSON string, which is then deserialized into objects.

All times are converted to UTC ticks for comparison, ensuring consistency across time zones. Only events that have valid eventModel entries are returned; any jobs without this key are skipped.

InitializeAsync()

Initializes the Quartz.NET scheduler, installs necessary SQLite libraries for the platform, and configures a persistent store using the project database.

public static Task InitializeAsync()

Returns

Task

Remarks

Must be called once at application startup before scheduling or starting any jobs. Initializes the default thread pool with maximum concurrency of 1, enables persistent storage, and uses JSON serialization for job data.

StartAsync()

Starts the Quartz.NET scheduler, allowing it to begin executing jobs.

public static Task StartAsync()

Returns

Task

Remarks

Ensures that has been called before starting.

StopAsync()

Stops the Quartz.NET scheduler, preventing further job execution.

public static Task StopAsync()

Returns

Task

Remarks

Safely shuts down the scheduler if it has been initialized. Does nothing if the scheduler is null.

  • Remarks
  • Properties
    • Scheduler
  • Methods
    • EnsureInitilization()
    • GetEventsByTimeRangeSql(DateTime, DateTime)
    • InitializeAsync()
    • StartAsync()
    • StopAsync()