* Added reconnect support for MySQL Data interfaces if they time out. (Grid/User modes only now, Log todo)

* Begun writing support for supporting the "Start" region login parameter.
zircon^2
Adam Frisby 2007-05-30 02:36:48 +00:00
parent e9aa24feff
commit b0de1b93f9
4 changed files with 85 additions and 6 deletions

View File

@ -75,6 +75,7 @@ namespace OpenGrid.Framework.Data.MySQL
} }
catch (Exception e) catch (Exception e)
{ {
database.Reconnect();
Console.WriteLine(e.ToString()); Console.WriteLine(e.ToString());
return null; return null;
} }
@ -106,6 +107,7 @@ namespace OpenGrid.Framework.Data.MySQL
} }
catch (Exception e) catch (Exception e)
{ {
database.Reconnect();
Console.WriteLine(e.ToString()); Console.WriteLine(e.ToString());
return null; return null;
} }
@ -137,6 +139,7 @@ namespace OpenGrid.Framework.Data.MySQL
} }
catch (Exception e) catch (Exception e)
{ {
database.Reconnect();
Console.WriteLine(e.ToString()); Console.WriteLine(e.ToString());
return null; return null;
} }

View File

@ -16,6 +16,7 @@ namespace OpenGrid.Framework.Data.MySQL
class MySQLManager class MySQLManager
{ {
IDbConnection dbcon; IDbConnection dbcon;
string connectionString;
/// <summary> /// <summary>
/// Initialises and creates a new MySQL connection and maintains it. /// Initialises and creates a new MySQL connection and maintains it.
@ -29,7 +30,7 @@ namespace OpenGrid.Framework.Data.MySQL
{ {
try try
{ {
string connectionString = "Server=" + hostname + ";Port=" + port + ";Database=" + database + ";User ID=" + username + ";Password=" + password + ";Pooling=" + cpooling + ";"; connectionString = "Server=" + hostname + ";Port=" + port + ";Database=" + database + ";User ID=" + username + ";Password=" + password + ";Pooling=" + cpooling + ";";
dbcon = new MySqlConnection(connectionString); dbcon = new MySqlConnection(connectionString);
dbcon.Open(); dbcon.Open();
@ -51,6 +52,28 @@ namespace OpenGrid.Framework.Data.MySQL
dbcon = null; dbcon = null;
} }
/// <summary>
/// Reconnects to the database
/// </summary>
public void Reconnect()
{
lock (dbcon)
{
try
{
// Close the DB connection
dbcon.Close();
// Try reopen it
dbcon = new MySqlConnection(connectionString);
dbcon.Open();
}
catch (Exception e)
{
Console.WriteLine("Unable to reconnect to database " + e.ToString());
}
}
}
/// <summary> /// <summary>
/// Runs a query with protection against SQL Injection by using parameterised input. /// Runs a query with protection against SQL Injection by using parameterised input.
/// </summary> /// </summary>
@ -70,12 +93,49 @@ namespace OpenGrid.Framework.Data.MySQL
return (IDbCommand)dbcommand; return (IDbCommand)dbcommand;
} }
catch
{
lock (dbcon)
{
// Close the DB connection
try
{
dbcon.Close();
}
catch { }
// Try reopen it
try
{
dbcon = new MySqlConnection(connectionString);
dbcon.Open();
}
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine("Unable to reconnect to database " + e.ToString());
}
// Run the query again
try
{
MySqlCommand dbcommand = (MySqlCommand)dbcon.CreateCommand();
dbcommand.CommandText = sql;
foreach (KeyValuePair<string, string> param in parameters)
{
dbcommand.Parameters.Add(param.Key, param.Value);
}
return (IDbCommand)dbcommand;
}
catch (Exception e)
{
// Return null if it fails.
Console.WriteLine("Failed during Query generation: " + e.ToString()); Console.WriteLine("Failed during Query generation: " + e.ToString());
return null; return null;
} }
} }
}
}
public SimProfileData getSimRow(IDataReader reader) public SimProfileData getSimRow(IDataReader reader)
{ {

View File

@ -51,6 +51,7 @@ namespace OpenGrid.Framework.Data.MySQL
} }
catch (Exception e) catch (Exception e)
{ {
database.Reconnect();
Console.WriteLine(e.ToString()); Console.WriteLine(e.ToString());
return null; return null;
} }
@ -78,6 +79,7 @@ namespace OpenGrid.Framework.Data.MySQL
} }
catch (Exception e) catch (Exception e)
{ {
database.Reconnect();
Console.WriteLine(e.ToString()); Console.WriteLine(e.ToString());
return null; return null;
} }
@ -116,6 +118,7 @@ namespace OpenGrid.Framework.Data.MySQL
} }
catch (Exception e) catch (Exception e)
{ {
database.Reconnect();
Console.WriteLine(e.ToString()); Console.WriteLine(e.ToString());
return null; return null;
} }

View File

@ -395,10 +395,23 @@ namespace OpenGridServices.UserServer
// If user specified additional start, use that // If user specified additional start, use that
if (requestData.ContainsKey("start")) if (requestData.ContainsKey("start"))
{ {
string startLoc = (string)requestData["start"]; string startLoc = ((string)requestData["start"]).Trim();
if (!(startLoc == "last" || startLoc == "home")) if (!(startLoc == "last" || startLoc == "home"))
{ {
// Ignore it! Heh. // Format: uri:Ahern&162&213&34
try
{
string[] parts = startLoc.Remove(0, 4).Split('&');
string region = parts[0];
////////////////////////////////////////////////////
//SimProfile SimInfo = new SimProfile();
//SimInfo = SimInfo.LoadFromGrid(theUser.currentAgent.currentHandle, _config.GridServerURL, _config.GridSendKey, _config.GridRecvKey);
}
catch (Exception e)
{
}
} }
} }