9.7 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |
|---|---|---|---|---|---|
|
2026-04-16T04:36:54.084304+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | eb93c7718734fde3 |
ViewModel
Documentation: AddEditHardwareViewModel
1. Purpose
This module implements the AddEditHardwareViewModel class, which serves as the view model for the Add/Edit Hardware UI flow. It encapsulates the logic for displaying, editing, and saving hardware configuration data (e.g., DAS units, SLICE6 devices), including validation, state management, and integration with other system modules (e.g., SLICE6 tree view, event aggregation, region navigation). It supports two operational modes: adding new hardware and editing existing hardware, and enforces constraints such as disallowing StandIn hardware in contexts where it is not permitted (e.g., data recorders). It acts as the intermediary between the UI (IAddEditHardwareView) and the underlying domain model (IAddEditHardwareHardware, IISOHardware), coordinating persistence and inter-module communication via Prism events.
2. Public Interface
AddEditHardwareViewModel(IAddEditHardwareView view, IRegionManager regionManager, IEventAggregator eventAggregator, IUnityContainer unityContainer)
- Behavior: Primary constructor. Initializes the view, sets up event subscriptions (
RaiseNotification,BusyIndicatorChangeNotification), and assigns dependencies. Assignsthisas the view’sDataContext.
AddEditHardwareViewModel()
- Behavior: Parameterless constructor required for XAML binding (e.g., design-time or Unity resolution fallback). Does not initialize dependencies.
void SetSLICE6TreeView(ISLICE6TreeView treeView, IHardwareListViewModel treeViewModel)
- Behavior: Injects references to the SLICE6 tree view and its view model. Required for SLICE6-specific operations (e.g., saving associations, reloading tree). May be called after construction.
void Activated()
- Behavior: Called when the view is activated. Enforces that
StandInis disabled ifAllowStandinisfalseand the hardware instance is non-null.
void SetHardware(IDASHardware hw, IISOHardware isoHW)
- Behavior: Initializes or resets the
Hardwareproperty. Ifhwisnull, creates a newModel.Hardwareinstance; otherwise, constructs a newModel.Hardwarefrom the providedhwandisoHW.
IISOHardware GetISOHardware()
- Behavior: Converts the internal
Hardwareto anIISOHardware. IfHardware.StandInistrueandSerialNumberis not a valid GUID, generates a new GUID, updates bothHardware.SerialNumberandisoHW.SerialNumber, setsFirstUseDatetonull,IsFirstUseValidtotrue, andCalDatetoDateTime.Today.
bool Validate(IISOHardware isoHW, ref List<string> errors, ref List<string> warnings, bool displayWindow, bool IsAdd)
- Behavior: Performs validation on
isoHW. Checks:- Serial number validity (
ValidateSerialNumber) - Uniqueness of serial number only if
IsAddistrue(viaModel.Hardware.CheckUniqueSN) - IP address validity (
ValidateIPAddress)
- Serial number validity (
- Appends error/warning messages to
errors/warnings. CallsPublishPageErrorifdisplayWindowistrue. Returnsfalseif any validation fails.
void PublishPageError(bool displayWindow, List<string> errors, List<string> warnings)
- Behavior: If
displayWindowistrueand eithererrorsorwarningsis non-empty, publishes aPageErrorEventwith combined messages.
void SaveSLICE6Associations()
- Behavior: If
Hardware.HardwareTypeisSLICE6DB,SLICE6DB3, orSLICE6DB_InDummy, callsSLICE6TreeViewModel.SaveSLICE6Associations(Hardware.SerialNumber).
void Save()
- Behavior: Persists the current
HardwareviaModel.Hardware.Save(...), passingTestId, andmodel.IsAdd. Then:- Calls
SaveSLICE6Associations() - Publishes a
HardwareSavedEventwith(DASId, SerialNumber) - Calls
SLICE6TreeViewModel.LoadTreeView(SerialNumber)ifSLICE6TreeViewModelis non-null.
- Calls
void NotifyModified()
- Behavior: If
NotificationsOnistrue, publishes aPageModifiedEventwith statusModified.
void Cleanup(), Task CleanupAsync(), void Initialize(), void Initialize(object), void Initialize(object, object), Task InitializeAsync(), Task InitializeAsync(object), void Unset()
- Behavior: No-op stubs. Present to satisfy interface contracts (e.g.,
IInitialize,ICleanup), but contain no logic.
void OnPropertyChanged(string propertyName)
- Behavior: Raises the
PropertyChangedevent for the specified property.
event PropertyChangedEventHandler PropertyChanged
- Behavior: Standard
INotifyPropertyChangedimplementation.
Properties:
-
bool AllowStandin { get; set; } = true
Controls whether StandIn hardware is permitted. Defaults totrue. Set externally (e.g.,falsefor data recorders). -
IAddEditHardwareView View { get; set; }
Reference to the associated view. -
IAddEditHardwareHardware Hardware { get; set; }
The current hardware instance. Setting it triggers property change notifications forHardware,SerialNumber,FirmwareVersion,IPAddress, and callsSLICE6TreeViewModel.LoadTreeView(...). -
int? TestId { get; set; }
Optional test context ID, used during save. -
bool NotificationsOn { get; set; } = false
Enables/disablesPageModifiedEventpublishing. -
bool IsBusy { get; set; }
Bound to busy indicator UI. Set viaOnBusyIndicatorNotification. -
bool IsMenuIncluded { get; set; },bool IsNavigationIncluded { get; set; }
UI layout flags; triggerOnPropertyChangedon change. -
ISLICE6TreeView SLICE6TreeView { get; private set; },IHardwareListViewModel SLICE6TreeViewModel { get; private set; }
References injected viaSetSLICE6TreeView. May benull. -
InteractionRequest<Notification> NotificationRequest { get; },InteractionRequest<Confirmation> ConfirmationRequest { get; }
Prism interaction requests used to show popups (e.g., notifications, confirmations).
3. Invariants
Hardwareis nevernull; defaults tonew Model.Hardware()ifSetHardware(null, ...)is called.Hardware.StandInis forced tofalseduringActivated()ifAllowStandinisfalseandHardwareis non-null.Hardware.SerialNumbermay be overwritten (replaced with a new GUID) inGetISOHardware()ifStandInistrueand the currentSerialNumberis not a valid GUID.Validate(...)only enforces serial number uniqueness (CheckUniqueSN) whenIsAddistrue.IsBusyis updated synchronously on the publisher thread viaOnBusyIndicatorNotification(bool).SLICE6TreeViewModelmay benull; all calls to it are guarded with?..
4. Dependencies
Imports / Dependencies:
- Prism Framework:
IEventAggregator,IRegionManager,Unity,Prism.Events,Prism.Interactivity,Prism.Regions. - Common Libraries:
DTS.Common.Events.*(e.g.,RaiseNotification,PageModifiedEvent,PageErrorEvent,HardwareSavedEvent)DTS.Common.Interface.Hardware.AddEditHardware(IAddEditHardwareView,IAddEditHardwareHardware)DTS.Common.Interface.DataRecorders(IDASHardware,IISOHardware)DTS.Common.Interface.DASFactory.Diagnostics(ISLICE6TreeView)DTS.Common.Interface.DASFactory.Diagnostics.HardwareList(IHardwareListViewModel)DTS.Common.Utilities.Logging(APILogger)DTS.Common.Interactivity(InteractionRequest<...>)DTS.Common.Enums.Hardware.HardwareTypes(used inSaveSLICE6Associations)
- Model Layer:
Model.Hardware(internal namespace, used for persistence, conversion, validation, and uniqueness checks).
Consumed By:
IAddEditHardwareView(XAML view) binds to this view model.- Other modules (e.g.,
HardwareListViewModel) may callSetSLICE6TreeView(...)to wire SLICE6 tree integration. - Event subscribers for
PageModifiedEvent,PageErrorEvent,HardwareSavedEvent.
5. Gotchas
- Dual constructors: The parameterless constructor is required for XAML but leaves dependencies (
_eventAggregator,_regionManager, etc.) uninitialized. Calling methods likeActivated()orSetHardware(...)without prior injection may causeNullReferenceException. GetISOHardware()mutates state: IfStandInistrueandSerialNumberis not a GUID, it modifiesHardware.SerialNumberandisoHW.SerialNumberin-place. This side effect is not obvious from the method name.Validate(...)only checks uniqueness on add:CheckUniqueSNis skipped during edit (IsAdd == false), even if the serial number was changed.SLICE6TreeViewModel.LoadTreeView(...)is called onHardwaresetter: This may trigger expensive tree reloads even whenHardwareis set to the same instance (e.g., via property binding updates).NotificationsOndefaults tofalse:NotifyModified()does nothing unless explicitly enabled. This may lead to missed “page modified” signals if forgotten.OnRaiseNotificationstrips title fromNotificationContentEventArgs: The originaleventArgsWithTitle.Titleis used as the popup title, but the message content is reconstructed with an empty string for the third parameter (likely legacy or for compatibility).- No-op lifecycle methods:
Initialize,Cleanup, etc., are present but empty. Developers may assume they do work; they do not. IsAddis not stored in the view model: It is passed only toValidate(...)andSave(...). If the view model is reused across multiple add/edit operations,IsAddmust be tracked externally (e.g., viaparameterormodel.IsAdd).
None identified beyond the above.