9.1 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||
|---|---|---|---|---|---|---|
|
2026-04-16T03:15:37.036883+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 936720bfac8d31e1 |
ChannelCodes
Documentation: ChannelCode Module
1. Purpose
This module provides core data structures and command logic for handling channel codes in the DTS system. It defines the ChannelCode class (a concrete implementation of IChannelCode) that represents a channel with an identifier, code string, name, type (User/ISO), and status, and includes constructors for instantiation from database readers or other channel codes. It also defines TextPastedArgs, a data carrier for paste events, and PasteCommandClass, a ICommand implementation that intercepts text paste operations on UI text boxes, processes clipboard content, and publishes structured events (TextPastedEvent) when multi-field or structured paste occurs—while allowing simple single-field pastes to be handled by standard text change logic. The module supports UI binding, event-driven architecture (via Prism’s IEventAggregator), and ISO code coercion via a delegate.
2. Public Interface
TextPastedArgs class
TextPastedArgs(string text, IChannelCode channelCode, string id, object tag)
Constructor. Initializes a new instance with the pastedtext, thechannelCode(used asSender), a uniqueid(e.g.,"ChannelCode"), and an arbitrarytag(typically from the UI element).string Text { get; }
The raw text content that was pasted (from clipboard).object Sender { get; }
TheIChannelCodeinstance associated with the paste operation (set from thechannelCodeparameter).string Id { get; }
A string identifier for the paste operation (e.g.,"ChannelCode").object Tag { get; }
TheTagproperty of the UI element (e.g.,TextBox) where the paste occurred.
ChannelCode class
ChannelCode(IDataReader reader, IReadOnlyDictionary<short, string> channelTypeLookup)
Constructor. Populates the instance from anIDataReaderby reading"Id","Code","CodeTypeInt", and"Name"fields. UseschannelTypeLookupto mapCodeTypeInttoChannelCodeType.Useror.ISO.ChannelCode()
Default constructor. InitializesCodeTypetoChannelCodeType.ISO.ChannelCode(IChannelCode channelCode)
Copy constructor. CopiesId,Code,Name, andCodeTypefrom anotherIChannelCode.int Id { get; set; }
The numeric identifier of the channel code. Initialized to-1by default.UIItemStatus ItemStatus { get; set; }
Status of the item (e.g., Added, Modified, Deleted). Initialized toUIItemStatus.None.string Code { get; set; }
The code string (e.g.,"A1"). Protected backing field_code.string Name { get; set; }
The human-readable name. Protected backing field_name.ChannelCodeType CodeType { get; set; }
Enumerated type of the code (UserorISO).const string PASTE_ID = "ChannelCode"
A constant identifier used for paste operations (note:PasteCommandClassuses its ownIdparameter, not this constant).ICommand PasteCommand { get; set; } = null
Command bound to paste operations (e.g., Ctrl+V). Defaults tonullto avoid exceptions during UI construction.override bool Equals(object obj)
Compares twoChannelCodeinstances for equality based onCode,Name, andCodeType(case-sensitive string equality). Returnsfalseifobjis not aChannelCode.~ChannelCode()
Finalizer. Clears_codeand_nametonullto reduce memory footprint if the object is held longer than expected before cleanup.
PasteCommandClass class
PasteCommandClass(string id)
Constructor. Stores theidin theIdproperty.string Id { get; }
Identifier for this paste command instance (e.g.,"ChannelCode"or a unique control ID).bool CanExecute(object parameter)
Always returnstrue.void Execute(object parameter)
Executes the paste logic:- Validates
parameteris aTextBox. - Resolves
IChannelCodefromTextBox.DataContext, supportingChannelCodeBuilderandChannelNameBuilderwrappers. - Reads clipboard text.
- If clipboard text is a single line without delimiters (
,,;,\t), publishesPageModifiedEventand returns early (no structured paste). - Otherwise, clears
CodeandName(via self-assignment to trigger property change), then publishesTextPastedEventwith aTextPastedArgsinstance containing the clipboard text, channel code,Id, andTextBox.Tag. - Catches exceptions and publishes
PageErrorEventwith the error message.
- Validates
event EventHandler CanExecuteChanged
Required byICommand; not raised by this implementation.
CoerceISOCodeDelegate delegate
string CoerceISOCodeDelegate(string val, bool uniqueISOCodesRequired, bool useISOCodeFilterMapping)
A delegate for custom logic to transform or validate an incoming ISO code string (val) before assignment, based on system constraints (uniqueISOCodesRequired,useISOCodeFilterMapping). Used to enforce ISO code uniqueness or apply filtering rules.
3. Invariants
ChannelCode.CodeandChannelCode.Namemust be non-null strings (though they may be empty). TheCodeandNameproperties useSetProperty, implying change notifications are raised on assignment.ChannelCode.Iddefaults to-1and is only valid when set to a non-negative integer (typically from database).ChannelCode.CodeTypedefaults toChannelCodeType.ISOwhen constructed via the parameterless constructor.TextPastedArgs.Textis the raw clipboard content at the time of paste, including any embedded delimiters.TextPastedArgs.Senderis always the resolvedIChannelCodeinstance (ornullif resolution fails—though thePasteCommandClass.Executemethod returns early if resolution fails, soSendershould never benullin published events).PasteCommandClass.CanExecutealways returnstrue, meaning paste is always enabled in the UI.- Single-line, non-delimited paste bypasses
TextPastedEventand only triggersPageModifiedEvent.
4. Dependencies
-
Depends on:
DTS.Common.Events(forPageModifiedEvent,TextPastedEvent,PageErrorEvent,PageModifiedArg,TextPastedArgs,PageErrorArg).DTS.Common.Interface.Channels.ChannelCodes(forIChannelCodeinterface).Prism.Events(forIEventAggregator).Prism.Ioc(forContainerLocator.Container).DTS.Common.Base(forBasePropertyChanged, enablingINotifyPropertyChanged).DTS.Common.Controls,DTS.Common.Enums,DTS.Common.Enums.Channels(forUIItemStatus,ChannelEnumsAndConstants,ChannelCodeType).System.Data(IDataReader),System.Windows(TextBox,ICommand),System.Windows.Controls.DTS.Common.Utility(forUtility.GetInt,Utility.GetString,Utility.GetShort).
-
Depended on by:
- UI components (e.g.,
TextBoxcontrols) that bindPasteCommandtoPasteCommandClass. - Event handlers for
TextPastedEvent(to process structured paste). ChannelCodeBuilderandChannelNameBuilder(implied byPasteCommandClass.Executechecking for theirDataContext).
- UI components (e.g.,
5. Gotchas
PASTE_IDconstant is unused inPasteCommandClass: ThePasteCommandClassuses its ownIdparameter (passed to its constructor) instead of theChannelCode.PASTE_IDconstant. This may cause confusion if expecting consistency.- Self-assignment of
Code/NameinExecute: The lineschannelCode.Code = channelCode.Code;are used to trigger property change notifications without modifying the value. This is a workaround to force UI updates before publishingTextPastedEvent. PasteCommanddefaults tonull: To avoid exceptions during UI construction (per comment),PasteCommandis not initialized. UI must explicitly assign aPasteCommandClassinstance.EqualsignoresId: TwoChannelCodeinstances with differentIdbut identicalCode,Name, andCodeTypeare considered equal. This may be intentional for business logic (e.g., comparing definitions) but could cause issues ifIdis expected to be unique.CanExecuteChangedis never raised:PasteCommandClassimplementsICommandbut does not raiseCanExecuteChanged. UI frameworks relying on this event (e.g., WPF) may not update command availability dynamically.- Clipboard access is synchronous:
Clipboard.GetText()is called directly inExecute, which may block the UI thread or throw if clipboard access is denied. Error handling only captures exceptions and publishesPageErrorEvent. TextPastedArgs.Senderis typed asobject: Though it is always anIChannelCode, the interface usesobjectinstead ofIChannelCode, requiring casting by consumers.