/
OracleProviderConnectorOptions.cs
62 lines (44 loc) · 1.86 KB
/
OracleProviderConnectorOptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
namespace Steeltoe.Connector.Oracle;
public class OracleProviderConnectorOptions : AbstractServiceConnectorOptions
{
public const string Default_Server = "localhost";
public const int Default_Port = 1521;
private const string ORACLE_CLIENT_SECTION_PREFIX = "oracle:client";
private readonly bool _bindingsFound;
public OracleProviderConnectorOptions()
{
}
public OracleProviderConnectorOptions(IConfiguration config)
: base()
{
if (config == null)
{
throw new ArgumentNullException(nameof(config));
}
var section = config.GetSection(ORACLE_CLIENT_SECTION_PREFIX);
section.Bind(this);
_bindingsFound = config.HasCloudFoundryServiceConfigurations() || config.HasKubernetesServiceBindings();
}
public string ConnectionString { get; set; }
public string Server { get; set; } = Default_Server;
public int Port { get; set; } = Default_Port;
public string Username { get; set; }
public string Password { get; set; }
public string ServiceName { get; set; }
public int ConnectionTimeout { get; set; } = 15;
internal Dictionary<string, string> Options { get; set; } = new Dictionary<string, string>();
public override string ToString()
{
if (!string.IsNullOrEmpty(ConnectionString) && !_bindingsFound)
{
return ConnectionString;
}
return string.Format("User Id={0};Password={1};Data Source={2}:{3}/{4};Connection Timeout={5}", Username, Password, Server, Port, ServiceName, ConnectionTimeout);
}
}