6.7 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |
|---|---|---|---|---|---|
|
2026-04-16T04:35:38.785908+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 0ee538e93daa667b |
View
Documentation: AddEditHardwareView (WPF View for Hardware Configuration)
1. Purpose
The AddEditHardwareView class is the WPF UI view layer for configuring and editing hardware devices in the system. It implements the IAddEditHardwareView interface and INotifyPropertyChanged to support data binding, and is responsible for rendering hardware type selection, module management (add/remove), and dynamic UI updates based on database version and view model state. It acts as the presentation layer for the AddEditHardwareViewModel, coordinating user interactions (e.g., button clicks, selection changes, text input) with the underlying data model via event handlers and property synchronization.
2. Public Interface
Properties
-
public bool AllowStandin { get; }
Determines whether the SLICE6TreeView UI element should be visible. ReturnstrueifDataContextis null or not anIAddEditHardwareViewModel; otherwise, delegates tovm.AllowStandin. -
public int ViewDbVersion { get; set; }
Gets or sets the database version used to filter available hardware types. Setting this clears the cached hardware type list (_allDASTypes) and refreshes thecbHardwareTypes.ItemsSource.
Methods
public void Activated()
Called when the view is activated. Triggers a property change notification forAllowStandin, and ifvm.SLICE6TreeViewis non-null, assigns it toSLICE6TreeView.Content.
Event Handlers (Private, but part of public behavior via XAML wiring)
-
private void btnRemoveModule_Click(object sender, RoutedEventArgs e)
Removes the module associated with the clicked button’sDataContextfrom its owning hardware, then notifies the view model of modification. -
private void btnAdd_Click(object sender, RoutedEventArgs e)
Adds a new module to the hardware associated with the clicked button’sDataContext, then notifies the view model of modification. -
private void cb_SelectionChanged(object sender, SelectionChangedEventArgs e),
private void cb_Checked(object sender, RoutedEventArgs e),
private void cb_Unchecked(object sender, RoutedEventArgs e),
private void tb_TextChanged(object sender, TextChangedEventArgs e)
All invokevm.NotifyModified()to signal that the underlying data has changed.
Protected/Helper Methods (Not public API, but part of implementation)
-
protected bool SetProperty<T>(ref T storage, T value, string propertyName = null)
ImplementsINotifyPropertyChangedsemantics: updatesstorageonly if value differs, raisesPropertyChanged, and returnstrueif changed. -
protected void OnPropertyChanged(string propertyName = null)
Raises thePropertyChangedevent.
3. Invariants
-
Thread Safety for Hardware Type Caching:
_allDASTypesis populated and cleared under alockon the static list.AvailableDASType()andPopulateDASTypes()use this lock to ensure thread-safe initialization and version-based filtering. -
Database Version Dependency:
The list of available hardware types (_allDASTypes) is dynamically filtered based onViewDbVersion. Specific hardware types (e.g.,SLICE6_AIR_BR,SLICE6_AIR_TC,SLICE_PRO_CAN_FD) are only included ifConnectionDbVersionmeets or exceeds their respective version constants (Constants.SLICE6AIR_BR_DB_VERSION, etc.). -
View Model Contract:
The view assumesDataContextis anIAddEditHardwareViewModel(orAddEditHardwareViewModelin handlers). If not, operations silently exit (e.g.,vm.NotifyModified()is not called). -
Module Ownership:
Module removal (btnRemoveModule_Click) requires theDataContextof the clicked control to be anIAddEditHardwareDASModulewith a validOwningHardwarereference.
4. Dependencies
Imports / Dependencies Used
DTS.Common: Core types, includingConstants,DbOperations,EnumDescriptionTypeConverter.DTS.Common.Converters:EnumDescriptionTypeConverterused for sorting hardware types by description.DTS.Common.Enums.Hardware:HardwareTypes,SLICEPROSIMConfigurations,SLICETCConfigurations,RackSizes.DTS.Common.Interface.Hardware.AddEditHardware:IAddEditHardwareView,IAddEditHardwareViewModel,IAddEditHardwareDASModule,IAddEditHardwareHardware.- WPF Framework:
System.Windows,System.Windows.Controls,System.ComponentModel.
Assumed Dependencies
AddEditHardwareViewModel: Concrete implementation ofIAddEditHardwareViewModel, used in handlers (e.g.,vm.NotifyModified()).- XAML file
AddEditHardwareView.xaml: Defines UI controls likecbHardwareTypes,cbSliceProSimConfigurations,SLICE6TreeView, etc., which are referenced in code-behind. Constantsclass: Must defineSLICE6AIR_BR_DB_VERSION,SLICE_TC_DB_VERSION,SLICE_PRO_CAN_FD_DB_VERSION, andMINIMUM_LTS_DB_VERSION.
5. Gotchas
-
Static State Mutation on Version Change:
SettingViewDbVersionclears_allDASTypesglobally, affecting all instances ofAddEditHardwareViewin the app domain. This is a shared static cache—changing version for one view resets hardware type availability for others. -
Silent Failures on Invalid Contexts:
Event handlers (btnRemoveModule_Click,btnAdd_Click,cb_*,tb_TextChanged) exit early ifDataContextis not the expected type or ifctrlView.DataContextis notAddEditHardwareViewModel. No error is logged or thrown—behavior is silently skipped. -
AllowStandinLogic is Inverted in Edge Cases:
Returnstrue(i.e., show the tree view) whenDataContextis null or not anIAddEditHardwareViewModel. This may be counterintuitive—typically, missing view model would imply hiding UI elements. -
Hardware Type Sorting Relies on Enum Descriptions:
_allDASTypes.Sort()usesEnumDescriptionTypeConverter.GetEnumDescription()for ordering. If descriptions are missing, empty, or non-unique, sorting may be inconsistent or throw. -
No Validation on
ViewDbVersion:
ViewDbVersionaccepts anyint. If set to a value belowMINIMUM_LTS_DB_VERSION, behavior is undefined (though_allDASTypesis cleared and repopulated using the provided version). -
Hardcoded Configuration Arrays:
_availableSliceProSimConfigurations,_availableSliceTCConfigurations, and_availableRackSizesare static and unversioned—no dynamic filtering based on database version is applied to these.
None identified beyond the above.