=============== LIBRARY RULES =============== From library maintainers: - Use LinkTo() pattern to connect dataflow components - Call Execute() on sources and Wait() on destinations to run a dataflow - Use IConnectionManager implementations for database access - Prefer generic typed components (e.g. DbSource) over non-generic variants - All dataflow components support async execution via TPL Dataflow ### Start SQL Server Docker Container Source: https://github.com/rpsft/etlbox/blob/master/docs/examples/controlflow-dataflow-basics.md Command to initialize a SQL Server instance using Docker. ```csharp docker run -d --name sql_server_demo -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=reallyStrongPwd123' -p 1433:1433 microsoft/mssql-server-linux ``` -------------------------------- ### CSV File Content Example Source: https://github.com/rpsft/etlbox/blob/master/docs/examples/across-files-databases.md An example of the expected content for the `NameList.csv` file. Ensure the file has headers and data in the correct format. ```csharp LastName,FirstName Bunny,Bugs ,Tweety Devil,Tasmanian Duck,Daffy Sylvester, Porky Pig Yosemite,Sam Fudd,Elmer ``` -------------------------------- ### Example CSV file content Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/file-sources-destinations.md Sample structure for a CSV file with a header row. ```text Row_Nr;Value 1;Test1 2;Test2 ``` -------------------------------- ### Configure Copy to Output Directory in .csproj Source: https://github.com/rpsft/etlbox/blob/master/docs/controlflow/logging.md Example of how to configure your .csproj file to ensure the nlog.config file is copied to the output directory during the build process. ```xml ... PreserveNewest ``` -------------------------------- ### Execute Data Flow Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/simple-flow.md Starts the reading process from the source. ```csharp source.Execute(); ``` -------------------------------- ### Register Custom Step and Create Reader with DI Source: https://github.com/rpsft/etlbox/blob/master/docs/changelog/TECH-DEBT-DI-ServiceProvider-Activator.md Example of registering a custom step and creating a DataFlowXmlReader with DI support using a built ServiceProvider. ```csharp // Register custom step with dependencies services.AddTransient(); services.AddSingleton(); // Create reader with DI support var serviceProvider = services.BuildServiceProvider(); var reader = new DataFlowXmlReader(dataFlow, serviceProvider: serviceProvider); ``` -------------------------------- ### Initialize SqlConnectionManager for SQL Server Source: https://github.com/rpsft/etlbox/blob/master/docs/controlflow/overview.md Example of creating a SqlConnectionManager for SQL Server. This object is used to establish connections to the database. ```csharp SqlConnectionManager connectionManager = new SqlConnectionManager("Data Source=.; Database=Sample; Integrated Security=SSPI"); ``` -------------------------------- ### Basic DBMerge Data Flow Setup Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/db-merge.md Sets up a basic data flow using DbSource and DBMerge to synchronize data between a source and destination table. Ensure 'MyMergeRow' class and 'connection' object are defined. ```csharp DbSource source = new DbSource(connection, "SourceTable"); DBMerge merge = new DBMerge(connection, "DestinationTable"); source.LinkTo(dest); source.Execute(); merge.Wait(); ``` -------------------------------- ### Example CSV Output Source: https://github.com/rpsft/etlbox/blob/master/docs/examples/across-files-databases.md This is an example of the CSV file content after exporting data with a semicolon delimiter. Note the inclusion of the 'Id' column, which corresponds to the 'Id' property in the 'NameListElement' class. ```text Id;FirstName;LastName 1;Bunny;Bugs 2;;Tweety 3;Devil;Tasmanian 4;Duck;Daffy 5;Sylvester; 6;Porky Pig; 7;Yosemite;Sam 8;Fudd;Elmer ``` -------------------------------- ### Implement CustomDestination with Action Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/other-sources-destinations.md Create a custom destination by providing an action that is executed for each incoming record. This example inserts row data into a SQL table. ```csharp CustomDestination dest = new CustomDestination( row => { SqlTask.ExecuteNonQuery(Connection, "Insert row", $"INSERT INTO dbo.CustomDestination VALUES({row.Id},'{row.Value}')"); } ); ``` -------------------------------- ### Read JSON Data with JsonSource Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/file-sources-destinations.md Example of a JSON file structure and the corresponding C# code to read it into a POCO. ```json [ { "Col1": 1, "Col2": "Test1" }, { "Col1": 2, "Col2": "Test2" }, { "Col1": 3, "Col2": "Test3" } ] ``` ```csharp public class MySimpleRow { public int Col1 { get; set; } public string Col2 { get; set; } } JsonSource source = new JsonSource("http://test.com/"); ``` -------------------------------- ### Aggregate Registration for Consumers Source: https://github.com/rpsft/etlbox/blob/master/docs/changelog/TECH-DEBT-DI-ServiceProvider-Activator.md Example of how consuming applications can aggregate multiple ETLBox package registrations into a single call. Do not include this in library packages to avoid circular dependencies. ```csharp // Example: consumers can create this in their own project public static class EtlBoxServiceCollectionExtensions { public static IServiceCollection AddEtlBox(this IServiceCollection services) { services.AddEtlBoxCore(); services.AddEtlBoxCsv(); services.AddEtlBoxJson(); services.AddEtlBoxXml(); services.AddEtlBoxSerialization(); // ... other libraries as needed return services; } } ``` -------------------------------- ### Duplicate Data with Multicast Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/transformations.md Use Multicast to duplicate incoming data to multiple destinations. This example sends data to a JSON file and a database table. ```csharp var source = new CsvSource("test.csv"); var multicast = new Multicast(); var destination1 = new JsonDestination("test.json"); var destination2 = new DbDestination("TestTable"); source.LinkTo(multicast); multicast.LinkTo(destination1); multicast.LinkTo(destination2); ``` -------------------------------- ### Execute Data Flow Source: https://github.com/rpsft/etlbox/blob/master/README.md Start the source execution and wait for all destination components to complete processing. ```C# source.Execute(); sqlDest.Wait(); csvDest.Wait(); ``` -------------------------------- ### Execute and Wait for Pipeline Source: https://github.com/rpsft/etlbox/blob/master/docs/examples/controlflow-dataflow-basics.md Starts the execution of the data source and ensures the destination completes processing all received data. ```csharp source.Execute(); dest.Wait(); ``` -------------------------------- ### Configure RowDuplication Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/transformations.md Examples for basic row duplication, specifying duplicate counts, and using predicates for conditional duplication. ```csharp DbSource source = new DbSource("SourcTable"); RowDuplication duplication = new RowDuplication(); MemoryDestination dest = new MemoryDestination(); source.LinkTo(duplication); duplication.LinkTo(dest); ``` ```csharp RowDuplication duplication = new RowDuplication(10); ``` ```csharp RowDuplication duplication = new RowDuplication( row => row.Col1 == 1 || row.Col2 == "Test" ); ``` -------------------------------- ### Synchronous Dataflow Execution Example Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/linking-execution.md Demonstrates synchronous execution of a dataflow, pausing program execution until the source is executed and the destination is waited upon. Useful for easier debugging. ```csharp //Prepare the flow DbSource source = new DbSource("SourceTable"); RowTransformation rowTrans = new RowTransformation( row => row ); DbDestination dest = new DbDestination("DestTable"); source.LinkTo(row); //Execute the source source.Execute(); //Wait for the destination dest.Wait(); ``` -------------------------------- ### Define CustomSource with Data Generation Logic Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/other-sources-destinations.md Implement a custom source by providing a function to generate data and a function to signal the end of data. This example uses a list of strings to create rows with an ID and Value. ```csharp public class MyRow { public int Id { get; set; } public string Value { get; set; } } List Data = new List() { "Test1", "Test2", "Test3" }; int _readIndex = 0; CustomSource source = new CustomSource( () => { return new MyRow() { Id = _readIndex++, Value = Data[_readIndex] }; }, () => _readIndex >= Data.Count); ``` -------------------------------- ### Configure NLog for Database Logging Source: https://github.com/rpsft/etlbox/blob/master/docs/controlflow/logging.md Extend your nlog.config file to include a Database target for logging. This requires manual setup of the logging table and defining the target and parameters. ```xml INSERT INTO etllog (LogDate, Level, Stage, Message, TaskType, TaskAction, TaskHash, Source) SELECT @LogDate, @Level, @Stage, @Message, @Type, @Action, @Hash, @Logger ``` -------------------------------- ### ETL Data Flow with ExpandoObject Transformation Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/data-types.md A data flow example using DbSource, RowTransformation, and DbDestination with ExpandoObject. It reads data, performs a sum operation on dynamic properties, and writes the result to a destination table. ```csharp DbSource source = new DbSource("sourceTable"); //Act RowTransformation trans = new RowTransformation( sourcedata => { dynamic c = sourcedata as ExpandoObject; c.DestColSum = c.SourceCol1 + c.SourceCol2; return c; }); DbDestination dest = new DbDestination("destTable"); ``` -------------------------------- ### Execute SQL and Custom Code with Logging Source: https://github.com/rpsft/etlbox/blob/master/docs/controlflow/logging.md These tasks demonstrate how ETLBox automatically logs the start and end of task executions. `SqlTask.ExecuteNonQuery` logs SQL operations, while `Sequence.Execute` logs custom code blocks. ```csharp SqlTask.ExecuteNonQuery("some sql", "Select 1 as test"); Sequence.Execute("some custom code", () => { }); ``` -------------------------------- ### ETLBox Custom Layout Renderers for NLog Source: https://github.com/rpsft/etlbox/blob/master/docs/controlflow/logging.md Examples of ETLBox-specific layout renderers that can be used within NLog's layout attribute for detailed log formatting. ```csharp //The default log message of the component or task: layout="${etllog}" ``` ```csharp //The current value defined in ControlFlow.Stage: layout="${etllog:LogType=Stage}" ``` ```csharp //The class name of the task or component that produces the log output: layout="${etllog:LogType=Type}" ``` ```csharp //A component can can produce more than on log message. //Actions can be 'START' (first log message), 'END' (component finished), 'RUN', 'LOG': layout="${etllog:LogType=Action} ``` ```csharp //The hash value of the specific task or component, derived from the type and the name layout="${etllog:LogType=Hash}" ``` ```csharp //If a load process was started, the load process id is in here layout="${etllog:LogType=LoadProcessKey}" ``` -------------------------------- ### Initialize .NET Console Project Source: https://github.com/rpsft/etlbox/blob/master/docs/examples/controlflow-dataflow-basics.md Commands to create a new .NET console application and add the ETLBox package. ```bash dotnet new console ``` ```bash dotnet add package ETLBox ``` -------------------------------- ### Create DbDestination Source: https://github.com/rpsft/etlbox/blob/master/docs/examples/controlflow-dataflow-basics.md Initializes a DbDestination to load MyData objects into a specified database table. Requires a pre-existing database connection. ```csharp DbDestination dest = new DbDestination(dbConnection, "Table1"); ``` -------------------------------- ### Create Database Task Source: https://github.com/rpsft/etlbox/blob/master/docs/examples/controlflow-dataflow-basics.md Execute a task to create a new database. ```csharp CreateDatabaseTask.Create(masterConnection, "demo"); ``` -------------------------------- ### Execute the data flow synchronously Source: https://github.com/rpsft/etlbox/blob/master/docs/examples/rating-orders.md Starts the data flow and waits for completion of the source and destination blocks. ```csharp //Execute the data flow synchronously sourceOrderData.Execute(); destOrderTable.Wait(); destRating.Wait(); ``` -------------------------------- ### Create DbDestination component Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/simple-flow.md Initializes a database destination for the Order object. ```csharp DbDestination dest = new DbDestination(connMan, "OrderTable"); ``` -------------------------------- ### Create a Postgres Connection Manager Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/db-sources-destinations.md Initializes a PostgresConnectionManager instance. ```csharp PostgresConnectionManager connectionManager = new PostgresConnectionManager("Server=10.37.128.2;Database=ETLBox_DataFlow;User Id=postgres;Password=etlboxpassword;"); ``` -------------------------------- ### Create a MySQL Connection Manager Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/db-sources-destinations.md Initializes a MySqlConnectionManager instance. ```csharp MySqlConnectionManager connectionManager = new MySqlConnectionManager("Server=10.37.128.2;Database=ETLBox_ControlFlow;Uid=etlbox;Pwd=etlboxpassword;"; ``` -------------------------------- ### Handle Nested JSON Arrays Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/file-sources-destinations.md ETLBox automatically detects the start of an array within a nested JSON structure. ```json { "data": { "array": [ { "Col1": 1, "Col2": "Test1" }, ... ] } } ``` -------------------------------- ### Initialize SqlConnectionManager Source: https://github.com/rpsft/etlbox/blob/master/docs/controlflow/overview.md Sets up a connection manager for SQL Server using a connection string. This is required before using Control Flow Tasks. ```csharp SqlConnectionManager connectionManager = new SqlConnectionManager("Data Source=.; Database=Sample; Integrated Security=SSPI"""); ``` -------------------------------- ### Track ETL Process Execution Source: https://github.com/rpsft/etlbox/blob/master/docs/controlflow/logging.md Wraps ETL tasks to record start, success, or failure states in the load process table. ```csharp StartLoadProcessTask.Start("Process 1", "Starting process"); try { /* ... some tasks or data flow */ EndLoadProcessTask.End("The process ended successfully"); } catch (Exception e) { AbortLoadProcessTask.Abort(e.ToString()); } ``` -------------------------------- ### Create a SQL Server Connection Manager Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/db-sources-destinations.md Initializes a DbSource using a SqlConnectionManager with a raw connection string. ```csharp DbSource source = DbSource ( new SqlConnectionManager("Data Source=.;Integrated Security=SSPI;Initial Catalog=ETLBox;") , "SourceTable" ); ``` -------------------------------- ### Create a SQLite Connection Manager Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/db-sources-destinations.md Initializes a SQLiteConnectionManager instance. ```csharp SQLiteConnectionManager connectionManager = new SQLiteConnectionManager("Data Source=.\\db\\SQLiteControlFlow.db;Version=3;"); ``` -------------------------------- ### Create Load Process Table Source: https://github.com/rpsft/etlbox/blob/master/docs/controlflow/logging.md Initializes the default load process table in the database. ```csharp CreateLoadProcessTableTask.Create(connection); ``` -------------------------------- ### Create ETLBox Log Table and Configure NLog Source: https://github.com/rpsft/etlbox/blob/master/docs/controlflow/logging.md Use these tasks to automatically create the necessary logging table in your database and configure NLog to use it. Ensure you have a SqlConnectionManager instance pointing to your database. ```csharp var SqlConnectionManager connection = new SqlConnectionManager("Data Source=.;Integrated Security=SSPI;Initial Catalog=ETLBox_Logging"); CreateLogTableTask.Create(connection); ControlFlow.AddLoggingDatabaseToConfig(connection); ``` -------------------------------- ### Use task instances Source: https://github.com/rpsft/etlbox/blob/master/docs/controlflow/overview.md Create task instances directly when static accessors do not provide the required functionality. ```csharp RowCountTask task = new RowCountTask("demotable"); int count = task.Count().Rows; ``` -------------------------------- ### Configure a basic CsvSource Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/file-sources-destinations.md Initializes a CsvSource with custom delimiter and blank line handling. ```csharp CsvSource source = new CsvSource("Demo.csv"); source.Configuration.Delimiter = ";"; source.Configuration.IgnoreBlankLines = true; ``` -------------------------------- ### Define and Create Database Tables with ETLBox Source: https://github.com/rpsft/etlbox/blob/master/docs/examples/rating-orders.md Use ETLBox TableDefinition to define schema for 'orders', 'customer', and 'customer_rating' tables. Includes creating tables and inserting initial data into the 'customer' table. ```csharp ControlFlow.DefaultDbConnection = new SqlConnectionManager("Data Source=.;Initial Catalog=demo;Integrated Security=false;User=sa;password=YourStrong@Passw0rd"); TableDefinition OrderDataTableDef = new TableDefinition("orders", new List() { new TableColumn("Key", "int",allowNulls: false, isPrimaryKey:true, isIdentity:true), new TableColumn("Number","nvarchar(100)", allowNulls: false), new TableColumn("Item","nvarchar(200)", allowNulls: false), new TableColumn("Amount","money", allowNulls: false), new TableColumn("CustomerKey","int", allowNulls: false) }); TableDefinition CustomerTableDef = new TableDefinition("customer", new List() { new TableColumn("Key", "int",allowNulls: false, isPrimaryKey:true, isIdentity:true), new TableColumn("Name","nvarchar(200)", allowNulls: false), }); TableDefinition CustomerRatingTableDef = new TableDefinition("customer_rating", new List() { new TableColumn("Key", "int",allowNulls: false, isPrimaryKey:true, isIdentity:true), new TableColumn("CustomerKey", "int",allowNulls: false), new TableColumn("TotalAmount","decimal(10,2)", allowNulls: false), new TableColumn("Rating","nvarchar(3)", allowNulls: false) }); //Create demo tables & fill with demo data OrderDataTableDef.CreateTable(); CustomerTableDef.CreateTable(); CustomerRatingTableDef.CreateTable(); SqlTask.ExecuteNonQuery("Fill customer table", "INSERT INTO customer values('Sandra Kettler')"); SqlTask.ExecuteNonQuery("Fill customer table", "INSERT INTO customer values('Nick Thiemann')"); SqlTask.ExecuteNonQuery("Fill customer table", "INSERT INTO customer values('Zoe Rehbein')"); SqlTask.ExecuteNonQuery("Fill customer table", "INSERT INTO customer values('Margit Gries')"); ``` -------------------------------- ### Create Database Table Source: https://github.com/rpsft/etlbox/blob/master/docs/examples/controlflow-dataflow-basics.md Define a connection to the target database and create a table with specific columns. ```csharp var dbConnection = new SqlConnectionManager("Data Source=.;Initial Catalog=demo;Integrated Security=false;User=sa;password=reallyStrongPwd123"); CreateTableTask.Create(dbConnection, "Table1", new List() { new TableColumn("ID","INT",allowNulls:false, isPrimaryKey:true, isIdentity:true), new TableColumn("Col1","NVARCHAR(100)",allowNulls:true), new TableColumn("Col2","SMALLINT",allowNulls:true) }); ``` -------------------------------- ### NLog Configuration for File Logging Source: https://github.com/rpsft/etlbox/blob/master/docs/controlflow/logging.md An nlog.config setup for logging to files. It creates a 'logs' directory and separates log entries into files based on their log level, using custom ETLBox layout renderers. ```xml ``` -------------------------------- ### Create an ODBC Connection Manager Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/db-sources-destinations.md Initializes a DbSource using an SqlODBCConnectionManager for SQL Server or Access. ```csharp DbSource source = DbSource ( new SqlODBCConnectionManager("Driver={SQL Server};Server=.;Database=ETLBox_ControlFlow;Trusted_Connection=Yes"), "SourceTable" ); ``` -------------------------------- ### Create Data Flow Components in C# Source: https://github.com/rpsft/etlbox/blob/master/docs/overview.md Initializes connection managers and defines source, transformation, and destination components for a data flow pipeline. Requires connection strings for MySql and Sql Server. ```csharp var sourceCon = new MySqlConnectionManager("Server=10.37.128.2;Database=ETLBox_ControlFlow;Uid=etlbox;Pwd=etlboxpassword;"); var destCon = new SqlConnectionManager("Data Source=.;Integrated Security=SSPI;Initial Catalog=ETLBox;"); DbSource source = new DbSource(sourceCon, "SourceTable"); RowTransformation rowTrans = new RowTransformation( row => { row.Value += 1; return row; }); Multicast multicast = new Multicast(); DbDestination sqlDest = new DbDestination(destCon, "DestinationTable"); CsvDestination csvDest = new CsvDestination("example.csv"); ``` -------------------------------- ### Configure CSV Source and Database Destination Source: https://github.com/rpsft/etlbox/blob/master/docs/examples/across-files-databases.md Sets up the components for reading data from a CSV file and writing it to a database table. The `NameList.csv` file must exist in the output directory. ```csharp //Import CSV CsvSource sourceCSV = new CsvSource("NameList.csv"); DbDestination importDest = new DbDestination(conMan, "NameTable"); ``` -------------------------------- ### Execute Data Flow Source: https://github.com/rpsft/etlbox/blob/master/docs/examples/across-files-databases.md Links the CSV source to the database destination and executes the data flow. `Execute()` starts the process, and `Wait()` ensures all data is written before the program continues. For asynchronous operations, consider `ExecuteAsync()` and `Completion()`. ```csharp sourceCSV.LinkTo(importDest); sourceCSV.Execute(); importDest.Wait(); ``` -------------------------------- ### Execute Control Flow Tasks in C# Source: https://github.com/rpsft/etlbox/blob/master/README.md Demonstrates common database operations like executing SQL, counting rows, and creating tables using ETLBox tasks. ```C# var conn = new SqlConnectionManager("Server=10.37.128.2;Database=ETLBox_ControlFlow;Uid=etlbox;Pwd=etlboxpassword;"); //Execute some Sql SqlTask.ExecuteNonQuery(conn, "Do some sql",$@"EXEC myProc"); //Count rows int count = RowCountTask.Count(conn, "demo.table1").Value; //Create a table (works on all databases) CreateTableTask.Create(conn, "Table1", new List() { new TableColumn(name:"key",dataType:"INT",allowNulls:false,isPrimaryKey:true, isIdentity:true), new TableColumn(name:"value", dataType:"NVARCHAR(100)",allowNulls:true) }); ``` -------------------------------- ### Implement Concrete Class DI Constructors Source: https://github.com/rpsft/etlbox/blob/master/docs/changelog/TECH-DEBT-DI-ServiceProvider-Activator.md Demonstrates how concrete classes accept ILogger for DI resolution while maintaining backward compatibility with parameterless constructors. ```csharp public class DbSource : DataFlowSource { // Existing parameterless constructor (backward compatibility) public DbSource() : this(logger: null) { } // Existing constructors chain to the logger-accepting one public DbSource(string tableName) : this(logger: null) { TableName = tableName; } // New: DI-resolved constructor public DbSource(ILogger>? logger) : base(logger) { } public DbSource(IConnectionManager connectionManager, ILogger>? logger = null) : base(logger) { ConnectionManager = connectionManager; } } ``` -------------------------------- ### Basic NLog Configuration for Console Logging Source: https://github.com/rpsft/etlbox/blob/master/docs/controlflow/logging.md A minimal nlog.config file to enable logging to the console. Ensure this file is in your project's root and set to copy to the output directory. ```xml ``` -------------------------------- ### Configure ETL Data Flow Source: https://github.com/rpsft/etlbox/blob/master/docs/examples/across-files-databases.md Sets up an ETL data flow pipeline using ETLBox, including a PostgreSQL source, a row transformation to create a FullName, and a SQL Server destination. ```csharp PostgresConnectionManager postgresConMan = new PostgresConnectionManager(PostgresConnectionString); SqlConnectionManager sqlConMan = new SqlConnectionManager(SqlServerConnectionString); DbSource source = new DbSource(postgresConMan, "NameTable"); RowTransformation trans = new RowTransformation( row => { row.FullName = row.LastName + "," + row.FirstName; return row; }) ; DbDestination dest = new DbDestination(sqlConMan, "FullNameTable"); //Linking the components source.LinkTo(trans); trans.LinkTo(dest); ``` -------------------------------- ### Implement custom logic with ColumnMap Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/data-types.md Shows how to use ColumnMap with custom getters and setters for data transformation during read/write operations. ```csharp [ColumnMap("Id")] public string Key { get { return _key; set { _key = value.ToString(); } public int _key; ``` ```csharp [ColumnMap("Hash")] public string HashValue => HashHelper.Encrypt_Char40(this.Key); ``` -------------------------------- ### Create SqlConnectionManager Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/simple-flow.md Configures a connection manager for SQL Server databases. ```csharp SqlConnectionManager connMan = new SqlConnectionManager("Data Source=.;Initial Catalog=demo;Integrated Security=false;User=sa;password=reallyStrongPwd123"); ``` -------------------------------- ### Initialize DbSource with SQL Statement Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/db-sources-destinations.md Initialize a DbSource component by providing a custom SQL query to retrieve data. This allows for more complex data selection criteria. ```csharp DbSource source = new DbSource() { Sql = "SELECT * FROM SourceTable" }; ``` -------------------------------- ### Establish Postgres Connection Source: https://github.com/rpsft/etlbox/blob/master/docs/examples/across-files-databases.md Defines the connection string for a Postgres database and creates a connection manager. Ensure the connection string details are accurate for your environment. ```csharp string PostgresConnectionString = @"Server=.;Database=demodataflow;User Id=postgres;Password=etlboxpassword;"; PostgresConnectionManager conMan = new PostgresConnectionManager(PostgresConnectionString); ``` -------------------------------- ### Execute full ETL pipeline for web service Source: https://github.com/rpsft/etlbox/blob/master/docs/examples/web-services.md Links a web service source to a memory destination and executes the data flow. ```csharp JsonSource source = new JsonSource("https://jsonplaceholder.typicode.com/todos"); MemoryDestination dest = new MemoryDestination(200); source.LinkTo(dest); source.Execute(); dest.Wait(); //dest.Data will now contain all items from the web service ``` -------------------------------- ### Manage Database Views Source: https://github.com/rpsft/etlbox/blob/master/docs/controlflow/overview.md Create, alter, or drop database views. ```csharp CreateViewTask.CreateOrAlter(connectionManager, "View1", "SELECT 1 AS Test"); ``` ```csharp DropViewTask.Drop(connectionManager, "viewname"); DropViewTask.DropIfExists(connectionManager, "viewname"); ``` -------------------------------- ### Initialize DbSource with Table Name Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/db-sources-destinations.md Use this to initialize a DbSource component by passing the table name directly. It utilizes the default connection manager. ```csharp DbSource source = new DbSource("SourceTable"); ``` -------------------------------- ### Create Database Tables Source: https://github.com/rpsft/etlbox/blob/master/docs/controlflow/overview.md Use CreateTableTask to define and create tables. You can pass either a list of columns or a TableDefinition object. ```csharp List columns = new List() { new TableColumn("Id", "INT",allowNulls:false,isPrimaryKey:true, isIdentity: true), new TableColumn("value2", "DATE", allowNulls:true), new TableColumn("value3", "DECIMAL(10,2)",allowNulls:false) { DefaultValue = "3.12" }, new TableColumn("compValue", "BIGINT",allowNulls:true) { ComputedColumn = "(value1 * value2)" } }; CreateTableTask.Create(connectionManager, "tablename", columns); ``` ```csharp TableDefinition CustomerTableDef = new TableDefinition("customer", new List() { new TableColumn("CustomerKey", "int",allowNulls: false, isPrimaryKey:true, isIdentity:true), new TableColumn("Name","nvarchar(200)", allowNulls: false), }); CreateTableTask.Create(connectionManager, CustomerTableDef); ``` -------------------------------- ### Create CsvSource component Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/simple-flow.md Initializes a CSV source to read data from a file. ```csharp CsvSource source = new CsvSource("demodata.csv"); ``` -------------------------------- ### Basic DbSource to DbDestination Data Transfer Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/db-sources-destinations.md Demonstrates a basic ETL process where data is extracted from a source table and loaded into a destination table using DbSource and DbDestination components. ```csharp DbSource source = new DbSource("SourceTable"); DbDestination dest = new DbDestination("DestinationTable"); //Link everything together source.LinkTo(dest); //Start the data flow source.Execute(); dest.Wait() ``` -------------------------------- ### Route data with predicates and Multicast Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/linking-execution.md Use predicates to conditionally route data to different destinations, utilizing Multicast to send data to multiple targets. ```csharp source.LinkTo(multicast); multicast.LinkTo(dest1, row => row.Value2 <= 2); multicast.LinkTo(dest2, row => row.Value2 > 2); source.Execute(); dest1.Wait(); dest2.Wait(); ``` -------------------------------- ### Manage Databases Source: https://github.com/rpsft/etlbox/blob/master/docs/controlflow/overview.md Create, drop, or check for the existence of databases (not supported in SQLite). ```csharp //Create a database CreateDatabaseTask.CreateOrAlter(connectionManager, "DBName"); //Drop a database DropDatabaseTask.DropIfExists(connectionManager, "DBName"); //Check if a database exists bool exists = IfDatabaseExistsTask.IsExisting(connectionManager, "DBName"); ``` -------------------------------- ### Implement Library-Specific Service Extensions Source: https://github.com/rpsft/etlbox/blob/master/docs/changelog/TECH-DEBT-DI-ServiceProvider-Activator.md Provides modular registration methods for specific ETLBox packages like CSV, JSON, XML, and Serialization. ```csharp // ETLBox.Csv public static class EtlBoxCsvServiceCollectionExtensions { public static IServiceCollection AddEtlBoxCsv(this IServiceCollection services) { services.AddTransient>(); services.AddTransient>(); return services; } } // ETLBox.Json public static class EtlBoxJsonServiceCollectionExtensions { public static IServiceCollection AddEtlBoxJson(this IServiceCollection services) { services.AddTransient>(); services.AddTransient>(); return services; } } // ETLBox.Xml public static class EtlBoxXmlServiceCollectionExtensions { public static IServiceCollection AddEtlBoxXml(this IServiceCollection services) { services.AddTransient>(); services.AddTransient>(); return services; } } // ETLBox.Serialization public static class EtlBoxSerializationServiceCollectionExtensions { public static IServiceCollection AddEtlBoxSerialization(this IServiceCollection services) { services.AddTransient(); return services; } } ``` -------------------------------- ### Configure CSV Source Source: https://github.com/rpsft/etlbox/blob/master/docs/examples/rating-orders.md Initializes a CsvSource to read data from a file with a specified delimiter. ```csharp //Read data from csv file CsvSource sourceOrderData = new CsvSource("DemoData.csv"); sourceOrderData.Configuration.Delimiter = ";"; ``` -------------------------------- ### Retrieve Logs and Load Processes as JSON Source: https://github.com/rpsft/etlbox/blob/master/docs/controlflow/logging.md Fetches the contents of the load process or log tables formatted as JSON strings. ```csharp var jsonLoadProcesses = GetLoadProcessAsJSONTask.GetJSON(); var jsonLog = GetLogAsJSONTask.GetJSON(); ``` -------------------------------- ### Manage Database Indexes Source: https://github.com/rpsft/etlbox/blob/master/docs/controlflow/overview.md Create, drop, or check for the existence of indexes. ```csharp //Create an index CreateIndexTask.CreateOrRecreate(connection, "indexname", "tablename", new List() { "index_column_1", "index_column_1" }); //Drop an index DropIndexTask.DropIfExists(connectionManager, "indexname", "tablename"); //Check if an index exists bool exists = IfIndexExistsTask.IsExisting(connectionManager, "indexname", "tablename"); ``` -------------------------------- ### Custom Data Flow Step with Constructor Injection Source: https://github.com/rpsft/etlbox/blob/master/docs/changelog/TECH-DEBT-DI-ServiceProvider-Activator.md Demonstrates a custom data flow source class that utilizes constructor injection for its dependencies. ```csharp // Custom step with constructor injection public class MyCustomSource : DataFlowSource { private readonly IMyService _myService; public MyCustomSource(IMyService myService) { _myService = myService; } } ``` -------------------------------- ### Implement LookupTransformation with Attributes Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/transformations.md Uses MatchColumn and RetrieveColumn attributes to map lookup data to input rows. ```csharp public class LookupData { [MatchColumn("LookupId")] public int Id { get; set; } [RetrieveColumn("LookupValue")] public string Value { get; set; } } public class InputDataRow { public int LookupId { get; set; } public string LookupValue { get; set; } } MemorySource source = new MemorySource(); source.Data.Add(new InputDataRow() { LookupId = 1 }); MemorySource lookupSource = new MemorySource(); lookupSource.Data.Add(new LookupData() { Id = 1, Value = "Test1" }); var lookup = new LookupTransformation(); lookup.Source = lookupSource; MemoryDestination dest = new MemoryDestination(); source.LinkTo(lookup); lookup.LinkTo(dest); ``` -------------------------------- ### Manage Database Schemas Source: https://github.com/rpsft/etlbox/blob/master/docs/controlflow/overview.md Create, drop, or check for the existence of schemas in SQL Server or Postgres. ```csharp //Create a schema CreateSchemaTask.CreateOrAlter(connectionManager, "SchemaName"); //Drop a schema DropSchemaTask.DropIfExists(connectionManager, "SchemaName"); //Check if a schema exists bool exists = IfSchemaExistsTask.IsExisting(connectionManager, "SchemaName"); ``` -------------------------------- ### Create and Assign Property to ExpandoObject Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/data-types.md Demonstrates how to create an ExpandoObject and assign a dynamic property to it. This object can be used with ETLBox for flexible data handling. ```csharp dynamic sampleObject = new ExpandoObject(); sampleObject.test = "Dynamic Property"; ///Sample object now has a property "test" of type string with the value "Dynamic Property" ``` -------------------------------- ### Configure and Execute CSV Export Source: https://github.com/rpsft/etlbox/blob/master/docs/examples/across-files-databases.md Set up ETLBox components to export data from a database to a CSV file. This includes creating source and destination objects, linking them, and executing the data flow. Customize CSV delimiters via the configuration object. ```csharp DbSource sourceTable = new DbSource(conMan, "NameTable"); CsvDestination destCSV = new CsvDestination("Export.csv"); destCSV.Configuration.Delimiter = ";"; sourceTable.LinkTo(destCSV); sourceTable.Execute(); destCSV.Wait(); ``` -------------------------------- ### Use Connection String Wrapper Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/db-sources-destinations.md Wraps raw connection strings in a ConnectionString object to access additional helper methods like GetMasterConnection. ```csharp SqlConnectionString etlboxConnString = new SqlConnectionString("Data Source=.;Integrated Security=SSPI;Initial Catalog=ETLBox;"); SqlConnectionString masterConnString = etlboxConnString.GetMasterConnection(); //masterConnString is equal to "Data Source=.;Integrated Security=SSPI;" SqlConnectionManager conectionToMaster = new SqlConnectionManager(masterConnString); ``` -------------------------------- ### Write data to JSON file Source: https://github.com/rpsft/etlbox/blob/master/docs/examples/web-services.md Initializes a JsonDestination to output data flow records into a JSON file. ```csharp JsonDestination dest = new JsonDestination("file.json"); ``` -------------------------------- ### Create an Aggregation block Source: https://github.com/rpsft/etlbox/blob/master/docs/examples/rating-orders.md Initializes an Aggregation transformation and links it to a preceding multicast block. ```csharp //Create rating for existing customers based total of order amount Aggregation aggregation = new Aggregation(); multiCast.LinkTo(aggregation); ``` -------------------------------- ### Define SQL Connection Manager Source: https://github.com/rpsft/etlbox/blob/master/docs/examples/controlflow-dataflow-basics.md Instantiate a connection manager using a SQL Server connection string. ```csharp var masterConnection = new SqlConnectionManager("Data Source=.;Integrated Security=false;User=sa;password=reallyStrongPwd123"); ``` -------------------------------- ### Manage Table Lifecycle Source: https://github.com/rpsft/etlbox/blob/master/docs/controlflow/overview.md Tasks for dropping tables and checking their existence. ```csharp DropTableTask.Drop(connectionManager, "DropTableTest"); DropTableTask.DropIfExists(connectionManager, "DropTableTest"); ``` ```csharp bool exists = IfTableOrViewExistsTask.IsExisting(connectionManager, "tablename"); ``` -------------------------------- ### Current DataFlowXmlReader Instance Creation Source: https://github.com/rpsft/etlbox/blob/master/docs/changelog/TECH-DEBT-DI-ServiceProvider-Activator.md Shows the current method of creating instances within DataFlowXmlReader using DataFlowActivator. ```csharp var list = DataFlowActivator.CreateInstance(type); ``` ```csharp var instance = DataFlowActivator.CreateInstance(type); ``` -------------------------------- ### Store Data in Destination Source: https://github.com/rpsft/etlbox/blob/master/docs/examples/rating-orders.md Connects the multicast output to a database destination for storage. ```csharp //Store Order in Orders table DbDestination destOrderTable = new DbDestination("orders"); multiCast.LinkTo(destOrderTable); ``` -------------------------------- ### Clone ETLBox Repository Source: https://github.com/rpsft/etlbox/blob/master/README.md Command to clone the ETLBox source code repository from GitHub. ```bash git clone https://github.com/rpsft/etlbox.git ``` -------------------------------- ### Retrieve master connection string Source: https://github.com/rpsft/etlbox/blob/master/docs/controlflow/overview.md Use the ConnectionString-Wrapper to obtain a connection without a specific catalog, useful for database creation tasks. ```csharp PostgresConnectionString conStringWrapper = new PostgresConnectionString("Server=10.37.128.2;Database=ETLBox_DataFlow;User Id=postgres;Password=etlboxpassword;"); PostgresConnectionString connectionWithoutCatalog = conStringWrapper.GetMasterConnection(); PostgresConnectionManager connectionManager = new PostgresConnectionManager(connectionWithoutCatalog); ``` -------------------------------- ### Write XML with Custom Row Class Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/file-sources-destinations.md Instantiate XmlDestination with a custom row class to serialize data into an XML file based on the defined structure and attributes. ```csharp XmlDestination dest = new XmlDestination("dest.xml", ResourceType.File); ``` -------------------------------- ### Convert collection assertions Source: https://github.com/rpsft/etlbox/blob/master/docs/changelog/TECH-DEBT-Eliminate-FluentAssertions.md Maps collection size and content checks to xUnit Assert methods. ```csharp // BEFORE list.Should().HaveCount(5); list.Should().NotBeEmpty(); list.Should().HaveCountGreaterThan(0); list.Should().ContainEquivalentOf(expectedItem); // AFTER Assert.Equal(5, list.Count); Assert.NotEmpty(list); Assert.NotEmpty(list); Assert.Contains(list, item => /* equivalence check */); ``` -------------------------------- ### Configure NLog Source: https://github.com/rpsft/etlbox/blob/master/docs/examples/controlflow-dataflow-basics.md XML configuration for NLog to enable debug logging to the console. ```csharp ``` -------------------------------- ### Convert simple value assertions Source: https://github.com/rpsft/etlbox/blob/master/docs/changelog/TECH-DEBT-Eliminate-FluentAssertions.md Maps basic FluentAssertions value checks to xUnit Assert methods. ```csharp // BEFORE (FluentAssertions) result.Should().Be(42); result.Should().NotBe(0); result.Should().BeTrue(); result.Should().BeFalse(); result.Should().BeNull(); result.Should().NotBeNull(); // AFTER (xUnit Assert) Assert.Equal(42, result); Assert.NotEqual(0, result); Assert.True(result); Assert.False(result); Assert.Null(result); Assert.NotNull(result); ``` -------------------------------- ### Create CsvSource Source: https://github.com/rpsft/etlbox/blob/master/docs/examples/controlflow-dataflow-basics.md Initializes a CsvSource to read data from a specified CSV file. ```csharp CsvSource source = new CsvSource("input.csv"); ``` -------------------------------- ### Use fluent notation for linking Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/linking-execution.md Chained notation for linking components, which is not compatible with Multicast or MergeJoin components. ```csharp //Link the components source.LinkTo(row).LinkTo(dest); ``` ```csharp source.LinkTo(row).LinkTo(dest) ``` -------------------------------- ### RowCount with ADO.NET Source: https://github.com/rpsft/etlbox/blob/master/docs/controlflow/overview.md Classic ADO.NET code to establish a connection and count rows in a table. Requires manual connection management and SQL execution. ```csharp string connectionString = "Data Source=.; Database=Sample; Integrated Security=SSPI"; using (SqlConnection con = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand("select count(*) from demotable", con); con.Open(); int numrows = (int)cmd.ExecuteScalar(); } ``` -------------------------------- ### Write CSV Data with CsvDestination Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/file-sources-destinations.md Defines a POCO class with CsvHelper attributes and initializes a CsvDestination. ```csharp public class MySimpleRow { [Name("Header1")] [Index(1)] public int Col1 { get; set; } [Name("Header2")] [Index(2)] public string Col2 { get; set; } } CsvDestination dest = new CsvDestination("./SimpleWithObject.csv"); ``` ```csharp Header1,Header2 1,Test1 2,Test2 3,Test3 ``` -------------------------------- ### Map SQL statement columns to POCO properties Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/data-types.md Illustrates mapping columns from a custom SQL query to POCO properties using aliases. ```csharp //Prepare table SqlTask.ExecuteNonQuery(@"CREATE TABLE demotable ( Value1 INT NULL, Value2 VARCHAR(100) NULL )"); public class MyNewRow { public int Value1 { get; set; } public string AnotherValue { get; set } } DbSource source = new DbSource() { Sql = "SELECT Value1, Value2 AS AnotherValue FROM demotable" }; ``` -------------------------------- ### Convert dictionary assertions Source: https://github.com/rpsft/etlbox/blob/master/docs/changelog/TECH-DEBT-Eliminate-FluentAssertions.md Maps dictionary key existence checks to xUnit Assert methods. ```csharp // BEFORE dict.Should().ContainKey("key"); dict.Should().NotContainKey("key"); // AFTER Assert.True(dict.ContainsKey("key")); Assert.False(dict.ContainsKey("key")); // or Assert.Contains("key", (IDictionary)dict); Assert.DoesNotContain("key", (IDictionary)dict); ``` -------------------------------- ### Basic ExcelSource Usage Source: https://github.com/rpsft/etlbox/blob/master/docs/dataflow/file-sources-destinations.md Use this to load data from an Excel file into a strongly-typed object when the first row contains headers. ```csharp public class ExcelData { public string Col1 { get; set; } public int Col2 { get; set; } } ExcelSource source = new ExcelSource ("src/DataFlow/ExcelDataFile.xlsx"); ```