mirror of
https://github.com/sebastian-heinz/mhf-server.git
synced 2025-04-03 13:28:30 +08:00
69 lines
2.0 KiB
C#
69 lines
2.0 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Runtime.Serialization;
|
|
using Mhf.Server.Common;
|
|
using Mhf.Server.Model;
|
|
|
|
namespace Mhf.Server.Setting
|
|
{
|
|
[DataContract]
|
|
public class DatabaseSetting
|
|
{
|
|
public DatabaseSetting()
|
|
{
|
|
Type = DatabaseType.SQLite;
|
|
SqLiteFolder = Path.Combine(Util.ExecutingDirectory(), "Files/Database");
|
|
Host = "localhost";
|
|
Port = 3306;
|
|
Database = "Mhf";
|
|
User = string.Empty;
|
|
Password = string.Empty;
|
|
|
|
string envDbType = Environment.GetEnvironmentVariable("DB_TYPE");
|
|
switch (envDbType)
|
|
{
|
|
case "sqlite":
|
|
Type = DatabaseType.SQLite;
|
|
break;
|
|
}
|
|
|
|
string envDbUser = Environment.GetEnvironmentVariable("DB_USER");
|
|
if (!string.IsNullOrEmpty(envDbUser))
|
|
{
|
|
User = envDbUser;
|
|
}
|
|
|
|
string envDbPass = Environment.GetEnvironmentVariable("DB_PASS");
|
|
if (!string.IsNullOrEmpty(envDbPass))
|
|
{
|
|
Password = envDbPass;
|
|
}
|
|
}
|
|
|
|
public DatabaseSetting(DatabaseSetting databaseSettings)
|
|
{
|
|
Type = databaseSettings.Type;
|
|
SqLiteFolder = databaseSettings.SqLiteFolder;
|
|
Host = databaseSettings.Host;
|
|
Port = databaseSettings.Port;
|
|
User = databaseSettings.User;
|
|
Password = databaseSettings.Password;
|
|
Database = databaseSettings.Database;
|
|
}
|
|
|
|
[DataMember(Order = 0)] public DatabaseType Type { get; set; }
|
|
|
|
[DataMember(Order = 1)] public string SqLiteFolder { get; set; }
|
|
|
|
[DataMember(Order = 2)] public string Host { get; set; }
|
|
|
|
[DataMember(Order = 3)] public short Port { get; set; }
|
|
|
|
[DataMember(Order = 4)] public string User { get; set; }
|
|
|
|
[DataMember(Order = 5)] public string Password { get; set; }
|
|
|
|
[DataMember(Order = 6)] public string Database { get; set; }
|
|
}
|
|
}
|