--- source_files: - DataPRO/Modules/SystemSettings/QASettings/ViewModel/QASettingsViewModel.cs generated_at: "2026-04-16T04:41:41.270479+00:00" model: "Qwen/Qwen3-Coder-Next-FP8" schema_version: 1 sha256: "26d85367d0fdc737" --- # ViewModel ## Documentation: QASettingsViewModel --- ### 1. Purpose The `QASettingsViewModel` serves as the view model for the QA Settings module in the application, implementing the `IQASettingsViewModel` interface and adhering to Prism’s MVVM pattern. It acts as the intermediary between the `IQASettingsView` UI and underlying system services (e.g., event aggregation, region management, dependency injection), enabling UI-driven interactions such as displaying notifications, managing busy state, and exposing configuration-related properties (e.g., counts of sensors, test setups). It also subscribes to global events (`RaiseNotification`, `BusyIndicatorChangeNotification`) to synchronize UI state with application-wide events. --- ### 2. Public Interface #### `QASettingsViewModel` (class) - **`IQASettingsView View { get; }`** Reference to the associated view instance; set during construction and used to bind `DataContext`. - **`InteractionRequest NotificationRequest { get; }`** Prism interaction request used to trigger notification popups (e.g., informational messages). Raised via `OnRaiseNotification`. - **`InteractionRequest ConfirmationRequest { get; }`** Prism interaction request used to trigger confirmation dialogs (currently declared but not used in the provided source). - **`bool IsBusy { get; set; }`** Indicates whether the view/model is currently performing a long-running operation. Bound to a busy indicator in the UI. - **`bool IsDirty { get; }`** Property indicating whether changes have been made (currently always `false`; no logic implemented to set it). - **`bool IsMenuIncluded { get; set; }`** Controls visibility of the menu in the view (default `false`). - **`bool IsNavigationIncluded { get; set; }`** Controls visibility of navigation controls in the view (default `false`). - **`string HeaderInfo { get; }`** Returns the literal string `"MainRegion"`; likely used as a header or region identifier. - **`string NumberOfSensorModelsText { get; set; }`** String representation of `_numberOfSensorModels` (formatted with thousand separators); setter parses input to `int`. - **`string NumberOfTestSetupsText { get; set; }`** String representation of `_numberOfTestSetups`. - **`string NumberOfGroupsText { get; set; }`** String representation of `_numberOfGroups`. - **`string NumberOfSensorsText { get; set; }`** String representation of `_numberOfSensors`. - **`string NumberOfGroupTemplatesText { get; set; }`** String representation of `_numberOfGroupTemplates`. - **`DelegateCommand CreateCommand { get; }`** Command bound to a UI action (e.g., a button). Invokes `CreateMethod()` asynchronously (note: `async void`—see *Gotchas*). #### Interface Implementations - **`void Cleanup()` / `Task CleanupAsync()`** No-op stubs; no cleanup logic implemented. - **`void Initialize()` / `void Initialize(object parameter)` / `void Initialize(object parameter, object model)` / `Task InitializeAsync()` / `Task InitializeAsync(object parameter)`** No-op stubs; no initialization logic implemented. - **`void Activated()`** No-op stub; likely part of Prism’s `INavigationAware` or custom lifecycle interface. - **`event PropertyChangedEventHandler PropertyChanged`** Standard `INotifyPropertyChanged` implementation; used for data binding. - **`void OnPropertyChanged(string propertyName)`** Raises `PropertyChanged` event for the given property. - **`bool SetProperty(ref T storage, T value, string propertyName = null)`** Declared but throws `NotImplementedException`; not used. - **`void IBasePropertyChanged.OnPropertyChanged(string propertyName)`** Explicit interface implementation of `IBasePropertyChanged.OnPropertyChanged`, delegating to `OnPropertyChanged`. --- ### 3. Invariants - `View.DataContext` is always set to `this` (the view model instance) during construction. - `_eventAggregator` subscriptions are established in the constructor and persist for the lifetime of the instance. - `IsBusy` is updated synchronously in response to `BusyIndicatorChangeNotification` events. - `NumberOf*Text` properties parse their setters as `int` without validation—invalid input will throw `FormatException`. - `IsDirty` is read-only and never set to `true` in the current implementation. - `NotificationRequest` is raised with a `Notification` object containing a `NotificationContentEventArgs` (with empty strings for unused fields) and the original title. - The class is marked `[PartCreationPolicy(CreationPolicy.Shared)]`, implying a singleton lifetime within the MEF container. --- ### 4. Dependencies #### Imports / Dependencies - **Prism Framework**: - `Prism.Events.IEventAggregator` (for event pub/sub) - `Prism.Regions.IRegionManager` (for region navigation) - `Prism.Commands.DelegateCommand` (for command binding) - `Prism.Interactivity.InteractionRequest` (for popup notifications) - **Unity Container**: `IUnityContainer` (dependency injection) - **Custom Interfaces/Events**: - `IQASettingsView` (view interface) - `DTS.Common.Events.RaiseNotification`, `DTS.Common.Events.BusyIndicatorChangeNotification` (event types) - `DTS.Common.Base.IBasePropertyChanged` (custom interface) - **System Components**: `System.ComponentModel.INotifyPropertyChanged`, `System.Threading.Tasks.Task` #### Exports / Used By - Exported as `IQASettingsView` via `[Export(typeof(IQASettingsView))]`, implying it is consumed by a Prism region or view locator expecting that interface. - Likely consumed by the `QASettingsView` UI (e.g., XAML view bound to this VM). --- ### 5. Gotchas - **`async void` in `CreateMethod()`**: The `CreateMethod()` handler is `async void`, which is generally discouraged (no way to await or handle exceptions properly). This may lead to unobserved exceptions. - **`SetProperty` throws `NotImplementedException`**: The `SetProperty` method (commonly used in MVVM to reduce boilerplate for property setters) is declared but unimplemented. This suggests incomplete refactoring or copy-paste from a base class. - **No validation in property setters**: All `NumberOf*Text` setters use `int.Parse(value)` without error handling. Invalid input (e.g., non-numeric strings) will crash the UI thread. - **Unused `ConfirmationRequest`**: Declared but never raised—likely leftover from design or future use. - **`IsDirty` is always `false`**: No logic tracks changes; this property is effectively dead code. - **`HeaderInfo` is hardcoded**: Returns `"MainRegion"` literally—likely a placeholder or misnamed constant. - **`IBasePropertyChanged` interface**: Custom interface (not `INotifyPropertyChanged`) is implemented explicitly, but its purpose is unclear from this file alone. - **No disposal logic**: `_eventAggregator` subscriptions are not unsubscribed in `Cleanup()`/`CleanupAsync()`—risk of memory leaks if the view model outlives its view.