UniCacheXML Service

Windows Service that generates XML cache files from UniData/AFTEC on a cron schedule. Provides offline data snapshots consumed by ProApps desktop applications.


Overview

PSI.UniCacheXml.Service (registered as PSIMonitorService) is a .NET Framework 4.8 Windows Service running on PS-WS3. It connects to the AFTEC ERP database on a configurable cron schedule and serializes query results into XML files on the network. ProApps and other consumers read these XML caches instead of hitting UniData directly for common lookup data.

Beyond cache generation, the service also handles email notifications, timesheet processing, and on-demand job requests.

Schedule.xml (cron triggers)
        │
        ▼
PSIMonitorService ──► UniData (MRP-PROD)
        │                    │
        │                    ▼
        │              Query results
        │                    │
        ▼                    ▼
  XML cache files ◄── Serialize to XML
        │
        ▼
  ProApps / consumers read cached XML
FeatureDescription
ServerPS-WS3
Service NamePSIMonitorService
Framework.NET Framework 4.8 (WinExe)
Service AccountLocal System (automatic start)
Version1.0.0.6
SchedulingNCrontab cron expressions in Schedule.xml
Logginglog4net → SQL database + email alerts

Source: C:\git\PSI.All\PSI.Shared\trunk\PSI.Windows.Services\PSI.Monitor.Service (in the PSI.All monorepo)


Cache Files Generated

The service generates 40+ XML cache files at varying frequencies. These are the primary data source for ProApps lookup fields, dropdowns, and list views.

Every 5 Minutes

FileData
RedBookList.xmlActive Redbook/RFC records
ServiceTicketList.xmlService tickets
EngChgList.xmlEngineering change notices

Every 15 Minutes

FileData
VendorList.xmlVendor master list

Every 30 Minutes

FileData
Contact1287List.xmlContact records
EmployeePublic1287List.xmlEmployee directory
ShipToList.xmlShip-to addresses
Account1287List.xmlCustomer accounts
SPN1287List.xmlSPN records
EmailXrefList.xmlEmail cross-references
QuoteHeadList.xmlQuote headers
NCNChangeList.xmlNon-conformance changes
InvoiceList.xmlInvoices

Hourly

FileData
JobMaster1287List.xmlJob master records
Project1287List.xmlProject records
TMFList.xmlTMF data
Customer1287List.xmlCustomer master
FOBList.xmlFOB terms
IndustryClassList.xmlIndustry classifications
DispatchFocusCache.xmlDispatch priority focus

Every 4 Hours

FileData
FreightList.xmlFreight records

Daily (Midnight)

FileData
CountryList.xmlCountry codes
EntityTypeList.xmlEntity types
StateList.xmlState/province codes
CWOXREFList.xmlCost center / work order cross-ref
COCEList.xmlCost centers
MarketSourceList.xmlMarket sources
PriceCat1287List.xmlPrice categories
PTIPositionList.xmlPTI positions
IndustrySectorList.xmlIndustry sectors
CustomerAcctTypeList.xmlCustomer account types
PartTypeList.xmlPart types
ProcessTypeList.xmlProcess types
MachineTypeList.xmlMachine types
SPNPositionList.xmlSPN positions
SPNStatusList.xmlSPN statuses
MachineProcessTypeList.xmlMachine process types
SPNReasonList.xmlSPN reasons
CompetitorList.xmlCompetitors
ProjectSalesOrdersList.xmlProject sales orders
ProjectStatusList.xmlProject statuses
SPNQuoteList.xmlSPN quotes

Multiple Times Daily

FileSchedule
WO Cache Files5:30 AM, 9:30 AM, 12:30 PM, 2:30 PM, 4:30 PM, 5:30 PM

Additional Functions

Beyond XML cache generation, the service handles several other tasks:

Email Notifications

  • Reads pending notifications from UniData
  • Resolves Active Directory usernames to email addresses
  • Sends HTML emails with To/CC/BCC and file attachments via SMTP
  • Updates notification status in database after sending

Timesheet Processing

  • Check for Emailed Time Sheets — monitors for emailed timesheet submissions
  • Send Missing Time Sheet Email — sends reminders on weekdays at 7:30 AM and 7:30 PM

Job Requests

External systems can trigger on-demand tasks by dropping .rqst files into the job requests directory:

  • File format: Line 1 = Title="<schedule_title>", Line 2 = requestor
  • Processing: Up to 5 requests in parallel (MaxDegreeOfParallelism = 5)
  • Lifecycle: Service updates the file with status/result, then moves it to History/

Custom UD Commands

The UD Command task type allows executing arbitrary UniData SQL queries and exporting results to XML — useful for ad-hoc data extracts.


Scheduling

Cron Format

Tasks are defined in Schedule.xml using standard 5-field NCrontab cron expressions:

minute  hour  day-of-month  month  day-of-week

Example: 30 5,9,12,14,16,17 * * * = 5:30 AM, 9:30 AM, 12:30 PM, 2:30 PM, 4:30 PM, 5:30 PM daily.

Hot Reload

A FileSystemWatcher monitors Schedule.xml. Editing the file reinitializes all timers without restarting the service.

Immediate Execution

Tasks can be flagged with Immediately="true" in the schedule XML to run once on service startup.

Backup Window

Tasks automatically skip the 3:25 AM – 4:00 AM window to avoid conflicts with nightly AFTEC database backups. This window is hardcoded in the service.


Architecture

WCF Service Clients

The service uses three lazy-initialized WCF clients:

ClientServicePurpose
WOClientWOServiceWork order cache operations
TimeSheetClientTimeSheetServiceTimesheet email processing
DataClientDataServiceGeneral data queries and XML export

These services inherit from BaseService and use FileBasedCache.Serialize() and BaseController.GetRawData() for data retrieval and XML serialization.

Database Connection

  • Database: UniData on MRP-PROD (AFTEC ERP)
  • Session: UDSessionController with credentials from EnvironmentConstants
  • Cache paths: Configured via EnvironmentConstants.CacheFileReadPath / CacheFileWritePath

Thread Safety

  • ConcurrentDictionary tracks currently running tasks
  • Same task cannot run concurrently (skipped if already running)
  • Each scheduled task runs on its own System.Timers.Timer

Logging & Error Handling

log4net Configuration

AppenderLevelTarget
AdoNetAppenderDEBUG+SQL database (thread, level, logger, message, exception, user, PC)
SMTPAppenderERROR, FATALEmail alert to ops team

Fatal Error Recovery

  • Top-level exception handler exits with code 1
  • OS service recovery restarts the service automatically
  • On startup, clears any stale “Running” status flags from previous crash

Configuration Files

FilePurpose
Schedule.xmlProduction cron schedule (hot-reloadable)
Schedule.Debug.xmlDevelopment schedule
Config/App.Debug.configDebug environment settings
Config/App.Beta.configBeta environment settings
Config/App.Release.configProduction environment settings
Config/App.Sandbox.configSandbox environment settings

Dependencies

DependencyPurpose
NCrontab 3.3.3Cron expression parsing
log4netStructured logging
PSI.UniSessionManagerUniData session management
PSI.Common.ModelsShared data models
PSI.CommonShared utilities
PSI.Task.ModelTask tracking models


Last updated: March 2026