5.1 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |
|---|---|---|---|---|---|
|
2026-04-16T02:05:43.907445+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 2693b2d1a0d0acee |
Config
1. Purpose
The DTSConfig class provides a centralized, thread-safe mechanism for loading and accessing an alternate application configuration file (e.g., for plugin-specific or test-specific configs), overriding the default app.config/web.config. It enables runtime configuration of the config file path via DTSConfigInit, then exposes typed accessors (GetAppSetting, GetSection) to read settings and custom sections from that alternate file using .NET’s System.Configuration APIs. This supports scenarios like plugin isolation or environment-specific overrides without modifying the main executable’s config.
2. Public Interface
-
static void DTSConfigInit(string path)
Initializes the alternate configuration by setting the config file path and loading the configuration. Internally callsSetAltConfigPath(path). Ifpathisnullor empty, falls back toDTSConstants.CustomConfigPath. Must be called before other config accessors to ensureAltConfigis populated. -
static string GetAppSetting(string key)
Retrieves the value of an<add key="..." value="..."/>entry from theappSettingssection of the alternate configuration. Returnsstring.Emptyif the key is not found. Logs a warning viaAPILoggerwhen the key is absent. -
static object GetSection(string sectionName)
Retrieves a custom configuration section (e.g.,<section name="..." type="..." />) by name from the alternate configuration. Returnsnullif the section is not defined. Logs a warning viaAPILoggerwhen the section is absent. -
static string AltConfigPathGet()
Thread-safe getter for the current alternate config file path (stored inAltConfigPath). Returns the path string (may benullor empty if not set or reset). -
static void AltConfigPathSet(string path)
Thread-safe setter for the alternate config file path. UpdatesAltConfigPathbut does not reload the configuration—SetAltConfigPathmust be called to apply the new path and reinitializeAltConfig.
3. Invariants
- Thread Safety: All access to
AltConfigPathandAltConfigis guarded by a private static lock object (MyLock). Reads (AltConfigPathGet,GetAltConfig,GetAppSetting,GetSection) and writes (AltConfigPathSet,SetAltConfigPath) are serialized. - Fallback Behavior: When
AltConfigPathisnullor empty,SetAltConfigPathusesDTSConstants.CustomConfigPathas the config file path. - Configuration Loading:
AltConfigis lazily initialized on first call toSetAltConfigPath(viaDTSConfigInitor direct invocation) and not reloaded automatically on subsequent path changes—SetAltConfigPathmust be called again to refresh it. - Error Handling: Missing keys/sections are not thrown as exceptions; instead, they return
string.Empty/nullwith a log message. No fallback to default config is attempted.
4. Dependencies
-
Internal Dependencies:
DTS.Common.Utilities.Logging.APILogger— Used for logging missing config entries/sections.System.Configuration.ConfigurationManager,ExeConfigurationFileMap,ConfigurationUserLevel— For loading and accessing configuration files.DTSConstants.CustomConfigPath— Fallback path whenAltConfigPathis unset.
-
External Dependencies:
System.Configurationassembly (standard .NET Framework/Standard).- No direct runtime dependencies beyond .NET config APIs.
-
Depended Upon By:
- Plugin code (per
GetSection’s XML comment) to access plugin-specific configuration sections. - Any module requiring runtime-configurable settings without modifying the main executable’s config.
- Plugin code (per
5. Gotchas
AltConfigPathSetdoes not reload config: CallingAltConfigPathSetalone updates the stored path but does not reinitializeAltConfig. The configuration must be reloaded viaSetAltConfigPath(e.g.,DTSConfigInit) to apply changes.- No fallback to main config: If the alternate config file is missing, invalid, or lacks a requested key/section, the system logs a warning but returns
string.Empty/null—it does not fall back to the defaultapp.config. DTSConstants.CustomConfigPathis assumed but not defined here: The fallback path relies on an external constant (DTSConstants.CustomConfigPath). Its value and behavior are not visible in this file.- Thread-safety only covers state, not config validity: While access to
AltConfigis thread-safe, concurrent calls toSetAltConfigPathmay cause transient inconsistencies (e.g., one thread sets a path while another readsAltConfigbefore reinitialization completes). - No validation of config file path:
SetAltConfigPathdoes not validate whether the provided path exists or is readable;ConfigurationManager.OpenMappedExeConfigurationwill throw if the file is inaccessible (e.g.,FileNotFoundException), but this is not handled internally.