-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDbCredentials.cs
More file actions
104 lines (84 loc) · 3.28 KB
/
Copy pathDbCredentials.cs
File metadata and controls
104 lines (84 loc) · 3.28 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using Acme.Wattle.Testing;
using System.Diagnostics.CodeAnalysis;
namespace Acme.Wattle.Examples.Common;
/// <summary>
/// Параметры учётных записей подключения к БД.
/// </summary>
[SuppressMessage("ReSharper", "UnusedMember.Global")]
public static class DbCredentials
{
/// <summary>
/// Пример реестра Windows.
/// </summary>
public static readonly string RegistryFile = @"Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Acme\Testing]
""PostgreSqlUserID""=""postgres""
""PostgreSqlPassword""=""PostgreSqlPassword""
""SqlServerUserID""=""sa""
""SqlServerPassword""=""SqlServerPassword""
""SqlServerAdress""=""localhost""
""PostgreSqlAdress""=""localhost""
[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Acme\Testing]
""PostgreSqlUserID""=""postgres""
""PostgreSqlPassword""=""PostgreSqlPassword""
""SqlServerUserID""=""sa""
""SqlServerPassword""=""SqlServerPassword""
""SqlServerAdress""=""localhost""
""PostgreSqlAdress""=""localhost""";
/// <summary>
/// Адрес сервера с SQL Server.
/// По умолчанию адрес читается из реестра Windows;
/// Пример реестра Windows <see cref="RegistryFile"/>.
/// </summary>
public static bool TryGetServerAdressForSqlServer(out string serverAdress)
{
/*
serverAdress = "localhost";
return true;
*/
var result = WindowsRegistryHelpers.SqlServerTryGetServerAdress(out serverAdress);
return result;
}
/// <summary>
/// Адрес сервера с PostgreSQL.
/// По умолчанию адрес читается из реестра Windows;
/// Пример реестра Windows <see cref="RegistryFile"/>.
/// </summary>
public static bool TryGetServerAdressForPostgreSql(out string serverAdress)
{
/*
serverAdress = "localhost";
return true;
*/
var result = WindowsRegistryHelpers.PostgreSqlTryGetServerAdress(out serverAdress);
return result;
}
/// <summary>
/// Параметры учётной записи подключения к SQL Server.
/// По умолчанию параметры читаются из реестра Windows;
/// Пример реестра Windows <see cref="RegistryFile"/>.
/// </summary>
public static bool TryGetCredentialsForSqlServer(out (string UserName, string UserPassword) credentials)
{
/*
credentials = ("sa", "password");
return true;
*/
var result = WindowsRegistryHelpers.SqlServerTryGetUserCredentials(out credentials);
return result;
}
/// <summary>
/// Параметры учётной записи подключения к PostgreSQL.
/// По умолчанию параметры читаются из реестра Windows;
/// Пример реестра Windows <see cref="RegistryFile"/>.
/// </summary>
public static bool TryGetCredentialsForPostgreSql(out (string UserName, string UserPassword) credentials)
{
/*
credentials = ("postgres", "password");
return true;
*/
var result = WindowsRegistryHelpers.PostgreSqlTryGetUserCredentials(out credentials);
return result;
}
}