mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
* Uses MySQL Connector/NET from nuget * Adds SQL Server type to configuration. * Hostname for MySQL connections can include port - Format: <hostname>[:<port>] * Abstracted a bundle of stuff to be generic for both MSSQL and MySQL, including a number of variable and method names. (Mostly went from "sql..." -> "db..." * Changed MiscTools.DBDate() string building for MSSQL, uses DateTime.ToString() with a format which seemed simpler. * Unsure about which lines in .csproj are actually required, and which are auto-munged by Visual Studio. * ... This is my first C# (and VS!) work, be gentle! Signed-off-by: Mike Beattie <mike@ethernal.org>
32 lines
1.3 KiB
C#
32 lines
1.3 KiB
C#
using mRemoteNG.App;
|
|
using mRemoteNG.Security.SymmetricEncryption;
|
|
|
|
namespace mRemoteNG.Config.DatabaseConnectors
|
|
{
|
|
public class DatabaseConnectorFactory
|
|
{
|
|
public static IDatabaseConnector DatabaseConnectorFromSettings()
|
|
{
|
|
var sqlType = mRemoteNG.Settings.Default.SQLServerType;
|
|
var sqlHost = mRemoteNG.Settings.Default.SQLHost;
|
|
var sqlCatalog = mRemoteNG.Settings.Default.SQLDatabaseName;
|
|
var sqlUsername = mRemoteNG.Settings.Default.SQLUser;
|
|
var cryptographyProvider = new LegacyRijndaelCryptographyProvider();
|
|
var sqlPassword = cryptographyProvider.Decrypt(mRemoteNG.Settings.Default.SQLPass, Runtime.EncryptionKey);
|
|
|
|
return DatabaseConnector(sqlType, sqlHost, sqlCatalog, sqlUsername, sqlPassword);
|
|
}
|
|
|
|
public static IDatabaseConnector DatabaseConnector(string type, string server, string database, string username, string password)
|
|
{
|
|
switch (type)
|
|
{
|
|
case "mysql":
|
|
return new MySqlDatabaseConnector(server, database, username, password);
|
|
case "mssql":
|
|
default:
|
|
return new MSSqlDatabaseConnector(server, database, username, password);
|
|
}
|
|
}
|
|
}
|
|
} |