Environment Service
Cross-platform folder management, data path resolution, app initialization, and BeepDM environment setup
Source of truth (2026)
DataManagementEngineStandard/Services/EnvironmentService.cs(325 lines)
Table of Contents
Overview
EnvironmentService is a static utility class providing cross-platform folder management and application initialization. It is the foundation for all BeepDM application data storage.
- Cross-platform paths — Windows, macOS, and Linux folder locations via
RuntimeInformation - Folder hierarchy — Main Beep folder → App Repo folder → Application folders
- Initialization — Bootstraps
ConfigEditorwith default drivers, type mappings, and queries - Sanitization — Cross-platform safe folder names (invalid chars → underscores)
- Idempotency — All methods track whether they've been called and skip duplicates
Class Definition
public static class EnvironmentService
{
private static IDMEEditor _editor;
private static IServiceCollection Services;
public static string BeepDataPath { get; }
public static string AppRepoDataPath { get; }
// Idempotency flags
private static bool mappingcreated = false;
private static bool connectioncreated = false;
private static bool datasourcecreated = false;
// Folder creation
public static string CreateMainFolder();
public static string CreateMainFolder(this IDMEEditor editor);
public static string CreateAppRepofolder(string AppReponame = "");
public static string CreateAppfolder(string AppReponame, string appfolder);
public static string CreateAppfolder(string appfolder);
// Initialization (extension methods)
public static IServiceCollection CreateBeepMapping(this IDMEEditor editor);
public static void AddAllConnectionConfigurations(this IDMEEditor editor);
public static void AddAllDataSourceMappings(this IDMEEditor editor);
public static void AddAllDataSourceQueryConfigurations(this IDMEEditor editor);
// Internal helpers
private static string GetBaseFolderPath();
private static string SanitizeFolderName(string folderName);
private static bool CreateDirectorySafely(string path);
}
Folder Management
CreateMainFolder
Creates the root Beep data directory:
public static string CreateMainFolder()
// Returns: {BasePath}/TheTechIdea/Beep
// Sets: BeepDataPath
CreateAppRepofolder
Creates a named repository folder inside Beep root:
public static string CreateAppRepofolder(string AppReponame = "")
// Returns: {BeepDataPath}/{AppReponame}
// Sets: AppRepoDataPath
// Auto-creates BeepDataPath if needed
CreateAppfolder
Creates a sub-folder, with two overloads:
// Inside a specific app repo
public static string CreateAppfolder(string AppReponame, string appfolder)
// Returns: {BeepDataPath}/{AppReponame}/{appfolder}
// Directly inside Beep root
public static string CreateAppfolder(string appfolder)
// Returns: {BeepDataPath}/{appfolder}
Folder Creation Flow
GetBaseFolderPath()— Determines OS-appropriate base directoryCreateDirectorySafely()— Creates folders with error handlingSanitizeFolderName()— Cross-platform safe naming- Auto-creates parent directories as needed
Platform-Specific Paths
Determined via RuntimeInformation.IsOSPlatform():
| Platform | Detection | Base Path | Full Beep Path |
|---|---|---|---|
| Windows | OSPlatform.Windows |
CommonApplicationData |
C:\ProgramData\TheTechIdea\Beep |
| macOS | OSPlatform.OSX |
~/Library/Application Support |
~/Library/Application Support/TheTechIdea/Beep |
| Linux | (fallback) | ~/.config |
~/.config/TheTechIdea/Beep |
Typical App Structure
{BasePath}/TheTechIdea/Beep/
├── MyApp/ # App repo folder
│ ├── Config/ # Configuration files
│ │ ├── ConnectionConfig.json
│ │ ├── DataConnections.json
│ │ └── DataTypeMapping.json
│ ├── Pipelines/ # Pipeline definitions
│ │ └── {id}.pipeline.json
│ └── History/ # Run history and audit
├── InMemory/ # InMemory datasource files
└── Shared/ # Cross-app shared data
Initialization
EnvironmentService bootstraps ConfigEditor with all default configurations:
CreateBeepMapping
public static IServiceCollection CreateBeepMapping(this IDMEEditor editor)
// Calls all three initialization methods at once:
// 1. AddAllConnectionConfigurations
// 2. AddAllDataSourceMappings
// 3. AddAllDataSourceQueryConfigurations
AddAllConnectionConfigurations
public static void AddAllConnectionConfigurations(this IDMEEditor editor)
// Source: ConnectionHelper.GetAllConnectionConfigs()
// Target: ConfigEditor.DataDriversClasses
// Idempotent: connectioncreated flag
// Includes: All built-in driver definitions (SQLite, SQL Server, etc.)
AddAllDataSourceMappings
public static void AddAllDataSourceMappings(this IDMEEditor editor)
// Source: DataTypeFieldMappingHelper.GetMappings()
// Target: ConfigEditor.DataTypesMap
// Idempotent: mappingcreated flag
// Maps: CLR types ↔ datasource-specific types
AddAllDataSourceQueryConfigurations
public static void AddAllDataSourceQueryConfigurations(this IDMEEditor editor)
// Source: RDBMSHelper.CreateQuerySqlRepos()
// Target: ConfigEditor.QueryList
// Idempotent: datasourcecreated flag
// Populates: Schema query templates, entity discovery queries
Folder Name Sanitization
private static string SanitizeFolderName(string folderName)
{
// Replace invalid chars with underscores
char[] invalidChars = Path.GetInvalidFileNameChars();
foreach (char c in invalidChars)
folderName = folderName.Replace(c, '_');
// Trim whitespace
folderName = folderName.Trim();
// Enforce max length
if (folderName.Length > 100)
folderName = folderName.Substring(0, 100);
return folderName;
}
This ensures folders work across Windows, macOS, and Linux without filesystem errors.
Integration Points
EnvironmentService paths are consumed throughout BeepDM:
| Consumer | Path Pattern |
|---|---|
ConfigEditor | {AppRepoDataPath}/Config/ |
PipelineManager | {AppRepoDataPath}/Pipelines/ |
ObservabilityStore | {AppRepoDataPath}/Pipelines/History/ |
InMemoryDataSource | {BeepDataPath}/InMemory/ |
BeepService | Calls LoadConfigurations() → creates folders + loads configs |
SetupWizard | Uses paths for checkpoint persistence |
Usage Examples
Basic Setup
// Create folder hierarchy
var beepPath = EnvironmentService.CreateMainFolder();
Console.WriteLine($"Beep data: {beepPath}");
var repoPath = EnvironmentService.CreateAppRepofolder("MyApp");
Console.WriteLine($"App repo: {repoPath}");
var configPath = EnvironmentService.CreateAppfolder("MyApp", "Config");
Console.WriteLine($"Config: {configPath}");
Full Initialization with Editor
var editor = new DMEEditor();
// Create folders
EnvironmentService.CreateMainFolder();
EnvironmentService.CreateAppRepofolder("MyApp");
// Initialize configurations (all three at once)
editor.CreateBeepMapping();
// Or individually for more control:
editor.AddAllConnectionConfigurations();
editor.AddAllDataSourceMappings();
editor.AddAllDataSourceQueryConfigurations();
Checking Paths
Console.WriteLine($"Beep root: {EnvironmentService.BeepDataPath}");
Console.WriteLine($"App repo: {EnvironmentService.AppRepoDataPath}");
// On Windows: C:\ProgramData\TheTechIdea\Beep
// C:\ProgramData\TheTechIdea\Beep\MyApp
// On macOS: ~/Library/Application Support/TheTechIdea/Beep
// ~/Library/Application Support/TheTechIdea/Beep/MyApp
// On Linux: ~/.config/TheTechIdea/Beep
// ~/.config/TheTechIdea/Beep/MyApp
Cross-Platform Safety
// Unsafe name gets sanitized
var path = EnvironmentService.CreateAppfolder("My App: Data*");
// Result: creates folder named "My App_ Data_"
// Full automated setup (used by BeepService.Configure())
editor.CreateBeepMapping();
Console.WriteLine($"Drivers: {editor.ConfigEditor.DataDriversClasses.Count}");
Console.WriteLine($"Mappings: {editor.ConfigEditor.DataTypesMap.Count}");
Console.WriteLine($"Queries: {editor.ConfigEditor.QueryList.Count}");