10 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||
|---|---|---|---|---|---|---|
|
2026-04-16T04:27:22.495313+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 0eeac4044bafa708 |
Documentation: DbAPI.Channels.IChannels / Channels
1. Purpose
This module provides database access layer (DAL) functionality for managing channel-related data in the system, including channel definitions (Channels table), channel codes (e.g., ISO codes, user codes), channel settings (both global and group-specific), and channel code types. It serves as the primary interface for CRUD operations on channel data, enforcing authentication, validating parameters, and translating between .NET objects and SQL Server stored procedures. The module is part of the DbAPI namespace and is intended for internal use by higher-level components that need to persist or retrieve channel configuration data.
2. Public Interface
All methods are defined in the IChannels interface and implemented by the internal class Channels. Return values are ulong, where 0 (ERROR_SUCCESS) indicates success and non-zero values indicate error codes (e.g., from ErrorCodes).
Channel Codes
-
ulong ChannelCodesInsert(IUserDbRecord user, IConnectionDetails connection, IReadOnlyDictionary<ChannelEnumsAndConstants.ChannelCodeType, short> lookup, IChannelCode channelCode, out int id)
Inserts a new channel code record. On success,idis populated with the new database ID. RequireschannelCode.CodeandchannelCode.Nameto be non-null/non-empty. -
ulong ChannelCodesUpdate(IUserDbRecord user, IConnectionDetails connection, IReadOnlyDictionary<ChannelEnumsAndConstants.ChannelCodeType, short> lookup, IChannelCode channelCode)
Updates an existing channel code record. RequireschannelCode.Id,Code, andNameto be non-null/non-empty. -
ulong ChannelCodesDelete(IUserDbRecord user, IConnectionDetails connection, int? id, string code, string name, int? codeType)
Deletes channel code records matching any combination ofid,code,name, orcodeType. All parameters are optional; null means “match all”. -
ulong ChannelCodeTypesGet(IUserDbRecord user, IConnectionDetails connection, short? id, string codeType, out Tuple<short, string>[] records)
Retrieves channel code type definitions (ID and string name). Parameters are filters; null means “match all”. -
ulong ChannelCodesGet(IUserDbRecord user, IConnectionDetails connection, int? Id, string code, string name, ChannelEnumsAndConstants.ChannelCodeType? codeType, IReadOnlyDictionary<short, string> channelTypeLookup, out IChannelCode[] records)
Retrieves channel code records matching filters.channelTypeLookupis required (cannot be null) and maps code type IDs to names for deserialization.
Channel Settings
-
ulong ChannelSettingsUpdate(IUserDbRecord user, IConnectionDetails connection, int settingId, string defaultValue)
Updates theDefaultValueof a channel setting (bysettingId). -
ulong ChannelSettingsGet(IUserDbRecord user, IConnectionDetails connection, int? settingId, string settingName, out IChannelSettingRecord[] records)
Retrieves channel settings matchingsettingIdand/orsettingName. Parameters are optional. -
ulong GroupChannelSettingsDelete(IUserDbRecord user, IConnectionDetails connection, long channelId, int? settingId)
Deletes group channel settings for a givenchannelId. IfsettingIdis null, deletes all settings for the channel. -
ulong GroupChannelSettingsInsert(IUserDbRecord user, IConnectionDetails connection, int clientDbVersion, long channelId, IGroupChannelSettingRecord record)
Inserts a new group channel setting. Uses version-aware stored procedure resolution viaDatabase.Database.PrepareForDbAccess. -
ulong GroupChannelSettingsGet(IUserDbRecord user, IConnectionDetails connection, int clientDbVersion, List<long> channelIdList, out IGroupChannelSettingRecord[] records, out string[] errors)
Retrieves group channel settings for a list of channel IDs. Behavior differs based onclientDbVersion:- If
< Constants.BULK_GROUPCHANNELSETTINGS_GET_DB_VERSION: callssp_GroupChannelSettingsGetrepeatedly (one per channel). - Otherwise: calls a bulk version using a table-valued parameter (
dbo.StringList).
errorsis always initialized to an empty array (no errors are populated in current implementation).
- If
Channels (Main Table)
-
ulong ChannelsInsert(IUserDbRecord user, IConnectionDetails connection, ref IChannelDbRecord channel)
Inserts a new channel record. On success,channel.Idis updated with the new database ID. Nullable fields (DASId,SensorId) are handled conditionally (only added to command if > 0).IsoCode,IsoChannelName,UserCode,UserChannelNamedefault to""if null. -
ulong ChannelsUpdate(IUserDbRecord user, IConnectionDetails connection, IChannelDbRecord channel)
Updates an existing channel record. Requireschannel.Id. -
ulong ChannelsGet(IUserDbRecord user, IConnectionDetails connection, int clientDbVersion, long? channelId, int? groupId, int? dasId, int? sensorId, int? testSetupId, string testSetupName, out IChannelDbRecord[] channels)
Retrieves channel records matching filters. Gotcha: Filters out channels whoseUserChannelNameends withDFConstantsAndEnums.USER_CHANNEL_NAME_HUMIDITY(see Gotchas). -
ulong ChannelsDelete(IUserDbRecord user, IConnectionDetails connection, long id, out string errorString)
Deletes a channel byid. Returns error code and populateserrorString(from stored procedure or exception) on failure.
3. Invariants
- Authentication: All methods require the user to be logged in (
IsUserLoggedIn(user, connection)). ReturnsERROR_ACCESS_DENIEDotherwise. - Parameter Validation:
ChannelCodesInsert/ChannelCodesUpdate:channelCode.CodeandchannelCode.Namemust be non-null/non-empty.ChannelCodesGet:channelTypeLookupmust be non-null.ChannelsInsert:channel.Idis output-only; inputIdis ignored (butGroupId,DASId,DASChannelIndex, etc., must be set appropriately).
- Null Handling:
- Optional filter parameters (e.g.,
id,code,name,codeType) are passed as SQLNULLif null. - Nullable DB columns (
DASId,SensorId) are omitted from command parameters if ≤ 0.
- Optional filter parameters (e.g.,
- Error Reporting:
- Stored procedures return
@errorNumberand@errorMessage. Non-zero@errorNumber→ERROR_UNKNOWN. - Exceptions during execution are logged and return
ERROR_UNKNOWN.
- Stored procedures return
- Resource Cleanup: All methods dispose
SqlCommandand connection infinallyblocks.
4. Dependencies
Imports/Usings (from source)
- Core:
System,System.Data,System.Data.SqlClient,System.Diagnostics - DbAPI:
DbAPI.Connections,DbAPI.Errors,DbAPI.Logging - Common Types:
DTS.Common.Interface.Database(IUserDbRecord,IConnectionDetails)DTS.Common.Interface.Channels(IChannelCode,IChannelSettingRecord,IGroupChannelSettingRecord,IChannelDbRecord)DTS.Common.Classes.Channels,DTS.Common.Classes.ChannelCodes,DTS.Common.Classes.Groups.ChannelSettingsDTS.Common.Enums.Channels(ChannelEnumsAndConstants,ChannelCodeType)DTS.Common(Constants,Utility,DFConstantsAndEnums)
Inferred Dependencies
- Database:
- Stored procedures:
sp_ChannelCodesInsert,sp_ChannelCodesUpdate,sp_ChannelCodesDelete,sp_ChannelCodeTypeGet,sp_ChannelCodesGet,sp_ChannelSettingsUpdate,sp_ChannelSettingsGet,sp_GroupChannelSettingsDelete,sp_GroupChannelSettingsInsert,sp_GroupChannelSettingsGet,sp_ChannelsInsert,sp_ChannelsUpdate,sp_ChannelsGet,sp_ChannelsDelete. - User-defined table type:
dbo.StringList(used inGroupChannelSettingsGet).
- Stored procedures:
- Other Modules:
ConnectionManager(forGetSqlCommand)Database.Database(forGetStoredProcedureVersionCached,PrepareForDbAccess)LogManager(for logging)ErrorCodes(for return values)Utility(forGetShort,GetString)DFConstantsAndEnums(forUSER_CHANNEL_NAME_HUMIDITYconstant)
Implemented By
Channels(internal class in same namespace)
5. Gotchas
ChannelsGetfilters out humidity channels: The implementation explicitly skips records whereUserChannelName.EndsWith(DFConstantsAndEnums.USER_CHANNEL_NAME_HUMIDITY). This is hardcoded (comment references case #33192). Consumers cannot override this behavior.GroupChannelSettingsGetuses two different stored procedures: Behavior changes based onclientDbVersionrelative toConstants.BULK_GROUPCHANNELSETTINGS_GET_DB_VERSION. The older version loops over channels and reuses the sameSqlCommand(parameters cleared between iterations), while the newer uses a table-valued parameter. This implies version compatibility must be handled by callers.ChannelsInsertmutates input: Thechannelparameter isref, andchannel.Idis updated with the new database ID on success. Callers must pass a mutable instance.- Nullable DB columns handled inconsistently:
- In
ChannelsInsert,DASId/SensorIdare only added to the command if> 0. - In
ChannelsUpdate,DASIdis only added if> 0, butDASChannelIndexis always added (even if0).
This may cause issues if0is a valid value forDASChannelIndexbut not forDASId.
- In
ChannelSettingsUpdateusesExecuteReader()instead ofExecuteNonQuery(): Despite updating a setting (not returning rows), it callsExecuteReader()and then discards the reader. This is unusual and may be legacy behavior.ChannelCodesInsertlogs to wrong event: Error logs useLogManager.LogEvents.TestSetupsinstead of a channel-specific event. Likely copy-paste error.- No validation on
channelCode.CodeType: Thelookupdictionary is accessed directly (lookup[channelCode.CodeType]) without checking if the key exists. Will throwKeyNotFoundExceptionifchannelCode.CodeTypeis not inlookup.