--- source_files: - Common/DTS.Common.Import/Factories/CSVTestParserFactory.cs - Common/DTS.Common.Import/Factories/DatabaseLocksFactory.cs - Common/DTS.Common.Import/Factories/CSVSensorParserFactory.cs - Common/DTS.Common.Import/Factories/SaveVariantFactory.cs - Common/DTS.Common.Import/Factories/XmlParserFactory.cs generated_at: "2026-04-16T11:45:43.783393+00:00" model: "zai-org/GLM-5-FP8" schema_version: 1 sha256: "23d838f43f91b04f" --- # Documentation: DTS.Common.Import.Factories ## 1. Purpose This module provides factory classes for creating parsers, database locks, and persistence handlers for the DTS import system. It centralizes object creation logic for CSV parsing (tests and sensors), XML parsing across different schema versions, database locking mechanisms, and save operation variants. The factories enable version-specific parsing strategies and conditional object creation based on the presence of data in `ImportObject`. --- ## 2. Public Interface ### CSVTestParserFactory | Method | Signature | Description | |--------|-----------|-------------| | `CreateCSVParsers` | `public static IParseCSVTest[] CreateCSVParsers()` | Creates an array of CSV test parsers for versions 0, 5, and 6. Returns parsers in order: Version0, Version5, Version6. | ### DatabaseLocksFactory | Method | Signature | Description | |--------|-----------|-------------| | `Create` | `public static List Create(ImportObject importObject, User user, double strandedLockTimeoutMinutes)` | Creates lock objects for import operations based on data present in `importObject`. Conditionally creates `LockImportTestSetups`, `LockImportSensors`, and `LockImportGroups` if corresponding data collections are non-empty. | ### CSVSensorParserFactory | Method | Signature | Description | |--------|-----------|-------------| | `CreateCSVParsers` | `public static IReadOnlyDictionary CreateCSVParsers(ICalibrationImport import, ZeroMethodOptions zmOptions, IImportNotification importNotification, bool importCreateDynamicGroups, bool useISOCodeFilterMapping, bool useZeroForUnfiltered)` | Creates a dictionary of CSV sensor parsers keyed by version number. Includes versions 0, 2, 3, and 4. Each parser is initialized with the provided parameters before being added to the dictionary. | ### SaveVariantFactory | Method | Signature | Description | |--------|-----------|-------------| | `CreateVariants` | `public static List CreateVariants(ImportObject importObject, ImportNotification importNotification, User user, Func isCanceled, bool showCheckoutButton)` | Creates a list of persistence handlers based on data present in `importObject`. Handlers are created conditionally for: `CustomerDetails`, `TestEngineerDetails`, `LabDetails`, `SensorModels`, `Sensors` (with CSV vs non-CSV variants), `Users`, `GlobalSettings`, `Hardware`, `GroupTemplates`, `Groups`, and `TestSetups`. When `showCheckoutButton` is true, also creates a `SaveCheckoutTestSetup`. | ### XmlParserFactory | Property/Method | Signature | Description | |-----------------|-----------|-------------| | `UIItems` | `public static List UIItems { get; set; }` | Static property for UI items used during XML parsing. | | `ImportNotification` | `public static IImportNotification ImportNotification { get; set; }` | Static property for import notifications. | | `CreateXMLParsers` | `public static IEnumerable CreateXMLParsers(string fileName, IImportNotification importNotification, Func isCanceled, bool skipNormalizing)` | Creates XML parsers based on the file's import version. Routes to `LessThan20XMLVersion` for versions below `FileUtils.DataPRO20XmlVersion`, otherwise uses `GreaterOrEqual20XMLVersion`. | --- ## 3. Invariants 1. **Version-based dispatch**: `XmlParserFactory` uses `FileUtils.DataPRO20XmlVersion` as the threshold to select between pre-2.0 and 2.0+ parsing strategies. 2. **Conditional creation**: `DatabaseLocksFactory.Create` and `SaveVariantFactory.CreateVariants` only create handlers/locks when the corresponding data collections in `ImportObject` contain elements (checked via `.Any()`). 3. **Parser version keys**: `CSVSensorParserFactory.CreateCSVParsers` uses each parser's `Version` property as the dictionary key, guaranteeing unique keys per parser type. 4. **Shared progress calculation**: `SaveVariantFactory.CreateVariants` uses a single `PersistCalculator` instance across all save handlers, with counts accumulated via `AddToTotal()` before handlers are added to the list. 5. **Order-dependent processing**: Save handlers are added in a specific sequence (CustomerDetails → TestEngineerDetails → LabDetails → SensorModels → Sensors → Users → GlobalSettings → Hardware → GroupTemplates → Groups → TestSetups). 6. **Test setup naming convention**: When `showCheckoutButton` is true, test setup names are suffixed with `Serialization.RDF.File.SUFFIX_RUNTEST` and checkout setups with `Serialization.RDF.File.SUFFIX_CHECKOUT`. --- ## 4. Dependencies ### This module depends on: - `DTS.Common.Import.Interfaces` — `IParseCSVTest`, `IParseCSVSensor`, `ILockImport`, `IPersistImport`, `IParseVariant`, `ICalibrationImport`, `IImportNotification`, `IUIItems` - `DTS.Common.Import.Parsers.CSV` — `Version0CSVTestParser`, `Version5CSVTestParser`, `Version6CSVTestParser`, `Version0CSVSensorParser`, `Version2CSVSensorParser`, `Version3CSVSensorParser`, `Version4CSVSensorParser` - `DTS.Common.Import.DatabaseLocks` — `LockImportTestSetups`, `LockImportSensors`, `LockImportGroups` - `DTS.Common.Import.Persist` — `PersistCalculator`, `SaveCustomerDetails`, `SaveTestEngineerDetails`, `SaveLabDetails`, `SaveSensorModels`, `SaveCsvSourceSensor`, `SaveNonCsvSourceSensor`, `SaveUsers`, `SaveGlobalSettings`, `SaveCustomChannels`, `SaveHardware`, `SaveGroupTemplates`, `SaveGroups`, `SaveTestSetup`, `SaveCheckoutTestSetup` - `DTS.Common.Import.ImportOptions` — `ZeroMethodOptions` - `DTS.Common.Import.XML` — `XMLParseMMECustomChannels`, `XMLParseMMECustomMainLocations`, `XMLParseDASList`, `XMLParseSensors`, `XMLParseCalibrations`, `XMLParseGroupTemplates`, `XMLParseGroups`, `XMLParseTestSetups`, `XMLParseLabDetails`, `XMLParseCustomerDetails`, `XMLParseTestEngineerDetails`, `XMLParseUsers`, `XMLPre20ParseDASList`, `XMLPre20ParseSensors`, `XMLPre20ParseCalibrations`, `XMLPre20ParseGroupTemplates`, `XMLPre20ParseGroups`, `XMLPre20ParseTestSetups` - `DTS.Common.Enums.DBExport` — `TopLevelFields` - `DTS.Common.Utils` — `FileUtils` - `DTS.Slice.Users` — `User` - `System.Xml` — `XmlElement` ### Consumers of this module: - Cannot be determined from source alone; other modules in the codebase that require parser/lock/persistence handler creation would call these factories. --- ## 5. Gotchas 1. **Static mutable state in `XmlParserFactory`**: The properties `UIItems`, `ImportNotification`, and field `_isCancelled` are static and set during `CreateXMLParsers`. This could cause thread-safety issues or stale state if called concurrently. 2. **Non-sequential version numbers**: `CSVTestParserFactory` creates versions 0, 5, and 6 (skipping 1-4), while `CSVSensorParserFactory` creates versions 0, 2, 3, and 4 (skipping 1). The reason for these gaps is unclear from source alone. 3. **Misleading parameter name**: In `SaveVariantFactory.CreateVariants`, the `showCheckoutButton` parameter is used to determine "GM parse mode" and affects test setup naming, which is not obvious from the parameter name. (Comment references FB 38039.) 4. **Pre-2.0 XML wrapper pattern**: For XML versions below 2.0, parsers are wrapped in `XMLPre20Parse*` variants (e.g., `XMLPre20ParseSensors` wraps `XMLParseSensors`). This decorator-like pattern is specific to legacy format handling. 5. **Null-safe hardware channel counting**: In `SaveVariantFactory`, hardware channel counting uses `h?.Channels.Length ?? 0`, suggesting `Hardware` items or their `Channels` property may be null. 6. **Unused `saveCustomChannels` instance**: In `SaveVariantFactory`, `SaveCustomChannels` is instantiated unconditionally but only added to handlers if referenced by `SaveTestSetup`. Its standalone purpose is unclear from source alone.