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:
2026-02-08 18:28:56 -08:00
parent 119ac93394
commit 7121acb446
5 changed files with 29 additions and 58 deletions

View File

@@ -14,7 +14,7 @@ namespace MontoyaTech.MySqlPlus
/// <summary>
/// Returns the MySql Type this converter converts to.
/// </summary>
public string ConvertToType { get { return "BIGINT UNSIGNED"; } }
public string ConvertToType => "BIGINT UNSIGNED";
/// <summary>
/// Converts from a Unix Time to a DateTime.

View File

@@ -9,9 +9,7 @@ using System.Threading.Tasks;
namespace MontoyaTech.MySqlPlus
{
/// <summary>
/// This timestamp runs on its own and it
/// uses very little CPU usage to keep track of time. This is a very
/// useful system. This timestamp is in elapsed miliseconds.
/// An efficient elapsed miliseconds timestamp that can be used to keep track of time.
/// </summary>
internal class GlobalTimeStamp : IDisposable
{
@@ -117,6 +115,7 @@ namespace MontoyaTech.MySqlPlus
{
//Get the current timestamp
ulong current = instance._Current;
//Compare it.
if (current > b)
return (current - b);
@@ -148,18 +147,7 @@ namespace MontoyaTech.MySqlPlus
/// </summary>
~GlobalTimeStamp()
{
try
{
if (this.Running)
{
this.Running = false;
this.Watch.Stop();
this.RefreshThread = null;
}
}
catch { }
this.Dispose();
}
}
}

View File

@@ -49,27 +49,27 @@ namespace MontoyaTech.MySqlPlus
/// Creates a new managed MySqlConnection and sets its internal
/// MySql connection.
/// </summary>
/// <param name="conn"></param>
public MySqlManagedConnection(MySqlConnection conn)
/// <param name="connection"></param>
public MySqlManagedConnection(MySqlConnection connection)
{
if (string.IsNullOrWhiteSpace(conn.ConnectionString))
if (string.IsNullOrWhiteSpace(connection.ConnectionString))
throw new Exception("Connection string must be set on MySqlConnection.");
this.MySqlConnection = conn;
this.ConnectionString = conn.ConnectionString;
this.MySqlConnection = connection;
this.ConnectionString = connection.ConnectionString;
}
/// <summary>
/// Creates a new managed MySqlConnection and setups up the internal connection string and gets everything ready.
/// </summary>
/// <param name="conn"></param>
public MySqlManagedConnection(string conn)
/// <param name="connectionStr"></param>
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.");
this.MySqlConnection = new MySqlConnection(conn);
this.ConnectionString = conn;
this.MySqlConnection = new MySqlConnection(connectionStr);
this.ConnectionString = connectionStr;
}
/// <summary>
@@ -104,7 +104,7 @@ namespace MontoyaTech.MySqlPlus
else
throw new Exception("Failed to open a valid MySqlConnection.");
}
catch (Exception ex)
catch
{
//See if we have reached our max retry.
if (i + 1 >= maxRetrys || !retry)
@@ -438,7 +438,7 @@ namespace MontoyaTech.MySqlPlus
/// </summary>
~MySqlManagedConnection()
{
Dispose();
this.Dispose();
}
}
}

View File

@@ -7,7 +7,7 @@
<AssemblyName>MontoyaTech.MySqlPlus</AssemblyName>
<RootNamespace>MontoyaTech.MySqlPlus</RootNamespace>
<Title>MontoyaTech.MySqlPlus</Title>
<Version>1.1.9</Version>
<Version>1.2.0</Version>
<Company>MontoyaTech</Company>
<Description>A simple C# library to help work with MySql.</Description>
<Copyright>MontoyaTech 2023</Copyright>
@@ -27,7 +27,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="MySql.Data" Version="9.3.0" />
<PackageReference Include="MySql.Data" Version="9.6.0" />
</ItemGroup>
</Project>

View File

@@ -25,16 +25,6 @@ namespace MontoyaTech.MySqlPlus
/// </summary>
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>
/// The Id of this CachedAPISession.
/// </summary>
@@ -58,7 +48,7 @@ namespace MontoyaTech.MySqlPlus
/// </summary>
public override void Dispose()
{
InUse = false;
this.InUse = false;
//Set this again because we just stopped using this cached session.
this.LastUse = DateTime.UtcNow;
@@ -80,26 +70,31 @@ namespace MontoyaTech.MySqlPlus
/// </summary>
private static Thread UnCacheThread = null;
/// <summary>
/// Whether or not the API Session Cache is running.
/// </summary>
private static bool Running = false;
/// <summary>
/// The amount of time in minutes that a cached api session is allowed to live.
/// </summary>
private static int CacheLifeTime = 20;
public static int CacheLifeTime = 20;
/// <summary>
/// The amount of time in minutes before a cache is considered to be a zombie
/// and the result of a code bug somewhere.
/// </summary>
private static int ZombieCacheLifeTime = 5;
public static int ZombieCacheLifeTime = 5;
/// <summary>
/// The amount of time in seconds before we are allowed to attempt to uncache sessions.
/// </summary>
private static int UnCacheFrequency = 30;
public static int UnCacheFrequency = 30;
/// <summary>
/// Whether or not the API Session Cache is running.
/// Returns the next cached session.
/// </summary>
private static bool Running = false;
public static CachedMySqlSession Next => Get();
/// <summary>
/// Starts this MySqlSessionCache with a given MySqlConnectionString.
@@ -218,18 +213,6 @@ namespace MontoyaTech.MySqlPlus
result.InUse = true;
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;
}
}