init
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
---
|
||||
source_files:
|
||||
- DataPRO/Modules/DatabaseImporter/ConfigToDb/ConfigToDbMigrator.cs
|
||||
generated_at: "2026-04-16T04:28:52.088463+00:00"
|
||||
model: "Qwen/Qwen3-Coder-Next-FP8"
|
||||
schema_version: 1
|
||||
sha256: "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., `result` does not contain `"OldSettingsCouldNotBeFound"` or `"OldSettingsCouldNotBeProcessed"`), it then retrieves application settings.
|
||||
- If both are retrieved successfully, calls `InsertConfigSettingsIntoDb` to persist them.
|
||||
- Returns `true` only if all steps succeed; otherwise `false`.
|
||||
- **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`: Provides `DatabaseImport.DbOperations`, `DbOperationsEnum.StoredProcedure`, and `DbOperations.Users.UserFields`.
|
||||
- `DTS.Slice.Users.UserSettings`: Provides `SettingElementCollection` and `SettingElement` types (from .NET `System.Configuration`).
|
||||
- `System.Configuration`: Used via `ConfigurationManager.OpenExeConfiguration`.
|
||||
- `System.Data.SqlClient`: Used for `SqlCommand`, `SqlDbType`, `SqlParameter`.
|
||||
- `PropertyEnums.PropertyIds`: Enum defining property IDs for database storage (e.g., `LastUsedSampleRate`, `DefaultUploadFolder`).
|
||||
- `SupportedExportFormatBitFlags`: Nested enum used to decode `DefaultTestExportFormat` bitmask.
|
||||
|
||||
#### **External Dependencies**
|
||||
- SQL Server database with stored procedures:
|
||||
- `sp_UserPropertiesUpdateInsert`
|
||||
- `sp_UserGetIdsAll` (via `DbOperationsEnum.StoredProcedure.sp_UserGetIdsAll`)
|
||||
- Legacy `.config` files in .NET `clientSettings` format.
|
||||
|
||||
#### **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 `switch` blocks (e.g., `"SomeNewSetting"`) are ignored without warning or logging.
|
||||
- **Hardcoded Key-to-ID Mapping**: The mapping from config keys to `PropertyEnums.PropertyIds` is 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 returns `true` even if DB writes fail for some users.
|
||||
- **Culture-Specific Number Conversion**: The `"DefaultTestExcitationWarmupMS"` → seconds conversion uses `CultureInfo.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**: `ExportDesired` assumes the `settingValue` string can be parsed as an `int` (via `Convert.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.InnerXml` before insertion (e.g., empty strings, invalid XML, or type mismatches may be stored).
|
||||
- **Assumes Single Section per Group**: `GetConfigSettings` assumes each section group (e.g., `"userSettings"`) contains exactly one section and uses `Sections[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**: If `GetAllUserIds()` fails (e.g., DB connection issue), it returns an empty list, causing `InsertConfigSettingsIntoDb` to silently do nothing (no rows inserted) with no error indication.
|
||||
- **`migrateConfigToDb` Returns `true` Only on Full Success**: If user settings succeed but application settings fail, the method returns `false`, even though partial migration occurred.
|
||||
Reference in New Issue
Block a user