Cleaned up code and improved documentation. Bumped package version to 1.2.0. Upgraded to latest version of MySql.Data
This commit is contained in:
@@ -14,7 +14,7 @@ namespace MontoyaTech.MySqlPlus
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the MySql Type this converter converts to.
|
/// Returns the MySql Type this converter converts to.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string ConvertToType { get { return "BIGINT UNSIGNED"; } }
|
public string ConvertToType => "BIGINT UNSIGNED";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts from a Unix Time to a DateTime.
|
/// Converts from a Unix Time to a DateTime.
|
||||||
|
|||||||
@@ -9,9 +9,7 @@ using System.Threading.Tasks;
|
|||||||
namespace MontoyaTech.MySqlPlus
|
namespace MontoyaTech.MySqlPlus
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This timestamp runs on its own and it
|
/// An efficient elapsed miliseconds timestamp that can be used to keep track of time.
|
||||||
/// uses very little CPU usage to keep track of time. This is a very
|
|
||||||
/// useful system. This timestamp is in elapsed miliseconds.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class GlobalTimeStamp : IDisposable
|
internal class GlobalTimeStamp : IDisposable
|
||||||
{
|
{
|
||||||
@@ -117,6 +115,7 @@ namespace MontoyaTech.MySqlPlus
|
|||||||
{
|
{
|
||||||
//Get the current timestamp
|
//Get the current timestamp
|
||||||
ulong current = instance._Current;
|
ulong current = instance._Current;
|
||||||
|
|
||||||
//Compare it.
|
//Compare it.
|
||||||
if (current > b)
|
if (current > b)
|
||||||
return (current - b);
|
return (current - b);
|
||||||
@@ -148,18 +147,7 @@ namespace MontoyaTech.MySqlPlus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
~GlobalTimeStamp()
|
~GlobalTimeStamp()
|
||||||
{
|
{
|
||||||
try
|
this.Dispose();
|
||||||
{
|
|
||||||
if (this.Running)
|
|
||||||
{
|
|
||||||
this.Running = false;
|
|
||||||
|
|
||||||
this.Watch.Stop();
|
|
||||||
|
|
||||||
this.RefreshThread = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch { }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,27 +49,27 @@ namespace MontoyaTech.MySqlPlus
|
|||||||
/// Creates a new managed MySqlConnection and sets its internal
|
/// Creates a new managed MySqlConnection and sets its internal
|
||||||
/// MySql connection.
|
/// MySql connection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="conn"></param>
|
/// <param name="connection"></param>
|
||||||
public MySqlManagedConnection(MySqlConnection conn)
|
public MySqlManagedConnection(MySqlConnection connection)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(conn.ConnectionString))
|
if (string.IsNullOrWhiteSpace(connection.ConnectionString))
|
||||||
throw new Exception("Connection string must be set on MySqlConnection.");
|
throw new Exception("Connection string must be set on MySqlConnection.");
|
||||||
|
|
||||||
this.MySqlConnection = conn;
|
this.MySqlConnection = connection;
|
||||||
this.ConnectionString = conn.ConnectionString;
|
this.ConnectionString = connection.ConnectionString;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new managed MySqlConnection and setups up the internal connection string and gets everything ready.
|
/// Creates a new managed MySqlConnection and setups up the internal connection string and gets everything ready.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="conn"></param>
|
/// <param name="connectionStr"></param>
|
||||||
public MySqlManagedConnection(string conn)
|
public MySqlManagedConnection(string connectionStr)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(conn))
|
if (string.IsNullOrWhiteSpace(connectionStr))
|
||||||
throw new Exception("Invalid connection string passed, it must not be null or empty.");
|
throw new Exception("Invalid connection string passed, it must not be null or empty.");
|
||||||
|
|
||||||
this.MySqlConnection = new MySqlConnection(conn);
|
this.MySqlConnection = new MySqlConnection(connectionStr);
|
||||||
this.ConnectionString = conn;
|
this.ConnectionString = connectionStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -104,7 +104,7 @@ namespace MontoyaTech.MySqlPlus
|
|||||||
else
|
else
|
||||||
throw new Exception("Failed to open a valid MySqlConnection.");
|
throw new Exception("Failed to open a valid MySqlConnection.");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch
|
||||||
{
|
{
|
||||||
//See if we have reached our max retry.
|
//See if we have reached our max retry.
|
||||||
if (i + 1 >= maxRetrys || !retry)
|
if (i + 1 >= maxRetrys || !retry)
|
||||||
@@ -438,7 +438,7 @@ namespace MontoyaTech.MySqlPlus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
~MySqlManagedConnection()
|
~MySqlManagedConnection()
|
||||||
{
|
{
|
||||||
Dispose();
|
this.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<AssemblyName>MontoyaTech.MySqlPlus</AssemblyName>
|
<AssemblyName>MontoyaTech.MySqlPlus</AssemblyName>
|
||||||
<RootNamespace>MontoyaTech.MySqlPlus</RootNamespace>
|
<RootNamespace>MontoyaTech.MySqlPlus</RootNamespace>
|
||||||
<Title>MontoyaTech.MySqlPlus</Title>
|
<Title>MontoyaTech.MySqlPlus</Title>
|
||||||
<Version>1.1.9</Version>
|
<Version>1.2.0</Version>
|
||||||
<Company>MontoyaTech</Company>
|
<Company>MontoyaTech</Company>
|
||||||
<Description>A simple C# library to help work with MySql.</Description>
|
<Description>A simple C# library to help work with MySql.</Description>
|
||||||
<Copyright>MontoyaTech 2023</Copyright>
|
<Copyright>MontoyaTech 2023</Copyright>
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="MySql.Data" Version="9.3.0" />
|
<PackageReference Include="MySql.Data" Version="9.6.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -25,16 +25,6 @@ namespace MontoyaTech.MySqlPlus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime LastUse = DateTime.MinValue;
|
public DateTime LastUse = DateTime.MinValue;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The method that requested this cache.
|
|
||||||
/// </summary>
|
|
||||||
public string CallerMethod = "";
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The line of code that requested this cache.
|
|
||||||
/// </summary>
|
|
||||||
public string CallerLine = "";
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Id of this CachedAPISession.
|
/// The Id of this CachedAPISession.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -58,7 +48,7 @@ namespace MontoyaTech.MySqlPlus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override void Dispose()
|
public override void Dispose()
|
||||||
{
|
{
|
||||||
InUse = false;
|
this.InUse = false;
|
||||||
|
|
||||||
//Set this again because we just stopped using this cached session.
|
//Set this again because we just stopped using this cached session.
|
||||||
this.LastUse = DateTime.UtcNow;
|
this.LastUse = DateTime.UtcNow;
|
||||||
@@ -80,26 +70,31 @@ namespace MontoyaTech.MySqlPlus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private static Thread UnCacheThread = null;
|
private static Thread UnCacheThread = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether or not the API Session Cache is running.
|
||||||
|
/// </summary>
|
||||||
|
private static bool Running = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The amount of time in minutes that a cached api session is allowed to live.
|
/// The amount of time in minutes that a cached api session is allowed to live.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static int CacheLifeTime = 20;
|
public static int CacheLifeTime = 20;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The amount of time in minutes before a cache is considered to be a zombie
|
/// The amount of time in minutes before a cache is considered to be a zombie
|
||||||
/// and the result of a code bug somewhere.
|
/// and the result of a code bug somewhere.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static int ZombieCacheLifeTime = 5;
|
public static int ZombieCacheLifeTime = 5;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The amount of time in seconds before we are allowed to attempt to uncache sessions.
|
/// The amount of time in seconds before we are allowed to attempt to uncache sessions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static int UnCacheFrequency = 30;
|
public static int UnCacheFrequency = 30;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether or not the API Session Cache is running.
|
/// Returns the next cached session.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static bool Running = false;
|
public static CachedMySqlSession Next => Get();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Starts this MySqlSessionCache with a given MySqlConnectionString.
|
/// Starts this MySqlSessionCache with a given MySqlConnectionString.
|
||||||
@@ -218,18 +213,6 @@ namespace MontoyaTech.MySqlPlus
|
|||||||
|
|
||||||
result.InUse = true;
|
result.InUse = true;
|
||||||
result.LastUse = DateTime.UtcNow;
|
result.LastUse = DateTime.UtcNow;
|
||||||
|
|
||||||
//Get the caller information
|
|
||||||
var trace = new StackTrace();
|
|
||||||
|
|
||||||
var method = trace.GetFrame(1).GetMethod();
|
|
||||||
var methodName = method.Name;
|
|
||||||
var className = method.ReflectedType.Name;
|
|
||||||
var currNamespace = method.ReflectedType.Namespace;
|
|
||||||
|
|
||||||
result.CallerMethod = $"{currNamespace}.{className}.{methodName}()";
|
|
||||||
result.CallerLine = trace.GetFrame(1).GetFileLineNumber().ToString();
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user