Tracking down empty XML error

This commit is contained in:
Rick Falkvinge
2021-02-04 12:01:20 +01:00
parent ff7f4a57f2
commit a85d93f57c
2 changed files with 2 additions and 83 deletions
@@ -103,6 +103,7 @@ namespace Swarmops.Database
result.Add(ReadBackendServiceOrderFromDataReader(reader));
}
Console.WriteLine("Returning {0} records", result.Count);
return result.ToArray();
}
}
+1 -83
View File
@@ -100,89 +100,7 @@ namespace Swarmops.Database
[Obsolete ("Do not use. Use GetDatabaseForAdmin().", true)]
public static SwarmDb GetDatabaseAsAdmin()
{
string connectionString = string.Empty;
try
{
if (Path.DirectorySeparatorChar == '/' && HttpContext.Current == null)
{
// We are running under mono in a backend environment
using (StreamReader reader = new StreamReader (MonoConfigFile.Replace (".config", "-admin.config")))
{
connectionString = reader.ReadLine();
Logging.LogInformation (LogSource.PirateDb,
"SwarmDb initialized for Linux Backend: [" + connectionString + "]");
}
}
else if (HttpContext.Current != null)
{
// We are running a web application, under Mono (production) or Windows (development)
using (
StreamReader reader =
new StreamReader (
HttpContext.Current.Server.MapPath (WebConfigFile.Replace (".config", "-admin.config")))
)
{
connectionString = reader.ReadLine();
Logging.LogInformation (LogSource.PirateDb,
"SwarmDb initialized for web: [" + connectionString + "]");
}
}
else
{
// 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.Replace (".config", "-admin.config")))
{
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 (String.IsNullOrEmpty (connectionString))
{
if (HttpContext.Current != null) // dummy comment to force build, remove on sight
{
string hostName = HttpContext.Current.Request.Url.Host;
connectionString = "server=peregrine;database=" + hostName + ";user=" + hostName +
"-admin;password=" + hostName + "-admin";
// TODO: Replace "peregrine" with "localhost"
}
else
{
throw new InvalidOperationException (
"No database-as-admin connection string found -- write a connect string into the \"ActivizrAdminConnect\" environment var, or on one line into a file named database-admin.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;
}
return new SwarmDb (DbProviderFactories.GetFactory (DefaultProviderName), connectionString);
throw new InvalidOperationException();
}
}
}