74 lines
5.1 KiB
Markdown
74 lines
5.1 KiB
Markdown
---
|
||
source_files:
|
||
- DataPRO/DASFactoryDb/Config/Config.cs
|
||
generated_at: "2026-04-16T03:52:17.979930+00:00"
|
||
model: "Qwen/Qwen3-Coder-Next-FP8"
|
||
schema_version: 1
|
||
sha256: "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_DASInfoInsert` stored procedure. Returns the ID of the inserted/updated record (via `@new_id` output parameter).
|
||
- **Null/Default Handling**:
|
||
- `macAddress` → `string.Empty` if `null`.
|
||
- `maxEventStorageSpaceInBytes`, `numberOfBytesPerSampleClock` → `0` if `null`.
|
||
- `calibrationDate` → `SqlDateTime.MinValue` if `null` or less than `SqlDateTime.MinValue`.
|
||
- **Error Handling**: Delegates to `DbWrapper.ProcessReturn` after execution; throws on non-zero `@errorNumber`.
|
||
|
||
#### `void DASInfoClear(int iDASRecordId)`
|
||
- **Behavior**: Clears DAS device metadata by calling `sp_DASInfoClear`. Does nothing if `DbWrapper.Connected` is `false`.
|
||
- **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 calling `sp_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 (including `null` → `DBNull.Value` behavior depends on `SqlParameter` handling).
|
||
- **Error Handling**: Same as above; skips execution if not connected.
|
||
|
||
---
|
||
|
||
### 3. Invariants
|
||
- **Connection State**: `DASInfoClear` and `SetConfiguration` silently exit if `DbWrapper.Connected == false`. `DASInfoInsert` does *not* check connection state and will attempt execution regardless.
|
||
- **Parameter Validation**:
|
||
- `maxNumberOfModules` is bound as `SqlDbType.Int` despite being `uint`; potential overflow if `> int.MaxValue`.
|
||
- `maxEventStorageSpaceInBytes` and `numberOfBytesPerSampleClock` are `ulong?` but bound as `SqlDbType.Int`; values > `int.MaxValue` will overflow silently (to negative or truncated values).
|
||
- **Date Handling**: `calibrationDate` is clamped to `SqlDateTime.MinValue` (1753-01-01) if below it; `DateTime.MinValue` (0001-01-01) is converted to this minimum.
|
||
- **Error Propagation**: All methods rely on `DbWrapper.ProcessReturn` to interpret `@errorNumber` and `@errorMessage`; non-zero `@errorNumber` likely throws an exception (behavior depends on `DbWrapper.ProcessReturn` implementation, not visible here).
|
||
|
||
---
|
||
|
||
### 4. Dependencies
|
||
- **Internal Dependencies**:
|
||
- `DbWrapper` (static class): Provides `GetDASFactoryCommand()`, `Connected` property, and `ProcessReturn(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_DASInfoInsert`
|
||
- `sp_DASInfoClear`
|
||
- `sp_ConfigDataSet`
|
||
- Assumed schema: Tables/columns matching parameter names (e.g., `@IDASCommunicationRecordId`, `@ConfigurationData`, `@ConfigStore`).
|
||
|
||
---
|
||
|
||
### 5. Gotchas
|
||
- **Silent Data Truncation**: `maxEventStorageSpaceInBytes` and `numberOfBytesPerSampleClock` (`ulong?`) are cast to `int` (via `SqlDbType.Int`). Values > `2,147,483,647` will overflow or wrap, causing incorrect data.
|
||
- **No Connection Guard in `DASInfoInsert`**: Unlike `DASInfoClear`/`SetConfiguration`, this method proceeds even if `DbWrapper.Connected == false`, risking runtime exceptions.
|
||
- **`macAddress` Null Handling**: Converts `null` to `string.Empty` before binding, which may mask missing data (e.g., DB might accept empty string as valid).
|
||
- **`xml` Parameter**: No validation or encoding checks; malformed XML or non-UTF-8 data could cause DB errors.
|
||
- **Resource Management**: `cmd.Connection.Dispose()` in `finally` blocks may conflict with `DbWrapper`’s connection lifecycle if it manages pooled connections.
|
||
- **Missing Return Value**: `SetConfiguration` retrieves `@new_id` but 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.* |