8.8 KiB
8.8 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||
|---|---|---|---|---|---|---|
|
2026-04-16T04:25:47.865565+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 6d8f47b7e121e9aa |
Documentation: IDataRecorders Interface and DataRecorders Implementation
1. Purpose
This module provides data access service (DAS) functions for managing data recorders (DAS units) and their associated channels in the database. It serves as the persistence layer for DAS-related operations—including CRUD (Create, Read, Update, Delete), channel management, and hierarchical relationships (e.g., parent/child encapsulated DAS). The interface IDataRecorders defines the contract, while the internal class DataRecorders implements it using SQL Server stored procedures and ADO.NET. It enforces user authentication, logs errors, and ensures database version compatibility for certain DAS types (e.g., SLICE6_AIR_TC).
2. Public Interface
The interface IDataRecorders defines the following public methods:
ulong DASChannelsDelete(IUserDbRecord user, IConnectionDetails connection, string hardwareId)
- Behavior: Deletes all DAS channel records associated with the given
hardwareId(format:SerialNumber_DASType). - Returns:
ERROR_SUCCESS(0) on success; otherwise, an error code (e.g.,ERROR_ACCESS_DENIED,ERROR_UNKNOWN). - Note: Does not delete the DAS record itself—only its channels.
ulong DASChannelsInsert(IUserDbRecord user, IConnectionDetails connection, string hardwareId, ref IDASChannelDBRecord record)
- Behavior: Inserts a new DAS channel record into the database. On success, populates
record.DaschannelIdwith the new database ID. - Returns:
ERROR_SUCCESS(0) on success;ERROR_MISSING_PARAMETERifrecordorhardwareIdis null/empty;ERROR_ACCESS_DENIEDif user not logged in;ERROR_UNKNOWNon failure. - Note: Modifies the
recordparameter by reference to update theDaschannelId.
ulong DASChannelsGet(IUserDbRecord user, IConnectionDetails connection, string hardwareId, out IDASChannelDBRecord[] channels)
- Behavior: Retrieves all DAS channel records for the given
hardwareId. IfhardwareIdisnull, returns all DAS channel records. - Returns:
ERROR_SUCCESS(0) on success;ERROR_ACCESS_DENIEDif user not logged in;ERROR_UNKNOWNon failure. - Output:
channelsis always initialized to an array (possibly empty) on return.
ulong DASChildrenGet(IUserDbRecord user, IConnectionDetails connection, string dasSerialNumber, out string[] childrenSerialNumbers)
- Behavior: Retrieves serial numbers of all child DAS units associated with the given parent
dasSerialNumber. Used for encapsulated/compacted DAS discovery. - Returns:
ERROR_SUCCESS(0) on success;ERROR_ACCESS_DENIEDif user not logged in;ERROR_UNKNOWNon failure. - Output:
childrenSerialNumbersis always initialized to an array (possibly empty) on return.
ulong DASDelete(IUserDbRecord user, IConnectionDetails connection, int DASId, string serialNumber, bool embedded)
- Behavior: Deletes a DAS record from the database. Requires either
DASId > 0or non-null/non-emptyserialNumber.- Removes associated test setup entries.
- Removes channel assignments (and channels if not
embedded). - Deletes DAS channels and metadata.
- Returns:
ERROR_SUCCESS(0) on success;ERROR_MISSING_PARAMETERif bothDASId ≤ 0andserialNumberis null/empty;ERROR_ACCESS_DENIEDif user not logged in;ERROR_UNKNOWNon failure.
ulong DASGet(IUserDbRecord user, IConnectionDetails connection, int clientDbVersion, string DASSerial, string position, out IDASDBRecord[] das)
- Behavior: Retrieves DAS records matching the search criteria.
- If both
DASSerialandDASIdare omitted (vianull/empty), returns all DAS records. - Does not enforce user permission checks (only login status).
- If both
- Returns:
ERROR_SUCCESS(0) on success;ERROR_ACCESS_DENIEDif user not logged in;ERROR_UNKNOWNon failure. - Output:
dasmay benullor an empty array on success.
ulong DASInsert(IUserDbRecord user, IConnectionDetails connection, IDASDBRecord das)
- Behavior: Inserts a new DAS record into the database. On success, populates
das.DASIdwith the new database ID. - Returns:
ERROR_SUCCESS(0) on success;ERROR_MISSING_PARAMETERifdasisnull;ERROR_ACCESS_DENIEDif user not logged in;ERROR_UNKNOWNon failure or version mismatch. - Special Behavior: For
DASType == SLICE6_AIR_TC, verifiesserverDbVersion >= SLICE_TC_DB_VERSION; otherwise, returnsERROR_UNKNOWN.
ulong DASUpdate(IUserDbRecord user, IConnectionDetails connection, IDASDBRecord das)
- Behavior: Updates an existing DAS record in the database.
- Returns:
ERROR_SUCCESS(0) on success;ERROR_ACCESS_DENIEDif user not logged in;ERROR_UNKNOWNon failure. - Note: Does not validate presence of
DASId; relies on stored procedure logic to locate the record.
3. Invariants
- User Authentication: All methods require the user to be logged in (checked via
IsUserLoggedIn(user, connection)). Failure returnsERROR_ACCESS_DENIED. - Parameter Validation:
DASChannelsInsert: Fails early ifrecord == nullorhardwareIdis null/empty/whitespace.DASDelete: Requires at least one ofDASId > 0or non-emptyserialNumber.DASInsert: Fails early ifdas == null.
- Database Version Compatibility: For
SLICE6_AIR_TCDAS types, insertion is blocked ifserverDbVersion < SLICE_TC_DB_VERSION. - Output Initialization: All
outarray parameters (channels,childrenSerialNumbers,das) are initialized to a non-null array (possibly empty) before returning. - Resource Cleanup: All database connections (
cmd.Connection) are disposed infinallyblocks. - Error Reporting: SQL stored procedure errors are logged via
LogManager, and the method returnsERROR_UNKNOWN(not the raw DB error code).
4. Dependencies
Module Dependencies
- Imports/Usings:
DbAPI.Connections(forIsUserLoggedIn,ConnectionManager,GetDatabaseVersion)DbAPI.Errors(forErrorCodes)DbAPI.Logging(forLogManager)DTS.Common.Interface.DataRecorders(forIDASChannelDBRecord,IDASDBRecord)DTS.Common.Interface.Database(forIUserDbRecord,IConnectionDetails)DTS.Common.Classes,DTS.Common.Enums.*(for types likeHardwareTypes,DFConstantsAndEnums)System.Data,System.Data.SqlClient(ADO.NET types)
External Dependencies
- Database: Requires SQL Server with the following stored procedures:
sp_DASChannelsDeletesp_DASChannelsInsertsp_DASChannelsGetsp_DASChildrenGetsp_DASDeletesp_DASGetsp_DASInsertsp_DASUpdate
- Database Version: Must support
SLICE_TC_DB_VERSIONconstant forSLICE6_AIR_TCDAS types.
Depended Upon
- Consumers: Other modules in
DbAPI.DAS(e.g., higher-level services or UI layers) that need DAS CRUD operations.
5. Gotchas
- Parameter Name Typo: In
DASChannelsGet, the parameterconnetion(missing 'c') is used instead ofconnection. This is consistent in both interface and implementation. DASUpdateDoes Not ValidateDASId: Unlike typical updates,DASUpdatedoes not requiredas.DASIdto be set; it relies on the stored procedure to locate the record (likely viaSerialNumberor other fields). This could cause unintended updates ifSerialNumberis not unique or stable.DASInsertModifies Input Record: Thedasparameter is mutated to include the newDASIdon success. Callers must be aware of this side effect.DASChannelsInsertModifies Input Record: Similarly,recordis mutated to includeDaschannelId.DASGetIgnoresDASIdParameter: The interface declaresint DASIdbut the implementation does not use it (seeDASGetsignature inIDataRecorders.cs). OnlyDASSerialandpositionare used. This is likely a legacy or incomplete parameter.DASDeleteBehavior withembeddedFlag: Whenembedded == true, channels are not deleted (only assignments are removed). Whenembedded == false, channels are deleted. This is critical for correct usage.DASInsertVersion Check is Hardcoded: The version check forSLICE6_AIR_TCis hardcoded and does not use a configurable constant beyondDTS.Common.Constants.SLICE_TC_DB_VERSION. Ensure this constant is up-to-date.- No Transaction Handling: Operations are executed individually (no explicit transaction scope), risking partial failures if multiple operations must succeed/fail together.
Console.WriteLinein Production Code:DataRecorders.cscontainsConsole.WriteLinecalls (e.g., inDASDelete), which may leak debug output in production.