internal readonly int CompressionBlockSize = 1024 * 8; // Maybe it should be configurable internal ClickHouseConnectionSettings(ClickHouseConnectionStringBuilder builder) { if (string.IsNullOrWhiteSpace(builder.Host)) { throw new ArgumentException("The host is not defined.", nameof(builder)); } if (builder.BufferSize <= 0) { throw new ArgumentException("The size of the buffer must be a positive number.", nameof(builder)); } Host = builder.Host; Port = builder.Port; User = builder.User; Password = string.IsNullOrEmpty(builder.Password) ? null : builder.Password; Database = string.IsNullOrEmpty(builder.Database) ? null : builder.Database; ReadWriteTimeout = builder.ReadWriteTimeout; BufferSize = builder.BufferSize; ClientName = builder.ClientName; ClientVersion = builder.ClientVersion; Compress = builder.Compress; CommandTimeout = builder.CommandTimeout; TlsMode = builder.TlsMode; RootCertificate = builder.RootCertificate; ServerCertificateHash = ParseHashString(builder.ServerCertificateHash); ParametersMode = builder.ParametersMode; }
/// <summary> /// Initializes a new instance of <see cref="ClickHouseConnection"/> with the settings. /// </summary> /// <param name="stringBuilder">The connection string builder which will be used for building the connection settings.</param> /// <param name="typeInfoProvider">Optional parameter. The provider of types for the connection. If the value is not specified the default type provider (<see cref="DefaultTypeInfoProvider.Instance"/>) will be used.</param> public ClickHouseConnection(ClickHouseConnectionStringBuilder stringBuilder, IClickHouseTypeInfoProvider?typeInfoProvider) { if (stringBuilder == null) { throw new ArgumentNullException(nameof(stringBuilder)); } var connectionSettings = stringBuilder.BuildSettings(); _connectionState = new ClickHouseConnectionState(ConnectionState.Closed, null, connectionSettings, 0); _typeInfoProvider = typeInfoProvider; }
private static (ClickHouseConnectionSettings settings, string connectionString) GetConnectionSettingsInternal(Action <ClickHouseConnectionStringBuilder>?updateSettings) { const string envVariableName = "CLICKHOUSE_TEST_CONNECTION"; const string configFileName = "clickHouse.dbconfig"; const string conStrExample = "host=clickhouse.example.com; port=9000; user=default;"; var configTextFromEnvVar = Environment.GetEnvironmentVariable(envVariableName); if (configTextFromEnvVar != null) { try { var builder = new ClickHouseConnectionStringBuilder(configTextFromEnvVar); updateSettings?.Invoke(builder); return(builder.BuildSettings(), configTextFromEnvVar); } catch (Exception ex) { throw new InvalidOperationException($"The connection string from the environment variable '{envVariableName}' is not valid. Connection string example: '{conStrExample}'. {ex.Message}", ex); } } string configPath = Path.Combine(AppContext.BaseDirectory, configFileName); if (!File.Exists(configPath)) { throw new InvalidOperationException( "The connection string is required. " + $"Please, set the environment variable '{envVariableName}' or write the connection string to the file '{configFileName}'. " + $"Connection string example: '{conStrExample}'."); } string configText = File.ReadAllText(configPath); try { var builder = new ClickHouseConnectionStringBuilder(configText); updateSettings?.Invoke(builder); return(builder.BuildSettings(), configText); } catch (Exception ex) { throw new InvalidOperationException($"The connection string from the file '{configFileName}' is not valid. Connection string example: '{conStrExample}'. {ex.Message}", ex); } }
public static ClickHouseConnectionSettings GetConnectionSettings() { const string configFileName = "clickHouse.dbconfig"; const string conStrExample = "host=domain.com; port=9000; user=default;"; string configPath = Path.Combine(AppContext.BaseDirectory, configFileName); if (!File.Exists(configPath)) { throw new FileNotFoundException($"File '{configFileName}' not found. This file is required. It should contain the connection string. Connection string example: '{conStrExample}'."); } string configText = File.ReadAllText(configPath); try { var builder = new ClickHouseConnectionStringBuilder(configText); return(builder.BuildSettings()); } catch (Exception ex) { throw new InvalidOperationException($"The connection string from the file '{configFileName}' is not valid. Connection string example: {ex.Message}", ex); } }
internal readonly int CompressionBlockSize = 1024 * 8; // Maybe it should be configurable internal ClickHouseConnectionSettings(ClickHouseConnectionStringBuilder builder) { if (string.IsNullOrWhiteSpace(builder.Host)) { throw new ArgumentException("The host is not defined.", nameof(builder)); } if (builder.BufferSize <= 0) { throw new ArgumentException("The size of the buffer must be a positive number.", nameof(builder)); } Host = builder.Host; Port = builder.Port; User = builder.User; Password = builder.Password; Database = builder.Database; ReadWriteTimeout = builder.ReadWriteTimeout; BufferSize = builder.BufferSize; ClientName = builder.ClientName; ClientVersion = builder.ClientVersion; Compress = builder.Compress; CommandTimeout = builder.CommandTimeout; }
/// <summary> /// Initializes a new instance of <see cref="ClickHouseConnection"/> with the settings and the default type provider. /// </summary> /// <param name="stringBuilder">The connection string builder which will be used for building the connection settings.</param> public ClickHouseConnection(ClickHouseConnectionStringBuilder stringBuilder) : this(stringBuilder, null) { }