8.0 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
2026-04-16T11:31:09.102777+00:00 | zai-org/GLM-5-FP8 | 1 | 5cf7683c6017efd4 |
Documentation: DTS.Common.Storage
1. Purpose
The DTS.Common.Storage namespace provides the data access layer, database schema definitions, and connection management utilities for the DTS DataPRO system. It bridges the application logic and the persistence layer (SQL Server and LocalDB). This module defines database schemas via constants and enums for Sensors, Test Setups, and MME (Measurement and Monitoring Equipment) tables, manages local/remote database connections, handles test history serialization, and provides utilities for type conversion and user data migration.
2. Public Interface
DTS.Common.Storage.DatabaseServices
An abstract class providing static methods for database lifecycle management.
static void RestoreLocalDatabase(string defaultDbName): Restores the local database from.BAKfiles by stopping the LocalDB instance, copying files, and restarting the instance.static void BackupLocalDatabase(string defaultDbName): Creates backups of the local database.mdfand_log.ldffiles.static int SetupLocal(string defaultDbName): Initializes the connection for a local database usingDbOperations.static int SetupLocal2(string defaultDbName): Initializes the connection for a local database usingLocalOnlyOperations.static int SetupForRemoteDb(string dbHost, bool userNTLMAuthentication, string user, string password, string defaultDbName): Configures the connection for a centralized remote SQL database.static bool SimpleDbTest(): Executes a simple query (SELECT TOP 1 [DASId] FROM [DAS]) to verify database connectivity.
DTS.Common.Storage.LocalOnlyOperations
A singleton class used to access the local database independently of the remote database connection.
static LocalOnlyOperations Connection { get; }: Singleton instance accessor.static void CreateParam(IDbCommand icmd, string name, SqlDbType type, object value): Adds a parameter to a command. Note: Contains specific logic to convertDateTimevalues to strings orSqlDateTime.MinValue.static SqlCommand GetSQLCommand(bool newCommand): Retrieves aSqlCommand. Reuses a static command object unlessnewCommandis true. Manages connection opening automatically.int ExecuteCommand(IDbCommand icmd): Executes a non-query command against a newly opened connection.string GetLocalConnectionString(): Constructs and caches the connection string usingServerandDbNameproperties.
DTS.Common.Storage.TestHistory
A serializable entity class representing a record from the test history table.
TestHistory(IDataReader reader): Constructor that populates the object from a data reader.static TestHistory[] GetTestHistory(string name): Retrieves all test histories matching a test setup name via the stored proceduresp_TestHistoryGet.static string SerializeToString(TestHistory[] histories): Serializes an array ofTestHistoryobjects to an XML string using theTestHistoryCollectionhelper class.
DTS.Common.Storage.TypeConvertor
A sealed utility class for mapping between .NET types, DbType, and SqlDbType.
static Type ToNetType(DbType dbType)static Type ToNetType(SqlDbType sqlDbType)static DbType ToDbType(Type type)static DbType ToDbType(SqlDbType sqlDbType)static SqlDbType ToSqlDbType(Type type)static SqlDbType ToSqlDbType(DbType dbType)
DTS.Common.Storage.UserMigrationHelper
A helper class for migrating user data from database version 52 to 53.
UserMigrationHelper(DataRow row): Parses user data, permissions, and visibility from aDataRow.void Commit(Dictionary<string, long> IUIItemNameToID): Inserts the user intoDataPROUsersand related tables (UserUIItemSettings,TagAssignments). Supports both MSSQL and SQLite execution paths.
DTS.Common.Storage.DbOperations (Partial Classes)
Contains nested abstract classes defining database schemas via constants and enums.
DbOperations.SensorDB:- Constants:
SensorCalibrationTable,SensorDataTable,SensorModelsTable. - Enums:
SensorDataFields,SensorModelFields,SensorCalibrationFields,SensorCalibrationRecordFields.
- Constants:
DbOperations.MMETables:- Constants:
MMEPossibleChannelsTable,MMEDirectionsTable,MMEFilterClassesTable, etc. - Enums:
MMEPossibleChannelsFields,MMEDirectionsFields, etc. - Legacy Constants:
MyType,CustomChannelType,Id(marked as replaced in specific versions).
- Constants:
DbOperations.TestSetups:- Constants:
HardwareTable,DASSettingsTable,TestSetupsTable, etc. - Enums:
HardwareFields,ChannelSettingFields,Fields,SettingsFields, etc.
- Constants:
3. Invariants
- Singleton Access:
LocalOnlyOperations.ConnectionandDbOperations.Connectionare accessed via a singleton pattern protected by a lock (DbLock). - Schema Consistency: The
enumvalues inSensorDB,MMETables, andTestSetupsdefine the column order or IDs for database tables.SerialNumberinSensorDataFieldsis explicitly value1. - Type Mapping:
TypeConvertormaintains a static 1-to-1 mapping between specific .NET types (e.g.,bool,DateTime,int) and SQL types (e.g.,Bit,DateTime,Int). Unsupported types throwApplicationException. - Connection String:
LocalOnlyOperationsuses Windows Authentication (Trusted_Connection=TRUE) exclusively for its connection string.
4. Dependencies
- External Libraries:
System.Data.SqlClient: Used heavily for SQL Server interaction.System.Xml.Serialization: Used byTestHistoryfor XML serialization.DTS.Common.Utilities.Logging: Used for logging (APILogger.Log).DbAPI: Used for connection details and error codes (DbAPI.Connections.ConnectionDetails,DbAPI.Errors.ErrorCodes).
- Internal Coupling:
DatabaseServicesdepends onLocalOnlyOperations,DbOperations, andUtils.Database.UserMigrationHelperdepends onDbOperationsto determine if MSSQL or SQLite is being used (DbOperations._usingMSSQL).TestHistorydepends onDbOperations.GetSQLCommand.
5. Gotchas
- Static Command Reuse:
LocalOnlyOperations.GetSQLCommand()reuses a staticSqlCommandfield (cmd) by default. IfnewCommandis false, the same object is returned for every call. WhileParameters.Clear()is called, this creates shared state which may cause issues in multi-threaded scenarios. - DateTime Conversion Hack: In
LocalOnlyOperations.CreateParam,DateTimeobjects are converted to formatted strings (yyyy-MM-dd HH:mm:ss) rather than being passed as native SQL parameters. Additionally,DateTimevalues belowSqlDateTime.MinValueare clamped toSqlDateTime.MinValue. This is likely a workaround for SQL ServerDateTimerange limitations. - SQLite vs MSSQL Duality:
UserMigrationHelper.CommitchecksDbOperations._usingMSSQLto switch betweenExecuteCommandandExecuteSQLiteCommand. However,LocalOnlyOperationsappears hardcoded to useSqlConnection(MSSQL), suggesting the SQLite support is incomplete or localized to specific migration paths. - Legacy Schema Constants:
DbOperations.MMETablescontains constantsMyType,CustomChannelType, andIdwith comments indicating they were replaced by different string values in software versions 1.3.496 through 1.3.515. Developers should use the current constants (TYPE,ID) rather than the legacy ones. - Typo: The class
TypeConvertoris spelled with an "or" suffix instead of the standard "er" (TypeConverter).