Connections & ConnectionProperties
IDataConnection implementations, connection properties, and driver configuration
Source files
DataManagementEngineStandard/Connections/DefaulDataConnection.csDataManagementEngineStandard/Connections/FileConnection.csDataManagementModelsStandard/ConfigUtil/ConnectionProperties.csDataManagementModelsStandard/ConfigUtil/ConnectionDriversConfig.csDataManagementModelsStandard/DataBase/IDataConnection.cs
Table of Contents
Overview
The connections layer binds BeepDM abstractions to concrete connection models. It provides:
- Connection abstraction -
IDataConnectioninterface for all connection types - Connection properties -
ConnectionPropertiesas the standard connection config - Driver configuration -
ConnectionDriversConfigfor driver metadata - Default connection -
DefaulDataConnectionfor standard datasources - File connection -
FileConnectionfor file-based datasources
IDataConnection Interface
public interface IDataConnection
{
IConnectionProperties ConnectionProp { get; set; }
ConnectionDriversConfig DataSourceDriver { get; set; }
ConnectionState ConnectionStatus { get; set; }
IDMEEditor DMEEditor { get; set; }
IDMLogger Logger { get; set; }
IErrorsInfo ErrorObject { get; set; }
bool InMemory { get; set; }
int ID { get; set; }
string GuidID { get; set; }
// Connection operations
ConnectionState OpenConnection();
ConnectionState OpenConnection(DataSourceType dbtype, string host, int port,
string database, string userid, string password, string parameters);
ConnectionState OpenConnection(DataSourceType dbtype, string connectionstring);
ConnectionState CloseConn();
string ReplaceValueFromConnectionString();
}
ConnectionProperties
The standard configuration object for all data source connections:
public class ConnectionProperties : IConnectionProperties
{
public string ConnectionName { get; set; }
public string ConnectionString { get; set; }
public DataSourceType DatabaseType { get; set; }
public DatasourceCategory Category { get; set; }
public string DriverName { get; set; }
public string DriverVersion { get; set; }
public string FileName { get; set; }
public string Host { get; set; }
public int Port { get; set; }
public string Database { get; set; }
public string UserID { get; set; }
public string Password { get; set; }
public string Parameters { get; set; }
public bool UseConnectionString { get; set; }
public string GuidID { get; set; }
}
Connection String Pattern
// RDBMS
var sqlite = new ConnectionProperties
{
ConnectionName = "MyDB",
ConnectionString = "Data Source=./app.db",
DatabaseType = DataSourceType.SqlLite,
Category = DatasourceCategory.RDBMS,
DriverName = "SQLite"
};
// File-based
var csv = new ConnectionProperties
{
ConnectionName = "MyCSV",
ConnectionString = "./data/",
FileName = "customers.csv",
DatabaseType = DataSourceType.Csv,
Category = DatasourceCategory.FileBased
};
// Web API
var api = new ConnectionProperties
{
ConnectionName = "MyAPI",
ConnectionString = "https://api.example.com/v1",
DatabaseType = DataSourceType.WebService,
Category = DatasourceCategory.CLOUD
};
DefaulDataConnection
The base connection implementation for standard datasources:
public class DefaulDataConnection : IDataConnection
{
public DefaulDataConnection();
public DefaulDataConnection(IDMEEditor dmEditor);
public IConnectionProperties ConnectionProp { get; set; }
public ConnectionDriversConfig DataSourceDriver { get; set; }
public ConnectionState ConnectionStatus { get; set; }
public IDMEEditor DMEEditor { get; set; }
public IDMLogger Logger { get; set; }
public IErrorsInfo ErrorObject { get; set; }
public bool InMemory { get; set; }
public int ID { get; set; }
public string GuidID { get; set; }
public ConnectionState OpenConnection();
public ConnectionState OpenConnection(DataSourceType dbtype, string host,
int port, string database, string userid, string password, string parameters);
public ConnectionState OpenConnection(DataSourceType dbtype, string connectionstring);
public ConnectionState CloseConn();
public string ReplaceValueFromConnectionString();
}
This is the base class for datasource-specific connections. It automatically initializes ConnectionProp, DataSourceDriver, and a new GuidID on construction.
FileConnection
Specialized connection for file-based datasources:
public class FileConnection : IDataConnection
{
public FileConnection(IDMEEditor dmEditor);
public IConnectionProperties ConnectionProp { get; set; }
public ConnectionDriversConfig DataSourceDriver { get; set; }
public ConnectionState ConnectionStatus { get; set; }
public IDMEEditor DMEEditor { get; set; }
public IDbConnection DbConn { get; set; }
public ConnectionState OpenConnection();
public ConnectionState CloseConn();
public string ReplaceValueFromConnectionString();
}
Open Flow
- Link ConnectionProperties to driver via
ConnectionHelper.LinkConnection2Drivers - Resolve dynamic values in connection string
- Verify file exists at resolved path
- If found: set
ConnectionState.Open - If not found: set
ConnectionState.Broken
ConnectionDriversConfig
Driver metadata registered in ConfigEditor.DataDriversClasses:
public class ConnectionDriversConfig
{
public string GuidID { get; set; }
public string PackageName { get; set; } // e.g., "SQLite"
public string DriverClass { get; set; } // e.g., "SQLite"
public string version { get; set; } // e.g., "1.0.0"
public string DbConnectionType { get; set; } // e.g., "SQLiteConnection"
public string ConnectionString { get; set; } // Template: "Data Source={Database};"
public string classHandler { get; set; } // e.g., "SQLiteDataSource"
public DatasourceCategory DatasourceCategory { get; set; }
public DataSourceType DatasourceType { get; set; }
public bool ADOType { get; set; } // true for ADO.NET providers
}
Driver Registration
var driver = new ConnectionDriversConfig
{
PackageName = "PostgreSQL",
DriverClass = "Npgsql",
version = "7.0.0",
DbConnectionType = "NpgsqlConnection",
ConnectionString = "Host={Host};Port={Port};Database={Database};Username={UserID};Password={Password}",
classHandler = "PostgreDataSource",
DatasourceCategory = DatasourceCategory.RDBMS,
DatasourceType = DataSourceType.Postgresql,
ADOType = true
};
editor.ConfigEditor.DataDriversClasses.Add(driver);
Connection States
| State | Value | Description |
|---|---|---|
Closed | 0 | Connection is closed |
Open | 1 | Connection is open and ready |
Connecting | 2 | Connection is being established |
Executing | 4 | Executing a command |
Fetching | 8 | Fetching data |
Broken | 16 | Connection is broken and needs repair |
Usage Examples
Creating a Connection
// Create properties
var props = new ConnectionProperties
{
ConnectionName = "ProductionDB",
DatabaseType = DataSourceType.SqlServer,
Category = DatasourceCategory.RDBMS,
Host = "prod-server",
Port = 1433,
Database = "ProductsDB",
UserID = "app_user",
Password = "secret"
};
// Add to config
editor.ConfigEditor.AddDataConnection(props);
editor.ConfigEditor.SaveDataconnectionsValues();
Opening a Connection
var state = editor.OpenDataSource("ProductionDB");
if (state == ConnectionState.Open)
{
var ds = editor.GetDataSource("ProductionDB");
// Use datasource...
}
else
{
var error = editor.ErrorObject;
Console.WriteLine($"Failed: {error.Message}");
}
File Connection
var fileProps = new ConnectionProperties
{
ConnectionName = "CSVData",
ConnectionString = "./data/",
FileName = "export_2024.csv",
DatabaseType = DataSourceType.Csv,
Category = DatasourceCategory.FileBased
};
editor.ConfigEditor.AddDataConnection(fileProps);
var fileDs = editor.GetDataSource("CSVData");
// FileConnection checks if ./data/export_2024.csv exists