124 lines
10 KiB
Markdown
124 lines
10 KiB
Markdown
|
|
---
|
||
|
|
source_files:
|
||
|
|
- DataPRO/Modules/DatabaseImporter/DatabaseImport/Classes/TestTemplate/ICachedContainer.cs
|
||
|
|
- DataPRO/Modules/DatabaseImporter/DatabaseImport/Classes/TestTemplate/HardwareInclusionInstruction.cs
|
||
|
|
- DataPRO/Modules/DatabaseImporter/DatabaseImport/Classes/TestTemplate/TestTemplateLite.cs
|
||
|
|
- DataPRO/Modules/DatabaseImporter/DatabaseImport/Classes/TestTemplate/RegionOfInterest.cs
|
||
|
|
- DataPRO/Modules/DatabaseImporter/DatabaseImport/Classes/TestTemplate/TestTemplateList.cs
|
||
|
|
generated_at: "2026-04-16T04:32:24.918567+00:00"
|
||
|
|
model: "Qwen/Qwen3-Coder-Next-FP8"
|
||
|
|
schema_version: 1
|
||
|
|
sha256: "d58cccdbb5baf57a"
|
||
|
|
---
|
||
|
|
|
||
|
|
# Documentation: TestTemplate Module
|
||
|
|
|
||
|
|
## 1. Purpose
|
||
|
|
This module provides foundational data structures and utilities for representing and manipulating test templates within the DatabaseImporter subsystem. It defines lightweight and extensible models for test configurations (e.g., `TestTemplateLite`), hardware inclusion/exclusion rules (`HardwareInclusionInstruction`), time-domain regions of interest (`RegionOfInterest`), and a caching interface (`ICachedContainer`) for hardware lookups. It also includes helper methods in `TestTemplateList` for serializing/deserializing sensor settings and managing system-wide test template state. The module exists to decouple test template representation from full database persistence, enabling in-memory manipulation, validation, and deferred commit—particularly useful during test import workflows where DAS hardware may be excluded via group-based rules (e.g., for "DASless" tests).
|
||
|
|
|
||
|
|
## 2. Public Interface
|
||
|
|
|
||
|
|
### `ICachedContainer` (Interface)
|
||
|
|
- **`DASHardware GetCachedHardware(string serialNumber)`**
|
||
|
|
Retrieves a cached `DASHardware` instance by serial number. Returns `null` if not found (behavior inferred from usage context).
|
||
|
|
- **`IISOHardware[] GetAllCachedHardware()`**
|
||
|
|
Returns all cached hardware items as an array of `IISOHardware`.
|
||
|
|
|
||
|
|
### `HardwareInclusionInstruction` (Class)
|
||
|
|
- **Constructor `HardwareInclusionInstruction(string hardwareId, Actions action)`**
|
||
|
|
Initializes a new instruction to add or remove hardware from a test, overriding group-derived inclusion.
|
||
|
|
- `hardwareId`: Identifier for the hardware item (e.g., serial number).
|
||
|
|
- `action`: Either `Actions.Remove` (exclude despite group membership) or `Actions.Add` (include despite absence from groups).
|
||
|
|
- **Properties**
|
||
|
|
- `HardwareId`: Read-only string identifier.
|
||
|
|
- `Action`: Read-only `Actions` enum value (`Remove` or `Add`).
|
||
|
|
|
||
|
|
### `TestTemplateLite` (Class)
|
||
|
|
- **Properties**
|
||
|
|
- `Name`: `string` — Name of the test template.
|
||
|
|
- `Description`: `string` — Optional description (defaults to `""`).
|
||
|
|
- `RecordingMode`: `RecordingModes` — Determines pre-trigger behavior.
|
||
|
|
- `PreTriggerSeconds`: `double` —
|
||
|
|
- Returns `0` for `Recorder` or `HybridRecorder` modes.
|
||
|
|
- Returns stored `_preTriggerSeconds` for `CircularBuffer` or other modes.
|
||
|
|
- Setter updates `_preTriggerSeconds` unconditionally.
|
||
|
|
- `ErrorMessage`: `string` — Raw error message (defaults to `string.Empty`).
|
||
|
|
- `CompletionErrorMessage`: `string` — Truncated error message (max 250 chars).
|
||
|
|
- `PostTriggerSeconds`: `double` — Post-trigger duration.
|
||
|
|
- `LastModified`: `DateTime` — Timestamp of last modification.
|
||
|
|
- `LastModifiedBy`: `string` — User who last modified the template.
|
||
|
|
- `IsComplete`: `bool` — Indicates if the template is fully configured.
|
||
|
|
|
||
|
|
### `RegionOfInterest` (Class)
|
||
|
|
- **Constructors**
|
||
|
|
- `RegionOfInterest()` — Default: `Suffix=""`, `Start=-1`, `End=1`, `IsEnabled=true`, `IsDefault=true`.
|
||
|
|
- `RegionOfInterest(bool isDefault)` — Sets `IsDefault`.
|
||
|
|
- `RegionOfInterest(string suffix, bool isDefault, double start, double end)` — Full initialization.
|
||
|
|
- **Properties**
|
||
|
|
- `Suffix`: `string` — Auto-normalized to start with `_` (e.g., `"foo"` → `"_foo"`; `""` remains `""`).
|
||
|
|
- `Start`: `double` — Clamped to `[PreTrigger, End - 0.01]`.
|
||
|
|
- `End`: `double` — Clamped to `[Start + 0.01, PostTrigger]`.
|
||
|
|
- `PreTrigger`: `double` — Setter updates `Start` if `Start < PreTrigger`.
|
||
|
|
- `PostTrigger`: `double` — Setter updates `End` if `End > PostTrigger`.
|
||
|
|
- `IsEnabled`: `bool` — Default `true`.
|
||
|
|
- `IsDefault`: `bool` — Read-only; set only via constructor.
|
||
|
|
- **Events**
|
||
|
|
- `PropertyChanged`: Implements `INotifyPropertyChanged` for UI binding.
|
||
|
|
|
||
|
|
### `TestTemplateList` (Class)
|
||
|
|
- **Static Properties**
|
||
|
|
- `TestTemplatesList`: Singleton instance (thread-safe via `lock`).
|
||
|
|
- **Instance Properties**
|
||
|
|
- `TemporaryTemplate`: `TestTemplate` — Holds a template in memory without DB persistence.
|
||
|
|
- **Static Methods**
|
||
|
|
- `GetSensorFromSettings(string settings, string serial, Dictionary<string, SensorData> lookup)`:
|
||
|
|
Parses `settings` (comma-separated `key=value` pairs) to populate a `SensorData` object. Falls back to `SensorsCollection.SensorsList.GetSensorBySerialNumber(serial)` if `lookup` is `null` or missing `serial`. Returns `null` if `serial` is null/empty or no `SensorData` found.
|
||
|
|
- `GetSensorFromSettings(string settings, string serial)`: Overload with `lookup=null`.
|
||
|
|
- `GetSensorSettings(SensorData sd)`: Serializes `sd` into a comma-separated `key=value` string. Only includes settings with non-default values (e.g., omits `Delay` if `DelayMS` is `0`).
|
||
|
|
- `SysBuiltObject(string serialNumber)`: Calls stored procedure `sp_TestObjectsGet` to determine if `serialNumber` corresponds to a system-built test object. Returns `bool`.
|
||
|
|
- `ConvertToDictionary(DataTable dt, ref Dictionary<string, List<Dictionary<string, object>>> lookup, string key)`: Populates `lookup` by grouping `dt` rows on `key`. Each row becomes a `Dictionary<string, object>` of column values.
|
||
|
|
- **Instance Methods**
|
||
|
|
- `Reload()`: Refreshes all related data collections (ISO DB, sensors, DAS hardware, etc.) and calls `Load()` (currently a no-op).
|
||
|
|
- `DeleteAll()`: Executes stored procedure `sp_TestSetupsDeleteAll` to clear all test setups. Handles output parameters for error info (logging suppressed in source).
|
||
|
|
|
||
|
|
## 3. Invariants
|
||
|
|
- **`RegionOfInterest`**:
|
||
|
|
- `Start < End` always holds (enforced via setter clamping).
|
||
|
|
- `Start ≥ PreTrigger` and `End ≤ PostTrigger` always hold (enforced via setter clamping and `PreTrigger`/`PostTrigger` setters).
|
||
|
|
- `Suffix` is normalized to start with `_` if non-empty and non-whitespace.
|
||
|
|
- **`TestTemplateLite`**:
|
||
|
|
- `PreTriggerSeconds` is `0` for `Recorder`/`HybridRecorder` modes regardless of stored `_preTriggerSeconds`.
|
||
|
|
- `CompletionErrorMessage` truncates `ErrorMessage` to 250 characters if longer.
|
||
|
|
- **`HardwareInclusionInstruction`**:
|
||
|
|
- `HardwareId` is never `null` or empty (enforced by constructor).
|
||
|
|
- **`TestTemplateList`**:
|
||
|
|
- `TestTemplatesList` is a singleton (lazy-initialized under lock).
|
||
|
|
- `GetSensorFromSettings` returns `null` if `serial` is null/empty or no matching sensor exists.
|
||
|
|
|
||
|
|
## 4. Dependencies
|
||
|
|
### Internal Dependencies
|
||
|
|
- **`DatabaseImport` namespace**: All types are internal to this module.
|
||
|
|
- **`ISO.TestObject.SensorSettings`**: Used in `GetSensorFromSettings`/`GetSensorSettings` (enum values drive parsing/serialization).
|
||
|
|
- **`SensorData`**: Core data type for sensor configuration (used in `GetSensorFromSettings`, `GetSensorSettings`).
|
||
|
|
- **`DASHardware`, `IISOHardware`**: Referenced in `ICachedContainer` (concrete types not defined in provided sources).
|
||
|
|
- **`RecordingModes`**: Enum used in `TestTemplateLite.PreTriggerSeconds` (concrete definition not provided).
|
||
|
|
- **`DigitalOutputModes`, `SquibFireMode`, `DigitalInputModes`**: Referenced in `GetSensorFromSettings` (enum definitions not provided).
|
||
|
|
- **Database Abstraction**:
|
||
|
|
- `DbOperations`, `DbOperationsEnum.StoredProcedure`, `SqlDbType`, `CommandType`, `SqlParameter`, `DataRow`, `DataTable` (from `System.Data`).
|
||
|
|
- Stored procedures: `sp_TestObjectsGet`, `sp_TestSetupsDeleteAll`.
|
||
|
|
- **UI Framework**: `Application.Current` (WPF `App` type) in `Reload()`.
|
||
|
|
- **Singleton Collections**: `SensorsCollection.SensorsList`, `CustomChannelList.List`, `SensorCalibrationList`, `DASHardwareList`, `TestEngineerDetailsList.TestEngineerList`, `TestObjectTemplateCollection.TemplateCollection`, `TestObjectList.TestObjectsList` (referenced in `Reload()`).
|
||
|
|
|
||
|
|
### External Dependencies
|
||
|
|
- `System`, `System.ComponentModel`, `System.Data`, `System.Data.SqlClient`, `System.Linq`, `System.Text`, `System.Windows` (WPF).
|
||
|
|
|
||
|
|
## 5. Gotchas
|
||
|
|
- **`PreTriggerSeconds` behavior**: For `Recorder`/`HybridRecorder` modes, `PreTriggerSeconds` always returns `0`, ignoring the stored `_preTriggerSeconds` value. This may cause confusion if persisted/serialized values are expected to be preserved.
|
||
|
|
- **`Suffix` normalization**: Non-empty suffixes are auto-prefixed with `_` (e.g., `"foo"` → `"_foo"`). Empty/whitespace suffixes remain unchanged.
|
||
|
|
- **`GetSensorFromSettings` fallback**: If `lookup` is provided but lacks `serial`, it falls back to `SensorsCollection.SensorsList.GetSensorBySerialNumber(serial)`. This dual-source lookup may mask missing data in `lookup`.
|
||
|
|
- **`GetSensorSettings` omits default values**: Settings with default/zero values (e.g., `DelayMS=0`) are excluded from the serialized string. This may cause deserialization to use defaults instead of explicit values if the caller expects all settings to be present.
|
||
|
|
- **`SysBuiltObject` return value**: Returns `false` if the stored procedure returns no rows, but does not distinguish between "not found" and "error occurred" (error handling logs are suppressed).
|
||
|
|
- **`DeleteAll` error handling**: Output parameters (`@ErrorSeverity`, `@ErrorState`, `@ErrorMessage`) are captured but not logged or propagated (commented-out logging suggests intentional suppression).
|
||
|
|
- **`TestTemplateLite` is incomplete**: The class is explicitly labeled a "lightweight" version and omits many fields of a full `TestTemplate`. Its `IsComplete` flag may not reflect full validation state.
|
||
|
|
- **`RegionOfInterest` clamping is cascading**: Setting `PreTrigger` may trigger `Start` updates (via `Start = PreTrigger`), and setting `Start` may trigger `End` updates (via `End = Start + 0.01`). This can cause unexpected side effects in UI bindings.
|
||
|
|
- **No documentation for `TestTemplate`**: `TemporaryTemplate` is typed as `TestTemplate`, but this class is not defined in the provided sources. Its structure and relationship to `TestTemplateLite` are unclear.
|