init
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
---
|
||||
source_files:
|
||||
- DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.TestModification/ViewModel/TestModificationViewModel.cs
|
||||
generated_at: "2026-04-16T11:08:10.828283+00:00"
|
||||
model: "zai-org/GLM-5-FP8"
|
||||
schema_version: 1
|
||||
sha256: "297454e79e1ccbbd"
|
||||
---
|
||||
|
||||
# Documentation: TestModificationViewModel
|
||||
|
||||
## 1. Purpose
|
||||
|
||||
`TestModificationViewModel` is a Prism-based ViewModel responsible for managing test data modifications within the DTS Viewer application. It provides functionality to modify channel properties such as T0 (time zero), sensitivity, line fit, EU multipliers/offsets, filters, and data flags. The module interfaces with the sensor database to retrieve and update calibration records, and coordinates with the broader application via event aggregation for channel selection, T0 shifting, and modification state synchronization.
|
||||
|
||||
---
|
||||
|
||||
## 2. Public Interface
|
||||
|
||||
### Constructor
|
||||
|
||||
```csharp
|
||||
public TestModificationViewModel(
|
||||
ITestModificationView view,
|
||||
IRegionManager regionManager,
|
||||
IEventAggregator eventAggregator,
|
||||
IUnityContainer unityContainer)
|
||||
```
|
||||
Initializes the ViewModel, sets up the View's DataContext, creates interaction requests, and subscribes to `RaiseNotification`, `GraphSelectedChannelsNotification`, `ShiftT0Event`, and `SetUseZeroForUnfilteredEvent` events.
|
||||
|
||||
---
|
||||
|
||||
### Public Methods
|
||||
|
||||
| Method | Signature | Description |
|
||||
|--------|-----------|-------------|
|
||||
| `Initialize` | `void Initialize()` | Override; no-op implementation. |
|
||||
| `Initialize` | `void Initialize(object parameter)` | Override; sets `Parent` property from parameter cast to `IBaseViewModel`. |
|
||||
| `UpdateDatabaseMethod` | `void UpdateDatabaseMethod()` | Updates calibration in the sensor database. Sets `CalibrationId` to -1, updates `ModifyDate` to current time, creates a new `SensorCalibration`, inserts via `DbOperations.SensorCalibrationsInsert`, and refreshes `Model.Cal` with latest calibration. Publishes `PageErrorEvent` on failure. |
|
||||
| `PublishChanges` | `void PublishChanges()` | If `Model.IsModifiedDataFlag` is true, saves data flag modification immediately via `TestModelManipulation.SaveModificationDataFlag`. Publishes `TestModificationChangedEvent` with the Model. |
|
||||
|
||||
---
|
||||
|
||||
### Public Properties
|
||||
|
||||
| Property | Type | Description |
|
||||
|----------|------|-------------|
|
||||
| `View` | `ITestModificationView` | Gets/sets the associated View. |
|
||||
| `Parent` | `IBaseViewModel` | Gets/sets the parent ViewModel. |
|
||||
| `NotificationRequest` | `InteractionRequest<Notification>` | Interaction request for displaying notifications. |
|
||||
| `ConfirmationRequest` | `InteractionRequest<Confirmation>` | Interaction request for displaying confirmations. |
|
||||
| `PreviewCommand` | `DelegateCommand` | Executes `PreviewMethod()` - calls `TestModelManipulation.PreviewLineFit(Model)`. |
|
||||
| `WriteCommand` | `DelegateCommand` | Executes `WriteMethod()` - validates T0, prompts user, calls `TestModelManipulation.SaveModification`. |
|
||||
| `UndoCommand` | `DelegateCommand` | Executes `UndoMethod()` - prompts user, calls `TestModelManipulation.UndoModification`. |
|
||||
| `UndoAllCommand` | `DelegateCommand` | Executes `UndoAllMethod()` - prompts user, calls `TestModelManipulation.UndoAllModification`. |
|
||||
| `UseISOCodeFilterMapping` | `bool` | Controls whether ISOCode field filter matches channel's SoftwareFilter. Default: `false`. |
|
||||
| `Model` | `TestModificationModel` | The model containing test modification state. Setter updates `Parent` reference. |
|
||||
| `UseZeroForUnfiltered` | `bool` | Gets/sets whether to use zero for unfiltered values. |
|
||||
| `IsFilterEnabled` | `bool` | Gets/sets filter enabled state. Raises `OnPropertyChanged`. |
|
||||
| `TestModificationVisability` | `bool` | Controls visibility of test modification UI. Raises `OnPropertyChanged`. |
|
||||
| `HeaderInfo` | `string` | Returns `"TestSummaryRegion"`. |
|
||||
| `IsBusy` | `bool` | Gets/sets busy state. Raises `OnPropertyChanged`. |
|
||||
| `IsDirty` | `bool` | Gets/sets dirty state. |
|
||||
| `IsNavigationIncluded` | `bool` | Gets/sets navigation inclusion state. |
|
||||
| `IsBackedUp` | `bool` | Gets (private sets) whether backup exists. Raises `OnPropertyChanged`. |
|
||||
|
||||
---
|
||||
|
||||
### Events
|
||||
|
||||
| Event | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `PropertyChanged` | `PropertyChangedEventHandler` | Raised when a property value changes. |
|
||||
|
||||
---
|
||||
|
||||
## 3. Invariants
|
||||
|
||||
1. **Single-Channel Selection**: `TestModificationVisability` is `true` only when exactly one channel is selected (`channels.Count == 1 && channels.Count(x => x.IsSelected) == 1`).
|
||||
|
||||
2. **T0 Validation**: T0 cannot be shifted beyond the bounds of the test dataset. `Model.ValidateT0()` must return `true` before write operations proceed.
|
||||
|
||||
3. **Calibration ID Reset**: When updating the database via `UpdateDatabaseMethod()`, `CalibrationId` is always set to `-1` before insertion.
|
||||
|
||||
4. **Analog Sensor Calibration Display**: Calibration records are only loaded/displayed for sensors where `SensorType == 0` (analog sensors).
|
||||
|
||||
5. **Calibration Sorting**: Calibrations are sorted ascending by `CalibrationDate`, then by `ModifyDate` as a tiebreaker. The "latest" calibration is the last element after sorting.
|
||||
|
||||
6. **Permission-Based Controls**: All edit controls (`EnableSensitivityControl`, `EnableLineFitControl`, `EnableDescriptionControl`, `EnableEUMultiplierControl`, `EnableEUOffsetControl`, `EnableFilterControl`, `IsT0Enabled`, `IsDataFlagEnabled`) are gated by `viewModel.DoesUserHaveEditPermission`.
|
||||
|
||||
---
|
||||
|
||||
## 4. Dependencies
|
||||
|
||||
### This Module Depends On:
|
||||
- `DTS.Common.Base` - `BaseViewModel<T>`
|
||||
- `DTS.Common.Events` - Event types (`PageErrorEvent`, `RaiseNotification`, `GraphSelectedChannelsNotification`, `ShiftT0Event`, `SetUseZeroForUnfilteredEvent`, `TestModificationChangedEvent`, `ShowT0CursorEvent`)
|
||||
- `DTS.Common.Interactivity` - `InteractionRequest<T>`, `Notification`, `Confirmation`
|
||||
- `DTS.Common.Interface` - `IBaseViewModel`, `ITestModificationViewModel`, `ITestModificationView`, `IViewerMainViewModel`
|
||||
- `DTS.Common.Interface.Sensors` - `ISensorDbRecord`, `ISensorCalDbRecord`
|
||||
- `DTS.Common.Settings` - `SettingsDB`, `Keys`
|
||||
- `DTS.Common.Storage` - (content not visible, inferred from namespace)
|
||||
- `DTS.Common.Utilities.Logging` - `APILogger`
|
||||
- `DTS.SensorDB` - `DbOperations`, `SensorCalibration`
|
||||
- `DTS.Viewer.ChartOptions.Model` - (content not visible)
|
||||
- `DTS.Viewer.TestModification.Model` - `TestModificationModel`, `TestModelManipulation`
|
||||
- `Prism.Commands` - `DelegateCommand`
|
||||
- `Prism.Events` - `IEventAggregator`
|
||||
- `Prism.Regions` - `IRegionManager`
|
||||
- `Unity` - `IUnityContainer`
|
||||
|
||||
### What Depends On This Module:
|
||||
- Not determinable from source alone. Inferred consumers would be the View (`TestModificationView`) and the main application shell via region navigation.
|
||||
|
||||
---
|
||||
|
||||
## 5. Gotchas
|
||||
|
||||
1. **Typo in Property Name**: `TestModificationVisability` is misspelled (should be "Visibility"). This may cause confusion when referencing the property.
|
||||
|
||||
2. **Malformed XML Comment**: The `GetLatestCalibration` method has a malformed XML comment with `<summary>` used as both opening and closing tag instead of `</summary>`.
|
||||
|
||||
3. **Silent Exception Swallowing**: `GetLatestCalibration` catches all exceptions and returns `null` without logging. The comment explicitly states: *"there's no access to APILogger here, so rather than adding a reference, just eat the error"*.
|
||||
|
||||
4. **Member Hiding with `new` Keyword**: Several members (`OnPropertyChanged`, `PropertyChanged`, `IsBusy`, `IsDirty`, `IsNavigationIncluded`) use the `new` keyword to hide base class members, which can lead to unexpected behavior when casting to base types.
|
||||
|
||||
5. **Yoda Condition Style**: The codebase uses Yoda conditions (`null == sensor` instead of `sensor == null`) consistently throughout.
|
||||
|
||||
6. **Hardcoded Calibration ID**: `cal.CalibrationId = -1` is used as a marker for new calibrations. The significance of `-1` is not documented in code.
|
||||
|
||||
7. **Static `IsPopulating` Property**: `IsPopulating` is a static property used to prevent `PublishChanges` from executing during model population, which could cause issues if multiple instances exist.
|
||||
|
||||
8. **Feature Request Reference**: A comment references an internal case URL: `http://manuscript.dts.local/f/cases/43735/` for the database update feature.
|
||||
Reference in New Issue
Block a user