9.4 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |
|---|---|---|---|---|---|
|
2026-04-16T04:33:34.717126+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | c54de3e2daf5d6b9 |
TestSetups
Purpose
The ImportTestSetup class is a WPF UserControl responsible for parsing and importing structured XML data representing test setup configurations (including sensors, calibrations, hardware, groups, and custom MME metadata) into the system’s database via stored procedures. It acts as the core ingestion layer for legacy or exported test setup files, supporting versioned import logic (v1.0 and v2.0) and maintaining in-memory collections of imported entities prior to database persistence. Its role is to translate XML fragments into domain objects and orchestrate their bulk insertion into the database while preserving data integrity and handling version-specific transformations.
Public Interface
Static Fields (Publicly Exposed Collections)
These collections hold imported data before it is persisted to the database. They are populated during XML processing and cleared by Cleanup().
| Field | Type | Description |
|---|---|---|
Directions |
List<MMEDirections> |
Custom MME direction definitions imported from XML. |
FilterClasses |
List<MMEFilterClasses> |
Custom MME filter class definitions. |
FineLoc1s |
List<MMEFineLocations1> |
First-level fine location definitions. |
FineLoc2s |
List<MMEFineLocations2> |
Second-level fine location definitions. |
FineLoc3s |
List<MMEFineLocations3> |
Third-level fine location definitions. |
MainLocs |
List<MMETransducerMainLocation> |
Transducer main location definitions. |
TestObjects |
List<MMETestObjects> |
Custom test object definitions. |
PhysicalDimensions |
List<MMEPhysicalDimensions> |
Physical dimension definitions. |
Positions |
List<MMEPositions> |
Position definitions. |
Calibrations |
List<SensorCalibration> |
Sensor calibration history records. |
CustomerDetails |
List<ISO.CustomerDetails> |
Customer metadata imported from XML. |
LabDetails |
List<ISO.LabratoryDetails> |
Laboratory metadata imported from XML. |
Sensors |
List<SensorData> |
Sensor definitions (note: declared public static readonly, but no direct population logic visible in this file—likely populated via ImportElement → stored procedure). |
_testSetups |
List<TestTemplate> |
Test setup templates (note: declared public static, not readonly). |
_sensorsWithDuplicateIds |
List<SensorData> |
Internal tracking for sensors with duplicate IDs (not exposed publicly). |
Static Methods
| Method | Signature | Description |
|---|---|---|
ProcessRootNode |
public static void ProcessRootNode(string name, string outerXML, DbImporter.SetStatusDelegate SetStatus) |
Dispatches XML fragment processing based on name (e.g., "SensorData", "TestSetup"). Maps element names to corresponding stored procedures and invokes ImportElement. Does not handle DbVersion or SensorCalibration directly—those have dedicated logic elsewhere (see ImportCalibrations). |
ImportElement |
private static void ImportElement(string storedProcedure, string storedProcedureParameter, string outerElementName, string outerXML) |
Wraps outerXML in <outerElementName>...</outerElementName>, executes the specified stored procedure with the XML as an @parameter, and captures output error info. Throws on failure. Does not log or handle errors beyond re-throwing. |
GetTestSetupName |
private static string GetTestSetupName(string outerXML) |
Extracts SetupName from <TestSetup/Fields/SetupName> in outerXML using XmlDocument. Returns null if not found. |
Cleanup |
private static void Cleanup() |
Clears all static collections listed above (including _sensorsWithDuplicateIds, _globalSettings, _customChannels, etc.). Resets state for a new import session. |
Nested Types (Referenced)
PossibleStatusenum: Defines UI states (Waiting,Working,Done,Failed).DbOperationsEnum.StoredProcedure: Used to resolve stored procedure names (e.g.,sp_DBImportSensors).SensorCalibration,SensorData,TestTemplate,DASHardware,User,TestObject, etc.: Domain types imported via XML or stored procedures.
Note
:
ProcessRootNodedoes not handleSensorCalibrationorDbVersion—those are processed separately (implied byImportCalibrationsmethod and_importedVersionusage).DbVersionis imported viaImportElement, but_importedVersionis set elsewhere (not shown here).
Invariants
-
XML Structure:
outerXMLpassed toProcessRootNodemust be a well-formed XML fragment corresponding to the expected schema for the givenname(e.g.,<SensorData>...</SensorData>).GetTestSetupNameassumesouterXMLcontains a<TestSetup>root with a<Fields>child containing<SetupName>.
-
Version Handling:
_importedVersion(private) must be set beforeImportCalibrationsis called (not shown in this file).- Calibration import logic diverges based on
_importedVersion == 1.0Dor2.0D. Version 1.0 applies transformations (e.g., settingSensitivityUnits,AtCapacity = false).
-
Database Interaction:
- All
ImportElementcalls use stored procedures with XML parameters. - Stored procedure output parameters
@errorNumberand@errorMessageare captured but only checked for non-zero@errorNumber; error messages are not propagated or logged in this method. - Command timeout is fixed at 60 seconds.
- All
-
State Management:
Cleanup()must be called before a new import to reset all static collections._sensorsWithDuplicateIdsis populated elsewhere (not visible here) but is cleared onCleanup().
Dependencies
Internal Dependencies
- Types:
DbOperations(providesGetSQLCommandandSetStatusDelegate).DbOperationsEnum.StoredProcedure(for stored procedure names).ISO.CustomerDetails,ISO.LabratoryDetails,SensorCalibration,SensorData,TestTemplate,DASHardware,User,TestObject,MME*types (e.g.,MMEDirections,MMEPossibleChannels).Test.Module.Channel.Sensor.SensUnits(used inImportCalibrationsfor v1.0 transformations).
- XAML:
ImportTestSetup.xaml(interaction logic partial class).
External Dependencies
- .NET Framework:
System.Data,System.Data.SqlClient,System.Xml,System.Windows.Controls. - Database: SQL Server (via stored procedures named
sp_DBImport*). - Calling Code:
DbImporter.SetStatusDelegate(likely fromDbImporterclass) for status reporting.
Depended Upon
- Likely invoked by
DbImporter(or similar orchestrator) during XML parsing of an import file. - Public static fields are consumed by downstream logic (e.g., UI binding, final commit to DB).
Gotchas
-
Static State Management:
- All data is held in static collections. This makes the class not thread-safe and unsuitable for concurrent imports without external synchronization.
Cleanup()must be called explicitly before each import; otherwise, stale data persists across sessions.
-
Incomplete Error Handling:
ImportElementcaptures@errorNumberand@errorMessagebut does nothing with them (commented-out error handling block). Errors are silently ignored unless an exception is thrown.ProcessRootNodedoes not handleSensorCalibrationorDbVersion—these require separate processing logic (implied byImportCalibrationsand_importedVersionusage), which is not visible here.
-
Version-Specific Logic Fragility:
- Calibration import for v1.0 assumes exactly one calibration record (
sc.Records.Records[0]). If the schema changes, this will throwIndexOutOfRangeException. _importedVersionis set elsewhere (not in this file), creating a hidden dependency.
- Calibration import for v1.0 assumes exactly one calibration record (
-
XML Parsing Assumptions:
GetTestSetupNameusesSelectSingleNodewithout null-checking beyond the null-conditional operator. IfSetupNameis missing, it returnsnull—callers must handle this.outerXMLis naively wrapped in<outerElementName>...</outerElementName>. IfouterXMLalready contains a root element, this produces invalid XML.
-
Naming Inconsistencies:
LabDetailsusesLabratoryDetails(misspelled) in the type name (ISO.LabratoryDetails)._testSetupsispublic static List<TestTemplate>, while other collections (e.g.,Calibrations) arereadonly. This suggests_testSetupsmay be reassigned elsewhere.
-
No Version Validation:
- No explicit check ensures
_importedVersionmatchesCurrentVersion(2.0). Mismatched versions may cause silent data loss or corruption.
- No explicit check ensures
-
Unused/Commented Code:
ProcessRootNodecontains commented-outCancelCheckcalls andpageparameters, suggesting legacy cancellation UI support that is no longer active.- The
//Store the compressed binary copy...comment in the"TestSetup"case indicates incomplete or deprecated functionality.
None identified from source alone for thread-safety, serialization, or external API contracts—these require examining
DbImporterand related types.