5.1 KiB
5.1 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |
|---|---|---|---|---|---|
|
2026-04-16T03:52:17.979930+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 609ad832d02ccb50 |
Config
Documentation: DASFactoryDb.Config.Config Module
1. Purpose
This module provides a thin, static wrapper around three SQL Server stored procedures (sp_DASInfoInsert, sp_DASInfoClear, and sp_ConfigDataSet) for managing DAS (Data Acquisition System) device metadata and configuration in the DASFactoryDb database. It abstracts low-level ADO.NET operations—including parameter binding, null handling, and error propagation—into strongly-typed C# methods. Its role is to ensure consistent, validated data persistence for DAS device information (e.g., MAC address, module limits, battery, calibration) and XML-based configuration blobs.
2. Public Interface
int DASInfoInsert(int iDASRecordId, string macAddress, int owningDASId, uint maxNumberOfModules, ulong? maxEventStorageSpaceInBytes, ulong? numberOfBytesPerSampleClock, string batteryId, DateTime? calibrationDate)
- Behavior: Inserts or updates DAS device metadata by calling the
sp_DASInfoInsertstored procedure. Returns the ID of the inserted/updated record (via@new_idoutput parameter). - Null/Default Handling:
macAddress→string.Emptyifnull.maxEventStorageSpaceInBytes,numberOfBytesPerSampleClock→0ifnull.calibrationDate→SqlDateTime.MinValueifnullor less thanSqlDateTime.MinValue.
- Error Handling: Delegates to
DbWrapper.ProcessReturnafter execution; throws on non-zero@errorNumber.
void DASInfoClear(int iDASRecordId)
- Behavior: Clears DAS device metadata by calling
sp_DASInfoClear. Does nothing ifDbWrapper.Connectedisfalse. - Note: No return value; errors are propagated via
DbWrapper.ProcessReturn.
void SetConfiguration(int iDASRecordId, string xml, int fileStore)
- Behavior: Stores XML configuration data as UTF-8 encoded binary (
VarBinary) by callingsp_ConfigDataSet. Returns the new configuration record ID via@new_id(not exposed in return value). - Null/Default Handling: No explicit null checks on
xml; passes raw bytes (includingnull→DBNull.Valuebehavior depends onSqlParameterhandling). - Error Handling: Same as above; skips execution if not connected.
3. Invariants
- Connection State:
DASInfoClearandSetConfigurationsilently exit ifDbWrapper.Connected == false.DASInfoInsertdoes not check connection state and will attempt execution regardless. - Parameter Validation:
maxNumberOfModulesis bound asSqlDbType.Intdespite beinguint; potential overflow if> int.MaxValue.maxEventStorageSpaceInBytesandnumberOfBytesPerSampleClockareulong?but bound asSqlDbType.Int; values >int.MaxValuewill overflow silently (to negative or truncated values).
- Date Handling:
calibrationDateis clamped toSqlDateTime.MinValue(1753-01-01) if below it;DateTime.MinValue(0001-01-01) is converted to this minimum. - Error Propagation: All methods rely on
DbWrapper.ProcessReturnto interpret@errorNumberand@errorMessage; non-zero@errorNumberlikely throws an exception (behavior depends onDbWrapper.ProcessReturnimplementation, not visible here).
4. Dependencies
- Internal Dependencies:
DbWrapper(static class): ProvidesGetDASFactoryCommand(),Connectedproperty, andProcessReturn(SqlParameter, SqlParameter).System.Data,System.Data.SqlClient,System.Text: For ADO.NET types and UTF-8 encoding.
- External Dependencies:
- SQL Server database with stored procedures:
sp_DASInfoInsertsp_DASInfoClearsp_ConfigDataSet
- Assumed schema: Tables/columns matching parameter names (e.g.,
@IDASCommunicationRecordId,@ConfigurationData,@ConfigStore).
- SQL Server database with stored procedures:
5. Gotchas
- Silent Data Truncation:
maxEventStorageSpaceInBytesandnumberOfBytesPerSampleClock(ulong?) are cast toint(viaSqlDbType.Int). Values >2,147,483,647will overflow or wrap, causing incorrect data. - No Connection Guard in
DASInfoInsert: UnlikeDASInfoClear/SetConfiguration, this method proceeds even ifDbWrapper.Connected == false, risking runtime exceptions. macAddressNull Handling: Convertsnulltostring.Emptybefore binding, which may mask missing data (e.g., DB might accept empty string as valid).xmlParameter: No validation or encoding checks; malformed XML or non-UTF-8 data could cause DB errors.- Resource Management:
cmd.Connection.Dispose()infinallyblocks may conflict withDbWrapper’s connection lifecycle if it manages pooled connections. - Missing Return Value:
SetConfigurationretrieves@new_idbut discards it; callers cannot confirm the inserted ID. - No Timeout Configuration: Command timeout defaults to
DbWrapper’s implementation (not specified here).
None identified beyond these.