Files

153 lines
9.8 KiB
Markdown
Raw Permalink Normal View History

2026-04-17 14:55:32 -04:00
---
source_files:
- DataPRO/Modules/PreviousDBVersions/Version57/DatabaseExport/Classes/TestTemplate/HardwareInclusionInstruction.cs
- DataPRO/Modules/PreviousDBVersions/Version57/DatabaseExport/Classes/TestTemplate/TestTemplateLite.cs
- DataPRO/Modules/PreviousDBVersions/Version57/DatabaseExport/Classes/TestTemplate/TestTemplateTableObject.cs
- DataPRO/Modules/PreviousDBVersions/Version57/DatabaseExport/Classes/TestTemplate/TestTemplateList.cs
generated_at: "2026-04-16T04:59:45.231634+00:00"
model: "Qwen/Qwen3-Coder-Next-FP8"
schema_version: 1
sha256: "45cdf642e27469a5"
---
# TestTemplate
## Documentation: `DatabaseExport.TestTemplate` Module (Version 57)
---
### 1. Purpose
This module provides lightweight, read-only representations of test templates stored in the database (`tblTestSetups`) and supporting infrastructure for template management, primarily for export or migration workflows in legacy database versions (v57). It includes classes to load essential metadata from the database without instantiating the full `TestTemplate` object (which may trigger expensive side effects), and utilities to serialize/deserialize sensor settings and manage tag metadata. The module supports operations like retrieving templates by name, listing all templates in a simplified form, and handling special cases like the "Quick checkout" temporary template.
---
### 2. Public Interface
#### `HardwareInclusionInstruction`
- **`HardwareInclusionInstruction(string hardwareId, Actions action)`**
Constructor. Initializes a rule to explicitly include or exclude a specific hardware item from a test, overriding group-based inclusion logic (e.g., to support "DAS-less" groups).
- **`HardwareId { get; }`**
The identifier of the hardware item to which the rule applies.
- **`Action { get; }`**
The action to take: `Actions.Remove` (exclude despite group membership) or `Actions.Add` (include despite absence from groups).
#### `TestTemplateLite`
- **`Name { get; set; }`**
Template name.
- **`Description { get; set; }`**
Template description (defaults to `""`).
- **`RecordingMode { get; set; }`**
Recording mode (e.g., `Recorder`, `CircularBuffer`).
- **`PreTriggerSeconds { get; set; }`**
Pre-trigger duration in seconds. *Behavior*: Returns `0.0` for `Recorder` or `HybridRecorder` modes; otherwise returns the stored value.
- **`PostTriggerSeconds { get; set; }`**
Post-trigger duration in seconds.
- **`LastModified { get; set; }`**
Timestamp of last modification.
- **`LastModifiedBy { get; set; }`**
User who last modified the template.
- **`IsComplete { get; set; }`**
Whether the template is marked as complete.
#### `TestTemplateTableObject`
- **`TestTemplateTableObject(string name, string description, RecordingModes recordingMode, DateTime lastModified, string lastModifiedBy, bool isComplete, string completionErrorMessage, bool useCustomerDetails, string customerDetails, int[] tagIds)`**
Constructor. Initializes a simplified row-like object representing a `tblTestSetups` entry.
- **`Name { get; private set; }`**
Template name.
- **`Description { get; private set; }`**
Template description.
- **`RecordingMode { get; private set; }`**
Recording mode enum value.
- **`LastModified { get; private set; }`**
Last modification timestamp.
- **`LastModifiedBy { get; private set; }`**
Last modifier user ID.
- **`IsComplete { get; private set; }`**
Completion status.
- **`CompletionErrorMessage { get; private set; }`**
Error message if template is incomplete.
- **`UseCustomerDetails { get; private set; }`**
Whether customer details are enabled.
- **`CustomerDetails { get; private set; }`**
Customer details string (likely an ID or reference).
- **`TagIds { get; private set; }`**
Array of tag IDs associated with the template.
#### `TestTemplateList`
- **`TemporaryTemplate { get; set; }`**
Holds a temporary `TestTemplate` instance (e.g., for "Quick checkout") without persisting to DB.
- **`GetTemplate(string name) → TestTemplate`**
Retrieves a `TestTemplate` instance from `tblTestSetups` by name. Only loads fields defined in `DbOperations.TestSetups.Fields`. Sets `tt._bIsLoaded = false` to indicate incomplete loading. Returns `null` if not found or on error. Special case: Returns `TemporaryTemplate` if `name == "Quick checkout"`.
- **`GetSensorFromSettings(string settings, string serial, Dictionary<string, SensorData> lookup) → SensorData`**
Parses a comma-separated settings string (e.g., `"3=100,5=+"`) into a `SensorData` object. Uses `lookup` if provided and contains `serial`; otherwise queries `SensorsCollection.SensorsList`. Returns `null` if sensor not found. Supports settings: `CFC`, `Position`, `Polarity`, `Range`, `Delay`, `Duration`, `OutputMode`, `SQMode`, `DIMode`, `LimitDuration`, `ActiveValue`, `DefaultValue`.
- **`GetSensorFromSettings(string settings, string serial) → SensorData`**
Overload without `lookup` (passes `null`).
- **`GetSensorSettings(SensorData sd) → string`**
Serializes `SensorData` into the same comma-separated format used by `GetSensorFromSettings`. Only includes settings with non-default/empty values.
- **`TestTemplatesList { get; }`**
Singleton accessor for `TestTemplateList`.
- **`SysBuiltObject(string serialNumber) → bool`**
Queries `tblTestObjects` for `SysBuilt` flag of a given serial number. Returns `false` if not found.
- **`ConvertToDictionary(DataTable dt, ref Dictionary<string, List<Dictionary<string, object>>> lookup, string key)`**
Populates `lookup` by grouping rows in `dt` by `key` column. Each row becomes a `Dictionary<string, object>` of column values.
- **`GetAllTemplates() → TestTemplateTableObject[]`**
Queries `tblTestSetups` for all templates and returns an array of `TestTemplateTableObject`. Handles `UserTags` blob → `int[]` conversion via `GetTagIds`. If `Dirty` flag is true, re-fetches the full `TestTemplate` to update `IsComplete` status.
- **`GetTagIds(byte[] bytes) → int[]`**
Converts a byte array (from `UserTags` column) into an `int[]` using `Buffer.BlockCopy`. Returns empty array on failure.
---
### 3. Invariants
- **`TestTemplateLite.PreTriggerSeconds`**:
For `RecordingModes.Recorder` and `RecordingModes.HybridRecorder`, `PreTriggerSeconds` is *always* `0.0`, regardless of the stored `_preTriggerSeconds` value.
- **`TestTemplateTableObject` immutability**:
All properties are `private set`, meaning instances are immutable after construction.
- **`TestTemplateList.GetTemplate` behavior**:
Templates loaded via `GetTemplate` are explicitly marked as *not fully loaded* (`_bIsLoaded = false`), indicating that only `tblTestSetups` fields were populated. Consumers must avoid relying on lazily-loaded data (e.g., channels, groups).
- **`TemporaryTemplate` special case**:
Only returned when `name == "Quick checkout"` (exact string match). Empty/whitespace names return `null`.
- **`TagIds` blob format**:
`UserTags` is stored as a `byte[]` and converted to `int[]` assuming 4-byte `int` elements (via `sizeof(int)`). Failure to parse yields an empty array.
---
### 4. Dependencies
#### Internal Dependencies (from source):
- **`DbOperations`**: Used for database access (`GetCommand`, `CreateParam`, `QueryDataSet`, `TestSetups` table/field enums).
- **`Properties.Settings.Default.DownloadFolder`**: Used as fallback for `ExportFolder` and `DownloadFolder` in `GetTemplate`.
- **`CustomerDetailsList.CustomerList`**, **`TestEngineerDetailsList.TestEngineerList`**, **`LabratoryDetailsList.LabratoryList`**: Used to resolve customer/test engineer/lab details from stored IDs.
- **`SensorsCollection.SensorsList`**: Used by `GetSensorFromSettings` to look up sensors by serial number.
- **`ISO.TestObject.SensorSettings`**: Enum defining sensor setting types (e.g., `CFC`, `Range`, `Delay`).
- **`OutputTOMDigitalChannel.DigitalOutputMode`**, **`OutputSquibChannel.SquibFireMode`**, **`DigitalInputScaleMultiplier.InputModes`**: Enums used in sensor settings parsing.
#### External Dependencies:
- **`System.Data`**: `SqlDbType`, `DataRow`, `DataTable`, `DataSet`.
- **`System.Globalization`**: `CultureInfo.InvariantCulture` for numeric parsing.
#### Inferred Consumers:
- Modules performing template export/migration (e.g., `DatabaseExport` namespace usage implies integration with export pipelines).
- Code needing lightweight template metadata (e.g., UI lists, version comparison, migration scripts).
---
### 5. Gotchas
- **`PreTriggerSeconds` logic is mode-dependent**:
The property setter stores the value in `_preTriggerSeconds`, but the getter *ignores* it for `Recorder`/`HybridRecorder` modes. This may cause confusion if consumers expect the stored value to be returned.
- **`GetTemplate` does *not* load full template data**:
Despite returning a `TestTemplate`, only `tblTestSetups` fields are populated. Consumers must not assume groups, channels, or other related data are available.
- **`Dirty` flag triggers redundant full load**:
In `GetAllTemplates`, if `Dirty` is true, `GetTemplate` is called to re-fetch `IsComplete`. This may be inefficient and could fail silently (exceptions are caught and ignored).
- **`GetTagIds` assumes fixed `int` size**:
Uses `sizeof(int)` (4 bytes) for conversion. May fail on platforms with non-standard `int` sizes or malformed blobs.
- **`TemporaryTemplate` is mutable and global**:
As a singleton property, `TemporaryTemplate` can be overwritten by any caller. No thread-safety is implied beyond the singleton initialization.
- **`GetSensorFromSettings` silently handles missing sensors**:
Returns `null` if sensor not found, but only after creating a placeholder `SensorData` with empty `SerialNumber` if `serial` is null/whitespace.
- **`GetSensorSettings` omits default/empty values**:
Only includes settings with non-default values. This may cause round-trip mismatches if consumers expect all settings to be serialized.
None identified beyond the above.