12 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
2026-04-17T15:29:48.477859+00:00 | zai-org/GLM-5-FP8 | 1 | f8c80457dce3204b |
DTS.Common.Storage Module Documentation
1. Purpose
The DTS.Common.Storage module provides data access infrastructure for a test and measurement system (DataPRO). It defines database schema constants (table names and field enumerations), manages connections to both local SQL Server LocalDB instances and remote databases, handles type conversion between .NET and SQL types, and provides utilities for test history management, database backup/restore, and user migration. The module serves as the persistence layer for sensor configurations, test setups, MME (Measurement/Monitoring Equipment) metadata, and user data.
2. Public Interface
DbOperations.SensorDB (abstract class)
Nested within DbOperations partial class. Contains schema constants and field enumerations for sensor-related tables.
Constants:
SensorCalibrationTable="tblSensorCalibrations"SensorDataTable="tblSensors"SensorModelsTable="tblSensorModels"
Enums:
SensorDataFields— 55 fields includingSerialNumber,UserSerialNumber,Model,Manufacturer,Status,Id,Capacity,BridgeType,CalInterval,LatestCalibrationId, etc.SensorModelFields— 32 fields includingModel,Manufacturer,Capacity,BridgeResistance,SupportedExcitation, etc.SensorCalibrationFields— 13 fields includingSerialNumber,CalibrationDate,Username,CalibrationRecords,SensorCalibrationId, etc.SensorCalibrationRecordFields— 7 fields includingSensitivity,Poly,AtCapacity,EngineeringUnits, etc.
DbOperations.MMETables (abstract class)
Nested within DbOperations partial class. Contains schema constants and field enumerations for MME reference tables.
Constants:
MyType="MyType"(legacy, replaced in v1.3.496)CustomChannelType="CustomChannelType"(legacy, replaced in v1.3.515)Id="Id"(legacy, replaced in v1.3.515)MMEPossibleChannelsTable,MMEDirectionsTable,MMEFilterClassesTable,MMEFineLocations1Table,MMEFineLocations2Table,MMEFineLocations3Table,MMEPhysicalDimensions,MMEPositionsTable,MMETestObjectsTable,MMEMainLocationTable
Enums:
MMEPossibleChannelsFields— 21 fields withCustomChannelFieldSizeAttributedecorationsMMEDirectionsFields,MMEFilterClassesFields,MMEFineLocations1Fields,MMEFineLocations2Fields,MMEFineLocations3Fields,MMEPhysicalDimensionFields,MMEPositionsFields,MMETestObjectsFields,MMEMainLocationsFields
DbOperations.TestSetups (abstract class)
Nested within DbOperations partial class. Contains schema constants and field enumerations for test configuration tables.
Constants:
HardwareTable="tblTestSetupHardware"DASSettingsTable="tblTestSetupDASSettings"ChannelSettingsTable="tblTestChannelSettings"TestSetupsTable="tblTestSetups"TestSetupObjectsTable="tblTestSetupObjects"TestObjectMetaDataTable="tblTestSetupObjectMetaData"TestObjectTemplatesTable="tblTestObjectTemplates"TestObjectsTable="tblTestObjects"TestGraphsTable="tblTestGraphs"
Enums:
HardwareFields,ChannelSettingFields,ChannelFields,SettingsFields,Fields,TestSetupObjectFields,TestSetupDASHardwareFields,TestSetupGroupFields,TestObjectMetaDataFields,TestObjectTemplatesFields,TestObjectsFields,GroupsGroupFields,GroupsGroupChannelFields,GroupsGroupHardwareListFields,GraphFields
LocalOnlyOperations (class)
Singleton class for local database access operations.
Constants:
BeginStatement="BEGIN TRAN;"CommitStatement="COMMIT TRAN;"UsingNtlmAuthentication=trueNoConnection="NoConnection"
Static Properties:
Connection— Singleton instance getter (thread-safe via lock onDbLock)cmd— StaticSqlCommandcache
Instance Properties:
Server— Database server addressDbName— Database nameUsername— Authentication usernamePassword— Authentication password
Methods:
static void CreateParam(IDbCommand icmd, string name, SqlDbType type, object value)— Creates and adds aSqlParameterto the command. HandlesDateTimeconversion to string format for dates belowSqlDateTime.MinValue.static IDbCommand GetCommand()— ReturnsGetSQLCommand().static SqlCommand GetSQLCommand()— ReturnsGetSQLCommand(false).static SqlCommand GetSQLCommand(bool newCommand)— Returns a cached or newSqlCommandwith an open connection. Clears parameters before returning.static IDbCommand GetSQLOnlyCommand()— Returns a newSqlCommandwithout connection setup.void ResetLocalConnectionString()— Clears cached connection string (thread-safe).string GetLocalConnectionString()— Builds and caches connection string usingTrusted_Connection=TRUE.int ExecuteCommand(IDbCommand icmd)— Executes a non-query command. ThrowsSystemException(NoConnection, ex)on connection failure.
DatabaseServices (abstract class)
Static methods for database lifecycle management.
Constants:
INSTANCE_NAME="DataPROInstance"LOCAL_SERVER=@"(localdb)\DataPROInstance"SCRIPTS_FOLDER="SQL Server Scripts"LOCAL_DB_FOLDER="db"ATTACH_DBS_BAT="AttachDBs.bat"
Methods:
static void RestoreLocalDatabase(string defaultDbName)— Stops LocalDB instance, restores.mdfand_log.ldffrom.BAKfiles, restarts instance.static void BackupLocalDatabase(string defaultDbName)— Stops LocalDB instance, copies.mdfand_log.ldfto.BAKfiles, restarts instance.static int SetupLocal(string defaultDbName)— ConfiguresDbOperations.Connectionfor local DB, returns connection DB version. ThrowsSystemExceptionon connection failure.static int SetupLocal2(string defaultDbName)— ConfiguresLocalOnlyOperations.Connectionfor local DB, returns connection DB version.static int SetupForRemoteDb(string dbHost, bool userNTLMAuthentication, string user, string password, string defaultDbName)— ConfiguresDbOperations.Connectionfor remote centralized DB.static bool SimpleDbTest()— Tests database connectivity by querying[DAS]table.
TestHistory (class)
Entity class representing test history records.
Properties:
TestHistoryId(long) — Primary keyTestSetupId(int) — Foreign key to test setupTestSetupName,TestSetupDescription,TestId(string)Destructive(bool)ArmTime(DateTime)TestSetup(byte[]) — Gzip-compressed XML
Constructors:
TestHistory()— Default constructor.TestHistory(IDataReader reader)— Populates instance from data reader, handlingDBNullchecks.
Static Methods:
static TestHistory[] GetTestHistory(string name)— Retrieves test histories via stored proceduresp_TestHistoryGet.static string SerializeToString(TestHistory[] histories)— Serializes array to XML usingXmlSerializer.
Nested Class:
TestHistoryCollection— Helper class for XML serialization withHistoriesproperty.
TypeConvertor (sealed class)
Type conversion utility between .NET, DbType, and SqlDbType.
Supported Types: bool, byte, byte[], DateTime, decimal, double, Guid, short, int, long, object, string, TimeSpan
Static Methods:
static Type ToNetType(DbType dbType)— ConvertsDbTypeto .NETType.static Type ToNetType(SqlDbType sqlDbType)— ConvertsSqlDbTypeto .NETType.static DbType ToDbType(Type type)— Converts .NETTypetoDbType.static DbType ToDbType(SqlDbType sqlDbType)— ConvertsSqlDbTypetoDbType.static SqlDbType ToSqlDbType(Type type)— Converts .NETTypetoSqlDbType.static SqlDbType ToSqlDbType(DbType dbType)— ConvertsDbTypetoSqlDbType.
UserMigrationHelper (class)
Migration utility for database version 52→53 user data migration.
Properties:
UserName,DisplayName,Password(string)Role(short)LastModified(DateTime)LastModifiedBy(string)LocalOnly(bool)Permissions—Dictionary<string, short>Visibility—Dictionary<string, bool>TagIds—int[]
Constructor:
UserMigrationHelper(DataRow row)— Parses user data fromDataRow, including tag deserialization from byte array.
Methods:
void Commit(Dictionary<string, long> IUIItemNameToID)— Inserts user intoDataPROUserstable, then inserts permissions intoUserUIItemSettingsand tags intoTagAssignments. Batches inserts in transactions of 25.
3. Invariants
- Singleton Pattern:
LocalOnlyOperations.Connectionis a singleton; the getter uses a lock (DbLock) to ensure thread-safe initialization. - Connection String Caching:
_localConnectioninLocalOnlyOperationsis cached after first access;ResetLocalConnectionString()must be called to refresh it. - DateTime Handling:
LocalOnlyOperations.CreateParamconvertsDateTimevalues belowSqlDateTime.MinValueto the minimum value, then formats as"yyyy-MM-dd HH:mm:ss"string. - Command Reuse:
GetSQLCommand(false)reuses a staticSqlCommandinstance; parameters are cleared before return. - Field Enum Values:
SensorDataFields.SerialNumberexplicitly starts at1; subsequent values auto-increment. - Nullable Type Support:
TypeConvertor.Find(Type)handles nullable types viaNullable.GetUnderlyingType. - Transaction Batching:
UserMigrationHelper.Commitbatches permission inserts in groups of 25 with explicitBEGIN TRAN/COMMIT TRAN.
4. Dependencies
This module depends on:
System.DataandSystem.Data.SqlClient— ADO.NET SQL Server clientSystem.Xml.Serialization— XML serialization forTestHistorySystem.IO— File operations for database backup/restoreDTS.Common.Utilities.Logging—APILoggerfor loggingDbAPI.Errors—ErrorCodesfor connection result checkingDbAPI.Connections—ConnectionDetailsclass
External dependencies inferred:
DbOperations(partial class) — Referenced byLocalOnlyOperations,TestHistory,UserMigrationHelper,DatabaseServicesbut not fully defined in provided sourcesUtils.Database—StopInstance,StartInstance,GetSqlServerLocalDbPath,GetODBCToolsPathUtils.FileUtils—DeleteFileOrMoveDbAPI.DbAPI.Connections—ConnectToDbmethod
5. Gotchas
-
Static Command Cache:
LocalOnlyOperations.cmdis a static field. Concurrent access toGetSQLCommand()withoutnewCommand: truecould lead to race conditions where one thread's connection is swapped mid-operation. -
DateTime Conversion Side Effect:
CreateParamconvertsDateTimeto a formatted string forSqlDbType.DateTime, which changes the parameter value type unexpectedly. NullDateTimevalues becomeSqlDateTime.MinValue. -
Legacy Field Name Constants:
MMETablescontains deprecated constants (MyType,CustomChannelType,Id) that were replaced in specific versions (1.3.496, 1.3.515). Code referencing these may be interacting with outdated schema expectations. -
Dual Database Execution Paths:
UserMigrationHelper.CommitchecksDbOperations._usingMSSQLto choose betweenExecuteCommandandExecuteSQLiteCommand. This suggests the system supports both SQL Server and SQLite, butLocalOnlyOperationsonly implements SQL Server-specific logic. -
Connection Disposal Pattern: Multiple methods (e.g.,
TestHistory.GetTestHistory,UserMigrationHelper.Commit) usefinally { cmd.Connection.Dispose(); }but thecmdobject itself is not disposed, potentially leaving resources unreleased. -
Hardcoded Stored Procedure:
TestHistory.GetTestHistoryreferencessp_TestHistoryGetstored procedure which is not defined in these sources. -
Incomplete Type Mapping:
TypeConvertormapsbyte[]toSqlDbType.Image(deprecated) rather thanVarBinary.