Beispiel #1
0
        public OutputHandlerBase Create(IServiceProvider serviceProvider, IConfigurationSection outputConfiguration)
        {
            var config = new SqlOutputSettings();

            outputConfiguration.Bind(config);
            Validator.ValidateObject(config, new ValidationContext(config));

            return(ActivatorUtilities.CreateInstance <SqlOutput>(serviceProvider, config));
        }
Beispiel #2
0
        public SqlOutput(SqlOutputSettings settings)
        {
            _settings       = settings;
            _connectionType = _settings.Driver switch
            {
                SqlOutputSettings.DbDriver.MySql => typeof(MySql.Data.MySqlClient.MySqlConnection),
                SqlOutputSettings.DbDriver.Postgres => typeof(Npgsql.NpgsqlConnection),
                SqlOutputSettings.DbDriver.SqlServer => typeof(System.Data.SqlClient.SqlConnection),
                _ => throw new ArgumentException("Invalid driver.", nameof(settings)),
            };
            _sqlWriter = _settings.Scheme switch
            {
                SqlOutputSettings.DbScheme.SimpleFlat => new SimpleFlatSqlWriter(),
                SqlOutputSettings.DbScheme.FullFlat => new FullFlatSqlWriter(),
                _ => throw new ArgumentException("Invalid scheme.", nameof(settings)),
            };

            if (_settings.Driver == SqlOutputSettings.DbDriver.Postgres)
            {
                // Registriert Enum-Type Mappings für Postgres
                Npgsql.NpgsqlConnection.GlobalTypeMapper.MapEnum <LogLevel>("log_level_type");
                Npgsql.NpgsqlConnection.GlobalTypeMapper.MapEnum <DbValueType>("log_value_type");
            }
        }