59 lines
4.6 KiB
Markdown
59 lines
4.6 KiB
Markdown
|
|
---
|
||
|
|
source_files:
|
||
|
|
- Common/DTS.CommonCore/Classes/TMAT/TMTTemplate.cs
|
||
|
|
generated_at: "2026-04-17T16:26:10.767228+00:00"
|
||
|
|
model: "zai-org/GLM-5-FP8"
|
||
|
|
schema_version: 1
|
||
|
|
sha256: "d946f7637f4d3229"
|
||
|
|
---
|
||
|
|
|
||
|
|
# TMAT
|
||
|
|
|
||
|
|
### Purpose
|
||
|
|
This module provides template processing functionality for TMT (likely Test Management Template) files. It enables reading template files and replacing placeholder patterns with actual values, supporting both global keys (program-level metadata) and channel-specific keys (per-channel configuration). The module uses an attribute-based enum pattern to associate string patterns with strongly-typed keys.
|
||
|
|
|
||
|
|
### Public Interface
|
||
|
|
- **`TMTGlobalKeys` (enum)**
|
||
|
|
- Enum values: `NameOfProgram`, `TestId`, `DASSerialNumber`, `DASIndex`, `DASSampleRate`, `TestTimeStamp`, `DASBitRate`, `StreamTimeFormat`, `UdpStreamTimeChannelId`, `UdpStreamDataChannelId`, `CreateDate`
|
||
|
|
- Each value is decorated with `[TMTKey("pattern")]` defining its placeholder pattern.
|
||
|
|
|
||
|
|
- **`TMTChannelKeys` (enum)**
|
||
|
|
- Enum values: `HardwareChannelNumber`, `ChannelName`, `CouplingMode`, `BridgeResistance`, `AAF`, `OffsetMV`, `InputRangeMV`, `MaxRangeEU`, `MinRangeEU`, `EU`, `ScaleFactorEU`, `OffsetEU`
|
||
|
|
- Patterns include a `{0}` format placeholder for channel number substitution.
|
||
|
|
|
||
|
|
- **`TMTKey` (Attribute class)**
|
||
|
|
- `public string Key { get; set; }` - The pattern string to look for during replacement.
|
||
|
|
- `public TMTKey(string key)` - Constructor accepting the pattern.
|
||
|
|
- `public static string GetKey(TMTGlobalKeys o)` - Returns the pattern string for a given global key.
|
||
|
|
- `public static string GetKey(TMTChannelKeys o, int channelNumber)` - Returns the formatted pattern string for a channel key, with channel number substituted.
|
||
|
|
|
||
|
|
- **`ITMTTemplate` (interface)**
|
||
|
|
- `void UpdateValue(TMTGlobalKeys key, string value)` - Updates all occurrences of the global key pattern with the provided value.
|
||
|
|
- `void UpdateValue(TMTChannelKeys key, string value, int channelNumber)` - Updates all occurrences of the channel key pattern with the provided value.
|
||
|
|
- `string[] GetAllLines()` - Returns all lines currently in the template.
|
||
|
|
|
||
|
|
- **`TMTTemplate` (class, implements `ITMTTemplate`)**
|
||
|
|
- `public TMTTemplate(string templateLocation)` - Constructor that reads all lines from the specified file path. Silently produces empty content if file does not exist.
|
||
|
|
- `public TMTTemplate(string[] lines)` - Constructor that initializes from an existing array of lines.
|
||
|
|
- `public void UpdateValue(TMTGlobalKeys key, string value)` - Replaces all occurrences of the key's pattern with value across all lines.
|
||
|
|
- `public void UpdateValue(TMTChannelKeys key, string value, int channelNumber)` - Replaces all occurrences of the channel key's pattern (formatted with channelNumber) with value across all lines.
|
||
|
|
- `public string[] GetAllLines()` - Returns the current state of all lines as an array.
|
||
|
|
|
||
|
|
### Invariants
|
||
|
|
- Pattern matching uses `string.Contains()` followed by `string.Replace()`, meaning patterns can match anywhere in a line, not just as whole tokens.
|
||
|
|
- If a file does not exist at `templateLocation`, the `_allLines` list remains empty (no exception is thrown).
|
||
|
|
- Channel key patterns use composite format strings with `{0}` as the channel number placeholder.
|
||
|
|
- All updates are performed in-place on the internal line list; the original file is never modified directly.
|
||
|
|
|
||
|
|
### Dependencies
|
||
|
|
- **Depends on:** `System.Collections.Generic` (for `List<string>`), `System.IO.File` (for reading files), `System.Reflection` (via `GetMember`, `GetCustomAttribute`).
|
||
|
|
- **Depended on by:** Cannot be determined from source alone; likely consumed by test configuration or data acquisition setup components.
|
||
|
|
|
||
|
|
### Gotchas
|
||
|
|
- **Silent failure on missing file:** The constructor `TMTTemplate(string templateLocation)` does not throw or indicate error if the file doesn't exist—it simply results in an empty template. Callers should verify file existence separately if this matters.
|
||
|
|
- **Multiple replacements per line:** If a pattern appears multiple times in a single line, `string.Replace()` will replace all occurrences. This may or may not be intended behavior.
|
||
|
|
- **No validation of channelNumber:** The `UpdateValue(TMTChannelKeys, string, int)` method does not validate that `channelNumber` is within any expected range.
|
||
|
|
- **Pattern collision risk:** Since matching uses `Contains()`, shorter patterns could inadvertently match within longer strings. For example, a pattern `{TEST ID}` could theoretically match inside `{TEST ID EXTRA}`.
|
||
|
|
- **No write-back to file:** The class only reads from files and returns modified lines via `GetAllLines()`. Persisting changes requires separate file writing logic.
|
||
|
|
|
||
|
|
---
|