93 lines
5.5 KiB
Markdown
93 lines
5.5 KiB
Markdown
---
|
|
source_files:
|
|
- Common/DTS.Common.DBSyncService/ProjectInstaller.cs
|
|
- Common/DTS.Common.DBSyncService/Program.cs
|
|
- Common/DTS.Common.DBSyncService/DBSyncService.Designer.cs
|
|
- Common/DTS.Common.DBSyncService/DBSyncService.cs
|
|
- Common/DTS.Common.DBSyncService/ProjectInstaller.Designer.cs
|
|
generated_at: "2026-04-16T11:31:44.939659+00:00"
|
|
model: "zai-org/GLM-5-FP8"
|
|
schema_version: 1
|
|
sha256: "5d52988c06d02137"
|
|
---
|
|
|
|
# Documentation: DTS.Common.DBSyncService
|
|
|
|
## 1. Purpose
|
|
|
|
This module implements a Windows Service skeleton for database synchronization operations. It provides the foundational infrastructure for running as a Windows Service, including installation support via `ProjectInstaller`, event logging capabilities, a configurable monitoring timer, and custom command handling. The service is designed to perform periodic monitoring activities and respond to custom commands, though the actual synchronization logic is not yet implemented (marked with TODO comments).
|
|
|
|
---
|
|
|
|
## 2. Public Interface
|
|
|
|
### `DBSyncService` (class)
|
|
**Inherits from:** `System.ServiceProcess.ServiceBase`
|
|
|
|
The main Windows Service implementation.
|
|
|
|
| Member | Signature | Description |
|
|
|--------|-----------|-------------|
|
|
| Constructor | `public DBSyncService()` | Initializes the service, configures event logging from `Settings.Default`, and optionally starts a monitoring timer if `Settings.Default.Monitoring` is enabled. |
|
|
| `OnTimer` | `public void OnTimer(object sender, ElapsedEventArgs args)` | Timer callback that writes an informational entry "Monitoring the System" to the event log. |
|
|
| `OnStart` | `protected override void OnStart(string[] args)` | Called when the service starts; logs "{ServiceName} started" to the event log. |
|
|
| `OnStop` | `protected override void OnStop()` | Called when the service stops; logs "{ServiceName} stopped" to the event log. |
|
|
| `OnCustomCommand` | `protected override void OnCustomCommand(int command)` | Handles custom service commands; currently contains empty switch cases for defined commands. |
|
|
| `CustomCommands` | `public enum CustomCommands` | Defines custom command identifiers: `SyncDb = 128`, `Command2 = 129`, `Command3 = 130`. |
|
|
| `eventLog` | `public System.Diagnostics.EventLog eventLog` | Public field for event logging (defined in designer partial). |
|
|
|
|
### `ProjectInstaller` (class)
|
|
**Inherits from:** `System.Configuration.Install.Installer`
|
|
|
|
Provides installation support for the Windows Service.
|
|
|
|
| Member | Signature | Description |
|
|
|--------|-----------|-------------|
|
|
| Constructor | `public ProjectInstaller()` | Initializes the installer via `InitializeComponent()`. |
|
|
|
|
### `Program` (static class)
|
|
Application entry point.
|
|
|
|
| Member | Signature | Description |
|
|
|--------|-----------|-------------|
|
|
| `Main` | `static void Main()` | Creates a `DBSyncService` instance and runs it via `ServiceBase.Run()`. |
|
|
|
|
---
|
|
|
|
## 3. Invariants
|
|
|
|
1. **Event Source Creation**: If the event source specified by `Settings.Default.ServiceName` does not exist, it will be created in the constructor with log name from `Settings.Default.Service`.
|
|
|
|
2. **Timer Behavior**: The monitoring timer is only instantiated and started if `Settings.Default.Monitoring` evaluates to `true`. The interval is determined by `Settings.Default.Interval` (default noted as 60 seconds in comments).
|
|
|
|
3. **Custom Command Range**: Custom commands use values starting at 128 (`SyncDb`), which is within the valid range for custom Windows Service commands (128-255).
|
|
|
|
4. **Service Name Consistency**: The service name "DBSyncService" is set in `ProjectInstaller.Designer.cs` via `DBSyncServiceInstaller.ServiceName`. Note: `DBSyncService.Designer.cs` sets `this.ServiceName = "Service1"`, which appears to be a designer default that may be overridden.
|
|
|
|
---
|
|
|
|
## 4. Dependencies
|
|
|
|
### This module depends on:
|
|
- `System.ServiceProcess` - Windows Service infrastructure (`ServiceBase`, `ServiceInstaller`, `ServiceProcessInstaller`)
|
|
- `System.Diagnostics` - Event logging (`EventLog`, `EventLogEntryType`)
|
|
- `System.Timers` - Timer for periodic monitoring
|
|
- `System.Configuration.Install` - Service installation framework (`Installer`, `RunInstallerAttribute`)
|
|
- `DTS.Common.DBSyncService.Properties` - Application settings (`Settings.Default`)
|
|
|
|
### What depends on this module:
|
|
- Cannot be determined from source alone. This appears to be a top-level executable service.
|
|
|
|
---
|
|
|
|
## 5. Gotchas
|
|
|
|
1. **Unimplemented Logic**: The `OnTimer` method contains a TODO comment: `// TODO: Insert monitoring activities here.` The actual synchronization/monitoring logic is not implemented.
|
|
|
|
2. **Empty Custom Command Handlers**: All three custom commands (`SyncDb`, `Command2`, `Command3`) have empty switch case bodies in `OnCustomCommand`. They are defined but perform no actions.
|
|
|
|
3. **Timer Lifetime Issue**: The `Timer` instance in the constructor is a local variable. If no other reference is maintained, it could be eligible for garbage collection, which would stop the timer. The timer should be stored as a class field.
|
|
|
|
4. **Service Name Mismatch**: `DBSyncService.Designer.cs` sets `this.ServiceName = "Service1"` (default designer value), while `ProjectInstaller.Designer.cs` sets `DBSyncServiceInstaller.ServiceName = "DBSyncService"`. The actual runtime service name comes from `Settings.Default.ServiceName`, making the designer value potentially misleading.
|
|
|
|
5. **Early Return in Constructor**: If `Settings.Default.Monitoring` is `false`, the constructor returns early, skipping timer setup. This is intentional but could cause confusion if monitoring is expected but not configured. |