Checking in types for BasicOutboundComms / -Recipients
This commit is contained in:
@@ -40,124 +40,7 @@ namespace Swarmops.Database
|
||||
[Obsolete ("Do not use. Use SwarmDb.GetDatabaseForReading(), ...ForWriting() or ...ForAdmin().", true)]
|
||||
public static SwarmDb GetDatabase()
|
||||
{
|
||||
Console.WriteLine("Entering GetDatabase()");
|
||||
|
||||
// First, check if a previous invocation has put anything in the cashe.
|
||||
string connectionString = _cachedConnectionString;
|
||||
|
||||
// During a cacheless invocation, the app/web config has priority.
|
||||
if (connectionString == null && ConfigurationManager.ConnectionStrings["Activizr"] != null)
|
||||
{
|
||||
Console.WriteLine("Initing from ConfigManager");
|
||||
|
||||
connectionString = ConfigurationManager.ConnectionStrings["Activizr"].ConnectionString;
|
||||
|
||||
Logging.LogInformation(LogSource.PirateDb,
|
||||
"SwarmDb initialized from Config ConnectionString: [" + connectionString +
|
||||
"]");
|
||||
}
|
||||
|
||||
// If the app/web config is empty, check the database config file on disk
|
||||
if (connectionString == null)
|
||||
{
|
||||
Console.WriteLine("Point 2");
|
||||
|
||||
try
|
||||
{
|
||||
if (Path.DirectorySeparatorChar == '/' && HttpContext.Current == null)
|
||||
{
|
||||
Console.WriteLine("Attempting to initialize using MonoConfigFile, which is " + MonoConfigFile);
|
||||
|
||||
// We are running under mono in a backend environment
|
||||
|
||||
using (StreamReader reader = new StreamReader(MonoConfigFile))
|
||||
{
|
||||
connectionString = reader.ReadLine();
|
||||
|
||||
Logging.LogInformation(LogSource.PirateDb,
|
||||
"SwarmDb initialized for Linux: [" + connectionString + "]");
|
||||
}
|
||||
}
|
||||
else if (HttpContext.Current != null)
|
||||
{
|
||||
Console.WriteLine("Point 3");
|
||||
|
||||
// We are running a web application, under Mono (production) or Windows (development)
|
||||
using (StreamReader reader = new StreamReader(HttpContext.Current.Server.MapPath(WebConfigFile))
|
||||
)
|
||||
{
|
||||
connectionString = reader.ReadLine();
|
||||
|
||||
Logging.LogInformation(LogSource.PirateDb,
|
||||
"SwarmDb initialized for web: [" + connectionString + "]");
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Point 4");
|
||||
|
||||
// We are running an application, presumably directly from Visual Studio.
|
||||
// If so, the current working directory is "PirateWeb/30/Console/bin".
|
||||
using (StreamReader reader = new StreamReader(AppConfigFile))
|
||||
{
|
||||
connectionString = reader.ReadLine();
|
||||
|
||||
Logging.LogInformation(LogSource.PirateDb,
|
||||
"SwarmDb initialized for application: [" + connectionString +
|
||||
"]");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Logging.LogWarning(LogSource.PirateDb, "Unable to read Database.Config - defaulting");
|
||||
// Ignore if we can't read the Database.config
|
||||
}
|
||||
|
||||
// To simplify future checks
|
||||
if (connectionString != null && connectionString.Length == 0)
|
||||
{
|
||||
connectionString = null;
|
||||
}
|
||||
}
|
||||
|
||||
// If we still have nothing, and we're running from web, then assume we have a dev environment and use the hostname as db, user, and pass.
|
||||
if (connectionString == null)
|
||||
{
|
||||
Console.WriteLine("Point 5");
|
||||
|
||||
if (HttpContext.Current != null)
|
||||
{
|
||||
string hostName = HttpContext.Current.Request.Url.Host;
|
||||
|
||||
connectionString = "server=peregrine;database=" + hostName + ";user=" + hostName + ";password=" + hostName; // TODO: Replace "peregrine" with "localhost"
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("No database connection string found -- write a connect string on one line into a file named database.config; see connectionstrings.com for examples"); // TODO: Replace with custom exception to present config screen
|
||||
}
|
||||
}
|
||||
|
||||
// Now write the correct data to the cache, for faster lookup next time.
|
||||
if (_cachedConnectionString == null)
|
||||
{
|
||||
_cachedConnectionString = connectionString;
|
||||
}
|
||||
|
||||
SwarmDb db = null;
|
||||
|
||||
try
|
||||
{
|
||||
db = new SwarmDb(DbProviderFactories.GetFactory(DefaultProviderName), connectionString);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception(
|
||||
"Unable to initalize SwarmDb using connection string \"" + connectionString + "\"", e); // TODO: REMOVE ON PRODUCTION -- CREDENTIALS LEAKAGE
|
||||
}
|
||||
|
||||
return db;
|
||||
throw new NotImplementedException("GetDatabase() is obsolete and has been deleted.");
|
||||
}
|
||||
|
||||
[Obsolete ("Do not use. Use GetDatabaseForAdmin().", true)]
|
||||
|
||||
Reference in New Issue
Block a user