6.1 KiB
6.1 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |
|---|---|---|---|---|---|
|
2026-04-16T04:28:52.088463+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 489635ffcf3025b3 |
ConfigToDb
Purpose
The ConfigToDbMigrator class facilitates migration of legacy application and user settings from an old configuration file (typically from a previous DataPRO installation) into the database-backed user property store. It reads settings from a specified legacy config path, maps known settings keys to standardized PropertyEnums.PropertyIds, performs type/conversion logic where necessary (e.g., milliseconds to seconds), and inserts the converted values into the database for all existing users via the sp_UserPropertiesUpdateInsert stored procedure. This enables backward compatibility during upgrades where settings previously stored in .config files are now persisted in a centralized, user-scoped database table.
Public Interface
bool migrateConfigToDb(string nextLowerPath, out string result)
- Behavior: Attempts to migrate user and application settings from the legacy config file located at
nextLowerPath + Resources.RegistryDataPROExe.- First retrieves user settings; if successful (i.e.,
resultdoes not contain"OldSettingsCouldNotBeFound"or"OldSettingsCouldNotBeProcessed"), it then retrieves application settings. - If both are retrieved successfully, calls
InsertConfigSettingsIntoDbto persist them. - Returns
trueonly if all steps succeed; otherwisefalse.
- First retrieves user settings; if successful (i.e.,
- Parameters:
nextLowerPath: Path to the directory containing the legacy DataPRO executable (e.g.,"C:\\Program Files\\DataPRO\\").result: Output string describing success/failure (e.g.,"Could not find settings file: {exception message} at {path}").
Invariants
- User and Application Settings Separation: User and application settings are processed independently; failure to retrieve user settings prevents application settings from being processed.
- Explicit Key Mapping: Only settings with explicitly listed keys (e.g.,
"LastUsedSampleRate","DefaultUploadFolder", etc.) are migrated. Any unmapped keys are silently ignored. - User-Scoped Insertion: Every migrated setting is inserted for all existing users (as returned by
GetAllUserIds()), not just the current user. - No Rollback: If an error occurs during DB insertion for one user or property, the method does not roll back prior successful inserts; it continues processing remaining users/properties.
- Path Assumption: Assumes the legacy config file resides at
nextLowerPath + Resources.RegistryDataPROExe(i.e., the default install path).
Dependencies
Internal Dependencies
ConfigToDb.Properties.Resources: Used for localized strings (Resources.UserSettings,Resources.ApplicationSettings,Resources.OldSettingsCouldNotBeFound,Resources.OldSettingsCouldNotBeProcessed).DTS.Common.Storage: ProvidesDatabaseImport.DbOperations,DbOperationsEnum.StoredProcedure, andDbOperations.Users.UserFields.DTS.Slice.Users.UserSettings: ProvidesSettingElementCollectionandSettingElementtypes (from .NETSystem.Configuration).System.Configuration: Used viaConfigurationManager.OpenExeConfiguration.System.Data.SqlClient: Used forSqlCommand,SqlDbType,SqlParameter.PropertyEnums.PropertyIds: Enum defining property IDs for database storage (e.g.,LastUsedSampleRate,DefaultUploadFolder).SupportedExportFormatBitFlags: Nested enum used to decodeDefaultTestExportFormatbitmask.
External Dependencies
- SQL Server database with stored procedures:
sp_UserPropertiesUpdateInsertsp_UserGetIdsAll(viaDbOperationsEnum.StoredProcedure.sp_UserGetIdsAll)
- Legacy
.configfiles in .NETclientSettingsformat.
Depended Upon
- Unknown from source alone — this class is likely invoked during application startup or upgrade workflows, but no callers are visible in the provided file.
Gotchas
- Silent Ignoring of Unmapped Settings: Settings not explicitly listed in the
switchblocks (e.g.,"SomeNewSetting") are ignored without warning or logging. - Hardcoded Key-to-ID Mapping: The mapping from config keys to
PropertyEnums.PropertyIdsis hardcoded; adding new settings requires code changes and recompilation. - No Error Propagation from DB: In
StoreInDb, if the stored procedure returns a non-zero@errorNumber, the error is not propagated or logged (only commented as a potential action). The method continues and returnstrueeven if DB writes fail for some users. - Culture-Specific Number Conversion: The
"DefaultTestExcitationWarmupMS"→ seconds conversion usesCultureInfo.InvariantCulture, but other numeric conversions (e.g.,Convert.ToDouble,Convert.ToInt32) use the current culture, risking parsing errors in non-US locales. - Bitmask Parsing Assumption:
ExportDesiredassumes thesettingValuestring can be parsed as anint(viaConvert.ToInt32) — if the config value is malformed or non-numeric, this will throw. - No Validation of Setting Values: No validation is performed on the
setting.Value.ValueXml.InnerXmlbefore insertion (e.g., empty strings, invalid XML, or type mismatches may be stored). - Assumes Single Section per Group:
GetConfigSettingsassumes each section group (e.g.,"userSettings") contains exactly one section and usesSections[0]. If multiple sections exist, only the first is used. - No Cleanup of Old Settings: After successful migration, the old config file is not modified or deleted — old settings may remain and cause confusion.
GetAllUserIds()Swallows Exceptions: IfGetAllUserIds()fails (e.g., DB connection issue), it returns an empty list, causingInsertConfigSettingsIntoDbto silently do nothing (no rows inserted) with no error indication.migrateConfigToDbReturnstrueOnly on Full Success: If user settings succeed but application settings fail, the method returnsfalse, even though partial migration occurred.