69 lines
5.8 KiB
Markdown
69 lines
5.8 KiB
Markdown
---
|
|
source_files:
|
|
- DTS Viewer/DTS.Viewer.Loader/ViewModel/ShellViewModel.cs
|
|
generated_at: "2026-04-16T14:06:17.211050+00:00"
|
|
model: "zai-org/GLM-5-FP8"
|
|
schema_version: 1
|
|
sha256: "4117e2f039d6caa8"
|
|
---
|
|
|
|
# Documentation: ShellViewModel.cs
|
|
|
|
## 1. Purpose
|
|
The `ShellViewModel` class serves as the main view model (or "Shell") for the `DTS.Viewer.Loader` module. It acts as the primary orchestrator for the application's UI shell, responsible for setting the data context on the associated `IShellView`, managing region navigation via the `IRegionManager`, and handling global application events (specifically notifications) via the `IEventAggregator`. It exposes properties to control UI layout elements like menu and navigation visibility and provides interaction requests for pop-up dialogs.
|
|
|
|
## 2. Public Interface
|
|
|
|
### Constructor
|
|
**`ShellViewModel(IShellView view, IRegionManager regionManager, IEventAggregator eventAggregator, IUnityContainer unityContainer)`**
|
|
Initializes the ViewModel. It sets the `View`'s `DataContext` to itself, initializes `InteractionRequest` objects, and subscribes to the `RaiseNotification` event.
|
|
|
|
### Properties
|
|
* **`View`** (`IShellView`): Gets the associated View instance.
|
|
* **`NotificationRequest`** (`InteractionRequest<Notification>`): Used to trigger notification pop-ups in the UI.
|
|
* **`ConfirmationRequest`** (`InteractionRequest<Confirmation>`): Used to trigger confirmation dialogs in the UI.
|
|
* **`ContextMainRegion`** (`Object`): Gets or sets the content of the `MainRegion` control on the View. Triggers `OnPropertyChanged` when set.
|
|
* **`Width`** / **`Height`** (`double`): Get or set the dimensions of the shell.
|
|
* **`IsMenuIncluded`** (`bool`): Gets or sets a value indicating whether the menu is included. Notifies the view on change.
|
|
* **`IsNavigationIncluded`** (`bool`): Gets or sets a value indicating whether navigation is included. Notifies the view on change.
|
|
* **`HeaderInfo`** (`string`): Returns the hardcoded string "MainRegion".
|
|
* **`IsBusy`** (`bool`): Property intended to track busy state (no logic observed).
|
|
* **`IsDirty`** (`bool`): Read-only property (returns default `false`).
|
|
|
|
### Methods
|
|
* **`void Initialize()`**: Empty implementation.
|
|
* **`void Initialize(object parameter)`**: Empty implementation.
|
|
* **`void Activated()`**: Empty implementation.
|
|
* **`List<FrameworkElement> GetRegions()`**: Returns a list of `FrameworkElement` objects named "Region" found within the `MainShell` of the `ShellView`.
|
|
* **`void Cleanup()`**: Throws `NotImplementedException`.
|
|
* **`Task CleanupAsync()`**: Throws `NotImplementedException`.
|
|
* **`Task InitializeAsync()`**: Throws `NotImplementedException`.
|
|
* **`Task InitializeAsync(object parameter)`**: Throws `NotImplementedException`.
|
|
|
|
## 3. Invariants
|
|
* **View-ViewModel Binding:** Upon construction, the `View.DataContext` is immediately assigned to the `ShellViewModel` instance (`this`).
|
|
* **Event Subscription:** The ViewModel is always subscribed to the `RaiseNotification` event via the `IEventAggregator` upon instantiation.
|
|
* **Concrete View Casting:** The `GetRegions` and `ContextMainRegion` members rely on casting the `IShellView` interface to the concrete `ShellView` class. Therefore, the injected `view` argument must be an instance of (or inherit from) `DTS.Viewer.Loader.ShellView`.
|
|
* **MEF Registration:** The class is exported as `IShellView` with a `Shared` creation policy, meaning the container will manage a singleton instance of this ViewModel.
|
|
|
|
## 4. Dependencies
|
|
|
|
### External Dependencies
|
|
* **Microsoft.Practices.Prism.Events:** Uses `IEventAggregator` for event handling.
|
|
* **Microsoft.Practices.Prism.Interactivity.InteractionRequest:** Uses `InteractionRequest`, `Notification`, and `Confirmation` for UI dialogs.
|
|
* **Microsoft.Practices.Prism.Regions:** Uses `IRegionManager` for region management.
|
|
* **Microsoft.Practices.Unity:** Uses `IUnityContainer` for dependency resolution.
|
|
* **System.ComponentModel.Composition:** Uses MEF attributes (`[Export]`, `[PartCreationPolicy]`).
|
|
|
|
### Internal Dependencies
|
|
* **DTS.Common.Events:** References `RaiseNotification` event and `NotificationContentEventArgs`.
|
|
* **DTS.Common.Interface:** References `IShellView`, `IViewerShellView`, `IViewerShellViewModel`.
|
|
* **DTS.Common.Utils:** References static `Utils.GetChildrenByName` method.
|
|
* **DTS.Viewer.Loader (ShellView):** Explicitly casts the interface to this concrete class to access `MainShell` and `MainRegion`.
|
|
|
|
## 5. Gotchas
|
|
* **NotImplementedExceptions:** The methods `Cleanup`, `CleanupAsync`, `InitializeAsync`, and `InitializeAsync(object parameter)` all throw `NotImplementedException`. Calling these methods will crash the application.
|
|
* **Broken Abstraction:** The code explicitly casts the `IShellView` interface to the concrete `ShellView` class in `GetRegions`, `ContextMainRegion`, and `LoadViewer`. This defeats the purpose of the interface and will cause an `InvalidCastException` if a different implementation of `IShellView` is injected.
|
|
* **Suspicious MEF Export:** The class is exported as `[Export(typeof(IShellView))]`, but the class itself implements `IShellViewModel`. This suggests the ViewModel is being registered as the View interface, which is unconventional and potentially a bug.
|
|
* **Dead Code:** The method `LoadViewer()` is commented out in the constructor but exists in the codebase. It attempts to resolve `IViewerShellView` and `IViewerShellViewModel` and manually set visibility, but it also casts `IViewerShellView` to `ShellView`, which may be incorrect if `IViewerShellView` is a different control.
|
|
* **Manual INPC:** The class manually implements `INotifyPropertyChanged` rather than inheriting from a base class (commented out `BaseViewModel<ShellViewModel>`), yet it imports `Microsoft.Practices.Prism.ViewModel`. This suggests a partial refactoring or inconsistent coding standards. |