12 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||
|---|---|---|---|---|---|---|
|
2026-04-16T03:34:31.793274+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | e1688a84f19142ea |
Export
Documentation: ExportTestSetup Module
Purpose
The ExportTestSetup static class orchestrates the preparation and serialization of test configuration data for export to XML. It aggregates test templates, associated groups, sensors, calibrations, DAS hardware, sensor models, ISO metadata (customer, engineer, lab), users, and global settings into dictionaries, validates and deduplicates entries, and writes them to an XML file using a structured writer. This module serves as the core export engine for test setup data, supporting both full exports and field-only exports (e.g., for partial updates or migrations). It bridges domain models (TestTemplate, IGroup, SensorData, etc.) with serialization infrastructure (IExportHeader-like patterns, XML writers) and database abstractions.
Public Interface
1. PrepareForExport
public static void PrepareForExport(
DataModel.TestTemplate t,
Dictionary<string, DataModel.TestTemplate> includedTests,
Dictionary<string, IGroup> includedGroups,
Dictionary<string, DataModel.DASHardware> includedDAS,
Dictionary<string, SensorData> includedSensors,
HashSet<int> sensorsAlreadyAdded,
Dictionary<string, SensorModel> includedSensorModels,
Dictionary<string, SensorCalibration[]> includedCalibration,
Dictionary<string, DTS.Common.ISO.CustomerDetails> includedCustomerDetails,
Dictionary<string, DTS.Common.ISO.TestEngineerDetails> includedTestEngineerDetails,
Dictionary<string, DTS.Common.ISO.LabratoryDetails> includedLabDetails,
bool savingRunningTest,
bool savingTTSImport
)
Behavior: Populates the provided dictionaries with data derived from the input TestTemplate t.
- Adds
ttoincludedTests. - Extracts and deduplicates ISO metadata (customer, engineer, lab) into respective dictionaries.
- Iterates over embedded groups in
t.Groups, collects associated sensors (via channels), calibrations, and DAS hardware, skipping test-specific digital outputs/squibs/digital inputs. - Resolves and processes non-embedded (static) groups via
GetNonEmbeddedGroup, ensuring thread-safe dispatcher invocation. - Deduplicates sensors and calibrations using
sensorsAlreadyAdded. - Collects sensor models and calibrations for non-test-specific sensors.
- Adds hardware from
t.GetHardware(). - If
savingTTSImportistrue, also includes all sensors (even unused ones) and their calibrations/models. - Mutates all input dictionaries and sets in-place.
2. ExportToFile
public static string ExportToFile(
Dictionary<string, DataModel.TestTemplate> includedTests,
Dictionary<string, IGroup> includedGroups,
Dictionary<string, DataModel.DASHardware> includedDAS,
Dictionary<string, SensorData> includedSensors,
Dictionary<string, SensorModel> includedSensorModels,
Dictionary<string, SensorCalibration[]> includedCalibration,
Dictionary<string, DTS.Common.ISO.CustomerDetails> includedCustomerDetails,
Dictionary<string, DTS.Common.ISO.TestEngineerDetails> includedTestEngineerDetails,
Dictionary<string, DTS.Common.ISO.LabratoryDetails> includedLabDetails,
Dictionary<string, DTS.Slice.Users.User> includedUsers,
Dictionary<string, string> includedGlobalSettings,
string exportFile,
string originalImportFile,
bool bUseFirstUseDate = true
)
Behavior: Serializes the aggregated data into an XML document and optionally writes it to exportFile.
- Uses
FileUtils.GetExportWriter(...)to create anXmlWriterwith progress tracking. - Writes
OriginalImportFileas an attribute on the root element. - Iterates over
TopLevelFieldsenum values, writing only non-empty sections in a fixed order (e.g.,Calibrations,DASList,Groups,Sensors,TestSetups, etc.). - Calls
WriteXML(ref writer)on each item in the dictionaries (e.g.,SensorData.WriteXML,SensorCalibration.WriteXML). - Returns the full XML string (via
StringBuilder) and writes it toexportFileif non-null. - Logs exceptions via
APILogger.Logand returnsstring.Emptyon failure.
3. PrepareForExportFields
public static void PrepareForExportFields(
DataModel.TestTemplate t,
Dictionary<string, DataModel.TestTemplate> includedTests,
Dictionary<string, DataModel.DASHardware> includedDAS
)
Behavior: A lightweight variant of PrepareForExport that only populates includedTests and includedDAS.
- Adds
ttoincludedTests. - Collects embedded and non-embedded group hardware into
includedDAS. - Does not process sensors, calibrations, groups, or metadata.
- Includes logic to remove unused DAS sample rates from
t.DASSampleRateList. - Intended for scenarios where only test setup and hardware metadata need updating (e.g., field-level sync).
4. ExportToFileFields
public static string ExportToFileFields(
Dictionary<string, DataModel.TestTemplate> includedTests,
Dictionary<string, DataModel.DASHardware> includedDAS,
string originalImportFile
)
Behavior: Serializes only TestSetups and DASList sections (no sensors, calibrations, groups, etc.).
- Uses the same XML writer infrastructure as
ExportToFile. - Skips all
TopLevelFieldsexceptDASListandTestSetups. - Returns the XML string (no file write).
- Used for minimal exports (e.g., updating only test and hardware definitions).
5. ExportHeader (Class)
public class ExportHeader : IExportHeader
Behavior: A simple data model for UI-level export header selection.
- Implements
INotifyPropertyChanged. - Properties:
HeaderName(string): Name of the export section/group.IsSelected(bool): Whether the header is selected for export.
- Raises
PropertyChangedon property changes. - Used to drive UI checkboxes or toggles for export sections (e.g., in a configuration dialog).
Invariants
-
Deduplication by Key:
includedTests,includedGroups,includedDAS,includedSensors,includedSensorModels,includedCalibration,includedCustomerDetails,includedTestEngineerDetails,includedLabDetails,includedUsers, andincludedGlobalSettingsuse string keys (e.g.,Name,SerialNumber) to avoid duplicates.sensorsAlreadyAddedusesDatabaseId(int) to prevent reprocessing sensors.
-
Hardware Deduplication:
includedDASusesSerialNumberas the key. Hardware is added only if not already present.
-
Sensor Exclusion Rules:
- Sensors marked
IsTestSpecificDigitalOutput,IsTestSpecificSquib, orIsTestSpecificDigitalInare excluded fromincludedSensorsandincludedCalibrationunlesssavingTTSImportistrue.
- Sensors marked
-
Static Group Resolution:
- Non-embedded groups must exist in the database (resolved via
GetNonEmbeddedGroup). If not,embeddedGroup.StaticGroupIdis set tonulland processing continues (no exception thrown).
- Non-embedded groups must exist in the database (resolved via
-
Thread Safety for Dispatcher:
- Access to
Application.Current.Dispatcherfor static group resolution usesCheckAccess()andBeginInvokewithManualResetEventto block on non-UI threads.
- Access to
-
XML Serialization Order:
- Sections are written in the order defined by
TopLevelFieldsenum (viaEnum.GetValues). Unsupported/empty sections are skipped.
- Sections are written in the order defined by
Dependencies
Imports/Usings (Direct Dependencies)
DTS.Common.Interface.ExportData(IExportHeader)DTS.Common.Interface.Groups.GroupList(IGroup,IGroupChannel)DTS.SensorDB(SensorData,SensorCalibration)DTS.Common.Interface.Sensors(ISensorData)DTS.Common.Interface.Channels(IGroupChannel)DTS.Common.Interface.DataRecorders(IDASHardware)DTS.Common.Storage(DbOperations,FileUtils)Prism.Ioc,Unity(ContainerLocator,IUnityContainer)DTS.Common.ISO(CustomerDetails,TestEngineerDetails,LabratoryDetails,Hardware,SensorModel)DTS.Common.Utils,DTS.Common.Utilities.Logging(APILogger)DTS.Common.Enums.DBExport(TopLevelFields)System,System.Linq,System.Windows,System.Threading,System.Text,System.Xml
External Services/Modules Used
SensorsCollection.SensorsList(static): For sensor lookup (GetAllSensors,GetOriginalSensorBySensorId).SensorModelCollection.SensorModelList(static): For sensor model lookup.DbOperations: For DAS (DASGet), channel defaults (GetChannelSettingDefaults).ContainerLocator.Container: For resolvingIUnityContainer→IGroupListViewModel.FileUtils.GetExportWriter: For XML writer creation.APILogger: For exception logging.
Depended Upon By
- UI layers (e.g., export dialogs) that use
ExportHeaderfor section selection. - Export workflows (e.g., full export, TTS import, field sync) that call
PrepareForExportorPrepareForExportFieldsbeforeExportToFile/ExportToFileFields.
Gotchas
-
savingTTSImportBehavior:- When
savingTTSImportistrue, all sensors (including unused ones) are added toincludedSensors/includedCalibration/includedSensorModels. This may significantly increase export size and processing time.
- When
-
Static Group Resolution Failure:
- If a static group referenced by
embeddedGroup.StaticGroupIdno longer exists in the database,GetNonEmbeddedGroupreturnsnull, andembeddedGroup.StaticGroupIdis set tonull. This silently discards the group’s channels/hardware. Pre-existing database records may be affected.
- If a static group referenced by
-
Thread-Safe Dispatcher Usage:
GetNonEmbeddedGroupusesManualResetEvent.WaitOne()to block on non-UI threads. This can cause deadlocks if the UI thread is blocked or the dispatcher is unavailable.
-
Hardware Serial Number Fallback:
GetHardwareSerialNumberreturnsstring.EmptyifhardwareIdis not found. This may causeGetDASto returnnull, skipping hardware inclusion (no error raised).
-
bUseFirstUseDateParameter:- Passed to
SensorData.WriteXML. Its effect is not documented in the source—behavior depends onSensorData.WriteXMLimplementation.
- Passed to
-
TopLevelFieldsEnum Gaps:- Many
TopLevelFieldsenum values (e.g.,CustomChannels,CustomDirections) are skipped in both export methods. This is intentional but may confuse readers expecting completeness.
- Many
-
No Validation of Input Dictionaries:
- The methods assume input dictionaries are properly initialized (not
null). Passingnullwill causeNullReferenceException.
- The methods assume input dictionaries are properly initialized (not
-
ExportHeaderNot Used in Export Logic:- Despite being in the same namespace (
Export),ExportHeaderis not used byExportTestSetup. It is likely used in UI layers for export section selection, but this is not evident from the source.
- Despite being in the same namespace (
-
ExportToFileFieldsDoes Not Write to File:- Unlike
ExportToFile,ExportToFileFieldsreturns the XML string but does not write toexportFile(parameter is unused). This is inconsistent and may cause confusion.
- Unlike
-
Hardcoded XML Version:
FileUtils.CurrentXmlVersionand assembly version (.ToString(4)) are hardcoded in writer initialization. Changes to versioning may break compatibility.
-
Calibration Null Handling:
- In
PrepareForExport, ifSensorCalibration.GetCalibrationsBySerialNumber(sd)returnsnull, the sensor is skipped. InsavingTTSImportmode, aTrace.WriteLinelogs"calibration record is null"but processing continues.
- In