9.2 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |||||
|---|---|---|---|---|---|---|---|---|---|
|
2026-04-16T02:07:25.656251+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 23d838f43f91b04f |
Import Factories Module Documentation
1. Purpose
This module provides factory classes responsible for constructing and configuring domain-specific parsers and persistence handlers used during data import operations. It centralizes the logic for instantiating versioned CSV and XML parsers (for tests, sensors), database lock objects, and save handlers for various import entities (e.g., sensors, groups, test setups). Its role is to decouple object creation from consumption, enabling version-aware and context-aware instantiation of import components based on input data format, version, and configuration options.
2. Public Interface
CSVTestParserFactory.CreateCSVParsers()
Signature: public static IParseCSVTest[] CreateCSVParsers()
Behavior: Returns an array of versioned CSV test parsers (Version0CSVTestParser, Version5CSVTestParser, Version6CSVTestParser) implementing IParseCSVTest. Parsers are returned in version order (v0, v5, v6). No initialization parameters are required.
DatabaseLocksFactory.Create(ImportObject, User, double)
Signature: public static List<ILockImport> Create(ImportObject importObject, User user, double strandedLockTimeoutMinutes)
Behavior: Returns a list of database lock objects implementing ILockImport, conditionally instantiated based on the presence of data in the ImportObject. Lock types created include:
LockImportTestSetups(ifimportObject.TestSetups()is non-empty)LockImportSensors(ifimportObject.Sensors()is non-empty)LockImportGroups(ifimportObject.StaticGroups()is non-empty)
Each lock is initialized with the provideduserandstrandedLockTimeoutMinutes.
CSVSensorParserFactory.CreateCSVParsers(...)
Signature:
public static IReadOnlyDictionary<int, IParseCSVSensor> CreateCSVParsers(
ICalibrationImport import,
ZeroMethodOptions zmOptions,
IImportNotification importNotification,
bool importCreateDynamicGroups,
bool useISOCodeFilterMapping,
bool useZeroForUnfiltered)
Behavior: Returns a dictionary mapping parser version numbers (int) to initialized IParseCSVSensor implementations (Version0CSVSensorParser, Version2CSVSensorParser, Version3CSVSensorParser, Version4CSVSensorParser). Each parser is initialized via its Initialize(...) method with the provided parameters. Keys are the parsers’ Version property values.
SaveVariantFactory.CreateVariants(...)
Signature:
public static List<IPersistImport> CreateVariants(
ImportObject importObject,
ImportNotification importNotification,
User user,
Func<bool> isCanceled,
bool showCheckoutButton)
Behavior: Returns a list of IPersistImport implementations (save handlers) for various import entities, conditionally instantiated based on content in importObject. Includes:
SaveCustomerDetails,SaveTestEngineerDetails,SaveLabDetails,SaveSensorModels,SaveUsers,SaveGlobalSettingsSaveCsvSourceSensororSaveNonCsvSourceSensor(based onimportObject.SourceFormat == ImportFormats.DTS_CSV)SaveHardware,SaveGroupTemplates,SaveGroups,SaveCustomChannelsSaveTestSetupand optionallySaveCheckoutTestSetup(ifimportObject.TestSetups()is non-empty andshowCheckoutButtonis true)
TheSaveTestSetupname is modified by appendingSerialization.RDF.File.SUFFIX_RUNTEST. IfshowCheckoutButtonis true, a secondSaveCheckoutTestSetupis created withSUFFIX_CHECKOUT. All handlers receiveisCanceledandimportNotification, and some receiveuseror other dependencies (e.g.,saveHardware,saveGroups). A sharedPersistCalculatorinstance is used to track progress totals.
XmlParserFactory.CreateXMLParsers(...)
Signature:
public static IEnumerable<IParseVariant> CreateXMLParsers(
string fileName,
IImportNotification importNotification,
Func<bool> isCanceled,
bool skipNormalizing)
Behavior: Returns an enumeration of IParseVariant implementations based on the XML file version (determined via FileUtils.GetImportXmlNode(...)).
- For versions <
FileUtils.DataPRO20XmlVersion: CallsLessThan20XMLVersion(...), wrapping parsers in pre-20-specific adapters (e.g.,XMLPre20ParseSensors,XMLPre20ParseCalibrations). - For versions ≥
FileUtils.DataPRO20XmlVersion: CallsGreaterOrEqual20XMLVersion(...), using direct parsers (e.g.,XMLParseSensors,XMLParseCalibrations).
SupportedTopLevelFieldsinclude:CustomChannels,CustomMainLocs,DASList,Sensors,Calibrations,GroupTemplates,Groups,TestSetups,LabDetails,CustomerDetails,TestEngineerDetails,Users.
Parsers are initialized withimportNotification,isCanceled, and version-specific parameters. Static propertiesUIItemsandImportNotificationare set before parsing.
3. Invariants
- Parser versioning: CSV parsers are versioned and returned in ascending order (e.g., v0, v5, v6 for tests; v0, v2, v3, v4 for sensors). XML parsers are selected based on a hard-coded version threshold (
FileUtils.DataPRO20XmlVersion). - Conditional instantiation: All factories instantiate components only when corresponding data exists in
ImportObject(e.g.,TestSetups().Any(),Sensors().Any()), avoiding unnecessary object creation. - Initialization consistency: For
CSVSensorParserFactory, all parsers are initialized with identical parameters and must be fully initialized before use (viaInitialize(...)). - Progress tracking:
SaveVariantFactoryuses a sharedPersistCalculatorinstance to accumulate total item counts across all save handlers. - Checkout behavior:
SaveCheckoutTestSetupis created only ifshowCheckoutButtonis true andTestSetups()is non-empty. The test setup name is modified usingSerialization.RDF.File.SUFFIX_RUNTEST/SUFFIX_CHECKOUT.
4. Dependencies
This module depends on:
DTS.Common.Import.Interfaces(IParseCSVTest,IParseCSVSensor,ILockImport,IPersistImport,IParseVariant,IImportNotification,ICalibrationImport)DTS.Slice.Users(User)DTS.Common.Import.DatabaseLocks(LockImportTestSetups,LockImportSensors,LockImportGroups)DTS.Common.Import.Parsers.CSV(Version0CSVTestParser,Version5CSVTestParser,Version6CSVTestParser,Version0CSVSensorParser,Version2CSVSensorParser,Version3CSVSensorParser,Version4CSVSensorParser)DTS.Common.Import.Persist(SaveCustomerDetails,SaveTestEngineerDetails,SaveLabDetails,SaveSensorModels,SaveCsvSourceSensor,SaveNonCsvSourceSensor,SaveUsers,SaveGlobalSettings,SaveHardware,SaveGroupTemplates,SaveGroups,SaveCustomChannels,SaveTestSetup,SaveCheckoutTestSetup,PersistCalculator)DTS.Common.Import.XML(XML parser types, e.g.,XMLParseSensors,XMLPre20ParseSensors)DTS.Common.Enums.DBExport(TopLevelFields)DTS.Common.Utils(FileUtils,Serialization.RDF.File)System.Xml(XmlElement,XmlDocument)
This module is depended upon by:
- Import orchestration logic (e.g.,
ImportService,ImportProcessor) that consumes these factories to build import pipelines.
(Exact callers are not visible in the provided source but are implied by the factory pattern usage.)
5. Gotchas
- Static state in
XmlParserFactory: The factory uses static properties (UIItems,ImportNotification) and a static field (_isCancelled) to pass context into parsers. This introduces thread-safety concerns ifCreateXMLParsersis called concurrently. SaveVariantFactorymutatesSaveCsvSourceSensor/SaveNonCsvSourceSensor: TheCurrentUserproperty is assigned after construction, not via constructor. Callers must ensure this is set before use.SaveTestSetup.TestSetupNamemodification: The test setup name is modified only whenshowCheckoutButtonis true, appendingSUFFIX_RUNTEST. This behavior is tied to GM parse mode (per comment//FB 38039), but the condition isshowCheckoutButton, not a dedicated flag.- XML version threshold: The version split (
< 20vs>= 20) is based onFileUtils.DataPRO20XmlVersion, but the constant itself is not defined in the provided source—its value must be verified externally. LessThan20XMLVersionearly exit: Returns an empty list ifnode == null || node.ChildNodes == null, but does not log or signal an error. Callers must handle empty results gracefully.SaveGroupsandSaveTestSetupdependencies:SaveGroupsandSaveTestSetupconstructors requiresaveHardwareandsaveGroups(respectively) as parameters, but these are instantiated after their dependencies in the factory method. This implies the factory method must construct them in dependency order (e.g.,saveHardwarebeforesaveGroups,saveGroupsbeforesaveTestSetup).