--- source_files: - DataPRO/Modules/TestSetups/CachedItemsList/ViewModel/CachedItemsListViewModel.cs generated_at: "2026-04-16T04:52:03.540484+00:00" model: "Qwen/Qwen3-Coder-Next-FP8" schema_version: 1 sha256: "cb6b20481dcc9200" --- # ViewModel ### **Purpose** The `CachedItemsListViewModel` class serves as the ViewModel for the `CachedItemsList` module, responsible for managing and exposing a list of items (sensors, hardware, and calibrations) that may be out of sync between the current test setup and the persistent database. It coordinates UI state (e.g., busy indicators, notifications), integrates with Prism’s event aggregation and region management, and provides a foundation for detecting discrepancies (e.g., missing or modified items). Though the core logic for populating `CachedItems` is currently commented out, the class defines the structure and infrastructure needed to support cache validation and synchronization workflows. --- ### **Public Interface** #### **Constructor** ```csharp public CachedItemsListViewModel( ICachedItemsListView view, IRegionManager regionManager, IEventAggregator eventAggregator, IUnityContainer unityContainer) ``` Initializes the ViewModel, sets the `View` and its `DataContext`, registers event subscriptions for `RaiseNotification` and `BusyIndicatorChangeNotification`, and initializes `InteractionRequest` properties for UI notifications. #### **Properties** - `public ICachedItemsListView View { get; set; }` Reference to the associated view. Set during construction. - `public ICachedItem[] CachedItems { get; set; } = new ICachedItem[0];` Array of cached items representing potential discrepancies. *Currently unpopulated in active code*. - `public bool IsDirty => false;` Always returns `false`; no dirty-state tracking logic is implemented. - `public bool IsBusy { get; set; }` Binds to UI busy indicator. Raises `PropertyChanged` on change. - `public bool IsMenuIncluded { get; set; }` Controls visibility of menu UI elements. Raises `PropertyChanged` on change. - `public bool IsNavigationIncluded { get; set; }` Controls visibility of navigation UI elements. Raises `PropertyChanged` on change. - `public bool HasOutofDateCachedItems => CachedItems.Any();` Indicates if any cached items exist (i.e., potential discrepancies). *Always `false` while `CachedItems` is empty*. - `public bool HasMissingSensors { get; }` Returns `true` if `CachedItems` contains at least one sensor item with `DBTime == DateTime.MinValue`. *Currently always `false`*. #### **Methods** - `public void Unset()` Empty stub; no cleanup logic. - `public void Cleanup()` Empty stub; no cleanup logic. - `public Task CleanupAsync()` Returns `Task.CompletedTask`; no async cleanup. - `public void Initialize()` Empty stub. - `public void Initialize(object parameter)` Empty stub. - `public void Initialize(object parameter, object model)` Empty stub. - `public Task InitializeAsync()` Returns `Task.CompletedTask`. - `public Task InitializeAsync(object parameter)` Returns `Task.CompletedTask`. - `public void Activated()` Empty stub. - `public bool SetCachedItems(ISensorData[] sensors, ISensorCalibration[] sensorCalibrations, IDASHardware[] hardware, IDASHardware[] allDAS)` *Currently returns `false` immediately.* Intended to compare in-memory sensor/hardware/calibration data against database records and populate `CachedItems` with discrepancies. Logic is commented out but includes: - Grouping sensors by type (analog, squib, digital input/output). - Filtering out test-specific digital outputs (via `IsTestSpecificDigitalOutput`). - Detecting out-of-date or missing items by comparing `LastModified`/`CalibrationDate`/`ModifyDate`. - Using `DbOperations` methods (e.g., `SensorsAnalogGet`, `SensorCalibrationsGet`) to fetch DB records. - Returning `true` if any discrepancies were found. #### **Event Handlers (Private)** - `private void OnBusyIndicatorNotification(bool eventArg)` Updates `IsBusy` based on event argument. - `private void OnRaiseNotification(NotificationContentEventArgs eventArgsWithTitle)` Converts `NotificationContentEventArgs` to `Notification` and raises `NotificationRequest`. #### **InteractionRequests** - `public InteractionRequest NotificationRequest { get; }` Used to trigger notification popups. - `public InteractionRequest ConfirmationRequest { get; }` Used to trigger confirmation dialogs. #### **Event** - `public event PropertyChangedEventHandler PropertyChanged;` Implements `INotifyPropertyChanged`. - `public void OnPropertyChanged(string propertyName)` Raises `PropertyChanged` for the specified property. --- ### **Invariants** - `CachedItems` is always a non-null array (default: empty). - `IsBusy` is synchronized with the `BusyIndicatorChangeNotification` event. - `IsTestSpecificDigitalOutput` uses the constant `TEST_SPECIFIC_DIGITAL_OUT = "TSD_"` to exclude test-specific digital outputs from cache validation. - `HasMissingSensors` relies on `DBTime == DateTime.MinValue` and `ObjectType == Resources.StringResources.Sensor` to identify missing sensors. - `CachedItems` is *not* populated in the current implementation (all `Initialize*`/`SetCachedItems` methods are no-ops or stubs). --- ### **Dependencies** #### **Imports/References** - `DTS.Common.Events` (e.g., `RaiseNotification`, `BusyIndicatorChangeNotification`) - `DTS.Common.Interface.TestSetups.CachedItemsList` (e.g., `ICachedItemsListViewModel`, `ICachedItemsListView`, `ICachedItem`) - `DTS.Common.Interface.DataRecorders` (e.g., `IDASHardware`) - `DTS.Common.Interface.Sensors` (e.g., `ISensorData`, `ISensorCalibration`) - `Prism.Events` (`IEventAggregator`) - `Prism.Regions` (`IRegionManager`) - `Unity` (`IUnityContainer`) - `DTS.Common.Interactivity` (`InteractionRequest`) - `System.ComponentModel` (`INotifyPropertyChanged`) #### **External Components Used** - `DbOperations` (referenced in commented code, e.g., `DbOperations.SensorsAnalogGet`) — *not imported directly but assumed to be available at runtime*. - `Resources.StringResources` (e.g., `Resources.StringResources.Sensor`) — *assumed static resource*. #### **Depended Upon By** - `ICachedItemsListView` (view) binds to this ViewModel. - Other modules may publish `RaiseNotification` or `BusyIndicatorChangeNotification` events consumed by this ViewModel. --- ### **Gotchas** - **Critical functionality is commented out**: The `SetCachedItems` method and all initialization logic are non-functional. The class currently does *not* populate `CachedItems` or detect discrepancies. - **`IsDirty` is hardcoded to `false`**: No actual dirty-state tracking is implemented. - **`DbOperations` is not imported**: The commented code references `DbOperations`, but no `using` or `using static` directive for it exists. Its availability at runtime is unverifiable from this file alone. - **`Resources.StringResources` usage is implicit**: No `using` directive for the `Resources` namespace is present; its structure and members (e.g., `Sensor`, `Hardware`, `SensorCal`) are assumed. - **`TEST_SPECIFIC_DIGITAL_OUT` prefix `"TSD_"` is hardcoded**: No configuration or external definition is provided for this value. - **`CachedItems` is a public auto-property**: Direct mutation (e.g., `CachedItems = new ICachedItem[0]`) bypasses `OnPropertyChanged`, but the property is *not* raised when set (only `IsBusy`, `IsMenuIncluded`, `IsNavigationIncluded` raise `PropertyChanged`). This may cause UI binding issues if `CachedItems` is reassigned. - **No disposal logic**: `Unset`, `Cleanup`, and `CleanupAsync` are empty; event subscriptions (e.g., `_eventAggregator`) are not unsubscribed, risking memory leaks. - **`IsTestSpecificDigitalOutput` is static but uses instance constant**: The method is `static`, but `TEST_SPECIFIC_DIGITAL_OUT` is an instance field—though valid in C#, this is unusual and could be confusing.