7.7 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||
|---|---|---|---|---|---|---|
|
2026-04-16T02:39:51.595748+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 9a72b7f2cc9cf8aa |
ChannelCodes
Documentation: ChannelCode Module
1. Purpose
This module provides core data and command infrastructure for handling channel codes—named identifiers (e.g., ISO or user-defined codes) used to categorize or label channels in the system. It defines the ChannelCode class as the canonical implementation of IChannelCode, including persistence support via IDataReader, equality semantics, and property change notification. It also defines PasteCommandClass, a ICommand implementation that intercepts text paste operations in UI text boxes, processes clipboard content (including multi-line or delimited data), and publishes structured TextPastedArgs events for downstream handling—while suppressing default paste behavior to enable custom logic.
2. Public Interface
class ChannelCode : BasePropertyChanged, IChannelCode
-
int Id { get; set; }
Unique numeric identifier for the channel code. Initialized to-1by default. -
UIItemStatus ItemStatus { get; set; }
Status of the item (e.g.,None,New,Modified,Deleted). UsesSetPropertyfor change notification. -
string Code { get; protected set; }
The code string (e.g.,"A1","ISO-8601"). Protected setter allows subclassing. -
string Name { get; protected set; }
Human-readable name for the channel code (e.g.,"Temperature Sensor"). -
ChannelEnumsAndConstants.ChannelCodeType CodeType { get; set; }
Enumerated type of the code:UserorISO. Default isISOin parameterless constructor. -
const string PASTE_ID = "ChannelCode"
Static identifier used to correlate paste operations with this channel code type. -
ICommand PasteCommand { get; set; } = null
Command bound to text boxes to handle paste operations. Defaults tonullto avoid exceptions during UI construction. -
ChannelCode(IDataReader reader, IReadOnlyDictionary<short, string> channelTypeLookup)
Constructor that initializes the instance from a database record. ReadsId,Code,Name, andCodeTypeIntcolumns. UseschannelTypeLookupto mapCodeTypeInttoChannelCodeType(UserorISO) via string keys ("User"/"ISO"). -
ChannelCode()
Parameterless constructor. SetsCodeTypetoISO. -
ChannelCode(IChannelCode channelCode)
Copy constructor. CopiesId,Code,Name, andCodeTypefrom anotherIChannelCode. -
override bool Equals(object obj)
Equality comparison based onCode,Name, andCodeType. Returnsfalseifobjis not aChannelCode. -
~ChannelCode()
Finalizer that nulls_codeand_nameto reduce memory footprint if the object is held longer than expected.
class PasteCommandClass : ICommand
-
string Id { get; }
Identifier passed at construction; used to tag paste events. -
bool CanExecute(object parameter)
Always returnstrue. -
void Execute(object parameter)
Handles paste logic:- Requires
parameterto be aTextBox. - Attempts to resolve
IChannelCodefromTextBox.DataContext, with fallbacks toChannelCodeBuilderorChannelNameBuilderview models. - Reads clipboard text.
- If clipboard contains exactly one line and no delimiters (
,,;,\t), publishes aPageModifiedEventand exits early (single-field paste is handled byTextChanged). - Otherwise:
- Resets
CodeandNameproperties (no-op assignment to trigger change notifications). - Publishes a
TextPastedEventwith aTextPastedArgsinstance containing:Text: full clipboard contentSender: resolvedIChannelCodeId:PasteCommandClass.IdTag:TextBox.Tag
- Resets
- Catches and reports exceptions via
PageErrorEvent.
- Requires
-
PasteCommandClass(string id)
Constructor storingidinIdproperty.
delegate string CoerceISOCodeDelegate(...)
string CoerceISOCodeDelegate(string val, bool uniqueISOCodesRequired, bool useISOCodeFilterMapping)
Signature for a delegate used to transform or validate incoming ISO codes. Not implemented in this file—only declared.
3. Invariants
-
ChannelCode.CodeandChannelCode.Namemust be non-null
Initialized tostring.Emptyand never set tonull(viaSetPropertyand constructor defaults). -
ChannelCode.Iddefaults to-1
A value of-1indicates the code has not been persisted or assigned. -
ChannelCode.CodeTypedefaults toISO
Unless explicitly set otherwise (e.g., via constructor withIDataReaderor copy constructor). -
Equality is based on
Code,Name, andCodeType
Idis not part of equality semantics. -
Paste command only processes
TextBoxparameters
Non-TextBoxinputs are silently ignored. -
Clipboard text is split by
Environment.NewLine
Only single-line, non-delimited text bypassesTextPastedEvent; all other cases trigger it.
4. Dependencies
This module depends on:
DTS.Common.Base
ProvidesBasePropertyChanged(base class forChannelCode).DTS.Common.Interface.Channels.ChannelCodes
DefinesIChannelCodeinterface.DTS.Common.Enums
ProvidesUIItemStatus,ChannelEnumsAndConstants(enumChannelCodeType, string constants"User","ISO").DTS.Common.Events
DefinesPageModifiedEvent,TextPastedEvent,PageErrorEvent, and argument types (PageModifiedArg,TextPastedArgs,PageErrorArg).System.Data
ForIDataReader.System.Windows/System.Windows.Controls/System.Windows.Input
ForUIElement,TextBox,ICommand.Microsoft.Practices.Prism.Events
ForIEventAggregator.Microsoft.Practices.ServiceLocation
ForServiceLocator.
This module is depended on by:
- Any UI layer components that bind
ChannelCodeinstances to views (e.g.,ChannelCodeBuilder,ChannelNameBuilder). - Event handlers subscribed to
TextPastedEvent. - Code that constructs
ChannelCodeinstances from database readers or clones them.
5. Gotchas
-
PasteCommanddefaults tonull
To avoid exceptions during UI construction (per inline comment: "putting a null here avoids wasteful exception"). Consumers must explicitly assign aPasteCommandClassinstance. -
ChannelCode.EqualsignoresId
Two codes with different IDs but identicalCode,Name, andCodeTypeare considered equal. This may cause issues if IDs are expected to be unique in comparisons. -
~ChannelCode()finalizer nulls fields but does not prevent GC of the object
This is a cleanup heuristic, not a disposal pattern. NoIDisposableimplementation is present. -
Single-line paste with delimiters still triggers
TextPastedEvent
Only single-line, no-delimiter text skips the event; multi-line or single-line with,,;, or\talways publishTextPastedArgs. -
PasteCommand.Executesilently ignores invalid contexts
Ifparameteris not aTextBox, orDataContextis not anIChannelCode/builder, the method returns without error or logging (except viaPageErrorEventon exception). -
CoerceISOCodeDelegateis declared but not implemented here
Its purpose is documented, but no concrete implementation is provided in this module. -
ChannelCodeconstructor withIDataReaderrelies on column names and lookup dictionary
IfchannelTypeLookuplacks the key fromCodeTypeInt, or columns are missing, behavior is undefined (no explicit validation is present).