๐Ÿ“’ Documentation: IrbyImaging.BusinessLogic/Jobs/Reminders.cs


๐Ÿ“‘ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. UML Class Diagram
  4. Key Functional Areas
  5. Class, Constructors & Methods
  6. Helper Methods & Utilities
  7. Error Handling & Return Types
  8. Integration with Quartz.NET
  9. Sample Usage & Code Snippets
  10. Conclusion

1. Overview & Purpose

The Reminders class is part of the IrbyImaging.BusinessLogic.Jobs namespace and implements the Quartz.IJob interface. Its primary purpose is to:

  • Act as a scheduled job using Quartz.NET
  • Log execution details into a text file located under wwwroot/Quartz/Logs.txt
  • Serve as a template for any future reminder-based background tasks

๐ŸŽฏ Use Case: You might schedule this job to run at fixed intervals (e.g., daily at 8ย AM) to trigger reminder notifications or housekeeping tasks.


2. Dependencies & Technologies

Layer / Component Technology / Package
Background Jobs Quartz.NET
.NET Core Hosting IServiceProvider (for dependency injection)
File I/O System.IO (Directory, FileStream, StreamWriter)
Asynchronous Tasks System.Threading.Tasks

3. UML Class Diagram

classDiagram
    direction TB
    class Reminders {
        - IServiceProvider _provider
        + Reminders(IServiceProvider provider)
        + Task Execute(IJobExecutionContext context)
        + void Logs(string message)
    }
    Reminders ..|> IJob

4. Key Functional Areas

  1. Job Initialization
    • Injects an IServiceProvider for future service resolutions
  2. Job Execution
    • Implements Execute(IJobExecutionContext)
    • Writes a timestamped log entry to disk
  3. Logging Utility
    • Creates a folder wwwroot/Quartz if missing
    • Overwrites Logs.txt with the latest message

5. Class, Constructors & Methods

Class: Reminders

public class Reminders : IJob
{
    private readonly IServiceProvider _provider;

    public Reminders(IServiceProvider provider) { /*...*/ }
    public Task Execute(IJobExecutionContext context) { /*...*/ }
    public void Logs(string message) { /*...*/ }
}
Member Type Description
_provider IServiceProvider A DI container reference (reserved for future expansions).
Reminders(...) Constructor Sets the _provider field.
Execute(context) Task Entry-point invoked by Quartzโ€”writes a log and returns a completed task.
Logs(message) void Utility to write message into wwwroot/Quartz/Logs.txt.

6. Helper Methods & Utilities

๐Ÿ“‹ Logs(string message)

Writes timestamped or custom messages to a static file:

public void Logs(string message)
{
    var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Quartz");

    if (!Directory.Exists(path))
        Directory.CreateDirectory(path);

    path = Path.Combine(path, "Logs.txt");

    using FileStream fstream = new FileStream(path, FileMode.Create);
    using TextWriter writer = new StreamWriter(fstream);
    writer.WriteLine(message);
}
  • Directory.CreateDirectory: Ensures the Quartz folder exists under wwwroot.
  • FileMode.Create: Creates or overwrites Logs.txt on each run.

7. Error Handling & Return Types

Method Return Type Error Handling
Execute(...) Task Relies on Quartz job exception propagation.
Logs(...) void No explicit try/catchโ€”exceptions bubble up.

Note: For production readiness, consider wrapping file I/O in try/catch and log failures to a fallback or external monitoring service.


8. Integration with Quartz.NET

8.1. Registering the Job

services.AddQuartz(q =>
{
    q.UseMicrosoftDependencyInjectionJobFactory();
    q.ScheduleJob<Reminders>(trigger => trigger
        .WithIdentity("RemindersTrigger")
        .StartNow()
        .WithSimpleSchedule(x => x
            .WithIntervalInHours(24)
            .RepeatForever()
        )
    );
});
services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true);

8.2. Trigger Definition

  • Trigger Identity: RemindersTrigger
  • Schedule: Runs immediately and repeats every 24ย hours indefinitely

9. Sample Usage & Code Snippets

9.1. Scheduling Reminders Job

// In Startup.cs or Program.cs
public void ConfigureServices(IServiceCollection services)
{
    // Quartz & DI
    services.AddQuartz(...);
    services.AddQuartzHostedService(...);

    // Register Reminders
    services.AddTransient<Reminders>();
}

9.2. Customizing the Log Message

public Task Execute(IJobExecutionContext context)
{
    var userCount = GetPendingUserCount(); // hypothetical service from _provider
    var msg = $"{DateTime.Now} [Pending Users: {userCount}]";
    Logs(msg);
    return Task.CompletedTask;
}

10. Conclusion

โœจ Reminders.cs provides a lightweight, extensible Quartz.NET job template. It demonstrates:

  • Dependency Injection via IServiceProvider
  • Asynchronous Scheduling with IJob.Execute
  • Simple File Logging under wwwroot/Quartz/Logs.txt

You can extend it to send emails, push notifications, or perform any recurring background work by resolving and invoking additional services within the Execute method. Happy scheduling! ๐Ÿš€


End of Documentation