Files
2026-04-17 14:55:32 -04:00

102 lines
7.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
source_files:
- Common/DTS.Common.Property/ViewModel/PropertyViewModel.cs
generated_at: "2026-04-16T03:28:26.668106+00:00"
model: "Qwen/Qwen3-Coder-Next-FP8"
schema_version: 1
sha256: "07b6bc1210aae7cd"
---
# ViewModel
## Documentation: `PropertyViewModel` Module
---
### 1. **Purpose**
The `PropertyViewModel` class serves as the view model for a property editing UI in the DTS (Data Tracking System) application, implementing Prisms MVVM pattern and integrating with Unity dependency injection and region management. It acts as a bridge between the `IPropertyView` UI layer and underlying domain data (`_properties`), while also exposing Prism `InteractionRequest`s for displaying notifications and confirmations. It inherits from `BaseViewModel<IGraphPropertyViewModel>`, suggesting it participates in a broader graph-based property editing context (e.g., for editing properties of nodes/edges in a graph model), though current implementation is largely skeletal.
---
### 2. **Public Interface**
#### `PropertyViewModel(IPropertyView view, IRegionManager regionManager, IEventAggregator eventAggregator, IUnityContainer unityContainer)`
- **Behavior**: Constructor. Assigns the provided `view`, sets `view.DataContext = this`, initializes `NotificationRequest` and `ConfirmationRequest`, registers `OnRaiseNotification` as a handler for the `RaiseNotification` event via `EventAggregator`, and stores references to infrastructure services.
#### `InteractionRequest<Notification> NotificationRequest { get; }`
- **Behavior**: Prism interaction request used to raise notification popups (e.g., informational messages). Triggered internally via `OnRaiseNotification` when a `RaiseNotification` event is published.
#### `InteractionRequest<Confirmation> ConfirmationRequest { get; }`
- **Behavior**: Prism interaction request used to raise confirmation dialogs (e.g., yes/no prompts). *Currently unused in the provided source*.
#### `IPropertyView View { get; }`
- **Behavior**: Read-only reference to the associated view instance. Set during construction and never modified.
#### `string HeaderInfo { get; }`
- **Behavior**: Returns the static header string `"Graph Property"`.
#### `object Properties { get; set; }`
- **Behavior**: Holds arbitrary property data (likely a domain object or DTO representing editable properties). Raises `PropertyChanged` when set.
#### `override void Initialize(object parameter)`
- **Behavior**: Assigns `Parent` from the cast `parameter` to `IBaseWindowModel`. *Note: Does not call `base.Initialize(parameter)`.*
#### `void Initialize(object parameter, object properties)`
- **Behavior**: Assigns `Parent` and `_properties` from the respective parameters. *Note: Does not raise `PropertyChanged` for `Properties` here — only the property setter does.*
#### `override event PropertyChangedEventHandler PropertyChanged`
- **Behavior**: Overrides base `INotifyPropertyChanged` implementation. *Note: Uses `new` to hide base implementation.*
#### `override void Cleanup()`, `override Task CleanupAsync()`, `override void Activated()`, `override Task InitializeAsync()`, `override Task InitializeAsync(object parameter)`
- **Behavior**: All currently throw `NotImplementedException`. *These lifecycle methods are declared but not implemented.*
#### `override void Initialize()`, `override Task InitializeAsync()`
- **Behavior**: Empty overrides (no-op). *No base call or logic.*
---
### 3. **Invariants**
- `View.DataContext` is always set to `this` (`PropertyViewModel` instance) immediately after construction.
- `NotificationRequest` and `ConfirmationRequest` are initialized once and never reassigned.
- `EventAggregator.GetEvent<RaiseNotification>().Subscribe(OnRaiseNotification)` is called exactly once in the constructor — implying a single subscription for the lifetime of the instance (no unsubscription logic is present).
- `Parent` is assigned only via `Initialize(object parameter)` or `Initialize(object parameter, object properties)` — not in the constructor.
- `Properties` property setter triggers `OnPropertyChanged("Properties")`, ensuring UI binding updates.
---
### 4. **Dependencies**
#### **External Dependencies (via imports):**
- `DTS.Common.Base``BaseViewModel<IGraphPropertyViewModel>`
- `DTS.Common.Events``RaiseNotification`, `NotificationContentEventArgs`
- `DTS.Common.Interface``IPropertyView`, `IBaseWindowModel`, `IGraphPropertyViewModel`
- `Microsoft.Practices.Prism.Events``IEventAggregator`, `EventAggregator`
- `Microsoft.Practices.Prism.Interactivity.InteractionRequest``InteractionRequest<T>`, `Notification`, `Confirmation`
- `Microsoft.Practices.Prism.Regions``IRegionManager`
- `Microsoft.Practices.Unity``IUnityContainer`
#### **Internal Dependencies (inferred):**
- `BaseViewModel<IGraphPropertyViewModel>` — base class providing region/event/container infrastructure.
- `RaiseNotification` event (from `DTS.Common.Events`) — expected to be published elsewhere in the system to trigger notifications via this VM.
- `IBaseWindowModel` — expected to be passed as `parameter` during initialization (likely represents a parent window or graph context).
- `IPropertyView` — must be provided at construction; implies a corresponding view class implementing this interface.
#### **Depended upon by:**
- Likely consumed by Prism region navigation (e.g., via `IRegionManager.RequestNavigate`) given `IRegionManager` usage.
- `IUnityContainer` usage suggests it is registered and resolved via Unity DI.
---
### 5. **Gotchas**
- **Critical Unimplemented Methods**: `Activated()`, `Cleanup()`, `CleanupAsync()`, `InitializeAsync()`, and `InitializeAsync(object)` all throw `NotImplementedException`. This may cause runtime failures if Prisms lifecycle expects these to be called (e.g., during region navigation or view disposal).
- **Missing `IsBusy`/`IsDirty` Implementation**: Properties `IsBusy` and `IsDirty` throw `NotImplementedException` in both getter and setter — likely placeholders.
- **No Unsubscription from `RaiseNotification` Event**: The constructor subscribes to `RaiseNotification` but never unsubscribes. If `PropertyViewModel` instances are long-lived or reused, this could lead to memory leaks or duplicate notifications.
- **`Properties` setter uses `"Properties"` string literal**: Prone to refactoring errors (e.g., renaming field/property without updating string). No `nameof()` usage.
- **`new` keyword usage**: `new event PropertyChangedEventHandler`, `new IRegionManager`, `new bool IsBusy`, `new bool IsDirty` — suggests the base class (`BaseViewModel<...>`) declares members with the same names. This can cause confusion and subtle bugs if consumers expect base behavior.
- **`NotificationRequest.Raise(...)` expects `NotificationContentEventArgsWithoutTitle`**: The comment states the `Notification` object expects a `NotificationContentEventArgsWithoutTitle`, but the code constructs a `NotificationContentEventArgs`. This mismatch may indicate a bug or undocumented type alias/conversion — unclear from source alone.
- **No validation or null checks**: `parameter` is cast directly to `IBaseWindowModel` — will throw `InvalidCastException` if incorrect type is passed.
*None identified from source alone.**Correction*: The above gotchas are apparent from source analysis.