BuildFeed/BuildFeed.Model/MongoConfig.cs

42 lines
1.3 KiB
C#
Raw Permalink Normal View History

2016-08-19 13:45:52 +01:00
using System.Configuration;
2015-08-05 12:28:16 +01:00
namespace BuildFeed.Model
2015-08-05 12:28:16 +01:00
{
2017-02-23 20:53:49 +00:00
public static class MongoConfig
{
public static string Host { get; }
public static int Port { get; }
public static string Database { get; }
public static string Username { get; }
public static string Password { get; }
2015-08-05 12:28:16 +01:00
2017-02-23 20:53:49 +00:00
static MongoConfig()
{
Host = !string.IsNullOrEmpty(ConfigurationManager.AppSettings["data:MongoHost"])
? ConfigurationManager.AppSettings["data:MongoHost"]
: "localhost";
2015-08-05 12:28:16 +01:00
2017-04-17 11:11:45 +01:00
bool success = int.TryParse(ConfigurationManager.AppSettings["data:MongoPort"], out int port);
2017-02-23 20:53:49 +00:00
if (!success)
{
2017-04-17 11:11:45 +01:00
port = 27017; // mongo default port
2017-02-23 20:53:49 +00:00
}
2017-04-17 11:11:45 +01:00
Port = port;
2015-08-05 12:28:16 +01:00
2017-02-23 20:53:49 +00:00
Database = !string.IsNullOrEmpty(ConfigurationManager.AppSettings["data:MongoDB"])
? ConfigurationManager.AppSettings["data:MongoDB"]
: "MongoAuth";
2017-02-23 20:53:49 +00:00
Username = ConfigurationManager.AppSettings["data:MongoUser"] ?? "";
Password = ConfigurationManager.AppSettings["data:MongoPass"] ?? "";
}
2017-02-23 20:53:49 +00:00
public static void SetupIndexes()
{
BuildRepository b = new BuildRepository();
2017-04-17 11:11:45 +01:00
#pragma warning disable 4014
2017-02-23 20:53:49 +00:00
b.SetupIndexes();
2017-04-17 11:11:45 +01:00
#pragma warning restore 4014
2017-02-23 20:53:49 +00:00
}
}
2015-08-05 12:28:16 +01:00
}