Files
DP44/enriched-qwen3-coder-next/DTS Viewer/DTS.Viewer.Reports/DTS.Viewer.PSDReportResults/ViewModel.md
2026-04-17 14:55:32 -04:00

5.6 KiB

source_files, generated_at, model, schema_version, sha256
source_files generated_at model schema_version sha256
DTS Viewer/DTS.Viewer.Reports/DTS.Viewer.PSDReportResults/ViewModel/PSDReportResultsViewModel.cs
2026-04-16T13:39:37.629543+00:00 zai-org/GLM-5-FP8 1 7cb2cb6c499c73c1

Documentation: PSDReportResultsViewModel.cs

1. Purpose

PSDReportResultsViewModel is a Prism-based ViewModel responsible for displaying PSD (Power Spectral Density) report results, specifically GRMS (G-RMS) summary data for channels. It serves as a child view model that receives data via event aggregation from a parent view model, maintains an observable collection of results for UI binding, and provides user-initiated export functionality to PDF and CSV formats.


2. Public Interface

Class: PSDReportResultsViewModel

Inheritance: BaseViewModel<IPSDReportResultsViewModel>
Implements: IPSDReportResultsViewModel

Constructor

public PSDReportResultsViewModel(
    IPSDReportSettingsView view,
    IRegionManager regionManager,
    IEventAggregator eventAggregator,
    IUnityContainer unityContainer)

Initializes the view model, sets the View's DataContext to itself, and creates NotificationRequest and ConfirmationRequest instances.

Properties

Property Type Access Description
View IBaseView get/set The associated view instance.
Parent IBaseViewModel get/set Reference to the parent view model, used to filter event payloads.
Results ObservableCollection<IChannelGRMSSummary> get/set Collection of GRMS summary results bound to the UI.
NotificationRequest InteractionRequest<Notification> get/private set Interaction request for displaying notifications.
ConfirmationRequest InteractionRequest<Confirmation> get/private set Interaction request for displaying confirmations.
ExportToPDFCommand DelegateCommand get Lazily-initialized command that publishes SaveReportToPDFRequestedEvent.
ExportToCSVCommand DelegateCommand get Lazily-initialized command that publishes SaveReportToCSVRequestedEvent.

Methods

public override void Initialize(object parameter)

Sets Parent from the parameter, initializes Results as an empty collection, and subscribes to events.


3. Invariants

  • Parent Filtering: Event handlers OnGRMSValuesUpdated and OnGraphSelectedChannelsChanged will early-return if Parent does not match arg.ParentVM (or arg?.ParentVM). This ensures the view model only processes events intended for its specific parent context.
  • Results Initialization: Results is always initialized as a new empty ObservableCollection<IChannelGRMSSummary> in Initialize() before any events are processed.
  • Lazy Command Initialization: Both ExportToPDFCommand and ExportToCSVCommand are lazily instantiated using the null-coalescing pattern.
  • UIThread Subscription: OnGRMSValuesUpdated is explicitly subscribed with ThreadOption.UIThread, ensuring the handler executes on the UI thread.

4. Dependencies

External Dependencies (Imports)

Namespace Usage
DTS.Common.Base BaseViewModel<T>, IBaseView, IBaseViewModel
DTS.Common.Events PSDReportGRMSValuesUpdatedEvent, PSDReportGRMSValuesUpdatedEventArg, GraphSelectedChannelsNotification, GraphSelectedChannelsNotificationArg, SaveReportToPDFRequestedEvent, SaveReportToPDFRequestedEventArgs, SaveReportToCSVRequestedEvent, SaveReportToCSVRequestedEventArgs
DTS.Common.Interactivity InteractionRequest<T>, Notification, Confirmation
DTS.Common.Interface IPSDReportResultsViewModel, IChannelGRMSSummary, ITestChannel, IPSDReportSettingsView
DTS.Common.Utils ReplaceLast extension method (inferred from usage on string)
Prism.Commands DelegateCommand
Prism.Events IEventAggregator, ThreadOption
Prism.Regions IRegionManager
Unity IUnityContainer

Event Dependencies

  • Subscribes to:
    • PSDReportGRMSValuesUpdatedEvent — populates Results collection
    • GraphSelectedChannelsNotification — sets Directory for export operations
  • Publishes:
    • SaveReportToPDFRequestedEvent — triggered by ExportToPDFCommand
    • SaveReportToCSVRequestedEvent — triggered by ExportToCSVCommand

5. Gotchas

  1. Constructor Parameter Type Mismatch: The constructor accepts IPSDReportSettingsView but assigns it to View which is typed as IBaseView. This implies IPSDReportSettingsView must inherit from IBaseView, but the relationship is not visible in this file.

  2. Member Hiding with new Keyword: Both ConfirmationRequest and _regionManager use the new keyword, hiding base class members with the same names. This could cause unexpected behavior if the base class members are accessed through a base-class reference.

  3. Property Name Shadows System Type: The private property Directory shadows System.IO.Directory. While scoped locally, this could cause confusion during debugging or if using System.IO; is added.

  4. ReplaceLast Extension Method Undefined Here: The call to channels[0].BinaryFilePath.ReplaceLast("Binary", "Reports") depends on an extension method from DTS.Common.Utils. Its behavior (e.g., what happens if "Binary" is not found) is not defined in this source.

  5. No Unsubscribe Logic: The Subscribe() method subscribes to events, but there is no corresponding Unsubscribe() or cleanup in this file. If the view model lifecycle is not managed correctly, this could lead to memory leaks or stale event handlers.