Files
DP44/enriched-partialglm/DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.TestSummaryList/ViewModel.md

178 lines
11 KiB
Markdown
Raw Normal View History

2026-04-17 14:55:32 -04:00
---
source_files:
- DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.TestSummaryList/ViewModel/TestSummaryViewModel.cs
- DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.TestSummaryList/ViewModel/TestSummaryViewListModel.cs
generated_at: "2026-04-16T11:16:50.405785+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "b27cef2360f72751"
---
# Documentation: TestSummaryList ViewModels
## 1. Purpose
This module provides two ViewModel implementations (`TestSummaryViewModel` and `TestSummaryViewListModel`) for managing and displaying test summary lists within a modular WPF application built on the Prism framework. These ViewModels serve as intermediaries between test summary data models and views, handling user interactions, data folder/file selection, filtering, sorting, and event-based communication with other application components via `IEventAggregator`. The module appears to support a data viewer scenario where users can browse, filter, and select test summaries from DTS files.
---
## 2. Public Interface
### TestSummaryViewModel
**Constructor:**
```csharp
public TestSummaryViewModel(ITestSummaryListView view, IRegionManager regionManager, IEventAggregator eventAggregator, IUnityContainer unityContainer)
```
Initializes the ViewModel, sets the view's DataContext, creates interaction requests, and subscribes to `RaiseNotification` and `DataFolderChangedEvent` events.
**Methods:**
| Method | Signature | Description |
|--------|-----------|-------------|
| `Initialize` | `void Initialize()` | Empty override. |
| `Initialize` | `void Initialize(object parameter)` | Sets `Parent` property from parameter (cast to `IBaseWindowModel`). |
| `Activated` | `void Activated()` | **Throws `NotImplementedException`.** |
| `Cleanup` | `void Cleanup()` | **Throws `NotImplementedException`.** |
| `CleanupAsync` | `Task CleanupAsync()` | **Throws `NotImplementedException`.** |
| `InitializeAsync` | `Task InitializeAsync()` | **Throws `NotImplementedException`.** |
| `InitializeAsync` | `Task InitializeAsync(object parameter)` | **Throws `NotImplementedException`.** |
| `PublishSelectedTestSummaryList` | `void PublishSelectedTestSummaryList()` | Publishes `TestSummaryChangeNotification` and `TestSelectedChangedEvent` events with current selection. |
**Properties:**
| Property | Type | Description |
|----------|------|-------------|
| `TestSummaryListView` | `ITestSummaryListView` | The associated view instance. |
| `NotificationRequest` | `InteractionRequest<Notification>` | Interaction request for notifications. |
| `ConfirmationRequest` | `InteractionRequest<Confirmation>` | Interaction request for confirmations. |
| `ContextNavigationRegion` | `object` | Gets/sets content of `TestListRegion` on the view. |
| `SelectedTestSummary` | `TestSummary` | Currently selected test summary. |
| `SelectedTestSummaryList` | `List<ITestSummary>` | List of selected test summaries. |
| `TestSummaryList` | `ObservableCollection<ITestSummary>` | Collection of all test summaries. |
| `HeaderInfo` | `string` | Returns `"TestSummaryRegion"`. |
| `IsBusy` | `bool` | Busy indicator state. |
| `IsDirty` | `bool` | Dirty state flag. |
| `IsNavigationIncluded` | `bool` | Navigation inclusion flag. |
---
### TestSummaryViewListModel
**Constructor:**
```csharp
public TestSummaryViewListModel(ITestSummaryListView view, IRegionManager regionManager, IEventAggregator eventAggregator, IUnityContainer unityContainer)
```
Initializes the ViewModel, sets the view's DataContext, creates interaction requests, and stores dependencies.
**Methods:**
| Method | Signature | Description |
|--------|-----------|-------------|
| `Initialize` | `void Initialize()` | Empty override. |
| `Initialize` | `void Initialize(object parameter)` | Sets `Parent`, initializes `FilterView`, attaches collection change handlers, and subscribes to events. |
| `Activated` | `void Activated()` | Publishes `FilterParameterChangedEvent` with empty parameter. |
| `Cleanup` | `void Cleanup()` | Clears all test summary collections, resets `SelectedTestSummary`, and publishes selection change events. |
| `PublishSelectedTestSummaryList` | `void PublishSelectedTestSummaryList()` | Publishes `TestSummaryChangeNotification`, `TestSummaryCountNotification`, and `ResetZoomChangedEvent` events. |
| `OnFilterChanged` | `void OnFilterChanged(FilterParameterArgs args)` | Filters `FilteredTestSummaryList` based on `SetupName`, `Id`, or `Description` containing the parameter string (case-insensitive). |
| `RefreshDataFolder` | `void RefreshDataFolder()` | Publishes `DataFolderChangedEvent` via dispatcher with current selected folder. |
| `SelectDataFolder` | `void SelectDataFolder()` | Opens `OpenFileDialog` for DTS files and publishes `DataFileSelectedEvent` on selection. |
**Properties:**
| Property | Type | Description |
|----------|------|-------------|
| `FilterView` | `IFilterView` | Filter view instance resolved from container. |
| `View` | `ITestSummaryListView` | The associated view instance. |
| `NotificationRequest` | `InteractionRequest<Notification>` | Interaction request for notifications. |
| `ConfirmationRequest` | `InteractionRequest<Confirmation>` | Interaction request for confirmations. |
| `ContextNavigationRegion` | `object` | Gets/sets DataContext of `TestListRegion` on the view. |
| `IsFilterEnabled` | `bool` | Indicates if filtering is enabled (true when `TestSummaryList` has items). |
| `SelectedTestSummary` | `TestSummary` | Currently selected test summary. |
| `SelectedTestSummaryList` | `List<ITestSummary>` | List of selected test summaries. |
| `TestSummaryList` | `ObservableCollection<ITestSummary>` | Collection of all test summaries; setter updates `IsFilterEnabled` and `FilteredTestSummaryList`. |
| `FilteredTestSummaryList` | `ObservableCollection<ITestSummary>` | Filtered view of test summaries. |
| `HeaderInfo` | `string` | Returns `"TestSummaryRegion"`. |
| `IsBusy` | `bool` | Busy indicator state. |
| `IsDirty` | `bool` | Dirty state flag. |
| `IsNavigationIncluded` | `bool` | Navigation inclusion flag. |
| `SelectedDataFolder` | `string` | Selected data folder path; setter publishes `DataFolderChangedEvent`. |
| `SelectedDataFile` | `string` | Selected data file path; setter publishes `DataFolderChangedEvent`. |
| `SortableAttributes` | `List<string>` | List of localized sortable attribute names. |
| `SelectedSortIndex` | `int` | Index of selected sort attribute; setter triggers `SortTestSummaryList()`. |
**Commands:**
| Command | Type | Description |
|---------|------|-------------|
| `RefreshDataFolderCommand` | `DelegateCommand` | Refreshes the current data folder. |
| `SelectDataFolderCommand` | `DelegateCommand` | Opens file dialog to select a DTS file. |
**Nested Types:**
- `SortableAttribute` (enum): `TimeStampDescending`, `Timestamp`, `FileDateDescending`, `FileDate`, `IdDescending`, `Id`, `TestSetupDescending`, `TestSetup`
- `SortableAttributeHelper` (class): Helper for converting `SortableAttribute` to localized string via `StringResources.ResourceManager`.
---
## 3. Invariants
1. **Event Subscription Timing**: Both ViewModels subscribe to events in their constructors. `TestSummaryViewListModel` additionally calls `Subscribe()` during `Initialize(object parameter)`.
2. **Parent Parameter Casting**:
- `TestSummaryViewModel.Initialize(object parameter)` casts to `IBaseWindowModel`
- `TestSummaryViewListModel.Initialize(object parameter)` casts to `IBaseViewModel`
3. **Collection Synchronization**: In `TestSummaryViewListModel`, setting `TestSummaryList` automatically updates `FilteredTestSummaryList` and `IsFilterEnabled`.
4. **Property Change Propagation**: `TestSummaryViewListModel.TestSummaryList_CollectionChanged` attaches/detaches `PropertyChanged` handlers to items implementing `INotifyPropertyChanged`.
5. **Sorting Behavior**: `SortTestSummaryList()` clears and repopulates `FilteredTestSummaryList` in-place based on `SelectedSortIndex`.
6. **Filter Matching**: `OnFilterChanged` performs case-insensitive `Contains` matching on `SetupName`, `Id`, and `Description` fields.
---
## 4. Dependencies
### External Dependencies (from imports):
- **Prism Framework**: `Microsoft.Practices.Prism.Events`, `Microsoft.Practices.Prism.Interactivity.InteractionRequest`, `Microsoft.Practices.Prism.Regions`, `Prism.Events`, `Prism.Regions`, `Prism.Commands`
- **Unity**: `Microsoft.Practices.Unity`, `Unity`
- **System.Windows.Forms**: Used for `OpenFileDialog` in `TestSummaryViewListModel.SelectDataFolder()`
### Internal Dependencies (DTS.* namespaces):
- `DTS.Common.Base` (`BaseViewModel<T>`)
- `DTS.Common.Classes.TestMetadata` (`TestSummary`)
- `DTS.Common.Classes.Viewer.TestMetadata`
- `DTS.Common.Events` (`RaiseNotification`, `DataFolderChangedEvent`, `TestSummaryChangeNotification`, `TestSelectedChangedEvent`, `ShowStatus`, `FilterParameterChangedEvent`, `RefreshTestRequestEvent`, `TestSummaryCountNotification`, `ResetZoomChangedEvent`, `DataFileSelectedEvent`)
- `DTS.Common.Interface` (`IBaseWindowModel`, `IBaseViewModel`, `IFilterView`, `IFilterViewModel`)
- `DTS.Common.Interface.TestDefinition` (`ITestSummary`, `ITestSummaryListViewModel`, `ITestSummaryListView`)
- `DTS.Common.Interactivity`
- `DTS.Viewer.TestSummaryList.Model` (`TestSummaryModel`)
- `DTS.Viewer.TestSummaryList.Resources` (`StringResources`)
### Dependents:
- Views: `TestSummaryView`, `TestSummaryListView` (referenced via casting in `ContextNavigationRegion` properties)
---
## 5. Gotchas
1. **Stale XML Documentation**: The constructor XML comment in `TestSummaryViewModel` states "Creates a new instance of the TechnologyDoFrontEditViewModel" — this appears to be a copy-paste error from another ViewModel.
2. **NotImplementedException Methods**: In `TestSummaryViewModel`, the following methods throw `NotImplementedException`:
- `Activated()`
- `Cleanup()`
- `CleanupAsync()`
- `InitializeAsync()`
- `InitializeAsync(object parameter)`
These indicate incomplete implementation or placeholder code.
3. **Member Hiding with `new` Keyword**: Both ViewModels use `new` to hide inherited members (`PropertyChanged`, `OnPropertyChanged`, `IsBusy`, `IsDirty`, `IsNavigationIncluded`). This can lead to unexpected behavior when casting to base types.
4. **Inconsistent Event Signatures**:
- `TestSummaryViewModel.OnDataFolderChanged(string path)` takes a `string` parameter
- `TestSummaryViewListModel.OnDataFolderChanged(DataFolderSelectionArg arg)` takes a `DataFolderSelectionArg` parameter
Both subscribe to `DataFolderChangedEvent`, suggesting the event payload type changed or the ViewModels are used in different contexts.
5. **WinForms Interop in WPF**: `TestSummaryViewListModel.SelectDataFolder()` uses `System.Windows.Forms.OpenFileDialog` rather than a WPF dialog, requiring WinForms integration.
6. **Internal Field Assignment**: Both ViewModels create `TestSummaryModel` instances and set the private `_eventAggregator` field directly (e.g., `td._eventAggregator = _eventAggregator`), which bypasses encapsulation and suggests tight coupling.
7. **Typo in Property Name**: `TestSummaryViewListModel._selctedSortIndex` (missing 'e' in "selected") — minor but could cause confusion during debugging.