init
This commit is contained in:
87
docs/ai/DataPRO/DbAPI/Channels.md
Normal file
87
docs/ai/DataPRO/DbAPI/Channels.md
Normal file
@@ -0,0 +1,87 @@
|
||||
---
|
||||
source_files:
|
||||
- DataPRO/DbAPI/Channels/IChannels.cs
|
||||
- DataPRO/DbAPI/Channels/Channels.cs
|
||||
generated_at: "2026-04-17T15:58:55.611952+00:00"
|
||||
model: "zai-org/GLM-5-FP8"
|
||||
schema_version: 1
|
||||
sha256: "971339938de11eb6"
|
||||
---
|
||||
|
||||
# Documentation: DbAPI.Channels
|
||||
|
||||
## 1. Purpose
|
||||
The `DbAPI.Channels` namespace provides the database access layer for managing channel-related data. It implements the `IChannels` interface to perform CRUD operations on `Channels`, `ChannelCodes`, and `ChannelSettings` tables via SQL stored procedures. This module acts as the bridge between the application's business logic and the database, handling user authentication validation, ADO.NET command construction, and hydration of data objects from query results.
|
||||
|
||||
## 2. Public Interface
|
||||
|
||||
The public functionality is defined by the `IChannels` interface and implemented by the internal `Channels` class.
|
||||
|
||||
**Channel Code Operations**
|
||||
|
||||
* `ulong ChannelCodesInsert(IUserDbRecord user, IConnectionDetails connection, IReadOnlyDictionary<ChannelEnumsAndConstants.ChannelCodeType, short> lookup, IChannelCode channelCode, out int id)`
|
||||
* Inserts a new channel code record. Returns `ERROR_SUCCESS` (0) on success; returns the new record's ID via the `id` out parameter.
|
||||
* `ulong ChannelCodesUpdate(IUserDbRecord user, IConnectionDetails connection, IReadOnlyDictionary<ChannelEnumsAndConstants.ChannelCodeType, short> lookup, IChannelCode channelCode)`
|
||||
* Updates an existing channel code record identified by `channelCode.Id`.
|
||||
* `ulong ChannelCodesDelete(IUserDbRecord user, IConnectionDetails connection, int? id, string code, string name, int? codeType)`
|
||||
* Deletes channel codes matching the provided criteria. All filter parameters are nullable; non-null parameters are used to filter the delete operation.
|
||||
* `ulong ChannelCodesGet(IUserDbRecord user, IConnectionDetails connection, int? Id, string code, string name, ChannelEnumsAndConstants.ChannelCodeType? codeType, IReadOnlyDictionary<short, string> channelTypeLookup, out IChannelCode[] records)`
|
||||
* Retrieves channel codes matching the criteria. Requires a `channelTypeLookup` dictionary to map database IDs to enum types.
|
||||
* `ulong ChannelCodeTypesGet(IUserDbRecord user, IConnectionDetails connection, short? id, string codeType, out Tuple<short, string>[] records)`
|
||||
* Retrieves available channel code types (ID and string identifier).
|
||||
|
||||
**Channel Settings Operations**
|
||||
|
||||
* `ulong ChannelSettingsUpdate(IUserDbRecord user, IConnectionDetails connection, int settingId, string defaultValue)`
|
||||
* Updates the default value for a specific channel setting.
|
||||
* `ulong ChannelSettingsGet(IUserDbRecord user, IConnectionDetails connection, int? settingId, string settingName, out IChannelSettingRecord[] records)`
|
||||
* Retrieves channel settings, filtered by ID or name.
|
||||
|
||||
**Group Channel Settings Operations**
|
||||
|
||||
* `ulong GroupChannelSettingsDelete(IUserDbRecord user, IConnectionDetails connection, long channelId, int? settingId)`
|
||||
* Deletes settings for a specific channel. If `settingId` is null, all settings for the channel are deleted.
|
||||
* `ulong GroupChannelSettingsInsert(IUserDbRecord user, IConnectionDetails connection, int clientDbVersion, long channelId, IGroupChannelSettingRecord record)`
|
||||
* Inserts a new group channel setting record.
|
||||
* `ulong GroupChannelSettingsGet(IUserDbRecord user, IConnectionDetails connection, int clientDbVersion, List<long> channelIdList, out IGroupChannelSettingRecord[] records, out string[] errors)`
|
||||
* Retrieves settings for a list of channels. Logic varies based on `clientDbVersion` (see Gotchas).
|
||||
|
||||
**Channel Operations**
|
||||
|
||||
* `ulong ChannelsInsert(IUserDbRecord user, IConnectionDetails connection, ref IChannelDbRecord channel)`
|
||||
* Inserts a new channel. The `channel` parameter is passed by reference; its `Id` property is populated upon successful insertion.
|
||||
* `ulong ChannelsUpdate(IUserDbRecord user, IConnectionDetails connection, IChannelDbRecord channel)`
|
||||
* Updates an existing channel record.
|
||||
* `ulong ChannelsGet(IUserDbRecord user, IConnectionDetails connection, int clientDbVersion, long? channelId, int? groupId, int? dasId, int? sensorId, int? testSetupId, string testSetupName, out IChannelDbRecord[] channels)`
|
||||
* Retrieves channels based on various filter criteria.
|
||||
* `ulong ChannelsDelete(IUserDbRecord user, IConnectionDetails connection, long id, out string errorString)`
|
||||
* Deletes a channel by ID. Returns error details via the `errorString` out parameter.
|
||||
|
||||
## 3. Invariants
|
||||
|
||||
* **Return Codes:** All methods return a `ulong` error code. A value of `0` (`ErrorCodes.ERROR_SUCCESS`) indicates success; any non-zero value indicates failure.
|
||||
* **Authentication:** All public methods enforce authentication. They check `DbAPI.Connections.IsUserLoggedIn(user, connection)` before executing database logic. If this check fails, methods return `ErrorCodes.ERROR_ACCESS_DENIED`.
|
||||
* **Parameter Validation:** Methods performing inserts/updates validate that specific parameters (e.g., `channelCode.Code`, `channelCode.Name`) are not null or empty. Failure results in `ErrorCodes.ERROR_MISSING_PARAMETER`.
|
||||
* **Database Connection:** Methods rely on `ConnectionManager.GetSqlCommand` to establish commands. The `Channels` class itself does not manage connection pooling or opening logic directly but relies on these dependencies.
|
||||
* **Resource Cleanup:** All database commands are wrapped in `try/finally` blocks that dispose of the `SqlCommand` and its `Connection`.
|
||||
|
||||
## 4. Dependencies
|
||||
|
||||
**Internal Dependencies (DbAPI/DTS)**
|
||||
* `DbAPI.Connections`: Used for `IConnectionDetails`, `ConnectionManager`, and `IsUserLoggedIn` validation.
|
||||
* `DbAPI.Errors`: Provides `ErrorCodes` constants.
|
||||
* `DbAPI.Logging`: Provides `LogManager` for error logging.
|
||||
* `DbAPI.Database`: Used for `PrepareForDbAccess` and `GetStoredProcedureVersionCached`.
|
||||
* `DTS.Common.Interface.Channels`: Defines interfaces `IChannelCode`, `IChannelSettingRecord`, `IGroupChannelSettingRecord`, `IChannelDbRecord`.
|
||||
* `DTS.Common.Enums.Channels`: Defines `ChannelEnumsAndConstants`.
|
||||
* `DTS.Common.Classes`: Used for `Utility` helper methods (e.g., `GetShort`, `GetString`).
|
||||
|
||||
**External Dependencies**
|
||||
* `System.Data.SqlClient`: Used heavily for `SqlConnection`, `SqlCommand`, `SqlParameter`, and `SqlDataReader`.
|
||||
* `System.Data`: Used for `CommandType`, `ParameterDirection`, `DataTable`.
|
||||
|
||||
## 5. Gotchas
|
||||
|
||||
* **Critical Bug in `ChannelsUpdate`:** In the `ChannelsUpdate` method, the code checks the `@errorNumber` output parameter *before* calling `cmd.ExecuteNonQuery()`. This means the error check logic is effectively dead code; it checks uninitialized (or default) values, and the stored procedure is executed regardless of the check. The error logging for this method will not trigger correctly on database errors.
|
||||
* **Hardcoded Business Logic in `ChannelsGet`:** The `ChannelsGet` method contains hardcoded filtering logic. It silently excludes any channel where `UserChannelName` ends with `DFConstantsAndEnums.USER_CHANNEL_NAME_HUMIDITY`. This filtering happens client-side after retrieval, which may cause confusion if the database contains records that do not appear in the application layer.
|
||||
* **Documentation Mismatch in `ChannelCodesInsert`:** The XML documentation for `ChannelCodesInsert` states "channel code is modified with a new id if successful." However, the implementation passes `channelCode` by value (not `ref`) and does not
|
||||
148
docs/ai/DataPRO/DbAPI/Connections.md
Normal file
148
docs/ai/DataPRO/DbAPI/Connections.md
Normal file
@@ -0,0 +1,148 @@
|
||||
---
|
||||
source_files:
|
||||
- DataPRO/DbAPI/Connections/IConnectionDetails.cs
|
||||
- DataPRO/DbAPI/Connections/ConnectionDetails.cs
|
||||
- DataPRO/DbAPI/Connections/IConnections.cs
|
||||
- DataPRO/DbAPI/Connections/ConnectionManager.cs
|
||||
generated_at: "2026-04-17T15:54:12.769963+00:00"
|
||||
model: "zai-org/GLM-5-FP8"
|
||||
schema_version: 1
|
||||
sha256: "2046609d3e9bf292"
|
||||
---
|
||||
|
||||
# Documentation: DbAPI.Connections Namespace
|
||||
|
||||
## 1. Purpose
|
||||
|
||||
This module manages database connectivity for the DataPRO system, supporting both SQL Server LocalDB instances and remote/centralized databases. It handles the full lifecycle of LocalDB instances (creation, startup, shutdown, deletion, and database attachment), provides user authentication services with both NTLM and username/password modes, and maintains thread-safe tracking of active connections and logged-in users. The module serves as the data access foundation for the broader DataPRO application.
|
||||
|
||||
---
|
||||
|
||||
## 2. Public Interface
|
||||
|
||||
### IConnectionDetails (Interface)
|
||||
|
||||
Properties:
|
||||
- `bool UseNTLMAuthentication { get; set; }` - Controls whether NTLM authentication is used for database connections.
|
||||
- `string DbUser { get; set; }` - Username for database authentication when not using NTLM.
|
||||
- `string DbUserPassword { get; set; }` - Password for database authentication when not using NTLM.
|
||||
- `string InstanceName { get; set; }` - LocalDB instance name.
|
||||
- `string DbServer { get; set; }` - Database server address for remote connections.
|
||||
- `string DbName { get; set; }` - Target database name.
|
||||
- `bool UsingCentralizedDb { get; set; }` - Distinguishes between LocalDB (false) and remote DB (true) modes.
|
||||
- `string DbFolderPath { get; set; }` - Path to database files for LocalDB.
|
||||
- `string AttachDbsBatPath { get; set; }` - Path to attach.bat script for LocalDB database attachment.
|
||||
- `string ODBCToolsPath { get; set; }` - Path to SQLCMD.EXE directory.
|
||||
- `string SqlDbPath { get; set; }` - Path to SQL Server LocalDB installation.
|
||||
- `int ClientDbVersion { get; set; }` - Expected database version from client code.
|
||||
- `int ConnectionDbVersion { get; set; }` - Actual database version being used.
|
||||
|
||||
Methods:
|
||||
- `string GetConnectionString()` - Returns a connection string suitable for `SqlClient`.
|
||||
- `IConnectionDetails Clone()` - Returns a deep copy of the connection details.
|
||||
|
||||
---
|
||||
|
||||
### ConnectionDetails (Class)
|
||||
|
||||
Implements `IConnectionDetails`.
|
||||
|
||||
**Constructors:**
|
||||
- `ConnectionDetails()` - Default constructor with initialized defaults.
|
||||
- `ConnectionDetails(ConnectionDetails details)` - Copy constructor for cloning.
|
||||
|
||||
**Default Values:**
|
||||
| Property | Default Value |
|
||||
|----------|---------------|
|
||||
| `UseNTLMAuthentication` | `true` |
|
||||
| `DbUser` | `"DataPROUser"` |
|
||||
| `DbUserPassword` | `"DTSSealBeachHQ"` |
|
||||
| `InstanceName` | `"DataPROInstance"` |
|
||||
| `DbServer` | `@"(localdb)\DataPROInstance"` |
|
||||
| `DbName` | `"DataPRO"` |
|
||||
| `UsingCentralizedDb` | `false` |
|
||||
| `DbFolderPath` | `""` |
|
||||
| `AttachDbsBatPath` | `""` |
|
||||
| `SqlDbPath` | `""` |
|
||||
| `ODBCToolsPath` | `""` |
|
||||
|
||||
**Methods:**
|
||||
- `virtual string GetConnectionString()` - Returns cached connection string if available; otherwise builds and caches it. Format depends on `UseNTLMAuthentication`:
|
||||
- NTLM: `Server={DbServer};Database={DbName};Trusted_Connection=TRUE;`
|
||||
- SQL Auth: `Server={DbServer};Database={DbName};User Id={DbUser};Password={DbUserPassword};`
|
||||
- `override string ToString()` - Returns `"{DbServer}\{DbName}"` for centralized DB or `"Local\{DbName}"` for LocalDB.
|
||||
- `virtual IConnectionDetails Clone()` - Returns a new `ConnectionDetails` copied from the current instance.
|
||||
|
||||
---
|
||||
|
||||
### IConnections (Interface)
|
||||
|
||||
Methods:
|
||||
- `IConnectionDetails[] GetActiveConnections()` - Returns all successfully connected databases.
|
||||
- `ulong LoginUserHash(IConnectionDetails connection, string user, string hash, out IUserDbRecord userObject)` - Authenticates user with a pre-hashed password. Returns `0` (ERROR_SUCCESS) on success, `ERROR_LOGINFAILED` for failed login, `ERROR_UNKNOWN` for unexpected errors.
|
||||
- `ulong LoginUser(IConnectionDetails connection, string user, string password, out IUserDbRecord userObject)` - Authenticates user with plaintext password. Returns same error codes as `LoginUserHash`.
|
||||
- `ulong ConnectToDb(IConnectionDetails details)` - Establishes database connection. Returns `0` on success.
|
||||
- `bool IsUserLoggedIn(IUserDbRecord user, IConnectionDetails connection)` - Checks if a user is currently logged in to a specific database.
|
||||
- `Tuple<IUserDbRecord, IConnectionDetails>[] GetLoggedInUsers()` - Returns all logged-in users across all connected databases.
|
||||
- `void ClearConnections()` - Removes all logged-in users and database connections.
|
||||
|
||||
---
|
||||
|
||||
### ConnectionManager (Internal Class)
|
||||
|
||||
Internal implementation of `IConnections`. Not exported publicly.
|
||||
|
||||
**Additional Internal/Static Methods:**
|
||||
- `static ulong GetSqlCommand(IConnectionDetails con, out SqlCommand cmd, string commandText = "")` - Creates an open `SqlConnection` with a `SqlCommand`. Returns `ERROR_SUCCESS` or `ERROR_UNKNOWN`.
|
||||
|
||||
**Private Methods:**
|
||||
- `ulong Connect(IConnectionDetails details)` - Internal connection logic; clones details and routes to `ConnectRemote` or `ConnectLocal`.
|
||||
- `ulong ConnectRemote(IConnectionDetails details)` - Handles remote database connections.
|
||||
- `ulong ConnectLocal(IConnectionDetails details)` - Handles LocalDB lifecycle (stop, delete, create, start, attach).
|
||||
- `void StopInstance(IConnectionDetails details, LogDelegate log)` - Stops LocalDB instance.
|
||||
- `void DeleteInstance(IConnectionDetails details, LogDelegate log)` - Deletes LocalDB instance.
|
||||
- `void CreateInstance(IConnectionDetails details, LogDelegate log)` - Creates LocalDB instance.
|
||||
- `void StartInstance(IConnectionDetails details, LogDelegate log)` - Starts LocalDB instance.
|
||||
- `void AttachDatabases(IConnectionDetails details, LogDelegate log)` - Attaches DataPRO and ISO databases.
|
||||
- `static void AttachDatabase(IConnectionDetails details, string dbName, LogDelegate log)` - Attaches a single database via batch file.
|
||||
|
||||
---
|
||||
|
||||
## 3. Invariants
|
||||
|
||||
- **Thread Safety:** All access to `_loggedInUsers` is protected by `LOGIN_LOCK`, and all access to `_connections` is protected by `CONNECT_LOCK`.
|
||||
- **Connection String Caching:** `GetConnectionString()` caches the result in `_Connection` after first call; subsequent calls return the cached value.
|
||||
- **Error Code Convention:** All public methods returning `ulong` use `0` to indicate `ERROR_SUCCESS`. Non-zero values indicate errors.
|
||||
- **Clone Independence:** `Clone()` produces a deep copy; modifications to the clone do not affect the original.
|
||||
- **LocalDB Lifecycle Order:** When connecting to LocalDB, the system always executes: stop → delete → create → start → attach.
|
||||
- **Process Synchronization:** `PROCESS_LOCK` ensures only one external process (SqlLocalDB.exe or batch file) runs at a time.
|
||||
- **Password Hashing Format:** `LoginUser` hashes passwords using SHA256 with format `"{password}_{user}"` encoded in UTF-8, then Base64-encoded.
|
||||
|
||||
---
|
||||
|
||||
## 4. Dependencies
|
||||
|
||||
**This module depends on:**
|
||||
- `DbAPI.User` - For `User.GetUser()` and `IUserDbRecord`.
|
||||
- `DbAPI.Errors` / `DbAPI.Logging` - For `ErrorCodes`, `LogManager`, and `LogEvents`.
|
||||
- `DTS.Common.Interface.Database` - For `IUserDbRecord` interface.
|
||||
- `DTS.Common.Utils.Database` - For `SqlServerLocalDbException`, `LogDelegate`.
|
||||
- `DTS.Common.Utilities.Logging` - For `APILogger.Log`.
|
||||
- `System.Data.SqlClient` - For `SqlConnection` and `SqlCommand`.
|
||||
- `System.Security.Cryptography` - For `SHA256` password hashing.
|
||||
- `System.Diagnostics` - For `Process` execution.
|
||||
|
||||
**What depends on this module:**
|
||||
- Not determinable from the provided source files alone.
|
||||
|
||||
---
|
||||
|
||||
## 5. Gotchas
|
||||
|
||||
1. **Hardcoded Default Credentials:** `ConnectionDetails` defaults contain hardcoded credentials (`DbUser = "DataPROUser"`, `DbUserPassword = "DTSSealBeachHQ"`). These should be overridden in production use.
|
||||
|
||||
2. **ConnectRemote Does Not Validate:** The `ConnectRemote()` method unconditionally returns `ERROR_SUCCESS` without actually validating the connection. The actual connection validation only occurs when `GetSqlCommand()` is called later.
|
||||
|
||||
3. **LocalDB Instance Destruction:** Every call to `ConnectLocal()` destroys and recreates the LocalDB instance. This is destructive and may impact other processes sharing the same instance.
|
||||
|
||||
4. **Dual Database Attachment:** `AttachDatabases()` always attempts to attach both the configured `DbName` database AND a
|
||||
98
docs/ai/DataPRO/DbAPI/DAS.md
Normal file
98
docs/ai/DataPRO/DbAPI/DAS.md
Normal file
@@ -0,0 +1,98 @@
|
||||
---
|
||||
source_files:
|
||||
- DataPRO/DbAPI/DAS/IDataRecorders.cs
|
||||
- DataPRO/DbAPI/DAS/DataRecorders.cs
|
||||
generated_at: "2026-04-17T15:58:00.233947+00:00"
|
||||
model: "zai-org/GLM-5-FP8"
|
||||
schema_version: 1
|
||||
sha256: "ebd38454d2f83c37"
|
||||
---
|
||||
|
||||
# Documentation: DataRecorders Module
|
||||
|
||||
## 1. Purpose
|
||||
|
||||
This module provides the database abstraction layer for Data Acquisition System (DAS) hardware management within the DataPRO system. It implements CRUD operations for DAS devices and their associated channels through the `IDataRecorders` interface. The module handles persistence of DAS metadata, channel configurations, and parent-child relationships between encapsulated/compacted DAS units, serving as the bridge between the application layer and SQL stored procedures.
|
||||
|
||||
---
|
||||
|
||||
## 2. Public Interface
|
||||
|
||||
### Interface: `IDataRecorders` (namespace: `DbAPI.DAS`)
|
||||
|
||||
#### `ulong DASChannelsDelete(IUserDbRecord user, IConnectionDetails connection, string hardwareId)`
|
||||
Deletes all channels associated with a specific DAS hardware identifier. Returns `0` on success, non-zero error code on failure.
|
||||
|
||||
#### `ulong DASChannelsInsert(IUserDbRecord user, IConnectionDetails connection, string hardwareId, ref IDASChannelDBRecord record)`
|
||||
Inserts a DAS channel record into the database. The `record` parameter is passed by reference and is modified to include the newly assigned `DaschannelId` after successful insert. Returns `0` on success.
|
||||
|
||||
#### `ulong DASChannelsGet(IUserDbRecord user, IConnectionDetails connection, string HardwareId, out IDASChannelDBRecord[] channels)`
|
||||
Retrieves DAS channel records for a given hardware ID. Pass `null` for `HardwareId` to retrieve all channel records. Returns `0` on success; `channels` array is populated with results.
|
||||
|
||||
#### `ulong DASChildrenGet(IUserDbRecord user, IConnectionDetails connection, string dasSerialNumber, out string[] childrenSerialNumbers)`
|
||||
Retrieves serial numbers of child DAS units associated with a parent DAS (used for encapsulated/compacted DAS configurations). Returns `0` on success.
|
||||
|
||||
#### `ulong DASDelete(IUserDbRecord user, IConnectionDetails connection, int DASId, string serialNumber, bool embedded)`
|
||||
Deletes a DAS record from the database. Either `DASId` or `serialNumber` must be provided. Cascading behavior includes removal from test setups, channel assignments, and associated metadata. Returns `0` on success.
|
||||
|
||||
#### `ulong DASGet(IUserDbRecord user, IConnectionDetails connection, int clientDbVersion, string DASSerial, string position, out IDASDBRecord[] das)`
|
||||
Retrieves DAS records matching the specified criteria. Pass `null` for both `DASSerial` and `position` to retrieve all DAS records. Returns `0` on success; `das` array may be null or empty.
|
||||
|
||||
#### `ulong DASInsert(IUserDbRecord user, IConnectionDetails connection, IDASDBRecord das)`
|
||||
Inserts a new DAS record. The `das.DASId` property is updated with the newly assigned database ID after successful insert. Returns `0` on success.
|
||||
|
||||
#### `ulong DASUpdate(IUserDbRecord user, IConnectionDetails connection, IDASDBRecord das)`
|
||||
Updates an existing DAS record in the database. Returns `0` on success.
|
||||
|
||||
---
|
||||
|
||||
## 3. Invariants
|
||||
|
||||
- **Authentication Required**: All methods require a valid logged-in user via `DbAPI.Connections.IsUserLoggedIn(user, connection)`. Failure returns `ErrorCodes.ERROR_ACCESS_DENIED`.
|
||||
- **Return Code Convention**: All methods return `ulong` where `0` (`ErrorCodes.ERROR_SUCCESS`) indicates success; all other values indicate errors.
|
||||
- **Stored Procedure Usage**: All database operations are performed via SQL stored procedures (`sp_DASChannelsDelete`, `sp_DASChannelsInsert`, `sp_DASChannelsGet`, `sp_DASChildrenGet`, `sp_DASDelete`, `sp_DASGet`, `sp_DASInsert`, `sp_DASUpdate`).
|
||||
- **Connection Cleanup**: All methods dispose of the SQL connection in a `finally` block via `cmd.Connection.Dispose()`.
|
||||
- **Parameter Validation**:
|
||||
- `DASChannelsInsert`: `record` cannot be null; `hardwareId` cannot be null or whitespace.
|
||||
- `DASDelete`: Either `DASId > 0` or `serialNumber` must be non-empty.
|
||||
- `DASInsert`: `das` cannot be null.
|
||||
- **Side Effects on Insert**: Both `DASChannelsInsert` and `DASInsert` modify the input record's ID field (`DaschannelId` and `DASId` respectively) upon successful insertion.
|
||||
- **StandIn Logic**: For `DASInsert` and `DASUpdate`, `TestId` and `GroupId` parameters are only set if `das.StandIn` is `true`.
|
||||
|
||||
---
|
||||
|
||||
## 4. Dependencies
|
||||
|
||||
### This Module Depends On:
|
||||
- `DbAPI.Connections` - For `IConnectionDetails`, `IsUserLoggedIn()`, `ConnectionManager.GetSqlCommand()`
|
||||
- `DbAPI.User` - For `IUserDbRecord`
|
||||
- `DbAPI.Errors` - For `ErrorCodes` constants
|
||||
- `DbAPI.Logging` - For `LogManager`
|
||||
- `DbAPI.Database` - For `Database.PrepareForDbAccess()` (used in `DASGet`)
|
||||
- `DTS.Common.Interface.Database` - For `IDASChannelDBRecord`, `IDASDBRecord`
|
||||
- `DTS.Common.Interface.DataRecorders` - Referenced in interface
|
||||
- `DTS.Common.Classes` - For `DASChannelDBRecord`, `DASDBRecord`, `DFConstantsAndEnums.FIRST_USE_DATE_NOT_SET`
|
||||
- `DTS.Common.Enums.Hardware` - For `HardwareTypes.SLICE6_AIR_TC`
|
||||
- `DTS.Common.Constants` - For `SLICE_TC_DB_VERSION`
|
||||
- `System.Data.SqlClient` - For ADO.NET SQL client types
|
||||
|
||||
### Consumers:
|
||||
- Unclear from source alone. The `DataRecorders` class is `internal`, suggesting it is consumed by other classes within the `DbAPI.DAS` namespace or via dependency injection through the `IDataRecorders` interface.
|
||||
|
||||
---
|
||||
|
||||
## 5. Gotchas
|
||||
|
||||
1. **Inconsistent Command Preparation**: `DASGet` uses `Database.Database.PrepareForDbAccess()` while all other methods use `ConnectionManager.GetSqlCommand()`. The reason for this difference is unclear from source alone.
|
||||
|
||||
2. **Debug Code Left In**: `DASDelete` contains `Console.WriteLine` statements (lines ~226 and ~248) that appear to be debug artifacts.
|
||||
|
||||
3. **Exception Handling Inconsistency**: `DASUpdate` and `DASInsert` throw an exception when the stored procedure returns a non-zero error number, whereas other methods log and return `ERROR_UNKNOWN` without throwing.
|
||||
|
||||
4. **Hardware Version Check**: `DASInsert` contains special-case logic for `HardwareTypes.SLICE6_AIR_TC` that checks database version compatibility against `DTS.Common.Constants.SLICE_TC_DB_VERSION`. Other hardware types do not have this check.
|
||||
|
||||
5. **Typo in Interface**: The `DASChannelsGet` interface declaration has a parameter named `connetion` (misspelled), though the implementation correctly uses `connection`.
|
||||
|
||||
6. **Output Array Initialization**: `DASChannelsGet` and `DASChildrenGet` initialize their output arrays to empty arrays (`new IDASChannelDBRecord[0]` and `new string[0]`) before the login check, meaning access-denied failures still return valid empty arrays rather than null.
|
||||
|
||||
7. **DASUpdate Overwrites DASId**: The `DASUpdate` method sets `das.DASId` from the `@new_id` output parameter, which may be unexpected for an update operation.
|
||||
54
docs/ai/DataPRO/DbAPI/Database.md
Normal file
54
docs/ai/DataPRO/DbAPI/Database.md
Normal file
@@ -0,0 +1,54 @@
|
||||
---
|
||||
source_files:
|
||||
- DataPRO/DbAPI/Database/IDatabase.cs
|
||||
- DataPRO/DbAPI/Database/Database.cs
|
||||
generated_at: "2026-04-17T15:57:00.684177+00:00"
|
||||
model: "zai-org/GLM-5-FP8"
|
||||
schema_version: 1
|
||||
sha256: "7f88751dbad5ffc9"
|
||||
---
|
||||
|
||||
# Database Module Documentation
|
||||
|
||||
## 1. Purpose
|
||||
|
||||
This module provides database version management functionality for the DbAPI system. It enables retrieval of SQL Server versions, querying and inserting database version records, and resolving versioned stored procedure names. The module serves as an abstraction layer for database schema versioning, allowing the system to track and manage database migrations/versions across different database instances.
|
||||
|
||||
---
|
||||
|
||||
## 2. Public Interface
|
||||
|
||||
### Interface: `IDatabase`
|
||||
|
||||
**Location:** `DbAPI.Database` namespace
|
||||
|
||||
#### `int GetSQLVersion(IConnectionDetails connection)`
|
||||
Retrieves the major SQL Server version number from the specified database connection. Returns `0` on failure.
|
||||
|
||||
#### `ulong GetDatabaseVersion(IUserDbRecord user, IConnectionDetails connection, out int version)`
|
||||
Retrieves the highest database version number from the target database by calling the `sp_DBVersionGet` stored procedure. Returns `0` (`ERROR_SUCCESS`) on success; non-zero error codes on failure. The `version` output parameter is set to the maximum version number found, or `0` on error.
|
||||
|
||||
#### `ulong InsertDatabaseVersion(IUserDbRecord user, IConnectionDetails connection, int version, int step, DateTime date, string remarks, string userField)`
|
||||
Inserts a new database version record via the `sp_DbVersionInsert` stored procedure. Parameters:
|
||||
- `version` - Version number to insert
|
||||
- `step` - Step number to insert
|
||||
- `date` - DateTime for the record
|
||||
- `remarks` - Remarks string (max 255 characters based on SqlParameter size)
|
||||
- `userField` - User identifier to associate with the record (does not require validation against actual users)
|
||||
|
||||
Returns `0` (`ERROR_SUCCESS`) on success, `ERROR_ACCESS_DENIED` if user is not logged in, or `ERROR_UNKNOWN` on other failures.
|
||||
|
||||
---
|
||||
|
||||
### Class: `Database` (internal)
|
||||
|
||||
**Location:** `DbAPI.Database` namespace
|
||||
|
||||
Implements `IDatabase`. Not exposed outside the assembly.
|
||||
|
||||
#### Static Methods:
|
||||
|
||||
#### `string GetStoredProcedureVersion(IConnectionDetails connection, string storedProcedure, int clientDbVersion)`
|
||||
Determines the appropriate stored procedure name to call based on database and client versions. Returns the original `storedProcedure` name if version is 0, otherwise returns `{storedProcedure}_{version}`.
|
||||
|
||||
#### `string GetStoredProcedureVersionCached(IConnectionDetails connection
|
||||
47
docs/ai/DataPRO/DbAPI/Errors.md
Normal file
47
docs/ai/DataPRO/DbAPI/Errors.md
Normal file
@@ -0,0 +1,47 @@
|
||||
---
|
||||
source_files:
|
||||
- DataPRO/DbAPI/Errors/ErrorCodes.cs
|
||||
generated_at: "2026-04-17T16:29:44.608866+00:00"
|
||||
model: "zai-org/GLM-5-FP8"
|
||||
schema_version: 1
|
||||
sha256: "cd3e42ca1eeef316"
|
||||
---
|
||||
|
||||
# Errors
|
||||
|
||||
### Purpose
|
||||
This module defines a centralized registry of error codes used throughout the DbAPI system. It provides a standardized set of error constants (both system-level and application-specific) and a utility method for converting error codes to human-readable strings, enabling consistent error handling and reporting across the codebase.
|
||||
|
||||
### Public Interface
|
||||
|
||||
**Class: `ErrorCodes` (abstract)**
|
||||
- `public const ulong ERROR_SUCCESS = 0x0` - Indicates successful operation completion.
|
||||
- `public const ulong ERROR_INVALID_FUNCTION = 0x1` - Invalid function was called.
|
||||
- `public const ulong ERROR_FILE_NOT_FOUND = 0x2` - Specified file could not be located.
|
||||
- `public const ulong ERROR_PATH_NOT_FOUND = 0x3` - Specified path could not be located.
|
||||
- `public const ulong ERROR_ACCESS_DENIED = 0x5` - Access was denied to the requested resource.
|
||||
- `public const ulong ERROR_NOT_SUPPORTED = 0x32` - The requested operation is not supported.
|
||||
- `public const ulong INVALID_SESSIONID = 0x200` - Session identifier is invalid or expired.
|
||||
- `public const ulong ERROR_UNKNOWN = 0x201` - An unknown/unexpected error occurred.
|
||||
- `public const ulong ERROR_NOUSER = 0x202` - No user is associated with the operation.
|
||||
- `public const ulong ERROR_LOGINFAILED = 0x203` - Login attempt failed.
|
||||
- `public const ulong ERROR_MISSING_PARAMETER = 0x204` - A required parameter was not provided.
|
||||
- `public static string ResultToString(ulong hr)` - Converts an error code to its string representation. Returns the symbolic name for known codes (e.g., "SUCCESS", "ACCESS_DENIED") or the hexadecimal representation for unknown codes.
|
||||
|
||||
### Invariants
|
||||
- All error codes are defined as `ulong` (unsigned 64-bit integers).
|
||||
- `ERROR_SUCCESS` (0x0) is the only success code; all non-zero values indicate errors.
|
||||
- System-level errors (0x0-0x32 range) mirror Windows error codes.
|
||||
- Application-specific errors start at 0x200.
|
||||
- The class is `abstract`, preventing instantiation (intended to be used only for its static members).
|
||||
|
||||
### Dependencies
|
||||
- **Depends on:** None (standalone module with no imports).
|
||||
- **Depended on by:** Unclear from source alone; likely consumed by all DbAPI components for error handling and reporting.
|
||||
|
||||
### Gotchas
|
||||
- `ERROR_MISSING_PARAMETER` is defined as a constant but is **not handled** in the `ResultToString` switch statement—it will return the hex string "204" instead of a symbolic name.
|
||||
- The class is `abstract` but contains no virtual or abstract members; it functions as a static utility class pattern but could have been declared `static` instead.
|
||||
- Error code values 0x4, 0x6-0x31 are undefined/skipped in the constants list despite being in the system error range.
|
||||
|
||||
---
|
||||
92
docs/ai/DataPRO/DbAPI/Groups.md
Normal file
92
docs/ai/DataPRO/DbAPI/Groups.md
Normal file
@@ -0,0 +1,92 @@
|
||||
---
|
||||
source_files:
|
||||
- DataPRO/DbAPI/Groups/IGroupHardware.cs
|
||||
- DataPRO/DbAPI/Groups/IGroups.cs
|
||||
- DataPRO/DbAPI/Groups/GroupHardware.cs
|
||||
- DataPRO/DbAPI/Groups/Groups.cs
|
||||
generated_at: "2026-04-17T15:53:56.485523+00:00"
|
||||
model: "zai-org/GLM-5-FP8"
|
||||
schema_version: 1
|
||||
sha256: "c8fc5d8b5716c64f"
|
||||
---
|
||||
|
||||
# Documentation: DbAPI.Groups Module
|
||||
|
||||
## 1. Purpose
|
||||
|
||||
This module provides the database access layer for managing **Groups** and **GroupHardware** entities in the DataPRO system. It implements CRUD operations (Create, Read, Update, Delete) for both the `Groups` and `GroupHardware` database tables via stored procedure calls. The module enforces user authentication before any database operation and provides standardized error handling with logging. It serves as the data persistence layer for group-related functionality, bridging higher-level business logic with the underlying SQL database.
|
||||
|
||||
---
|
||||
|
||||
## 2. Public Interface
|
||||
|
||||
### Interface: `IGroupHardware`
|
||||
Defines operations for the `GroupHardware` junction table (associating hardware devices with groups).
|
||||
|
||||
| Method | Signature | Description |
|
||||
|--------|-----------|-------------|
|
||||
| `GroupHardwareInsert` | `ulong GroupHardwareInsert(IUserDbRecord user, IConnectionDetails connection, GroupHardwareDbRecord groupHardware, out int newId, out string errorMessage)` | Inserts a new record into the GroupHardware table. Returns `ERROR_SUCCESS` (0) on success; `newId` receives the generated ID. |
|
||||
| `GroupHardwareGet` | `ulong GroupHardwareGet(IUserDbRecord user, IConnectionDetails connection, int? groupId, string serialNumber, bool? embedded, out GroupHardwareDbRecord[] groupHardwareRecords)` | Retrieves one or more records from GroupHardware table. Supports filtering by `groupId`, `serialNumber`, and `embedded` flags. |
|
||||
| `GroupHardwareDelete` | `ulong GroupHardwareDelete(IUserDbRecord user, IConnectionDetails connection, int? groupId, int? dasId, out string errorString)` | Deletes an entry from GroupHardware table. Can filter by `groupId` and/or `dasId`. |
|
||||
|
||||
### Interface: `IGroups`
|
||||
Defines operations for the `Groups` table (group definitions).
|
||||
|
||||
| Method | Signature | Description |
|
||||
|--------|-----------|-------------|
|
||||
| `GroupsInsert` | `ulong GroupsInsert(IUserDbRecord user, IConnectionDetails connection, ref IGroupDbRecord group)` | Inserts a new record into Groups table. The `group` parameter is passed by `ref` and its `Id` property is populated with the new ID on success. |
|
||||
| `GroupsUpdate` | `ulong GroupsUpdate(IUserDbRecord user, IConnectionDetails connection, IGroupDbRecord group)` | Updates an existing record in Groups table. Uses `group.Id` to identify the record to update. |
|
||||
| `GroupsGet` | `ulong GroupsGet(IUserDbRecord user, IConnectionDetails connection, int? id, string serialNumber, string displayName, bool? embedded, int? staticGroupId, out IGroupDbRecord[] groups)` | Retrieves one or more records from Groups table. Supports filtering by `id`, `serialNumber`, `displayName`, `embedded`, and `staticGroupId`. |
|
||||
| `GroupsDelete` | `ulong GroupsDelete(IUserDbRecord user, IConnectionDetails connection, long id, out string errorString)` | Deletes a record from Groups table by `id`. |
|
||||
|
||||
### Return Values
|
||||
All methods return `ulong` error codes:
|
||||
- `0` = `ERROR_SUCCESS` (operation succeeded)
|
||||
- `ERROR_ACCESS_DENIED` = user authentication failed
|
||||
- `ERROR_UNKNOWN` = unexpected exception occurred
|
||||
- Other values = stored procedure-specific error codes
|
||||
|
||||
---
|
||||
|
||||
## 3. Invariants
|
||||
|
||||
1. **Authentication Required**: Every public method checks `DbAPI.Connections.IsUserLoggedIn(user, connection)` before proceeding. If this returns `false`, the method immediately returns `ERROR_ACCESS_DENIED`.
|
||||
|
||||
2. **Return Code Semantics**: A return value of `0` (`ERROR_SUCCESS`) always indicates success. All non-zero values indicate failure.
|
||||
|
||||
3. **Stored Procedure Usage**: All database operations are performed exclusively through stored procedures:
|
||||
- `sp_GroupHardwareInsert`, `sp_GroupHardwareGet`, `sp_GroupHardwareDelete`
|
||||
- `sp_GroupsInsert`, `sp_GroupsUpdate`, `sp_GroupsGet`, `sp_GroupsDelete`
|
||||
|
||||
4. **Connection Cleanup**: All methods dispose of the `SqlCommand.Connection` in a `finally` block, ensuring connections are released even on exceptions.
|
||||
|
||||
5. **Output Parameter Pattern**: Insert stored procedures return the new ID via an output parameter (`@new_id`). Delete and some other procedures return error information via `@errorNumber` and `@errorMessage` output parameters.
|
||||
|
||||
6. **Nullable Filter Parameters**: All filter parameters in `Get` methods are nullable, allowing flexible querying (e.g., query by `groupId` only, or combine multiple filters).
|
||||
|
||||
---
|
||||
|
||||
## 4. Dependencies
|
||||
|
||||
### This Module Depends On:
|
||||
| Dependency | Usage |
|
||||
|------------|-------|
|
||||
| `DbAPI.Connections` | `ConnectionManager.GetSqlCommand()`, `IsUserLoggedIn()` |
|
||||
| `DbAPI.Errors` | `ErrorCodes` constants (`ERROR_SUCCESS`, `ERROR_ACCESS_DENIED`, `ERROR_UNKNOWN`) |
|
||||
| `DbAPI.Logging` | `LogManager.Log()` for error logging |
|
||||
| `DTS.Common.Interface.Database` | `IUserDbRecord` interface |
|
||||
| `DTS.Common.Interface.Groups` | `IGroupDbRecord` interface |
|
||||
| `DTS.Common.Classes.Groups` | `GroupHardwareDbRecord`, `GroupDbRecord` concrete classes |
|
||||
| `System.Data.SqlClient` | ADO.NET SQL Server client (`SqlCommand`, `SqlParameter`, `SqlDataReader`) |
|
||||
|
||||
### Consumers (Inferred):
|
||||
- Any module that registers or resolves `IGroupHardware` or `IGroups` via dependency injection
|
||||
- Higher-level business logic layers that need to persist or retrieve group data
|
||||
|
||||
---
|
||||
|
||||
## 5. Gotchas
|
||||
|
||||
1. **Inconsistent Error Code Handling in `GroupHardwareDelete`**: When the stored procedure returns a non-zero error number, the method throws an exception and returns `ERROR_UNKNOWN` instead of returning the actual error code from the procedure. This differs from `GroupsDelete`, which correctly returns the stored procedure's error code.
|
||||
|
||||
2. **Misleading Log
|
||||
31
docs/ai/DataPRO/DbAPI/Logging.md
Normal file
31
docs/ai/DataPRO/DbAPI/Logging.md
Normal file
@@ -0,0 +1,31 @@
|
||||
---
|
||||
source_files:
|
||||
- DataPRO/DbAPI/Logging/LogManager.cs
|
||||
generated_at: "2026-04-17T16:14:40.267853+00:00"
|
||||
model: "zai-org/GLM-5-FP8"
|
||||
schema_version: 1
|
||||
sha256: "60dc472c9df3ec54"
|
||||
---
|
||||
|
||||
# Logging
|
||||
|
||||
### Purpose
|
||||
This module provides centralized logging infrastructure for the DbAPI system. It wraps a `TextLogger` to write timestamped, categorized log messages to a file named "DB.log" with support for log rotation, filtering by severity level, and thread-safe initialization. The module exposes a delegate-based sink (`DBAPILogWriter`) that can be used by other components to write raw log messages.
|
||||
|
||||
### Public Interface
|
||||
|
||||
**`LogManager` (internal class)**
|
||||
- `static Sink DBAPILogWriter` - Public field assigned to the internal `LogMsg` method; allows external code to write raw strings to the log.
|
||||
- `enum LogEvents` - Public enum defining log event categories: `Message`, `Connections`, `Login`, `Information`, `DataRecorders`, `Graphs`, `CalculatedChannels`, `Sensors`, `TestSetups`, `RegionsOfInterest`, `Tags`.
|
||||
- `static void Initialize(int logSize, string path, int minLog)` - Initializes the logger with the specified file size limit, directory path, and minimum log level filter. Creates "DB.log" in the given path. Thread-safe; subsequent calls are no-ops if already initialized.
|
||||
- `static void Log(TraceEventType eventType, LogEvents logEvent, string msg)` - Logs a message with the specified event type and category. Respects the `_MinLog` filter; messages whose event type is not in the filter are silently dropped.
|
||||
- `static void OnWriteException(Exception ex)` - Callback for handling write exceptions; writes the exception message to `Console.Error`.
|
||||
|
||||
### Invariants
|
||||
- `_LogWriter` is singleton-initialized; once set, `Initialize` returns immediately without reinitializing.
|
||||
- Initialization is guarded by `lock(MyLock)` for thread safety.
|
||||
- `_MinLog` defaults to `(TraceEventType.Error | TraceEventType.Warning)` if `Initialize` is not called or if `minLog` is not applied.
|
||||
- Log filtering uses bitwise AND: a message is logged only if `(_MinLog & (int)eventType) == (int)eventType`.
|
||||
|
||||
### Dependencies
|
||||
- **Depends on**: `DTS.Common.Utilities.Logging` (pro
|
||||
17
docs/ai/DataPRO/DbAPI/SPCaching.md
Normal file
17
docs/ai/DataPRO/DbAPI/SPCaching.md
Normal file
@@ -0,0 +1,17 @@
|
||||
---
|
||||
source_files:
|
||||
- DataPRO/DbAPI/SPCaching/SPCache.cs
|
||||
generated_at: "2026-04-17T16:46:40.360622+00:00"
|
||||
model: "zai-org/GLM-5-FP8"
|
||||
schema_version: 1
|
||||
sha256: "2ca8e70f321fe20b"
|
||||
---
|
||||
|
||||
# SPCaching
|
||||
|
||||
## Documentation: SPCache.cs
|
||||
|
||||
### 1. Purpose
|
||||
The `SPCache` class serves as a plain data container (DTO) within the `DbAPI.SPCaching` namespace. Its role is to store the result of a stored procedure version lookup based on a specific combination of client and database versions. It exists to optimize the system by caching these lookups, preventing the need to recalculate the appropriate stored procedure version for the same version parameters repeatedly.
|
||||
|
||||
### 2. Public Interface
|
||||
72
docs/ai/DataPRO/DbAPI/Sensors.md
Normal file
72
docs/ai/DataPRO/DbAPI/Sensors.md
Normal file
@@ -0,0 +1,72 @@
|
||||
---
|
||||
source_files:
|
||||
- DataPRO/DbAPI/Sensors/ISensors.cs
|
||||
generated_at: "2026-04-17T15:58:13.020676+00:00"
|
||||
model: "zai-org/GLM-5-FP8"
|
||||
schema_version: 1
|
||||
sha256: "aab63aa6f9bf9fbc"
|
||||
---
|
||||
|
||||
# Documentation: ISensors Interface
|
||||
|
||||
## 1. Purpose
|
||||
|
||||
The `ISensors` interface defines the database abstraction layer for sensor management within the DataPRO system. It provides a comprehensive API for CRUD operations across multiple sensor types (analog, digital input/output, squib, UART, CAN, thermocoupler) and their associated metadata (calibrations, diagnostic runs, input/output streams). This interface abstracts database persistence concerns from the rest of the application, enforcing user context and connection details for all operations.
|
||||
|
||||
---
|
||||
|
||||
## 2. Public Interface
|
||||
|
||||
### Analog Sensor Operations
|
||||
|
||||
| Method | Signature | Description |
|
||||
|--------|-----------|-------------|
|
||||
| `SensorsAnalogGet` | `ulong SensorsAnalogGet(IUserDbRecord user, IConnectionDetails connection, int? sensorId, string serialNumber, string eId, out IAnalogDbRecord[] sensors)` | Retrieves analog sensors matching search criteria. Null parameters act as wildcards. |
|
||||
| `SensorsAnalogUpdateInsert` | `ulong SensorsAnalogUpdateInsert(IUserDbRecord user, IConnectionDetails connection, IAnalogDbRecord record)` | Commits an analog sensor record to the database (insert or update). |
|
||||
| `SensorsAnalogBridgeResistanceGet` | `ulong SensorsAnalogBridgeResistanceGet(IUserDbRecord user, IConnectionDetails connection, string serialNumber, out double bridgeResistance)` | Retrieves the bridge resistance for a sensor by serial number. |
|
||||
|
||||
### Generic Sensor Operations
|
||||
|
||||
| Method | Signature | Description |
|
||||
|--------|-----------|-------------|
|
||||
| `SensorsGet` | `ulong SensorsGet(IUserDbRecord user, IConnectionDetails connection, string serialNumber, out ISensorDbRecord[] sensors)` | Retrieves sensors by serial number. |
|
||||
| `SensorsDelete` | `ulong SensorsDelete(IUserDbRecord user, IConnectionDetails connection, int sensorId, int sensorType)` | Deletes a specific sensor by ID and type. Sensor types: 0=analog, 1=digital in, 2=digital out, 3=squib, 4=UART. |
|
||||
| `SensorsDeleteAll` | `ulong SensorsDeleteAll(IUserDbRecord user, IConnectionDetails connection)` | Deletes ALL sensors in the database. |
|
||||
|
||||
### Calibration Operations
|
||||
|
||||
| Method | Signature | Description |
|
||||
|--------|-----------|-------------|
|
||||
| `SensorCalibrationsGet` | `ulong SensorCalibrationsGet(IUserDbRecord user, IConnectionDetails connection, int? sensorId, string serialNumber, out ISensorCalDbRecord[] calibrations)` | Retrieves calibrations matching criteria. |
|
||||
| `SensorCalibrationsInsert` | `ulong SensorCalibrationsInsert(IUserDbRecord user, IConnectionDetails connection, ISensorCalDbRecord cal, int sensorType, bool setCalibrationId)` | Inserts a new calibration record. |
|
||||
| `SensorCalibrationsDelete` | `ulong SensorCalibrationsDelete(IUserDbRecord user, IConnectionDetails connection, string sensorSerialNumber, DateTime? calibrationDate, DateTime? modifyDate)` | Deletes calibrations matching criteria. Nulls are wildcards. |
|
||||
|
||||
### Digital Input/Output Operations
|
||||
|
||||
| Method | Signature | Description |
|
||||
|--------|-----------|-------------|
|
||||
| `SensorsDigitalInGet` | `ulong SensorsDigitalInGet(IUserDbRecord user, IConnectionDetails connection, int? id, string serialNumber, string eId, out IDigitalInDbRecord[] records)` | Retrieves digital input settings matching criteria. |
|
||||
| `SensorsDigitalInUpdateInsert` | `ulong SensorsDigitalInUpdateInsert(IUserDbRecord user, IConnectionDetails connection, IDigitalInDbRecord record)` | Inserts or updates a digital input record. |
|
||||
| `SensorsDigitalOutGet` | `ulong SensorsDigitalOutGet(IUserDbRecord user, IConnectionDetails connection, int? Id, string serialNumber, out IDigitalOutDbRecord[] records)` | Retrieves digital output settings matching criteria. |
|
||||
| `SensorsDigitalOutUpdateInsert` | `ulong SensorsDigitalOutUpdateInsert(IUserDbRecord user, IConnectionDetails connection, IDigitalOutDbRecord record)` | Commits a digital output setting to the database. |
|
||||
|
||||
### Squib Operations
|
||||
|
||||
| Method | Signature | Description |
|
||||
|--------|-----------|-------------|
|
||||
| `SensorsSquibGet` | `ulong SensorsSquibGet(IUserDbRecord user, IConnectionDetails connection, int? Id, string serialNumber, string eId, out ISquibDbRecord[] records)` | Retrieves squib settings matching criteria. |
|
||||
| `SensorsSquibUpdateInsert` | `ulong SensorsSquibUpdateInsert(IUserDbRecord user, IConnectionDetails connection, ISquibDbRecord record)` | Inserts or updates a squib setting. |
|
||||
|
||||
### UART Operations
|
||||
|
||||
| Method | Signature | Description |
|
||||
|--------|-----------|-------------|
|
||||
| `SensorsUARTGet` | `ulong SensorsUARTGet(IUserDbRecord user, IConnectionDetails connection, int? Id, string SerialNumber, out IUARTRecord[] records)` | Retrieves UART settings. |
|
||||
| `SensorsUARTUpdateInsert` | `ulong SensorsUARTUpdateInsert(IUserDbRecord user, IConnectionDetails connection, ref IUARTRecord record)` | Inserts or updates a UART record. ID is updated on insert. |
|
||||
|
||||
### CAN Operations
|
||||
|
||||
| Method | Signature | Description |
|
||||
|--------|-----------|-------------|
|
||||
| `SensorsCanGet` | `ulong SensorsCanGet(IUserDbRecord user, IConnectionDetails connection, int? Id, string SerialNumber, out ICANRecord[] records)` | Retrieves CAN records. (No XML documentation in source.) |
|
||||
| `SensorsCanUpdateInsert`
|
||||
18
docs/ai/DataPRO/DbAPI/Tags.md
Normal file
18
docs/ai/DataPRO/DbAPI/Tags.md
Normal file
@@ -0,0 +1,18 @@
|
||||
---
|
||||
source_files:
|
||||
- DataPRO/DbAPI/Tags/ITags.cs
|
||||
- DataPRO/DbAPI/Tags/Tags.cs
|
||||
generated_at: "2026-04-17T17:00:24.835449+00:00"
|
||||
model: "zai-org/GLM-5-FP8"
|
||||
schema_version: 1
|
||||
sha256: "063f87e3808eec31"
|
||||
---
|
||||
|
||||
# Tags
|
||||
|
||||
*Auto-enrichment was unable to generate documentation for this module (model returned empty response after 3 attempts).*
|
||||
|
||||
## Source files
|
||||
|
||||
- `DataPRO/DbAPI/Tags/ITags.cs`
|
||||
- `DataPRO/DbAPI/Tags/Tags.cs`
|
||||
183
docs/ai/DataPRO/DbAPI/TestMetaData.md
Normal file
183
docs/ai/DataPRO/DbAPI/TestMetaData.md
Normal file
@@ -0,0 +1,183 @@
|
||||
---
|
||||
source_files:
|
||||
- DataPRO/DbAPI/TestMetaData/ICustomerDetails.cs
|
||||
- DataPRO/DbAPI/TestMetaData/ILabratoryDetails.cs
|
||||
- DataPRO/DbAPI/TestMetaData/ITestEngineerDetails.cs
|
||||
- DataPRO/DbAPI/TestMetaData/CustomerDetails.cs
|
||||
- DataPRO/DbAPI/TestMetaData/TestEngineerDetails.cs
|
||||
- DataPRO/DbAPI/TestMetaData/LabratoryDetails.cs
|
||||
generated_at: "2026-04-17T15:52:32.793882+00:00"
|
||||
model: "zai-org/GLM-5-FP8"
|
||||
schema_version: 1
|
||||
sha256: "b095a05a967160c2"
|
||||
---
|
||||
|
||||
# TestMetaData Module Documentation
|
||||
|
||||
## 1. Purpose
|
||||
|
||||
This module provides the database access layer for test metadata entities within the DataPRO system. It defines and implements CRUD operations for three core domain objects: `CustomerDetails`, `LabratoryDetails` (sic), and `TestEngineerDetails`. The module serves as an abstraction over SQL stored procedures, enforcing user authentication before any database operation and translating database results into strongly-typed record objects. Its role is to persist and retrieve test-related metadata that associates tests with customers, laboratories, and engineers.
|
||||
|
||||
---
|
||||
|
||||
## 2. Public Interface
|
||||
|
||||
### ICustomerDetails Interface
|
||||
|
||||
**`ulong CustomerDetailsInsert(IUserDbRecord user, IConnectionDetails connection, CustomerDetailsDbRecord customerDetailsDbRecord, out int newId, out string errorString)`**
|
||||
- Inserts a new record into the CustomerDetails table via `sp_CustomerDetailsInsert` stored procedure.
|
||||
- Returns the new record's ID in `newId` on success.
|
||||
- Returns `0` (ERROR_SUCCESS) on success; non-zero error codes otherwise.
|
||||
|
||||
**`ulong CustomerDetailsUpdate(IUserDbRecord user, IConnectionDetails connection, CustomerDetailsDbRecord customerDetailsDbRecord, out string errorString)`**
|
||||
- Updates an existing record in the CustomerDetails table via `sp_CustomerDetailsUpdate` stored procedure.
|
||||
- Returns `0` (ERROR_SUCCESS) on success; non-zero error codes otherwise.
|
||||
|
||||
**`ulong CustomerDetailsGet(IUserDbRecord user, IConnectionDetails connection, string name, out ICustomerDetailsDbRecord[] customerDetailsDbRecords)`**
|
||||
- Retrieves all customer details matching the provided name via `sp_CustomerDetailsGet` stored procedure.
|
||||
- Returns matching records in `customerDetailsDbRecords` array (may be `null` if no matches or error).
|
||||
- Returns `0` (ERROR_SUCCESS) on success; non-zero error codes otherwise.
|
||||
|
||||
**`ulong CustomerDetailsDelete(IUserDbRecord user, IConnectionDetails connection, string name, out string errorString)`**
|
||||
- Deletes an entry from the CustomerDetails table via `sp_CustomerDetailsDelete` stored procedure.
|
||||
- Returns `0` (ERROR_SUCCESS) on success; non-zero error codes otherwise.
|
||||
|
||||
---
|
||||
|
||||
### ILabratoryDetails Interface
|
||||
|
||||
**`ulong LabratoryDetailsInsert(IUserDbRecord user, IConnectionDetails connection, LabratoryDetailsDbRecord labratoryDetailsDbRecord, out int newId, out string errorString)`**
|
||||
- Inserts a new record into the LabratoryDetails table via `sp_LabratoryDetailsInsert` stored procedure.
|
||||
- Returns the new record's ID in `newId` on success.
|
||||
- Returns `0` (ERROR_SUCCESS) on success; non-zero error codes otherwise.
|
||||
|
||||
**`ulong LabratoryDetailsUpdate(IUserDbRecord user, IConnectionDetails connection, LabratoryDetailsDbRecord labratoryDetailsDbRecord, out string errorString)`**
|
||||
- Updates an existing record in the LabratoryDetails table via `sp_LabratoryDetailsUpdate` stored procedure.
|
||||
- Returns `0` (ERROR_SUCCESS) on success; non-zero error codes otherwise.
|
||||
|
||||
**`ulong LabratoryDetailsUpdateInsert(IUserDbRecord user, IConnectionDetails connection, LabratoryDetailsDbRecord labratoryDetailsDbRecord, out string errorString)`**
|
||||
- Performs an upsert operation (update existing or insert new) via `sp_LabratoryDetailsUpdateInsert` stored procedure.
|
||||
- Returns `0` (ERROR_SUCCESS) on success; non-zero error codes otherwise.
|
||||
|
||||
**`ulong LabratoryDetailsGet(IUserDbRecord user, IConnectionDetails connection, string name, out ILabratoryDetailsDbRecord[] labratoryDetailsDbRecords)`**
|
||||
- Retrieves all laboratory details matching the provided name via `sp_LabratoryDetailsGet` stored procedure.
|
||||
- Returns matching records in `labratoryDetailsDbRecords` array (may be `null` if no matches or error).
|
||||
- Returns `0` (ERROR_SUCCESS) on success; non-zero error codes otherwise.
|
||||
|
||||
**`ulong LabratoryDetailsDelete(IUserDbRecord user, IConnectionDetails connection, string name, out string errorString)`**
|
||||
- Deletes an entry from the LabratoryDetails table via `sp_LabratoryDetailsDelete` stored procedure.
|
||||
- Returns `0` (ERROR_SUCCESS) on success; non-zero error codes otherwise.
|
||||
|
||||
---
|
||||
|
||||
### ITestEngineerDetails Interface
|
||||
|
||||
**`ulong TestEngineerDetailsInsert(IUserDbRecord user, IConnectionDetails connection, TestEngineerDetailsDbRecord testEngineerDetailsDbRecord, out int newId, out string errorString)`**
|
||||
- Inserts a new record into the TestEngineerDetails table via `sp_TestEngineerDetailsInsert` stored procedure.
|
||||
- Returns the new record's ID in `newId` on success.
|
||||
- Returns `0` (ERROR_SUCCESS) on success; non-zero error codes otherwise.
|
||||
|
||||
**`ulong TestEngineerDetailsUpdate(IUserDbRecord user, IConnectionDetails connection, TestEngineerDetailsDbRecord testEngineerDetailsDbRecord, out string errorString)`**
|
||||
- Updates an existing record in the TestEngineerDetails table via `sp_TestEngineerDetailsUpdate` stored procedure.
|
||||
- Returns `0` (ERROR_SUCCESS) on success; non-zero error codes otherwise.
|
||||
|
||||
**`ulong TestEngineerDetailsUpdateInsert(IUserDbRecord user, IConnectionDetails connection, TestEngineerDetailsDbRecord testEngineerDetailsDbRecord, out string errorString)`**
|
||||
- Performs an upsert operation (update existing or insert new) via `sp_TestEngineerDetailsUpdateInsert` stored procedure.
|
||||
- Returns `0` (ERROR_SUCCESS) on success; non-zero error codes otherwise.
|
||||
|
||||
**`ulong TestEngineerDetailsGet(IUserDbRecord user, IConnectionDetails connection, string name, out ITestEngineerDetailsDbRecord[] testEngineerDetailsDbRecords)`**
|
||||
- Retrieves all test engineer details matching the provided name via `sp_TestEngineerDetailsGet` stored procedure.
|
||||
- Returns matching records in `testEngineerDetailsDbRecords` array (may be `null` if no matches or error).
|
||||
- Returns `0` (ERROR_SUCCESS) on success; non-zero error codes otherwise.
|
||||
|
||||
**`ulong TestEngineerDetailsDelete(IUserDbRecord user, IConnectionDetails connection, string name, out string errorString)`**
|
||||
- Deletes an entry from the TestEngineerDetails table via `sp_TestEngineerDetailsDelete` stored procedure.
|
||||
- Returns `0` (ERROR_SUCCESS) on success; non-zero error codes otherwise.
|
||||
|
||||
---
|
||||
|
||||
## 3. Invariants
|
||||
|
||||
- **Authentication Required**: All public methods must call `DbAPI.Connections.IsUserLoggedIn(user, connection)` before executing any database operation. If this returns `false`, the method must immediately return `ErrorCodes.ERROR_ACCESS_DENIED`.
|
||||
|
||||
- **Error Code Contract**: All methods return `ulong` error codes where `0` represents `ERROR_SUCCESS`. Any non-zero value indicates an error condition.
|
||||
|
||||
- **Stored Procedure Usage**: All database operations must use stored procedures (never inline SQL). Stored procedures follow naming convention `sp_<EntityName><Operation>` (e.g., `sp_CustomerDetailsInsert`).
|
||||
|
||||
- **Version Field**: The `@Version` parameter is always passed as `1` for all Insert and Update operations. The source does not indicate whether this is incremented elsewhere.
|
||||
|
||||
- **Connection Disposal**: All implementations must dispose of `cmd.Connection` in a `finally` block to ensure cleanup even on exceptions.
|
||||
|
||||
- **Output Parameter Pattern**: Stored procedures return error information via `@errorNumber` (int output) and `@errorMessage` (nvarchar(250) output) parameters.
|
||||
|
||||
- **New ID on Insert**: Insert operations must declare an output parameter `@new_id` (int) to receive the newly created record's identifier.
|
||||
|
||||
- **Record Filtering**: `Get` methods filter out records where `IsInvalidBlank()` returns `true` on the constructed record object.
|
||||
|
||||
---
|
||||
|
||||
## 4. Dependencies
|
||||
|
||||
### This Module Depends On:
|
||||
|
||||
| Dependency | Usage |
|
||||
|------------|-------|
|
||||
| `DbAPI.Connections` | `ConnectionManager.GetSqlCommand()`, `IsUserLoggedIn()` |
|
||||
| `DbAPI.Errors` | `ErrorCodes` constants (e.g., `ERROR_SUCCESS`, `ERROR_ACCESS_DENIED`, `ERROR_UNKNOWN`) |
|
||||
| `DbAPI.Logging` | `LogManager.Log()` for error logging |
|
||||
| `DTS.Common.Interface.Database` | `IUserDbRecord` interface |
|
||||
| `DTS.Common.Interface.TestMetaData` | `ICustomerDetailsDbRecord`, `ILabratoryDetailsDbRecord`, `ITestEngineerDetailsDbRecord` interfaces |
|
||||
| `DTS.Common.Classes.CustomerDetails` | `CustomerDetailsDbRecord` class |
|
||||
| `DTS.Common.Classes.LabratoryDetails` | `LabratoryDetailsDbRecord` class |
|
||||
| `DTS.Common.Classes.TestEngineerDetails` | `TestEngineerDetailsDbRecord` class |
|
||||
| `System.Data.SqlClient` | `SqlParameter`, `SqlCommand`, `SqlDataReader` |
|
||||
| `System.Data` | `CommandType`, `ParameterDirection` |
|
||||
|
||||
### What Depends On This Module:
|
||||
|
||||
Not determinable from the provided source files alone. The interfaces are public, while the implementing classes are `internal`, suggesting dependency injection or a factory pattern elsewhere in the codebase.
|
||||
|
||||
---
|
||||
|
||||
## 5. Gotchas
|
||||
|
||||
### Persistent Typo: "Labratory"
|
||||
The term "Laboratory" is consistently misspelled as "Labratory" throughout the codebase (namespace `DbAPI.LabratoryDetails`, interface `ILabratoryDetails`, class `LabratoryDetails`, stored procedures like `sp_LabratoryDetailsInsert`). This typo propagates to database object names and cannot be fixed without database migration.
|
||||
|
||||
### Double Connection Disposal in Delete Methods
|
||||
All three `Delete` methods (`CustomerDetailsDelete`, `LabratoryDetailsDelete`, `TestEngineerDetailsDelete`) contain nested `try/finally` blocks where `cmd.Connection.Dispose()` is called twice:
|
||||
```csharp
|
||||
try
|
||||
{
|
||||
try { /* ... */ }
|
||||
finally { cmd.Connection.Dispose(); } // First disposal
|
||||
}
|
||||
catch (Exception ex) { /* ... */ }
|
||||
finally { cmd.Connection.Dispose(); } // Second disposal
|
||||
```
|
||||
While `Dispose()` is typically idempotent, this is redundant and indicates a refactoring artifact.
|
||||
|
||||
### Inconsistent Exception Handling
|
||||
- `CustomerDetailsInsert`, `LabratoryDetailsInsert`, `TestEngineerDetailsInsert` do not catch exceptions; they propagate to the caller.
|
||||
- `CustomerDetailsUpdate`, `LabratoryDetailsUpdate`, `TestEngineerDetailsUpdate` catch exceptions and populate `errorString`.
|
||||
- `CustomerDetailsGet`, `LabratoryDetailsGet`, `TestEngineerDetailsGet` catch exceptions, log them via `LogManager.Log()`, and return `ERROR_UNKNOWN`.
|
||||
|
||||
### Missing Parameter in TestEngineerDetailsUpdate
|
||||
In `TestEngineerDetailsUpdate`, the `@LocalOnly` parameter is commented out:
|
||||
```csharp
|
||||
//cmd.Parameters.Add(new SqlParameter("@LocalOnly", SqlDbType.Bit) { Value = testEngineerDetailsDbRecord.LocalOnly });
|
||||
```
|
||||
This means the `LocalOnly` field cannot be updated via this method, unlike in `TestEngineerDetailsInsert` and `TestEngineerDetailsUpdateInsert`.
|
||||
|
||||
### Unused Output Parameter in LabratoryDetailsUpdate
|
||||
`LabratoryDetailsUpdate` declares `@new_id` as an output parameter but never reads its value after execution. This parameter is not present in `CustomerDetailsUpdate` or `TestEngineerDetailsUpdate`.
|
||||
|
||||
### Delete Parameter Naming Inconsistency
|
||||
- `CustomerDetailsDelete` and `TestEngineerDetailsDelete` pass the `name` parameter to `@Name`.
|
||||
- `LabratoryDetailsDelete` passes the `name` parameter to `@LabratoryName`.
|
||||
|
||||
### Hardcoded Version Value
|
||||
All Insert and Update methods pass `@Version = 1` unconditionally. It is unclear from the source whether versioning is implemented elsewhere or if this represents tech debt.
|
||||
|
||||
### errorString Not Always Populated
|
||||
The `errorString` output parameter is only populated when the stored procedure returns a non-zero `@errorNumber` or when an exception is caught. On successful operations, it remains an empty string, which is correct but worth noting for callers expecting null checks.
|
||||
159
docs/ai/DataPRO/DbAPI/TestSetups.md
Normal file
159
docs/ai/DataPRO/DbAPI/TestSetups.md
Normal file
@@ -0,0 +1,159 @@
|
||||
---
|
||||
source_files:
|
||||
- DataPRO/DbAPI/TestSetups/IGraphs.cs
|
||||
- DataPRO/DbAPI/TestSetups/ICalculatedChannels.cs
|
||||
- DataPRO/DbAPI/TestSetups/IRegionsOfInterest.cs
|
||||
- DataPRO/DbAPI/TestSetups/ITestSetups.cs
|
||||
- DataPRO/DbAPI/TestSetups/CalculatedChannels.cs
|
||||
- DataPRO/DbAPI/TestSetups/Graphs.cs
|
||||
generated_at: "2026-04-17T15:51:12.206877+00:00"
|
||||
model: "zai-org/GLM-5-FP8"
|
||||
schema_version: 1
|
||||
sha256: "37c4e37f0df42b66"
|
||||
---
|
||||
|
||||
# TestSetups Module Documentation
|
||||
|
||||
## 1. Purpose
|
||||
|
||||
This module provides the database access layer for test setup configuration data within the DataPRO system. It defines and implements CRUD operations for four primary entities: graphs (`IGraphs`/`Graphs`), calculated channels (`ICalculatedChannels`/`CalculatedChannels`), regions of interest (`IRegionsOfInterest`), and test setup metadata (`ITestSetups`). The module abstracts SQL Server stored procedure calls behind strongly-typed interfaces, handling user authentication, parameter marshalling, and error propagation. It serves as the persistence boundary between the application's domain model and the relational database.
|
||||
|
||||
---
|
||||
|
||||
## 2. Public Interface
|
||||
|
||||
### IGraphs Interface
|
||||
|
||||
| Method | Signature |
|
||||
|--------|-----------|
|
||||
| `GraphsGet` | `ulong GraphsGet(IUserDbRecord user, IConnectionDetails connection, int? graphId, int? testSetupId, out IGraphRecord[] records)` |
|
||||
| `GraphsUpdate` | `ulong GraphsUpdate(IUserDbRecord user, IConnectionDetails connection, IGraphRecord record)` |
|
||||
| `GraphsInsert` | `ulong GraphsInsert(IUserDbRecord user, IConnectionDetails connection, ref IGraphRecord record)` |
|
||||
| `GraphsDelete` | `ulong GraphsDelete(IUserDbRecord user, IConnectionDetails connection, int graphId)` |
|
||||
|
||||
**Behaviors:**
|
||||
- `GraphsGet`: Retrieves graph records filtered by optional `graphId` and/or `testSetupId`. Returns empty array if no matches.
|
||||
- `GraphsUpdate`: Updates an existing graph record identified by `record.GraphId`.
|
||||
- `GraphsInsert`: Inserts a new graph record. The `ref` parameter is mutated with the new `GraphId` from the database.
|
||||
- `GraphsDelete`: Removes a graph record by its database ID.
|
||||
|
||||
### ICalculatedChannels Interface
|
||||
|
||||
| Method | Signature |
|
||||
|--------|-----------|
|
||||
| `CalculatedChannelsDelete` | `ulong CalculatedChannelsDelete(IUserDbRecord user, IConnectionDetails connection, int calculatedChannelId)` |
|
||||
| `CalculatedChannelsGet` | `ulong CalculatedChannelsGet(IUserDbRecord user, IConnectionDetails connection, int? calculatedChannelId, string testSetupName, out ICalculatedChannelRecord[] records)` |
|
||||
| `CalculatedChannelsInsert` | `ulong CalculatedChannelsInsert(IUserDbRecord user, IConnectionDetails connection, ref ICalculatedChannelRecord record)` |
|
||||
| `CalculatedChannelsUpdate` | `ulong CalculatedChannelsUpdate(IUserDbRecord user, IConnectionDetails connection, ICalculatedChannelRecord record)` |
|
||||
|
||||
**Behaviors:**
|
||||
- `CalculatedChannelsGet`: Retrieves calculated channel records filtered by optional `calculatedChannelId` and/or `testSetupName`.
|
||||
- `CalculatedChannelsInsert`: Inserts a new calculated channel. The `ref` parameter is mutated with the new `Id` from the database.
|
||||
- `CalculatedChannelsUpdate`: Updates an existing calculated channel identified by `record.Id`.
|
||||
- `CalculatedChannelsDelete`: Removes a calculated channel by its database ID.
|
||||
|
||||
### IRegionsOfInterest Interface
|
||||
|
||||
| Method | Signature |
|
||||
|--------|-----------|
|
||||
| `RegionsOfInterestDelete` | `ulong RegionsOfInterestDelete(IUserDbRecord user, IConnectionDetails connection, int testSetupId)` |
|
||||
| `RegionsOfInterestInsert` | `ulong RegionsOfInterestInsert(IUserDbRecord user, IConnectionDetails connection, int clientDbVersion, int testSetupId, IRegionOfInterest regionOfInterest)` |
|
||||
| `RegionsOfInterestGet` | `ulong RegionsOfInterestGet(IUserDbRecord user, IConnectionDetails connection, int clientDbVersion, int testSetupId, out IRegionOfInterest[] records)` |
|
||||
| `TestSetupROIsDelete` | `ulong TestSetupROIsDelete(IUserDbRecord user, IConnectionDetails connection, int testSetupId)` |
|
||||
| `TestSetupROIsInsert` | `ulong TestSetupROIsInsert(IUserDbRecord user, IConnectionDetails connection, int testSetupId, IRegionOfInterest regionOfInterest, out int testSetupROIId)` |
|
||||
| `TestSetupROIsGet` | `ulong TestSetupROIsGet(IUserDbRecord user, IConnectionDetails connection, int testSetupId, out ITestSetupROIRecord[] records)` |
|
||||
| `ROIPeriodChannelsInsert` | `ulong ROIPeriodChannelsInsert(IUserDbRecord user, IConnectionDetails connection, int clientDbVersion, int testSetupROIId, string channelName, long channelId)` |
|
||||
| `ROIPeriodChannelsGet` | `ulong ROIPeriodChannelsGet(IUserDbRecord user, IConnectionDetails connection, int clientDbVersion, int testSetupROIId, out IROIPeriodChannelRecord[] roiPeriodChannelRecords)` |
|
||||
|
||||
**Behaviors:**
|
||||
- `RegionsOfInterestDelete`: Removes records from both `TestSetupROIs` and `ROIPeriodChannels` tables for a given `testSetupId`.
|
||||
- `RegionsOfInterestInsert`: Inserts records into both `TestSetupROIs` and `ROIPeriodChannels` tables.
|
||||
- `RegionsOfInterestGet`: Retrieves and combines records from `TestSetupROIs` and `ROIPeriodChannels` tables.
|
||||
- `TestSetupROIsInsert`: Inserts into `TestSetupROIs` table; outputs the new `testSetupROIId`.
|
||||
|
||||
### ITestSetups Interface
|
||||
|
||||
| Method | Signature |
|
||||
|--------|-----------|
|
||||
| `TestSetupHardwareDelete` | `ulong TestSetupHardwareDelete(IUserDbRecord user, IConnectionDetails connection, int? Id, int? dasId, int? testSetupId)` |
|
||||
| `TestSetupHardwareUpdate` | `ulong TestSetupHardwareUpdate(IUserDbRecord user, IConnectionDetails connection, ITestSetupHardwareRecord record)` |
|
||||
| `TestSetupHardwareInsert` | `ulong TestSetupHardwareInsert(IUserDbRecord user, IConnectionDetails connection, ITestSetupHardwareRecord record)` |
|
||||
| `TestSetupHardwareGet` | `ulong TestSetupHardwareGet(IUserDbRecord user, IConnectionDetails connection, int clientDbVersion, int? testSetupId, out ITestSetupHardwareRecord[] records)` |
|
||||
| `TestSetupGroupsInsert` | `ulong TestSetupGroupsInsert(IUserDbRecord user, IConnectionDetails connection, ITestSetupGroupRecord record)` |
|
||||
| `TestSetupGroupsUpdate` | `ulong TestSetupGroupsUpdate(IUserDbRecord user, IConnectionDetails connection, ITestSetupGroupRecord record)` |
|
||||
| `TestSetupGroupsGet` | `ulong TestSetupGroupsGet(IUserDbRecord user, IConnectionDetails connection, int? groupId, int? testSetupId, string testSetupName, out ITestSetupGroupRecord[] groups)` |
|
||||
| `TestSetupsMarkIsDirtyIsComplete` | `ulong TestSetupsMarkIsDirtyIsComplete(IUserDbRecord user, IConnectionDetails connection, string name, bool dirty, bool complete, string error)` |
|
||||
| `TestSetupsDeleteByDate` | `ulong TestSetupsDeleteByDate(IUserDbRecord user, IConnectionDetails connection, DateTime date)` |
|
||||
| `TestSetupsAndGroupsDeleteAll` | `ulong TestSetupsAndGroupsDeleteAll(IUserDbRecord user, IConnectionDetails connection)` |
|
||||
| `TestSetupsDeleteById` | `ulong TestSetupsDeleteById(IUserDbRecord user, IConnectionDetails connection, int[] ids)` |
|
||||
| `TestSetupsDeleteByName` | `ulong TestSetupsDeleteByName(IUserDbRecord user, IConnectionDetails connection, string[] names)` |
|
||||
| `TestSetupsUpdateInsert` | `ulong TestSetupsUpdateInsert(IUserDbRecord user, IConnectionDetails connection, int clientDbVersion, ref ITestSetupRecord record)` |
|
||||
| `TestSetupsGet` | `ulong TestSetupsGet(IUserDbRecord user, IConnectionDetails connection, int clientDbVersion, int? testSetupId, string testSetupName, double defaultROIStart, double defaultROIEnd, bool defaultIgnoreShortedStart, bool defaultIgnoreShortedTrigger, out ITestSetupRecord[] records, out string[] errors)` |
|
||||
|
||||
**Behaviors:**
|
||||
- `TestSetupHardwareDelete`: Requires at least one of `Id`, `dasId`, or `testSetupId` to be specified.
|
||||
- `TestSetupsMarkIsDirtyIsComplete`: Updates the `IsDirty` and `IsComplete` flags for a test setup by name.
|
||||
- `TestSetupsGet`: Accepts default ROI values for backward compatibility with older database versions that may lack ROI data.
|
||||
|
||||
---
|
||||
|
||||
## 3. Invariants
|
||||
|
||||
1. **Return Value Convention**: All methods return `ulong` where `0` equals `ERROR_SUCCESS`. Any non-zero value indicates an error.
|
||||
|
||||
2. **Authentication Requirement**: All public methods in `Graphs` and `CalculatedChannels` implementations call `DbAPI.Connections.IsUserLoggedIn(user, connection)` before executing database operations. Failure returns `ErrorCodes.ERROR_ACCESS_DENIED`.
|
||||
|
||||
3. **Null Record Handling**: Insert and Update methods in `CalculatedChannels` check for null `record` parameter and return `ErrorCodes.ERROR_MISSING_PARAMETER` if null.
|
||||
|
||||
4. **Resource Cleanup**: All implementations use `try/finally` blocks to dispose of `SqlCommand` and its `Connection`. The `SqlConnection` is disposed via `cmd.Connection.Dispose()`.
|
||||
|
||||
5. **Stored Procedure Usage**: All database operations use stored procedures (e.g., `sp_CalculatedChannelsInsert`, `sp_TestGraphsGet`). No inline SQL is used.
|
||||
|
||||
6. **Output Parameter Mutation**: Insert methods (`GraphsInsert`, `CalculatedChannelsInsert`) use `ref` parameters to return the newly assigned database ID to the caller.
|
||||
|
||||
7. **Error Propagation**: Stored procedures return errors via `@errorNumber` and `@errorMessage` output parameters. Non-zero error numbers are logged via `LogManager.Log` and result in `ErrorCodes.ERROR_UNKNOWN` being returned.
|
||||
|
||||
---
|
||||
|
||||
## 4. Dependencies
|
||||
|
||||
### This module depends on:
|
||||
|
||||
| Namespace | Purpose |
|
||||
|-----------|---------|
|
||||
| `DbAPI.Connections` | `IConnectionDetails`, `ConnectionManager.GetSqlCommand()`, `IsUserLoggedIn()` |
|
||||
| `DbAPI.Errors` | `ErrorCodes` constants (`ERROR_SUCCESS`, `ERROR_ACCESS_DENIED`, `ERROR_MISSING_PARAMETER`, `ERROR_UNKNOWN`) |
|
||||
| `DbAPI.Logging` | `LogManager.Log()`, `LogEvents` enum |
|
||||
| `DTS.Common.Interface.Database` | `IUserDbRecord` |
|
||||
| `DTS.Common.Interface.Graphs` | `IGraphRecord` |
|
||||
| `DTS.Common.Interface.TestSetups` | `ICalculatedChannelRecord`, `ITestSetupRecord`, `ITestSetupHardwareRecord`, `ITestSetupGroupRecord`, `ITestSetupROIRecord`, `IROIPeriodChannelRecord` |
|
||||
| `DTS.Common.Interface.RegionOfInterest` | `IRegionOfInterest` |
|
||||
| `DTS.Common.Classes.TestSetups` | Concrete implementations: `GraphRecord`, `CalculatedChannelRecord` |
|
||||
| `DTS.Common.Classes` | `Utility.GetBytesFromStringArray()` |
|
||||
| `System.Data.SqlClient` | `SqlConnection`, `SqlCommand`, `SqlParameter`, `SqlDataReader` |
|
||||
|
||||
### What depends on this module:
|
||||
Not determinable from the provided source files alone. The interfaces are public and the implementations are `internal`, suggesting they are consumed by other components within the `DbAPI` assembly.
|
||||
|
||||
---
|
||||
|
||||
## 5. Gotchas
|
||||
|
||||
1. **Incorrect Log Event in `CalculatedChannelsGet`**: The implementation logs errors using `LogEvents.Graphs` instead of `LogEvents.CalculatedChannels`:
|
||||
```csharp
|
||||
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.Graphs, $"sp_CalculatedChannelsGet failed: {ex.Message}");
|
||||
```
|
||||
This appears to be a copy-paste error.
|
||||
|
||||
2. **Incorrect Log Message in `GraphsDelete`**: The exception log message incorrectly references "GraphsInsert":
|
||||
```csharp
|
||||
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.Graphs, $"GraphsInsert exception {ex.Message}");
|
||||
```
|
||||
|
||||
3. **Inconsistent Command Disposal**: The `Graphs` class only disposes `cmd.Connection` in its `finally` block, while `CalculatedChannels` disposes both `cmd.Connection` and `cmd`. This may indicate inconsistent cleanup patterns.
|
||||
|
||||
4. **Missing XML Documentation**: The `IRegionsOfInterest` interface lacks XML documentation for `TestSetupROIsDelete`, `TestSetupROIsInsert`, `TestSetupROIsGet`, `ROIPeriodChannelsInsert`, and `ROIPeriodChannelsGet` methods.
|
||||
|
||||
5. **Undocumented `clientDbVersion` Parameter**: The purpose and valid values of the `clientDbVersion` parameter (present in `IRegionsOfInterest` and `ITestSetups` methods) is not documented in the interface. Comments in `TestSetupsGet` hint at Version 91 database compatibility concerns, but specifics are unclear from source alone.
|
||||
|
||||
6. **InputChannelIds Serialization**: `CalculatedChannelsInsert` and `CalculatedChannelsUpdate` serialize `InputChannelIds` using `Utility.GetBytesFromStringArray()` with `CultureInfo.InvariantCulture.TextInfo.ListSeparator`. The deserialization logic is not present in these files.
|
||||
52
docs/ai/DataPRO/DbAPI/User.md
Normal file
52
docs/ai/DataPRO/DbAPI/User.md
Normal file
@@ -0,0 +1,52 @@
|
||||
---
|
||||
source_files:
|
||||
- DataPRO/DbAPI/User/User.cs
|
||||
generated_at: "2026-04-17T16:46:12.769149+00:00"
|
||||
model: "zai-org/GLM-5-FP8"
|
||||
schema_version: 1
|
||||
sha256: "0503b861b2f057b5"
|
||||
---
|
||||
|
||||
# Documentation: `DbAPI.User.User`
|
||||
|
||||
## 1. Purpose
|
||||
|
||||
This module provides a basic implementation of `IUserDbRecord` representing a user entity within the DbAPI data access layer. It serves as a data transfer object for user records and contains a factory method (`GetUser`) to retrieve user records from the database via stored procedures. The class bridges the database schema with the application's user management system, handling user authentication lookups and role information.
|
||||
|
||||
---
|
||||
|
||||
## 2. Public Interface
|
||||
|
||||
### Class: `User` (internal)
|
||||
**Implements:** `IUserDbRecord`
|
||||
|
||||
#### Properties
|
||||
|
||||
| Property | Type | Description |
|
||||
|----------|------|-------------|
|
||||
| `ID` | `int` | Unique identifier for the user. |
|
||||
| `UserName` | `string` | Login username. |
|
||||
| `DisplayName` | `string` | Human-readable display name. |
|
||||
| `Password` | `string` | User password (storage format unclear from source). |
|
||||
| `Role` | `short` | Numeric role identifier. |
|
||||
| `LastModified` | `DateTime` | Timestamp of last modification. |
|
||||
| `LastModifiedBy` | `string` | Identifier of who last modified the record. |
|
||||
| `LocalOnly` | `bool` | Flag indicating whether user is local-only. |
|
||||
|
||||
#### Constructor
|
||||
|
||||
```csharp
|
||||
public User(int id, string user, string display, string pwd, short role, DateTime lastModified, string lastModifiedBy, bool local)
|
||||
```
|
||||
Initializes all properties with provided values.
|
||||
|
||||
#### Methods
|
||||
|
||||
```csharp
|
||||
internal static ulong GetUser(IConnectionDetails connection, out IUserDbRecord usr, string userName)
|
||||
```
|
||||
Retrieves a user record from the database by username. Returns an error code (`ulong`) and populates the `out` parameter `usr` with the retrieved `IUserDbRecord` on success.
|
||||
|
||||
**Return codes:**
|
||||
- `Errors.ErrorCodes.ERROR_SUCCESS` - User found and retrieved successfully.
|
||||
-
|
||||
28
docs/ai/DataPRO/DbAPI/obj/Debug/net48.md
Normal file
28
docs/ai/DataPRO/DbAPI/obj/Debug/net48.md
Normal file
@@ -0,0 +1,28 @@
|
||||
---
|
||||
source_files:
|
||||
- DataPRO/DbAPI/obj/Debug/net48/DbAPI.AssemblyInfo.cs
|
||||
generated_at: "2026-04-17T16:29:44.610214+00:00"
|
||||
model: "zai-org/GLM-5-FP8"
|
||||
schema_version: 1
|
||||
sha256: "15fdc15a8fca3f17"
|
||||
---
|
||||
|
||||
# net48
|
||||
|
||||
### Purpose
|
||||
This is an auto-generated assembly information file produced by the MSBuild build system during compilation of the DbAPI project for the x86 Debug configuration targeting .NET Framework 4.8. It contains assembly metadata attributes and is regenerated on each build. **This file should not be manually edited.**
|
||||
|
||||
### Public Interface
|
||||
None. This file contains only assembly-level attributes and exposes no types or members for programmatic use.
|
||||
|
||||
### Invariants
|
||||
- File is auto-generated by MSBuild's `WriteCodeFragment` task.
|
||||
- Manual changes will be overwritten on rebuild.
|
||||
- Targets .NET Framework 4.8 (runtime version 4.0.30319.42000).
|
||||
|
||||
### Dependencies
|
||||
- **Depends on:** `System`, `System.Reflection`.
|
||||
- **Depended on by:** None (build artifact only).
|
||||
|
||||
### Gotchas
|
||||
- This is a build output file located in the `obj` directory; it should not be checked into source control
|
||||
28
docs/ai/DataPRO/DbAPI/obj/x86/Debug/net48.md
Normal file
28
docs/ai/DataPRO/DbAPI/obj/x86/Debug/net48.md
Normal file
@@ -0,0 +1,28 @@
|
||||
---
|
||||
source_files:
|
||||
- DataPRO/DbAPI/obj/x86/Debug/net48/DbAPI.AssemblyInfo.cs
|
||||
generated_at: "2026-04-17T16:29:44.609522+00:00"
|
||||
model: "zai-org/GLM-5-FP8"
|
||||
schema_version: 1
|
||||
sha256: "9ca15db821307d8b"
|
||||
---
|
||||
|
||||
# net48
|
||||
|
||||
### Purpose
|
||||
This is an auto-generated assembly information file produced by the MSBuild build system during compilation of the DbAPI project for the x86 Debug configuration targeting .NET Framework 4.8. It contains assembly metadata attributes and is regenerated on each build. **This file should not be manually edited.**
|
||||
|
||||
### Public Interface
|
||||
None. This file contains only assembly-level attributes and exposes no types or members for programmatic use.
|
||||
|
||||
### Invariants
|
||||
- File is auto-generated by MSBuild's `WriteCodeFragment` task.
|
||||
- Manual changes will be overwritten on rebuild.
|
||||
- Targets .NET Framework 4.8 (runtime version 4.0.30319.42000).
|
||||
|
||||
### Dependencies
|
||||
- **Depends on:** `System`, `System.Reflection`.
|
||||
- **Depended on by:** None (build artifact only).
|
||||
|
||||
### Gotchas
|
||||
- This is a build output file located in the `obj` directory; it should not be checked into source control
|
||||
Reference in New Issue
Block a user