159 lines
9.2 KiB
Markdown
159 lines
9.2 KiB
Markdown
---
|
||
source_files:
|
||
- DataPRO/Users/UserSettings/OptimizationSettings.cs
|
||
- DataPRO/Users/UserSettings/CategoryAttributeEx.cs
|
||
- DataPRO/Users/UserSettings/DisplayAttributeEx.cs
|
||
- DataPRO/Users/UserSettings/DescriptionAttributeEx.cs
|
||
- DataPRO/Users/UserSettings/PropertyIdAttribute.cs
|
||
- DataPRO/Users/UserSettings/SampleRateConverter.cs
|
||
- DataPRO/Users/UserSettings/UserHistory.cs
|
||
- DataPRO/Users/UserSettings/PropertyEnums.cs
|
||
generated_at: "2026-04-17T15:47:31.625355+00:00"
|
||
model: "zai-org/GLM-5-FP8"
|
||
schema_version: 1
|
||
sha256: "a48b0e1e9bcfddff"
|
||
---
|
||
|
||
# Documentation: User Settings Module
|
||
|
||
## 1. Purpose
|
||
|
||
This module provides a user settings and property management system for the DataPRO application. It enables persistent storage of user-specific configuration in a database, with support for localized display in property grids via custom attributes. The module includes type converters for specialized UI editing (e.g., sample rate selection), an optimization settings system for hardware-specific transfer speed configurations, and comprehensive enumeration of all property categories, orders, and IDs used throughout the application for serialization and localization.
|
||
|
||
---
|
||
|
||
## 2. Public Interface
|
||
|
||
### OptimizationSettings (Users.UserSettings namespace)
|
||
A class for managing hardware optimization settings, deserialized from XML.
|
||
|
||
| Member | Signature | Description |
|
||
|--------|-----------|-------------|
|
||
| `Settings` | `List<Setting>` | Collection of hardware-specific settings. |
|
||
| `OptimizationSettings()` | Constructor | Default constructor. |
|
||
| `OptimizationSettings(string xmlOptimizationSettings)` | Constructor | Deserializes settings from XML string using `XmlToObject<OptimizationSettings>`. |
|
||
|
||
**Nested Class: `Setting`**
|
||
- `HardwareType` (`HardwareTypes`): The hardware type for this setting.
|
||
- `TransferSpeedSampleRateSettings` (`List<TransferSpeedSampleRate>`): Collection of sample rate configurations.
|
||
|
||
**Nested Class: `TransferSpeedSampleRate`**
|
||
- `MaxTransferSpeed` (`float`): Maximum transfer speed threshold.
|
||
- `MinTransferSpeed` (`float`): Minimum transfer speed threshold.
|
||
- `SampleRate` (`double`): The sample rate value.
|
||
|
||
---
|
||
|
||
### CategoryAttributeEx (DTS.Slice.Users.UserSettings namespace)
|
||
Extends `CategoryAttribute` to provide localized category names via `StringResources`.
|
||
|
||
| Member | Signature | Description |
|
||
|--------|-----------|-------------|
|
||
| `CategoryAttributeEx(PropertyEnums.PropertyCategories category)` | Constructor | Creates attribute from category enum. |
|
||
| `GetCategory()` | `PropertyEnums.PropertyCategories` | Returns the stored category enum value. |
|
||
| `GetLocalizedString(string value)` | `override string` | Looks up localized string via `StringResources.ResourceManager.GetString(value)`; returns `"##ResourceNotFound##" + value` if not found. |
|
||
|
||
---
|
||
|
||
### DisplayAttributeEx (DTS.Slice.Users.UserSettings namespace)
|
||
Extends `DisplayNameAttribute` to provide localized display names.
|
||
|
||
| Member | Signature | Description |
|
||
|--------|-----------|-------------|
|
||
| `DisplayAttributeEx(PropertyEnums.PropertyIds propertyId)` | Constructor | Creates attribute from property ID enum. |
|
||
| `DisplayAttributeEx(string propertyId)` | Constructor | Creates attribute from string property ID. |
|
||
| `DisplayName` | `override string` | Returns localized string via `StringResources.ResourceManager.GetString({propertyId}_DisplayName)`; returns `"##DisplayNameNotFound##" + {propertyId}` if not found. |
|
||
|
||
---
|
||
|
||
### DescriptionAttributeEx (DTS.Slice.Users.UserSettings namespace)
|
||
Extends `DescriptionAttribute` to provide localized descriptions.
|
||
|
||
| Member | Signature | Description |
|
||
|--------|-----------|-------------|
|
||
| `DescriptionAttributeEx(PropertyEnums.PropertyIds propertyId)` | Constructor | Creates attribute from property ID enum. |
|
||
| `DescriptionAttributeEx(string propertyId)` | Constructor | Creates attribute from string property ID. |
|
||
| `Description` | `override string` | Returns localized string via `StringResources.ResourceManager.GetString({propertyId}_Description)`; returns `"##DescriptionNotFound##" + {propertyId}` if not found. |
|
||
|
||
---
|
||
|
||
### PropertyIdAttribute (DTS.Slice.Users.UserSettings namespace)
|
||
Custom attribute for associating properties with unique IDs for database serialization.
|
||
|
||
| Member | Signature | Description |
|
||
|--------|-----------|-------------|
|
||
| `PropertyIdAttribute(PropertyEnums.PropertyIds propertyId)` | Constructor | Creates attribute with specified property ID. |
|
||
| `GetPropertyId(PropertyInfo o)` | `static int` | Returns the integer property ID from a `PropertyInfo`; throws `NullReferenceException` if `o` is null or lacks the attribute. |
|
||
| `GetPropertyIdEnum(PropertyInfo o)` | `static PropertyEnums.PropertyIds` | Returns the property ID as enum from a `PropertyInfo`; throws `NullReferenceException` if `o` is null or lacks the attribute. |
|
||
|
||
---
|
||
|
||
### SampleRateConverter (DTS.Slice.Users.UserSettings namespace)
|
||
Type converter for sample rate selection in property grids, providing a dropdown of valid rates from database configuration.
|
||
|
||
| Member | Signature | Description |
|
||
|--------|-----------|-------------|
|
||
| `AvailableSampleRatesDefault` | `static int[]` | Default sample rates array (24 values from 5 to 1,000,000). |
|
||
| `GetStandardValuesSupported(ITypeDescriptorContext context)` | `override bool` | Returns `true`. |
|
||
| `GetStandardValuesExclusive(ITypeDescriptorContext context)` | `override bool` | Returns `true` (only listed values allowed). |
|
||
| `GetStandardValues(ITypeDescriptorContext context)` | `override StandardValuesCollection` | Builds list from `SettingsDB.GetGlobalValueInt` using keys `SPSINDEX_{i}` for count from `SPSINDICE_COUNT`. |
|
||
|
||
---
|
||
|
||
### UserHistory (DTS.Slice.Users.UserSettings namespace)
|
||
User-specific properties persisted to database with property grid display support.
|
||
|
||
| Member | Signature | Description |
|
||
|--------|-----------|-------------|
|
||
| `UsersCurrentTestSetup` | `string` | Current test setup name. Default: `""`. ReadOnly. |
|
||
| `LastRunTestSetup` | `string` | Last executed test setup. Default: `""`. ReadOnly. |
|
||
| `LastUsedSampleRate` | `double` | Last used sample rate. Default: `20000D`. ReadOnly. |
|
||
| `ApplySensorDataToBlankChannels` | `bool` | Whether to apply sensor data to blank channels. Default: `true`. ReadOnly. |
|
||
| `ApplyHardwareAssignmentInHardwareDisco` | `bool` | Hardware assignment behavior. Default: `true`. ReadOnly, Not Browsable. |
|
||
| `ShowOptionsWhenApplyingSensorToBlankChannel` | `bool` | Show options dialog behavior. Default: `true`. ReadOnly. |
|
||
| `CreateAnyMissingUserHistory()` | `static void` | Creates missing property entries in `DefaultProperties` table and calls `TestSetupDefaults.CreateMissingUserSettingProperties`. |
|
||
|
||
---
|
||
|
||
### PropertyEnums (DTS.Slice.Users.UserSettings namespace)
|
||
Abstract class containing enums for property metadata.
|
||
|
||
| Enum | Description |
|
||
|------|-------------|
|
||
| `PropertyCategories` | 14 categories: `TestInfo`, `TestDetails`, `DiagnosticOptions`, `RealtimeOptions`, `ArmChecklist`, `ExportOptions`, `UploadOptions`, `UserHistory`, `ClockSyncOptions`, `UARTOptions`, `EmbeddedSensorSampleRateOptions`, `WakeMethodOptions`, `EmbeddedSensorTriggerOptions`, `TestHistoryOptions`. |
|
||
| `PropertyOrders` | Defines ordering within categories; values named descriptively (e.g., `AutoExpandInfoSections`, `DefaultSampleRate`). |
|
||
| `PropertyIds` | Unique integer IDs for properties (range 102–502). Examples: `DefaultUploadEnabled = 102`, `DefaultTestSampleRate = 103`, `UsersCurrentTestSetup = 401`, `DefaultCANFileType = 502`. |
|
||
|
||
---
|
||
|
||
## 3. Invariants
|
||
|
||
1. **Property ID Uniqueness**: Each value in `PropertyEnums.PropertyIds` must be unique; these serve as database keys.
|
||
2. **Attribute Requirement**: All properties in `UserHistory` must be decorated with `PropertyIdAttribute` for `CreateAnyMissingUserHistory()` to function correctly.
|
||
3. **Localization Key Format**: Display names follow `{PropertyId}_DisplayName` pattern; descriptions follow `{PropertyId}_Description` pattern.
|
||
4. **Database Storage Format**: Per XML doc comment, "data should always be stored in invariant form in the db."
|
||
5. **Sample Rate Validity**: `SampleRateConverter` only includes values where `value > 0` and excludes duplicates.
|
||
6. **Fallback Chain**: Settings fall back: user-specific value → database default → code-specified default (per XML doc comment).
|
||
|
||
---
|
||
|
||
## 4. Dependencies
|
||
|
||
### This Module Depends On:
|
||
- **DTS.Common.Enums.Hardware** - `HardwareTypes` enum used in `OptimizationSettings.Setting`
|
||
- **DTS.Common.Utilities.Xml** - `XmlToObject<T>` for XML deserialization
|
||
- **DTS.Common.Settings** - `SettingsDB.GetGlobalValueInt()` for sample rate configuration
|
||
- **DTS.Common.Storage** - `DbOperations` for database access (connection, commands, parameters)
|
||
- **System.ComponentModel** - Base attributes (`CategoryAttribute`, `DisplayNameAttribute`, `DescriptionAttribute`), `DoubleConverter`, type descriptor infrastructure
|
||
- **System.Data** - `SqlDbType`, `DataSet`, `DataRow` for database operations
|
||
- **System.Reflection** - `PropertyInfo` for attribute retrieval
|
||
|
||
### External Dependencies (Referenced but Not Defined in Source):
|
||
- `StringResources.ResourceManager` - Used for localization lookups
|
||
- `TestSetupDefaults` - `GetDefaultValueAsString()`, `CreateMissingUserSettingProperties()`
|
||
|
||
---
|
||
|
||
## 5. Gotchas
|
||
|
||
1. **Namespace Inconsistency**: Files declare different namespaces (`Users.UserSettings` vs `DTS.Slice.Users.UserSettings`). Several |