Files
2026-04-17 14:55:32 -04:00

5.3 KiB

source_files, generated_at, model, schema_version, sha256
source_files generated_at model schema_version sha256
Common/DTS.Common.Core/Config/DTSConfig.cs
2026-04-16T11:41:16.907673+00:00 zai-org/GLM-5-FP8 1 2693b2d1a0d0acee

Documentation: DTSConfig.cs

1. Purpose

DTSConfig is a static utility class that provides centralized access to application configuration settings from an alternate configuration file. It exists to allow the application to read settings from a custom .config file path rather than the default application configuration, supporting scenarios where configuration needs to be externalized or shared across components. The class acts as a configuration facade, wrapping System.Configuration.ConfigurationManager functionality with thread-safe access and logging for missing keys or sections.


2. Public Interface

AltConfigPathGet()

Signature: public static string AltConfigPathGet()

Returns the currently set alternate configuration file path. Thread-safe via locking on MyLock.


AltConfigPathSet(string path)

Signature: public static void AltConfigPathSet(string path)

Sets the alternate configuration file path. Updates AltConfigPath only; does not reload the configuration. Thread-safe via locking on MyLock.


DTSConfigInit(string path)

Signature: public static void DTSConfigInit(string path)

Initializes the configuration system by calling SetAltConfigPath(path). This is the primary entry point for setting up the alternate configuration at application startup.


GetAltConfig()

Signature: public static Configuration GetAltConfig()

Returns the System.Configuration.Configuration object representing the loaded alternate configuration file. Thread-safe via locking on MyLock.


SetAltConfigPath(string path)

Signature: public static void SetAltConfigPath(string path)

Sets the alternate configuration path and immediately loads the configuration file. If path is null or empty, falls back to DTSConstants.CustomConfigPath. Creates an ExeConfigurationFileMap and opens the configuration via ConfigurationManager.OpenMappedExeConfiguration. Thread-safe via locking on MyLock.


GetAppSetting(string key)

Signature: public static string GetAppSetting(string key)

Retrieves an application setting value by key from the alternate configuration's AppSettings section. Returns string.Empty if the key is not found (logs a warning via APILogger.Log). Does not throw exceptions for missing keys.


GetSection(string sectionName)

Signature: public static object GetSection(string sectionName)

Retrieves a configuration section by name from the alternate configuration. Returns null if the section is not found (logs a warning via APILogger.Log). Used by plugin code to retrieve plugin library sections.


3. Invariants

  • Thread Safety: All access to static fields (AltConfigPath, AltConfig) is protected by a lock on MyLock.
  • Configuration Initialization: AltConfig is populated when SetAltConfigPath() is called; calling GetAppSetting() or GetSection() before initialization will result in a NullReferenceException (not guarded against in source).
  • Fallback Path: When SetAltConfigPath(string path) receives a null or empty path, it uses DTSConstants.CustomConfigPath as the configuration file location.
  • Missing Key Handling: GetAppSetting() returns string.Empty for missing keys rather than null or throwing an exception.
  • Missing Section Handling: GetSection() returns null for missing sections and logs the absence.

4. Dependencies

This module depends on:

  • DTS.Common.Utilities.Logging — Uses APILogger.Log() for warning messages
  • System.Configuration — Uses Configuration, ConfigurationManager, ExeConfigurationFileMap, KeyValueConfigurationElement, ConfigurationUserLevel
  • System.Linq — Uses Cast<>() and FirstOrDefault()
  • DTSConstants.CustomConfigPath — Referenced constant (defined elsewhere, location not shown in source)

What depends on this module:

  • Unclear from source alone — No consumers are shown in this file. The GetSection() method documentation mentions "plugin code" as a consumer.

5. Gotchas

  1. Redundant API Surface: Both DTSConfigInit() and SetAltConfigPath() perform the same operation. DTSConfigInit() simply delegates to SetAltConfigPath() with no additional logic.

  2. Inconsistent Naming Convention: The class exposes both AltConfigPathGet()/AltConfigPathSet() (Java-style) and SetAltConfigPath() (C#-style) methods for similar operations, creating potential confusion.

  3. Uninitialized State Not Guarded: Calling GetAppSetting() or GetSection() before SetAltConfigPath() or DTSConfigInit() will throw a NullReferenceException since AltConfig starts as null.

  4. Empty Static Constructor: The static constructor is explicitly defined but empty, which is unnecessary.

  5. Silent Failure on Missing Keys: Missing configuration keys return string.Empty rather than throwing, which may mask configuration errors. Consumers must check for empty string rather than null.

  6. ReSharper Suppressions: The file suppresses InconsistentNaming warnings, suggesting naming conventions in this file deviate from project standards.