--- source_files: - Common/DTS.Common.DataModel/Classes/Export/ExportHeader.cs - Common/DTS.Common.DataModel/Classes/Export/ExportTestSetup.cs generated_at: "2026-04-17T15:42:08.031759+00:00" model: "zai-org/GLM-5-FP8" schema_version: 1 sha256: "ef0e1195e993a581" --- # Documentation: Export Module ## 1. Purpose This module provides data export functionality for test configurations. `ExportHeader` represents a selectable column header for export operations, implementing property change notification for UI binding. `ExportTestSetup` is a static utility class that aggregates test-related entities (tests, groups, sensors, hardware, calibrations, and ISO details) into dictionaries and serializes them to XML format for file export or data transfer. --- ## 2. Public Interface ### ExportHeader Class **Namespace:** `DataPROWin7.DataModel.Classes.Export` **Implements:** `IExportHeader` | Member | Signature | Description | |--------|-----------|-------------| | Constructor | `ExportHeader()` | Initializes a new instance with default values. | | Constructor | `ExportHeader(string headerName)` | Initializes with the specified `headerName`. | | Constructor | `ExportHeader(string headerName, bool isSelected)` | Initializes with `headerName` and `isSelected` state; chains to the headerName constructor. | | Property | `string HeaderName { get; set; }` | Gets or sets the header name; raises `PropertyChanged` on set. | | Property | `bool IsSelected { get; set; }` | Gets or sets selection state; defaults to `false`; raises `PropertyChanged` on set. | | Event | `PropertyChangedEventHandler PropertyChanged` | Event raised when a property value changes. | | Method | `void OnPropertyChanged(string propertyName = null)` | Protected method that invokes the `PropertyChanged` event. | --- ### ExportTestSetup Class **Namespace:** `DataPROWin7.DataModel.Classes` **Modifiers:** `public static` | Method | Signature | Description | |--------|-----------|-------------| | PrepareForExport | `void PrepareForExport(DataModel.TestTemplate t, Dictionary includedTests, Dictionary includedGroups, Dictionary includedDAS, Dictionary includedSensors, HashSet sensorsAlreadyAdded, Dictionary includedSensorModels, Dictionary includedCalibration, Dictionary includedCustomerDetails, Dictionary includedTestEngineerDetails, Dictionary includedLabDetails, bool savingRunningTest, bool savingTTSImport)` | Populates the provided dictionaries with all entities referenced by the test template `t`, including sensors, hardware, groups, calibrations, and ISO-related details. Handles embedded and non-embedded groups. | | ExportToFile | `string ExportToFile(Dictionary includedTests, Dictionary includedGroups, Dictionary includedDAS, Dictionary includedSensors, Dictionary includedSensorModels, Dictionary includedCalibration, Dictionary includedCustomerDetails, Dictionary includedTestEngineerDetails, Dictionary includedLabDetails, Dictionary includedUsers, Dictionary includedGlobalSettings, string exportFile, string originalImportFile, bool bUseFirstUseDate = true)` | Serializes all provided dictionaries to XML format using `TopLevelFields` enum ordering. Returns the XML string; writes to `exportFile` if non-null. Returns empty string on exception. | | PrepareForExportFields | `void PrepareForExportFields(DataModel.TestTemplate t, Dictionary includedTests, Dictionary includedDAS)` | Simplified preparation that only extracts tests and DAS hardware; does not process sensors, calibrations, or ISO details. Removes DAS entries from `t.DASSampleRateList` if not in `includedDAS`. | | ExportToFileFields | `string ExportToFileFields(Dictionary includedTests, Dictionary includedDAS, string originalImportFile)` | Simplified export that only writes `DASList` and `TestSetups` elements to XML. Returns empty string on exception. | --- ## 3. Invariants - **Dictionary Key Uniqueness:** All `included*` dictionary parameters must use unique keys appropriate to their type (e.g., `SerialNumber` for sensors/hardware, `Name` for tests/groups/customers). - **Thread Affinity:** `PrepareForExport` and `PrepareForExportFields` access `Application.Current.Dispatcher` for retrieving non-embedded groups; they handle both UI thread and background thread scenarios via `CheckAccess()` and `ManualResetEvent`. - **Sensor Deduplication:** `sensorsAlreadyAdded` (a `HashSet`) is used to prevent duplicate sensor entries across multiple groups or channels within a single export operation. - **Calibration Exclusion:** Sensors flagged as `IsTestSpecificDigitalOutput`, `IsTestSpecificSquib`, or `IsTestSpecificDigitalIn` are excluded from `includedCalibration` but still added to `includedSensors`. - **XML Element Ordering:** `ExportToFile` and `ExportToFileFields` iterate over `TopLevelFields` enum values, ensuring consistent element ordering in output XML. - **Static Group Validation:** If an embedded group's `StaticGroupId` references a non-existent or mismatched static group, `embeddedGroup.StaticGroupId` is set to `null` and processing continues. --- ## 4. Dependencies ### Imports (this module depends on): | Namespace | Purpose | |-----------|---------| | `DTS.Common.Interface.ExportData` | `IExportHeader` interface | | `DTS.Common.Interface.Groups.GroupList` | `IGroup`, `IGroupListViewModel` | | `DTS.SensorDB` | `SensorsCollection`, `SensorData`, `SensorCalibration`, `SensorModel`, `SensorModelCollection` | | `DTS.Common.Interface.Sensors` | `ISensorData` | | `DTS.Common.Interface.Channels` | `IGroupChannel` | | `DTS.Common.Interface.DataRecorders` | `IDASHardware` | | `DTS.Common.Storage` | `DbOperations` | | `DTS.Common.ISO` | `CustomerDetails`, `TestEngineerDetails`, `LabratoryDetails`, `Hardware` | | `DTS.Common.Utils` | `FileUtils` | | `DTS.Common.Utilities.Logging` | `APILogger` | | `DTS.Common.Enums.DBExport` | `TopLevelFields` enum | | `DTS.Slice.Users` | `User` class | | `Prism.Ioc` | `ContainerLocator` | | `Unity` | `IUnityContainer` | | `System.Windows` | `Application` for dispatcher access | | `System.Xml` | `XmlWriter` for XML serialization | | `System.ComponentModel` | `INotifyPropertyChanged` pattern | ### Dependents (inferred): - Callers of `ExportTestSetup.PrepareForExport*` and `ExportTestSetup.ExportToFile*` methods (exact modules unclear from source alone). - Consumers of `ExportHeader` for UI data binding scenarios. --- ## 5. Gotchas 1. **Unused Parameter:** The `savingRunningTest` parameter in `PrepareForExport` is never referenced in the method body. Its intended purpose is unclear from source alone. 2. **Dispatcher Blocking:** Both `PrepareForExport` and `PrepareForExportFields` use `ManualResetEvent.WaitOne()` to block when called from a non-UI thread while waiting for dispatcher operations. This could cause deadlocks if the UI thread is blocked waiting on the calling thread. 3. **Namespace Mismatch:** The namespace `DataPROWin7.DataModel.Classes.Export` and `DataPROWin7.DataModel.Classes` suggests legacy naming (referencing "Win7") that may not reflect current platform targets. 4. **Partial Export Handling:** `ExportToFileFields` does not write to a file despite accepting `originalImportFile`; it only returns the XML string. Contrast with `ExportToFile` which writes to `exportFile` when non-null. 5. **Null Return Ambiguity:** `GetDAS` returns `null` if no matching DAS is found in `dasList`. Callers do not appear to null-check the result before accessing properties (e.g., `h.SerialNumber`), which could cause `NullReferenceException`. 6. **Early Exit in PrepareForExport:** The method returns early if `!savingTTSImport`, skipping the final loop that adds all sensors with calibrations. This conditional behavior may be unexpected. 7. **Empty Calibration Handling:** When `SensorCalibration.GetCalibrationsBySerialNumber` returns null or empty, the sensor is still added to `includedSensors` but calibration data is omitted. A `Trace.WriteLine` diagnostic is emitted in one code path but not others.