Files
DP44/docs/ai/Common/DTS.Common.Import/Factories.md
2026-04-17 14:55:32 -04:00

5.8 KiB

source_files, generated_at, model, schema_version, sha256
source_files generated_at model schema_version sha256
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
2026-04-17T15:35:40.559078+00:00 zai-org/GLM-5-FP8 1 eef1e6fa8b308008

DTS.Common.Import.Factories Documentation

1. Purpose

This module provides a collection of factory classes responsible for creating and configuring parsers, persisters, and database locks for the DTS import system. The factories abstract the instantiation logic for versioned CSV parsers (tests and sensors), XML parsers (with version-specific handling), save handlers for various import entity types, and database locking mechanisms. This design centralizes object creation, enabling consistent initialization and easier maintenance of the import pipeline.


2. Public Interface

CSVTestParserFactory

Class: DTS.Common.Import.Factories.CSVTestParserFactory

Method Signature Description
CreateCSVParsers public static IParseCSVTest[] CreateCSVParsers() Creates and returns an array of CSV test parsers for versions 0, 5, and 6. Parsers are instantiated in order and returned as an array.

DatabaseLocksFactory

Class: DTS.Common.Import.Factories.DatabaseLocksFactory (static)

Method Signature Description
Create public static List<ILockImport> Create(ImportObject importObject, User user, double strandedLockTimeoutMinutes) Creates a list of lock import objects based on the contents of the provided ImportObject. Only creates locks for entity types that have data (TestSetups, Sensors, StaticGroups).

CSVSensorParserFactory

Class: DTS.Common.Import.Factories.CSVSensorParserFactory

Method Signature Description
CreateCSVParsers public static IReadOnlyDictionary<int, IParseCSVSensor> CreateCSVParsers(ICalibrationImport import, ZeroMethodOptions zmOptions, IImportNotification importNotification, bool importCreateDynamicGroups, bool useISOCodeFilterMapping, bool useZeroForUnfiltered) Creates a read-only dictionary mapping version numbers to CSV sensor parsers. Initializes parsers for versions 0, 2, 3, and 4 with the provided configuration parameters.

SaveVariantFactory

Class: DTS.Common.Import.Factories.SaveVariantFactory (static)

Method Signature Description
CreateVariants public static List<IPersistImport> CreateVariants(ImportObject importObject, ImportNotification importNotification, User user, Func<bool> isCanceled, bool showCheckoutButton) Creates a list of save handlers (IPersistImport) for all entity types present in the ImportObject. Handles CustomerDetails, TestEngineerDetails, LabDetails, SensorModels, Sensors, Users, GlobalSettings, Hardware, GroupTemplates, Groups, and TestSetups. Conditionally creates checkout test setups when showCheckoutButton is true.

XmlParserFactory

Class: DTS.Common.Import.XmlParserFactory (static)

Property Type Description
UIItems List<IUIItems> Static property for UI items used during XML parsing.
ImportNotification IImportNotification Static property for import notifications.
Method Signature Description
CreateXMLParsers public static IEnumerable<IParseVariant> CreateXMLParsers(string fileName, IImportNotification importNotification, Func<bool> isCanceled, bool skipNormalizing) Entry point for creating XML parsers. Reads the file to determine import version and delegates to version-specific factory methods.
LessThan20XMLVersion private static List<IParseVariant> LessThan20XMLVersion(XmlElement node, double importVersion) Creates parsers for XML versions below 2.0. Handles CustomChannels, CustomMainLocs, DASList, Sensors, Calibrations, GroupTemplates, Groups, and TestSetups.
GreaterOrEqual20XMLVersion private static List<IParseVariant> GreaterOrEqual20XMLVersion(XmlElement node, double importVersion, bool skipNormalizing) Creates parsers for XML versions 2.0 and above. Handles LabDetails, CustomerDetails, TestEngineerDetails, DASList, Sensors, Calibrations, GroupTemplates, Groups, TestSetups, and Users.

3. Invariants

  • CSVTestParserFactory: Always returns parsers in the order: Version0, Version5, Version6. The array length is always 3.
  • CSVSensorParserFactory: The returned dictionary is keyed by the parser's Version property (accessed via v0.Version, v2.Version, etc.). Versions 0, 2, 3, and 4 are always included.
  • DatabaseLocksFactory: Only creates lock objects for entity types where importObject.<Entities>().Any() returns true. An empty list is returned if no entities are present.
  • SaveVariantFactory:
    • A single shared PersistCalculator instance is used across all save handlers.
    • SaveCustomChannels and SaveHardware are instantiated regardless of whether data exists, but only added to saveHandlers if Hardware().Any() is true for SaveHardware.
    • SaveGroups is only added to saveHandlers if Groups().Any() or StaticGroups().Any() is true.
    • When showCheckoutButton is true, both SaveTestSetup and SaveCheckoutTestSetup are created for test setups.
  • XmlParserFactory:
    • The version threshold is FileUtils.DataPRO20XmlVersion. Versions below this use LessThan20XMLVersion; versions at or above use GreaterOrEqual20XMLVersion.
    • LessThan20XMLVersion returns an empty list if node or node.ChildNodes is null.
    • Unknown XML element names