11 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
2026-04-16T04:03:26.586662+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 1eb9bffd7fe29c43 |
Documentation: User Settings Module
1. Purpose
This module provides infrastructure for managing user-specific settings in the DataPRO system, including persistence to a database, localization via string resources, and UI integration for property grids. It defines core data structures (OptimizationSettings, UserHistory), attribute classes for metadata annotation (CategoryAttributeEx, DisplayAttributeEx, DescriptionAttributeEx, PropertyIdAttribute), and supporting utilities (SampleRateConverter). The module enables centralized storage and retrieval of user preferences (e.g., last used sample rate, export options, hardware assignments) with fallback to defaults defined in code or the database, while supporting localized display names and descriptions for UI rendering.
2. Public Interface
OptimizationSettings class (Users.UserSettings namespace)
-
OptimizationSettings()
Default constructor; initializes an emptySettingslist. -
OptimizationSettings(string xmlOptimizationSettings)
Constructor that deserializes XML-formatted optimization settings into theSettingslist usingXmlToObject<OptimizationSettings>.FromXml. -
Settingsproperty (List<Setting>)
Collection of hardware-specific optimization settings.-
Settingnested classHardwareType(HardwareTypes): Specifies the hardware type (e.g., SLICE, TDAS).TransferSpeedSampleRateSettings(List<TransferSpeedSampleRate>): List of sample rate configurations for transfer speed ranges.
-
TransferSpeedSampleRatenested classMaxTransferSpeed(float): Upper bound of transfer speed (bytes/sec? units unspecified).MinTransferSpeed(float): Lower bound of transfer speed.SampleRate(double): Sample rate (Hz) to use within the speed range.
-
CategoryAttributeEx class (DTS.Slice.Users.UserSettings namespace)
-
CategoryAttributeEx(PropertyEnums.PropertyCategories category)
Constructor that initializes the attribute with a category enum value and stores it internally. -
GetCategory()method
Returns the storedPropertyCategoriesenum value. -
GetLocalizedString(string value)override
Looks upvalueinStringResources.ResourceManager; returns"##ResourceNotFound##" + valueif not found.
DisplayAttributeEx class (DTS.Slice.Users.UserSettings namespace)
-
DisplayAttributeEx(PropertyEnums.PropertyIds propertyId)
Constructor for enum-based property ID lookup. -
DisplayAttributeEx(string propertyId)
Constructor for string-based property ID lookup. -
DisplayNameoverride
Constructs resource key as"{propertyId}_DisplayName"(using enum or string), looks up inStringResources.ResourceManager; returns"##DisplayNameNotFound##" + propertyIdif not found.
DescriptionAttributeEx class (DTS.Slice.Users.UserSettings namespace)
-
DescriptionAttributeEx(PropertyEnums.PropertyIds propertyId)
Constructor for enum-based property ID lookup. -
DescriptionAttributeEx(string propertyId)
Constructor for string-based property ID lookup. -
Descriptionoverride
Constructs resource key as"{propertyId}_Description"(using enum or string), looks up inStringResources.ResourceManager; returns"##DescriptionNotFound##" + propertyIdif not found.
PropertyIdAttribute class (DTS.Slice.Users.UserSettings namespace)
-
PropertyIdAttribute(PropertyEnums.PropertyIds propertyId)
Constructor that stores the property ID enum. -
GetPropertyId(PropertyInfo o)static method
Retrieves the integer property ID from aPropertyInfo'sPropertyIdAttribute. ThrowsNullReferenceExceptionif property or attribute is missing. -
GetPropertyIdEnum(PropertyInfo o)static method
Retrieves thePropertyIdsenum value from aPropertyInfo'sPropertyIdAttribute. ThrowsNullReferenceExceptionif property or attribute is missing.
SampleRateConverter class (DTS.Slice.Users.UserSettings namespace)
-
SampleRateConverter()
Default constructor. -
GetStandardValuesSupported(ITypeDescriptorContext context)override
Returnstrue, indicating a standard list of values is available. -
GetStandardValues(ITypeDescriptorContext context)override
Returns a sorted list of valid sample rates (asdouble[]) by:- Reading
SPSINDEX_COUNT(default 56) fromSettingsDB. - Iterating
i = 0toSPSINDEX_COUNT-1, fetchingSPSINDEX_{i}fromSettingsDB(defaulting toAvailableSampleRatesDefault[i]ifi < 27). - Filtering out duplicates and non-positive values.
Returns values as
StandardValuesCollection.
- Reading
-
AvailableSampleRatesDefaultstatic field (int[])
Hardcoded default sample rates (Hz):[5, 50, 100, ..., 1000000](27 values).
UserHistory class (DTS.Slice.Users.UserSettings namespace)
-
Static
CreateAnyMissingUserHistory()method
Ensures all properties defined inUserHistoryexist in theDefaultPropertiesdatabase table and creates user-specific entries. Uses reflection to inspect properties, checksDefaultPropertiestable for existing entries, and inserts missing defaults viaDbOperations. -
Instance Properties (all annotated with
[CategoryAttributeEx],[PropertyId],[DescriptionAttributeEx],[DisplayAttributeEx],[DefaultValue],[ReadOnly(true)]):UsersCurrentTestSetup(string, default"", ID401)LastRunTestSetup(string, default"", ID402)LastUsedSampleRate(double, default20000.0, ID403)ApplySensorDataToBlankChannels(bool, defaulttrue, ID404)ApplyHardwareAssignmentInHardwareDisco(bool, defaulttrue, ID434,[Browsable(false)])ShowOptionsWhenApplyingSensorToBlankChannel(bool, defaulttrue, ID405)
PropertyEnums class (DTS.Slice.Users.UserSettings namespace)
-
PropertyCategoriesenum
Categories for grouping settings in UI (e.g.,UserHistory,ExportOptions,RealtimeOptions). Used byCategoryAttributeEx. -
PropertyOrdersenum
Ordered list of property names (used for ordering within categories in UI). Not directly used in the provided source files. -
PropertyIdsenum
Integer-based IDs for properties (e.g.,UsersCurrentTestSetup = 401,DefaultSampleRate = 103). Used byPropertyIdAttribute,DisplayAttributeEx, andDescriptionAttributeEx.
3. Invariants
- Database storage format: All settings are stored in invariant (culture-agnostic) form in the database (e.g., numeric sample rates, English string keys).
- Fallback chain: When retrieving a setting, the system falls back in this order: user-specific value → default value in DB → default value in code (via
[DefaultValue]orTestSetupDefaults.GetDefaultValueAsString). - Resource key format: Display names and descriptions use keys of the form
"{PropertyId}_DisplayName"and"{PropertyId}_Description"(wherePropertyIdis the enum or string value). - Property ID uniqueness: Each
PropertyIdsenum value maps to a unique integer ID used as the primary key inDefaultPropertiestable. - Sample rate list construction:
SampleRateConverter.GetStandardValues()always returns a sorted list of unique, positive sample rates derived fromSettingsDBandAvailableSampleRatesDefault. - Attribute consistency: Properties in
UserHistorymust have exactly onePropertyIdAttribute, and its value must match the enum value used inPropertyIdAttribute/DisplayAttributeEx/DescriptionAttributeEx.
4. Dependencies
Module depends on:
DTS.Common.Enums.Hardware.HardwareTypes(forOptimizationSettings.Setting.HardwareType)DTS.Common.Utilities.Xml.XmlToObject<T>(for XML deserialization inOptimizationSettings)DTS.Common.Settings.SettingsDB(forSampleRateConverterto read global settings likeSPSINDEX_COUNT)DTS.Common.Storage.DbOperations(for database operations inUserHistory.CreateAnyMissingUserHistory)System.ComponentModel(forCategoryAttribute,DisplayNameAttribute,DescriptionAttribute,TypeConverter)System.Resources.ResourceManager(viaStringResources.ResourceManagerfor localization)TestSetupDefaults.GetDefaultValueAsString(for default value retrieval inCreateAnyMissingUserHistory)TestSetupDefaults.CreateMissingUserSettingProperties(for user-specific setting creation)
Module is depended on by:
- UI components (e.g., property grids) that use
UserHistoryproperties and attributes for display. - Settings persistence layer (e.g.,
DbOperations,SettingsDB) for reading/writing settings. - Code that consumes
OptimizationSettings(e.g., hardware-specific optimization logic). - Localization infrastructure (via
StringResources).
5. Gotchas
- Resource key mismatch: If a property ID is passed as a string to
DisplayAttributeEx/DescriptionAttributeEx, the resource key is"{string}_DisplayName"(e.g.,"MyProp_DisplayName"), not the enum name. Ensure string-based keys match this pattern. - Missing enum entries:
PropertyOrdersenum is defined but not used in the provided source files; its purpose is unclear without additional context. - Hardcoded defaults:
SampleRateConverteruses a hardcodedAvailableSampleRatesDefaultarray (27 values) as fallback, butSPSINDEX_COUNTdefaults to 56. This may cause out-of-bounds access ifSPSINDEX_COUNT > 27and missing DB entries exist. - Case sensitivity: Resource lookups are case-sensitive (via
ResourceManager.GetString), but enum-to-string conversion usesToString()(case-sensitive per C# conventions). - No validation in
OptimizationSettings: TheSettingandTransferSpeedSampleRateclasses have no validation (e.g.,MinTransferSpeed ≤ MaxTransferSpeed,SampleRate > 0). Invalid data may be deserialized silently. ApplyHardwareAssignmentInHardwareDiscois[Browsable(false)]: Though public, this property will not appear in standard property grids.SampleRateConvertermutates state:GetStandardValuesclears and repopulates_validSampleRateListon each call. Not thread-safe if used concurrently.PropertyIdAttribute.GetPropertyIdthrows on null/missing: No graceful handling; callers must ensure attributes exist before calling.