116 lines
7.6 KiB
Markdown
116 lines
7.6 KiB
Markdown
---
|
||
source_files:
|
||
- DataPRO/Modules/SystemSettings/ISOSettings/ViewModel/ISOSettingsViewModel.cs
|
||
generated_at: "2026-04-16T04:41:44.940794+00:00"
|
||
model: "Qwen/Qwen3-Coder-Next-FP8"
|
||
schema_version: 1
|
||
sha256: "3315a3b012311a0d"
|
||
---
|
||
|
||
# ViewModel
|
||
|
||
## Documentation: `ISOSettingsViewModel`
|
||
|
||
---
|
||
|
||
### **1. Purpose**
|
||
|
||
The `ISOSettingsViewModel` class serves as the MVVM-compliant view model for the ISO Settings module within the application. It acts as the intermediary between the `IISOSettingsView` (UI) and the `IISOSettingsModel` (data layer), managing UI state (e.g., busy status, dirty state, menu/navigation inclusion flags), handling user interactions via Prism’s `InteractionRequest` pattern, and coordinating data loading and saving. It subscribes to global events (e.g., `RaiseNotification`, `BusyIndicatorChangeNotification`) to decouple cross-module communication and integrates with Prism’s region management and Unity DI container for modular composition.
|
||
|
||
---
|
||
|
||
### **2. Public Interface**
|
||
|
||
#### **Constructor**
|
||
```csharp
|
||
public ISOSettingsViewModel(IISOSettingsView view, IRegionManager regionManager, IEventAggregator eventAggregator, IUnityContainer unityContainer)
|
||
```
|
||
- Initializes the view model, sets up event subscriptions, instantiates `ISOSettingsModel`, loads initial data via `Model.LoadData()`, and assigns it to `ISOData`. Also sets `View.DataContext = ISOData`.
|
||
|
||
#### **Properties**
|
||
| Property | Type | Description |
|
||
|---------|------|-------------|
|
||
| `View` | `IISOSettingsView` | Reference to the associated view. Set externally (e.g., via Prism navigation). |
|
||
| `Model` | `IISOSettingsModel` | Reference to the data model used for loading/saving ISO settings. Initialized in constructor. |
|
||
| `ISOData` | `IISOSettingsData` | The current ISO settings data model. Raises `PropertyChanged` on change. |
|
||
| `IsBusy` | `bool` | Indicates whether a long-running operation is in progress. Bound to UI busy indicator. |
|
||
| `IsDirty` | `bool` | *Declared but never set* — no logic updates this property (see *Gotchas*). |
|
||
| `IsMenuIncluded` | `bool` | UI state flag indicating whether the menu section is included in the view. |
|
||
| `IsNavigationIncluded` | `bool` | UI state flag indicating whether the navigation section is included in the view. |
|
||
| `HeaderInfo` | `string` | Returns `"MainRegion"` — likely used for region naming or header labeling. |
|
||
|
||
#### **InteractionRequests**
|
||
| Property | Type | Description |
|
||
|---------|------|-------------|
|
||
| `NotificationRequest` | `InteractionRequest<Notification>` | Triggers display of notification popups (e.g., alerts). |
|
||
| `ConfirmationRequest` | `InteractionRequest<Confirmation>` | Triggers confirmation dialogs (e.g., "Are you sure?"). |
|
||
|
||
#### **Methods**
|
||
| Method | Signature | Description |
|
||
|--------|-----------|-------------|
|
||
| `SaveData` | `public void SaveData()` | Delegates saving of `ISOData` to `Model.SaveData(ISOData)`. |
|
||
| `Cleanup` | `public void Cleanup()` | No-op stub. |
|
||
| `CleanupAsync` | `public Task CleanupAsync()` | Returns `Task.CompletedTask`. |
|
||
| `Initialize` | `public void Initialize()` / `Initialize(object)` / `Initialize(object, object)` | All no-op stubs. |
|
||
| `InitializeAsync` | `public Task InitializeAsync()` / `InitializeAsync(object)` | All return `Task.CompletedTask`. |
|
||
| `Activated` | `public void Activated()` | No-op stub. |
|
||
|
||
#### **Event Handling**
|
||
| Method | Signature | Description |
|
||
|--------|-----------|-------------|
|
||
| `OnBusyIndicatorNotification` | `private void OnBusyIndicatorNotification(bool eventArg)` | Sets `IsBusy = eventArg`. |
|
||
| `OnRaiseNotification` | `private void OnRaiseNotification(NotificationContentEventArgs eventArgsWithTitle)` | Converts `NotificationContentEventArgs` to `Notification` and raises `NotificationRequest`. |
|
||
| `OnPropertyChanged` | `public void OnPropertyChanged(string propertyName)` | Raises `PropertyChanged` event for the specified property. |
|
||
|
||
#### **Interface Implementation**
|
||
- Implements `INotifyPropertyChanged` (via `PropertyChanged` event and `OnPropertyChanged`).
|
||
- Exports as `[Export(typeof(IISOSettingsView))]` — *note: this is likely a misnomer; should be `IISOSettingsViewModel`* (see *Gotchas*).
|
||
|
||
---
|
||
|
||
### **3. Invariants**
|
||
|
||
- `ISOData` must be non-null after construction (initialized via `Model.LoadData()`).
|
||
- `View.DataContext` is always set to `ISOData` in the constructor.
|
||
- `IsBusy` is updated exclusively via `OnBusyIndicatorNotification(bool)`, triggered by `BusyIndicatorChangeNotification` events.
|
||
- `NotificationRequest` is raised only via `OnRaiseNotification(NotificationContentEventArgs)`, which wraps the event args in a `Notification` object with `Content` and `Title`.
|
||
- `Model` is instantiated once in the constructor and never reassigned.
|
||
- `IsMenuIncluded` and `IsNavigationIncluded` are boolean flags with no validation logic — their values are arbitrary until set by external code (e.g., view or user interaction).
|
||
|
||
---
|
||
|
||
### **4. Dependencies**
|
||
|
||
#### **Imports / Dependencies**
|
||
- **Prism Framework**: `IEventAggregator`, `IRegionManager`, `InteractionRequest<T>`, `Notification`, `Confirmation`.
|
||
- **Unity DI Container**: `IUnityContainer`.
|
||
- **Custom Interfaces**:
|
||
- `IISOSettingsView` (view interface)
|
||
- `IISOSettingsModel` (data model interface)
|
||
- `IISOSettingsData` (data contract for ISO settings)
|
||
- **Custom Events**:
|
||
- `RaiseNotification` (event type, likely from `DTS.Common.Events`)
|
||
- `BusyIndicatorChangeNotification` (event type, likely from `DTS.Common.Events`)
|
||
- **Namespaces**:
|
||
- `DTS.Common.Events`, `DTS.Common.Interactivity`, `DTS.Common.Interface`
|
||
- `ISOSettings.Model`
|
||
|
||
#### **Depended Upon**
|
||
- The module exports `ISOSettingsViewModel` as `IISOSettingsView` — suggesting it is consumed by Prism’s region navigation system as a view (though the export type is likely incorrect).
|
||
- Other modules may publish `RaiseNotification` or `BusyIndicatorChangeNotification` events to trigger UI feedback.
|
||
|
||
---
|
||
|
||
### **5. Gotchas**
|
||
|
||
- **Export Type Mismatch**: The class is decorated with `[Export(typeof(IISOSettingsView))]`, but it implements `IISOSettingsViewModel`. This is likely a bug — the export should be `typeof(IISOSettingsViewModel)` to align with Prism conventions and avoid runtime resolution errors.
|
||
- **`IsDirty` is Unused**: The `IsDirty` property is declared but never updated. No logic sets it to `true` (e.g., on data change), so it will always remain `false`.
|
||
- **No Validation on Save**: `SaveData()` directly passes `ISOData` to `Model.SaveData()` without validation or error handling in the view model.
|
||
- **Event Handler Logic is Fragile**: `OnRaiseNotification` constructs a new `NotificationContentEventArgs("", "", ...)` with empty strings for `Title2` and `Image2`, but the comment implies the `Notification` object expects a `NotificationContentEventArgsWithoutTitle` — this suggests a mismatch between the event args type and the expected payload, risking runtime issues if `NotificationContentEventArgs` is not compatible.
|
||
- **No Cleanup Logic**: `Cleanup()` and `CleanupAsync()` are empty. If `ISOSettingsViewModel` subscribes to long-lived events (e.g., `RaiseNotification`), it should unsubscribe in `Cleanup()` to prevent memory leaks — though Prism’s `EventAggregator` uses weak references by default, so this may be mitigated.
|
||
- **`Activated()` is a No-op**: The `IRegionMemberLifetime` or Prism lifecycle hooks (`Activated`, `Deactivated`) are not utilized beyond stubs.
|
||
- **Thread Safety**: `OnBusyIndicatorNotification` uses `ThreadOption.PublisherThread`, but no other thread-safety guarantees are documented for `IsBusy` or `ISOData` access.
|
||
|
||
---
|
||
|
||
*Documentation generated from source file `DataPRO/Modules/SystemSettings/ISOSettings/ViewModel/ISOSettingsViewModel.cs`.* |