BuildFeed/BuildFeed.Model/MongoConfig.cs

38 lines
957 B
C#
Raw Normal View History

2018-10-07 02:20:54 +08:00
namespace BuildFeed.Model
2015-08-05 19:28:16 +08:00
{
2018-10-07 02:20:54 +08:00
public class MongoConfig
2017-02-24 04:53:49 +08:00
{
2018-10-07 02:20:54 +08:00
public string Host { get; }
public int Port { get; }
public string Database { get; }
public string Username { get; }
public string Password { get; }
2015-08-05 19:28:16 +08:00
2018-10-07 02:20:54 +08:00
public MongoConfig(string host, int? port, string database, string username, string password)
2017-02-24 04:53:49 +08:00
{
2018-10-07 02:20:54 +08:00
Host = !string.IsNullOrEmpty(host)
? host
2017-02-24 04:53:49 +08:00
: "localhost";
2015-08-05 19:28:16 +08:00
2018-10-07 02:20:54 +08:00
if (!port.HasValue)
2017-02-24 04:53:49 +08:00
{
2017-04-17 18:11:45 +08:00
port = 27017; // mongo default port
2017-02-24 04:53:49 +08:00
}
2018-02-07 06:16:37 +08:00
2018-10-07 02:20:54 +08:00
Port = port.Value;
2015-08-05 19:28:16 +08:00
2018-10-07 02:20:54 +08:00
Database = !string.IsNullOrEmpty(database)
? database
2017-02-24 04:53:49 +08:00
: "MongoAuth";
2018-10-07 02:20:54 +08:00
Username = username ?? "";
Password = password ?? "";
2017-02-24 04:53:49 +08:00
}
2018-10-07 02:20:54 +08:00
public void SetupIndexes()
2017-02-24 04:53:49 +08:00
{
2018-10-07 02:20:54 +08:00
var b = new BuildRepository(this);
2017-02-24 04:53:49 +08:00
b.SetupIndexes();
}
}
2015-08-05 19:28:16 +08:00
}