---
title: PdfTrackingService
summary: API reference for PdfTrackingService.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-24
library: SAIF.Services
reference_type: package
---

# PdfTrackingService

Implements `IPdfTrackingService`, providing lookup of PDF tracking/status/application/processing code records via `IUnitOfWork`, and a folder-and-database purge routine that deletes expired PDF working directories (and, per commented-out code, optionally their database records) based on `IEnvironmentService`'s `pdfDataDirectory` setting. Registers its own AutoMapper maps for the PDF tracking data-model-to-contract conversions in its constructor.

## Purpose
- Retrieves PDF tracking records by file ID or numeric ID, and resolves status/application/processing code lookups.
- Identifies and purges expired PDF tracking folders (and, when uncommented, their corresponding database rows) older than a cutoff date, optionally scoped to an application type.
- Removes orphaned PDF working folders that no longer have a matching database tracking record.
- Provides a static cutoff-date normalization helper.

## Context
- Namespace: `SAIF.Services.Utilities.Pdf`
- Assembly/package: `SAIF.Services` (packaged inside the `SAIF.SAIFCode.Core` NuGet package)

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| PdfTrackingService(...) | `public PdfTrackingService(IEnvironmentService envSvc, IUnitOfWork uow, bool verbose = false)` | Stores the environment and unit-of-work collaborators, sets verbose logging, and registers the AutoMapper maps for PDF tracking/status/application/processing types. |
| GetTrackingInfo(fileId) | `public PdfTracking GetTrackingInfo(Guid fileId)` | Returns the tracking record whose `FileId` case-insensitively matches `fileId`, mapped to the `PdfTracking` contract. |
| GetTrackingInfo(id) | `public PdfTracking GetTrackingInfo(long id)` | Returns the tracking record with the given numeric `id`, mapped to the `PdfTracking` contract. |
| GetStatusType | `public PdfStatusType GetStatusType(PdfStatusTypes type)` | Returns the `PdfStatusType` whose description matches `type`'s name, case-insensitively. |
| GetApplicationType(type) | `public PdfApplicationType GetApplicationType(PdfApplicationTypes type)` | Returns the `PdfApplicationType` whose code matches `type`'s name, case-insensitively. |
| GetApplicationType(code) | `public PdfApplicationType GetApplicationType(string code)` | Returns the `PdfApplicationType` whose code case-insensitively matches `code`. |
| GetProcessingType | `public PdfProcessingType GetProcessingType(PdfProcessingTypes type)` | Returns the `PdfProcessingType` whose description matches `type`'s name, case-insensitively. |
| Purge(cutoffDate, fileId, commit) | `public void Purge(DateTime cutoffDate, Guid fileId, bool commit = true)` | Loads the single tracking record eligible for purge before `cutoffDate` matching `fileId` and purges its working folders (deleting from disk only when `commit` is true). |
| Purge(cutoffDate, appType, commit) | `public void Purge(DateTime cutoffDate, PdfApplicationType appType = null, bool commit = true)` | Loads all tracking records eligible for purge before `cutoffDate` (optionally filtered by `appType`) and purges each one's working folders, previewing rather than deleting when `commit` is false. |
| GetCutoffDate | `public static DateTime GetCutoffDate(DateTime? cutoffDate)` | Returns `cutoffDate`, or the current time if null or in the future, clamping purge cutoffs to "now or earlier". |

## Behavioral notes
- `Purge` operates in two phases: purge matching folders on disk (`PurgeFolders`), then (currently commented out) purge the eligible database records themselves — meaning the current build only removes folders, not tracking rows*.
- `PurgeFolder` swallows and logs any exception from `Directory.Delete` rather than propagating it, so a locked or in-use folder does not abort the overall purge run.
- The orphaned-folder cleanup path (`PurgeOrphanedFolders`, invoked from commented-out "step 3" code) is currently unreachable from the public `Purge` overloads*.
- Registers module-level AutoMapper maps for `PDFApplicationErrorCode`, `PDFTrackingCode`, `PDFStatusCode`, and `PDFTracking` in the constructor via `CreateMappings()`, meaning creating multiple instances re-registers the same static AutoMapper configuration*.

> **Note:** Statements marked with * were inferred from code structure, naming conventions, or
> contextual evidence where direct confirmation was not available in source artifacts. Statements
> marked with ** could not be confirmed; treat as unknown until verified.

## Sources
- Services/SAIF.Services/Utilities/Pdf/PdfTrackingService.cs
