9.6 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |||
|---|---|---|---|---|---|---|---|
|
2026-04-16T03:18:55.361650+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 48681046c7a61e91 |
ChannelSettingRecord, GroupChannelSettingRecord, and ChannelSettingBase Documentation
1. Purpose
This module defines core data structures for representing channel configuration settings within the DTS system. It provides three interrelated classes: ChannelSettingRecord (a lightweight record of a type of channel setting, including its ID, name, and default value), GroupChannelSettingRecord (a specific instance of a setting applied to a particular channel), and ChannelSettingBase (a richer, type-aware implementation of IChannelSetting that supports parsing and type conversion of setting values). Together, they enable storage, retrieval, and manipulation of channel-specific configuration parameters across different channel types (analog, digital, squib, UART, CAN, etc.), forming the data layer for channel configuration management.
2. Public Interface
ChannelSettingRecord
-
ChannelSettingRecord()
Default constructor; initializes an empty record. -
ChannelSettingRecord(IDataReader reader)
Populates the record from anIDataReaderby reading columns"Id","SettingName", and"DefaultValue"usingUtility.GetIntandUtility.GetString. -
int Id { get; set; }
Unique identifier for this setting type (e.g.,"Range"or"SquibCurrent"). -
string SettingName { get; set; }
Human-readable name of the setting (e.g.,"Range"). -
string DefaultValue { get; set; }
Default value string for this setting type (e.g.,"10"for a range setting).
Note: Inherits from
Common.Base.BasePropertyChanged, implyingINotifyPropertyChangedsupport for UI binding.
GroupChannelSettingRecord
-
GroupChannelSettingRecord()
Default constructor; initializes an empty record. -
GroupChannelSettingRecord(IDataReader reader, int storedProcedureVersionUsed)
Populates the record from anIDataReader. IfstoredProcedureVersionUsed >= Constants.BULK_GROUPCHANNELSETTINGS_GET_DB_VERSION, it reads"ChannelId"usingUtility.GetLong; otherwise,ChannelIdis left uninitialized (default0). Always reads"SettingId"(Utility.GetInt) and"SettingValue"(Utility.GetString). -
GroupChannelSettingRecord(long channelId, int settingId, string settingValue)
Constructor for direct initialization with explicit values. -
long ChannelId { get; set; }
Identifier of the channel to which this setting instance applies. -
int SettingId { get; set; }
Identifier of the setting type (corresponds toChannelSettingRecord.Id). -
string SettingValue { get; set; }
Actual value string assigned to this setting for the channel.
Note: Inherits from
BasePropertyChanged, implyingINotifyPropertyChangedsupport.
ChannelSettingBase
-
ChannelSettingBase(int settingType, string name, string defaultValue)
Constructor initializingSettingTypeId,SettingName, andDefaultValue.Valueis initialized tonull. -
ChannelSettingBase(IChannelSetting setting)
Copy constructor; initializes all properties from anotherIChannelSettinginstance. -
IChannelSetting Clone()
Returns a newChannelSettingBaseinstance with all properties copied from the current instance. -
long ChannelId { get; set; }
Channel identifier associated with this setting instance. -
int SettingTypeId { get; protected set; }
Type ID of the setting (e.g., used to group settings by channel type). -
string SettingName { get; protected set; }
Name of the setting (e.g.,"Range","SquibCurrent"). -
string DefaultValue { get; protected set; }
Default value string for this setting type. -
string Value { get; set; }
Current value string for this setting instance. -
double DoubleValue { get; set; }
ParsesValueas adouble(usingInvariantCulture); if parsing fails, returnsDoubleDefaultValue. Setting updatesValue. -
double DoubleDefaultValue { get; }
ParsesDefaultValueas adouble(usingInvariantCulture). -
int IntValue { get; set; }
ParsesValueas anint; if parsing fails, returnsIntDefaultValue. Setting updatesValue. -
int IntDefaultValue { get; }
ParsesDefaultValueas anint. -
bool BoolValue { get; set; }
ParsesValueas abool; if parsing fails, returnsBoolDefaultValue. Setting updatesValue. -
bool BoolDefaultValue { get; }
ParsesDefaultValueas abool. If parsing fails andDefaultValueis null/empty, returnsfalse; otherwise, returns!DefaultValue.Equals(0)(note: this is a string comparison, not numeric).
Note: Implements
IChannelSetting. Constants defined aspublic const stringfor known setting names (see Gotchas for caveats).
3. Invariants
-
ChannelSettingRecordId,SettingName, andDefaultValueare populated from database columns and must be non-null (exceptDefaultValue, which may be empty or null perUtility.GetStringbehavior).Idis expected to be unique per setting type.
-
GroupChannelSettingRecordSettingIdmust correspond to a validChannelSettingRecord.Id(enforced externally, not by this class).ChannelIdmay be uninitialized (0) if constructed viaIDataReaderconstructor withstoredProcedureVersionUsed < Constants.BULK_GROUPCHANNELSETTINGS_GET_DB_VERSION.SettingValuemay be null or empty.
-
ChannelSettingBaseSettingNameandDefaultValueare set only via constructor and remain immutable after construction (due toprotected set).Valueis mutable and may be null/empty.DoubleValue,IntValue, andBoolValuefall back to their respective*DefaultValueproperties ifValueis unparsable.BoolDefaultValuehas non-intuitive behavior: ifDefaultValuecannot be parsed asbool, and is non-empty, it returns!DefaultValue.Equals("0")(string comparison), not numeric evaluation.
4. Dependencies
Dependencies of this module:
DTS.Common.Interface.Channels
Defines interfacesIChannelSettingRecord,IGroupChannelSettingRecord, andIChannelSetting(consumed by these classes).DTS.Common.Base
ProvidesBasePropertyChanged(base class forChannelSettingRecordandGroupChannelSettingRecord).System.Data
Used forIDataReaderin constructors.DTS.Common(internal)Utilityclass (forGetInt,GetString,GetLong).Constants(forBULK_GROUPCHANNELSETTINGS_GET_DB_VERSION).
Dependencies on this module:
- Likely consumed by:
- Data access layers (to populate records from
IDataReader). - Channel configuration services (to manage per-channel settings).
- UI layers (via
INotifyPropertyChangedsupport).
- Data access layers (to populate records from
5. Gotchas
-
BoolDefaultValuelogic is error-prone:
IfDefaultValueis"1"or"true",bool.TryParsesucceeds. But ifDefaultValueis"0",bool.TryParsefails (since"0"is not a validboolstring), andBoolDefaultValuereturns!DefaultValue.Equals("0")→false. This is inconsistent with typicalboolparsing and may cause misinterpretation of"0"asfalseonly whenbool.TryParsefails. Prefer explicit"true"/"false"defaults. -
ChannelSettingBaseconstants are not exhaustive:
Thepublic const stringfields list known setting names (e.g.,"Range","SquibCurrent"), but are not validated against actual usage. New settings may be added without updating these constants, leading to string literals scattered elsewhere in the codebase. -
GroupChannelSettingRecordconstructor behavior depends onstoredProcedureVersionUsed:
IfstoredProcedureVersionUsed < Constants.BULK_GROUPCHANNELSETTINGS_GET_DB_VERSION,ChannelIdis not read from theIDataReader, leaving it at0. This introduces version-dependent data loading logic that may cause silent bugs if versioning is mismanaged. -
ChannelSettingBasedoes not enforceValueformat:
WhileDoubleValue,IntValue, andBoolValueprovide type-safe access,Valueitself is a rawstring. No validation ensuresValuematches the expected format forSettingName. -
Clone()returnsIChannelSetting, notChannelSettingBase:
The copy constructor isprivate, andClone()returns the interface type, limiting extensibility or deep-copy behavior in subclasses. -
No null-safety for
DefaultValuein numeric/bool conversions:
DoubleDefaultValue,IntDefaultValue, andBoolDefaultValuecalldouble.Parse,int.Parse, orbool.TryParseonDefaultValuewithout null checks. IfDefaultValueisnull, this will throwArgumentNullExceptionorFormatException. -
SettingNameisprotected set:
Cannot be modified after construction, butChannelSettingBaseis not sealed—subclasses could theoretically override behavior, though no subclasses are visible in the provided source. -
ChannelSettingRecordandGroupChannelSettingRecordshare naming but serve distinct roles:
ChannelSettingRecorddefines a type of setting (e.g.,"Range"), whileGroupChannelSettingRecorddefines an instance (e.g., channel 123’s"Range"="10"). Confusing these roles is a common source of bugs.
None identified beyond the above.