QuellCode/CentronERP war nur als Gitlink (Submodul-Referenz auf 79c1142) getrackt, ohne .gitmodules und ohne erreichbares Remote. Der Untersuchungsgegenstand der Versuchsreihe war damit nicht reproduzierbar gesichert: Ein Klon haette ein leeres Verzeichnis erhalten, und die Belege der 3.287 Anforderungen waeren nicht ueberpruefbar gewesen. Umstellung: - Historie nach c:\DEV\CentronERP_git_snapshot_79c1142 ausgelagert (vollstaendig lesbar, enthaelt 79c1142 und Vorgaenger 89ccfd6) - Gitlink aus dem Index entfernt - Dateiinhalt aufgenommen: 24.557 Dateien, rund 333 MB Die verschachtelte .gitignore der Codebasis gilt weiter, Build-Artefakte bleiben ausgeschlossen. Details in Versuche/Versuch_01/_Codebasis-Nachweis.md
6.2 KiB
Settings Management in c-entron.NET
This guide explains how application settings are managed in the c-entron.NET project, covering both legacy and current approaches, and providing best practices for working with settings.
Overview
The c-entron.NET application uses two separate database tables for storing application settings:
- Stammdat - Legacy settings table with historical settings
- ApplicationSettings - Current table for new settings
This dual-table approach exists for historical reasons, and all new settings should be added to the ApplicationSettings table.
Settings Tables
Legacy: Stammdat Table
The Stammdat table contains many historical settings that are accessed through the AppSettingsConst enum.
- Enum File:
src/backend/Centron.BL/Administration/Settings/AppSettingsConst.cs - Access: Settings are accessed through the
AppSettingsBL.GetSettings(AppSettingsConst)method - Updates: Although we maintain these settings, no new settings should be added to this table
Current: ApplicationSettings Table
The ApplicationSettings table is the current standard for all new application settings.
- Enum File:
src/backend/Centron.Interfaces/Administration/Settings/ApplicationSettingID.cs - Next Free ID: Tracked in a comment at line 15 of
ApplicationSettingID.cs - Access: Settings are accessed through the
AppSettingsBL.GetSettings(ApplicationSettingID)method - Settings Descriptions: Defined in
src/backend/Centron.Interfaces/Administration/Settings/ApplicationSettingDefinitions.cs
ID Management
When adding new settings, you must:
-
Check the next available ID from the comment in
ApplicationSettingID.cs:// Next Centron Settings ID : 10370 // Current Riverbird Settings ID : 50035 -
Use the next ID in sequence (in this case, 10370)
-
Update the comment with the next available ID after adding your setting
The Riverbird setting IDs (starting with 50xxx) are not used by c-entron.NET.
Setting Definitions
For each new setting in ApplicationSettingID.cs, you must add a corresponding description in the ApplicationSettingDefinitions.cs file:
case ApplicationSettingID.YourNewSetting:
return "Description of what this setting does and how it's used.";
The description should clearly explain:
- The purpose of the setting
- What data it stores
- Any relevant format or validation constraints
Accessing Settings
Group Setting Classes
The client never accesses settings tables directly. Instead, we use "group setting classes" to manage related settings. These classes:
- Load settings from the database
- Provide a strongly-typed interface for accessing settings
- Manage updating settings back to the database
Example: Loading Settings
// Example from ReceiptWebServiceBL.GetReceiptInvoiceSettings()
var appSettings = this._appSettingsBL.GetSettings
(
ApplicationSettingID.InvoiceArchiveActive,
ApplicationSettingID.IsZugferdInvoiceActive,
// additional settings...
);
var settings = new ReceiptInvoiceSettingsDTO
{
IsInvoiceArchiveActive = appSettings.GetBool(ApplicationSettingID.InvoiceArchiveActive, false),
IsZugferdInvoiceActive = appSettings.GetBool(ApplicationSettingID.IsZugferdInvoiceActive, false),
// map other settings...
};
return Result<ReceiptInvoiceSettingsDTO>.AsSuccess(settings);
Example: Saving Settings
// Example from ReceiptWebServiceBL.SaveReceiptInvoiceSettings()
var updateSettings = this._appSettingsBL.GetSettingsForUpdate
(
ApplicationSettingID.InvoiceArchiveActive,
ApplicationSettingID.IsZugferdInvoiceActive,
// additional settings...
);
// Update values
updateSettings.UpdateBool(ApplicationSettingID.InvoiceArchiveActive, settings.IsInvoiceArchiveActive.Value);
updateSettings.UpdateBool(ApplicationSettingID.IsZugferdInvoiceActive, settings.IsZugferdInvoiceActive.Value);
// update other settings...
// Save all changes
updateSettings.SaveSettings();
return Result<bool>.AsSuccess(true);
API Integration
Settings are exposed through API methods, allowing client applications to retrieve and update settings.
API Patterns
- All setting API methods must use HTTP POST
- Get methods return a DTO containing the settings
- Save methods accept a DTO with the settings to update
Example API Methods
// In ICentronRestService.cs
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json)]
Result<ReceiptInvoiceSettingsDTO> GetReceiptInvoiceSettings();
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json)]
Result<bool> SaveReceiptInvoiceSettings(ReceiptInvoiceSettingsDTO settings);
Best Practices
Adding New Settings
- Use the next available ID from the comment in
ApplicationSettingID.cs - Add your setting to the
ApplicationSettingIDenum - Update the "Next Centron Settings ID" comment
- Add a detailed description in
ApplicationSettingDefinitions.cs - Create or update group setting classes to access your setting
Setting Types
Application settings support multiple data types:
- Boolean: Use
GetBool()/UpdateBool()methods - Integer: Use
GetInt()/UpdateInt()methods - String: Use
GetString()/UpdateString()methods - Large String: Use
GetLargeString()/UpdateLargeString()methods - Enum: Use
GetEnum<T>()/UpdateEnum<T>()methods - Decimal: Use
GetDecimal()/UpdateDecimal()methods
Default Values
When retrieving settings, always provide a default value in case the setting doesn't exist:
// Example with default value
bool isActive = appSettings.GetBool(ApplicationSettingID.SomeSetting, false);
Common Scenarios
Creating a New Group Settings Class
- Define a DTO class to hold the settings
- Create Get method that loads settings from AppSettingsBL
- Create Save method that updates settings with AppSettingsBL
- Add corresponding API methods
Migrating Legacy Settings
When migrating settings from Stammdat to ApplicationSettings:
- Add the new setting to ApplicationSettingID
- Add its description to ApplicationSettingDefinitions
- Update code to read from both sources during transition
- Eventually remove the old setting access after migration