mirror of
https://github.com/dotnetcore/FreeSql.git
synced 2026-02-08 17:30:55 +08:00
- 补充 ObjectPool Async CancellationToken 参数;#2177
This commit is contained in:
@@ -69,11 +69,11 @@ namespace FreeSql.Internal.CommonProvider
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public Task<Object<DbConnection>> GetAsync()
|
||||
async public Task<Object<DbConnection>> GetAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var conn = _connectionFactory();
|
||||
if (conn.State != ConnectionState.Open)
|
||||
await conn.OpenAsync();
|
||||
await conn.OpenAsync(cancellationToken);
|
||||
return Object<DbConnection>.InitWith(this, Interlocked.Increment(ref _id), conn);
|
||||
}
|
||||
#endif
|
||||
@@ -128,11 +128,11 @@ namespace FreeSql.Internal.CommonProvider
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public Task<Object<DbConnection>> GetAsync()
|
||||
async public Task<Object<DbConnection>> GetAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var conn = _connectionFactory();
|
||||
if (conn.State != ConnectionState.Open)
|
||||
await conn.OpenAsync();
|
||||
await conn.OpenAsync(cancellationToken);
|
||||
return Object<DbConnection>.InitWith(this, Interlocked.Increment(ref _id), conn);
|
||||
}
|
||||
#endif
|
||||
@@ -195,7 +195,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
|
||||
#if net40
|
||||
#else
|
||||
public Task OnGetAsync(Object<DbConnection> obj)
|
||||
public Task OnGetAsync(Object<DbConnection> obj, CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.Internal.ObjectPool
|
||||
@@ -49,7 +50,7 @@ namespace FreeSql.Internal.ObjectPool
|
||||
/// 获取资源
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<Object<T>> GetAsync();
|
||||
Task<Object<T>> GetAsync(CancellationToken cancellationToken = default);
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.Internal.ObjectPool
|
||||
@@ -81,7 +82,7 @@ namespace FreeSql.Internal.ObjectPool
|
||||
/// 从对象池获取对象成功的时候触发,通过该方法统计或初始化对象
|
||||
/// </summary>
|
||||
/// <param name="obj">资源对象</param>
|
||||
Task OnGetAsync(Object<T> obj);
|
||||
Task OnGetAsync(Object<T> obj, CancellationToken cancellationToken);
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -366,7 +366,7 @@ namespace FreeSql.Internal.ObjectPool
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public Task<Object<T>> GetAsync()
|
||||
async public Task<Object<T>> GetAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var obj = GetFree(true);
|
||||
if (obj == null)
|
||||
@@ -400,7 +400,7 @@ namespace FreeSql.Internal.ObjectPool
|
||||
|
||||
try
|
||||
{
|
||||
await Policy.OnGetAsync(obj);
|
||||
await Policy.OnGetAsync(obj, cancellationToken);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
using FreeSql.Internal.ObjectPool;
|
||||
using ClickHouse.Driver.ADO;
|
||||
using FreeSql.Internal.ObjectPool;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ClickHouse.Driver.ADO;
|
||||
|
||||
namespace FreeSql.ClickHouse
|
||||
{
|
||||
@@ -154,7 +154,7 @@ namespace FreeSql.ClickHouse
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public Task OnGetAsync(Object<DbConnection> obj)
|
||||
async public Task OnGetAsync(Object<DbConnection> obj, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
if (_pool.IsAvailable)
|
||||
@@ -165,12 +165,12 @@ namespace FreeSql.ClickHouse
|
||||
throw new Exception(CoreErrorStrings.S_ConnectionStringError_Check(this.Name));
|
||||
}
|
||||
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false)
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync(false, cancellationToken)) == false)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
await obj.Value.OpenAsync();
|
||||
await obj.Value.OpenAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -231,11 +231,11 @@ namespace FreeSql.ClickHouse
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false)
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
await PingCommand(that).ExecuteNonQueryAsync();
|
||||
await PingCommand(that).ExecuteNonQueryAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Collections.Concurrent;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.Dameng
|
||||
@@ -153,7 +154,7 @@ namespace FreeSql.Dameng
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public Task OnGetAsync(Object<DbConnection> obj)
|
||||
async public Task OnGetAsync(Object<DbConnection> obj, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
if (_pool.IsAvailable)
|
||||
@@ -164,12 +165,12 @@ namespace FreeSql.Dameng
|
||||
throw new Exception(CoreErrorStrings.S_ConnectionStringError_Check(this.Name));
|
||||
}
|
||||
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false)
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync(false, cancellationToken)) == false)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
await obj.Value.OpenAsync();
|
||||
await obj.Value.OpenAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -230,11 +231,11 @@ namespace FreeSql.Dameng
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false)
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
await PingCommand(that).ExecuteNonQueryAsync();
|
||||
await PingCommand(that).ExecuteNonQueryAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.Duckdb
|
||||
@@ -126,7 +127,7 @@ namespace FreeSql.Duckdb
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public Task OnGetAsync(Object<DbConnection> obj)
|
||||
async public Task OnGetAsync(Object<DbConnection> obj, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
if (_pool.IsAvailable)
|
||||
@@ -135,7 +136,7 @@ namespace FreeSql.Duckdb
|
||||
throw new Exception(CoreErrorStrings.S_ConnectionStringError_Check(this.Name));
|
||||
|
||||
if (obj.Value.State != ConnectionState.Open)
|
||||
await obj.Value.OpenAndAttachAsync(Attaches);
|
||||
await obj.Value.OpenAndAttachAsync(Attaches, cancellationToken);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -206,26 +207,9 @@ namespace FreeSql.Duckdb
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false)
|
||||
async public static Task OpenAndAttachAsync(this DbConnection that, string[] attach, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var cmd = PingCommand(that))
|
||||
{
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (that.State != ConnectionState.Closed) try { that.Close(); } catch { }
|
||||
if (isThrow) throw;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
async public static Task OpenAndAttachAsync(this DbConnection that, string[] attach)
|
||||
{
|
||||
await that.OpenAsync();
|
||||
await that.OpenAsync(cancellationToken);
|
||||
|
||||
if (attach?.Any() == true)
|
||||
{
|
||||
@@ -235,7 +219,7 @@ namespace FreeSql.Duckdb
|
||||
|
||||
var cmd = that.CreateCommand();
|
||||
cmd.CommandText = sb.ToString();
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
await cmd.ExecuteNonQueryAsync(cancellationToken);
|
||||
cmd.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
using FreeSql.Internal.ObjectPool;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.Firebird
|
||||
@@ -124,7 +124,7 @@ namespace FreeSql.Firebird
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public Task OnGetAsync(Object<DbConnection> obj)
|
||||
async public Task OnGetAsync(Object<DbConnection> obj, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
if (_pool.IsAvailable)
|
||||
@@ -133,7 +133,7 @@ namespace FreeSql.Firebird
|
||||
throw new Exception(CoreErrorStrings.S_ConnectionStringError_Check(this.Name));
|
||||
|
||||
if (obj.Value.State != ConnectionState.Open)
|
||||
await obj.Value.OpenAsync();
|
||||
await obj.Value.OpenAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -183,23 +183,5 @@ namespace FreeSql.Firebird
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
await PingCommand(that).ExecuteNonQueryAsync();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (that.State != ConnectionState.Closed) try { that.Close(); } catch { }
|
||||
if (isThrow) throw;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using FreeSql.Internal.ObjectPool;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Data.Odbc;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.GBase
|
||||
@@ -143,7 +143,7 @@ namespace FreeSql.GBase
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public Task OnGetAsync(Object<DbConnection> obj)
|
||||
async public Task OnGetAsync(Object<DbConnection> obj, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
if (_pool.IsAvailable)
|
||||
@@ -154,12 +154,12 @@ namespace FreeSql.GBase
|
||||
throw new Exception(CoreErrorStrings.S_ConnectionStringError_Check(this.Name));
|
||||
}
|
||||
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false)
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync(false, cancellationToken)) == false)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
await obj.Value.OpenAsync();
|
||||
await obj.Value.OpenAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -220,11 +220,11 @@ namespace FreeSql.GBase
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false)
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
await PingCommand(that).ExecuteNonQueryAsync();
|
||||
await PingCommand(that).ExecuteNonQueryAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
using Kdbndp;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.KingbaseES
|
||||
@@ -154,7 +153,7 @@ namespace FreeSql.KingbaseES
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public Task OnGetAsync(Object<DbConnection> obj)
|
||||
async public Task OnGetAsync(Object<DbConnection> obj, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
if (_pool.IsAvailable)
|
||||
@@ -165,12 +164,12 @@ namespace FreeSql.KingbaseES
|
||||
throw new Exception(CoreErrorStrings.S_ConnectionStringError_Check(this.Name));
|
||||
}
|
||||
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false)
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync(false, cancellationToken)) == false)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
await obj.Value.OpenAsync();
|
||||
await obj.Value.OpenAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -231,11 +230,11 @@ namespace FreeSql.KingbaseES
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false)
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
await PingCommand(that).ExecuteNonQueryAsync();
|
||||
await PingCommand(that).ExecuteNonQueryAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using FreeSql.Internal.ObjectPool;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Data.OleDb;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.MsAccess
|
||||
@@ -123,7 +122,7 @@ namespace FreeSql.MsAccess
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public Task OnGetAsync(Object<DbConnection> obj)
|
||||
async public Task OnGetAsync(Object<DbConnection> obj, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
if (_pool.IsAvailable)
|
||||
@@ -133,7 +132,7 @@ namespace FreeSql.MsAccess
|
||||
throw new Exception(CoreErrorStrings.S_ConnectionStringError_Check(this.Name));
|
||||
|
||||
if (obj.Value.State != ConnectionState.Open)
|
||||
await obj.Value.OpenAsync();
|
||||
await obj.Value.OpenAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -183,23 +182,5 @@ namespace FreeSql.MsAccess
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
await PingCommand(that).ExecuteNonQueryAsync();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (that.State != ConnectionState.Closed) try { that.Close(); } catch { }
|
||||
if (isThrow) throw;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
using FreeSql.Internal.ObjectPool;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
|
||||
#if MySqlConnector
|
||||
using MySqlConnector;
|
||||
#else
|
||||
@@ -148,7 +149,7 @@ namespace FreeSql.MySql
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public Task OnGetAsync(Object<DbConnection> obj)
|
||||
async public Task OnGetAsync(Object<DbConnection> obj, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
if (_pool.IsAvailable)
|
||||
@@ -159,12 +160,12 @@ namespace FreeSql.MySql
|
||||
throw new Exception(CoreErrorStrings.S_ConnectionStringError_Check(this.Name));
|
||||
}
|
||||
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false)
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync(false, cancellationToken)) == false)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
await obj.Value.OpenAsync();
|
||||
await obj.Value.OpenAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -225,11 +226,11 @@ namespace FreeSql.MySql
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false)
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
await PingCommand(that).ExecuteNonQueryAsync();
|
||||
await PingCommand(that).ExecuteNonQueryAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using FreeSql.Internal.ObjectPool;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Data.Odbc;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.Odbc.Default
|
||||
@@ -144,7 +144,7 @@ namespace FreeSql.Odbc.Default
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public Task OnGetAsync(Object<DbConnection> obj)
|
||||
async public Task OnGetAsync(Object<DbConnection> obj, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
if (_pool.IsAvailable)
|
||||
@@ -156,12 +156,12 @@ namespace FreeSql.Odbc.Default
|
||||
throw new Exception(CoreErrorStrings.S_ConnectionStringError_Check(this.Name));
|
||||
}
|
||||
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false)
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync(false, cancellationToken)) == false)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
await obj.Value.OpenAsync();
|
||||
await obj.Value.OpenAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -222,11 +222,11 @@ namespace FreeSql.Odbc.Default
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false)
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
await PingCommand(that).ExecuteNonQueryAsync();
|
||||
await PingCommand(that).ExecuteNonQueryAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using FreeSql.Internal.ObjectPool;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Data.Odbc;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.Odbc.MySql
|
||||
@@ -143,7 +143,7 @@ namespace FreeSql.Odbc.MySql
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public Task OnGetAsync(Object<DbConnection> obj)
|
||||
async public Task OnGetAsync(Object<DbConnection> obj, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
if (_pool.IsAvailable)
|
||||
@@ -154,12 +154,12 @@ namespace FreeSql.Odbc.MySql
|
||||
throw new Exception(CoreErrorStrings.S_ConnectionStringError_Check(this.Name));
|
||||
}
|
||||
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false)
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync(false, cancellationToken)) == false)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
await obj.Value.OpenAsync();
|
||||
await obj.Value.OpenAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -220,11 +220,11 @@ namespace FreeSql.Odbc.MySql
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false)
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
await PingCommand(that).ExecuteNonQueryAsync();
|
||||
await PingCommand(that).ExecuteNonQueryAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using FreeSql.Internal.ObjectPool;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Data.Odbc;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.Odbc.Oracle
|
||||
@@ -154,7 +153,7 @@ namespace FreeSql.Odbc.Oracle
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public Task OnGetAsync(Object<DbConnection> obj)
|
||||
async public Task OnGetAsync(Object<DbConnection> obj, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
if (_pool.IsAvailable)
|
||||
@@ -165,12 +164,12 @@ namespace FreeSql.Odbc.Oracle
|
||||
throw new Exception(CoreErrorStrings.S_ConnectionStringError_Check(this.Name));
|
||||
}
|
||||
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false)
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync(false, cancellationToken)) == false)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
await obj.Value.OpenAsync();
|
||||
await obj.Value.OpenAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -231,11 +230,11 @@ namespace FreeSql.Odbc.Oracle
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false)
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
await PingCommand(that).ExecuteNonQueryAsync();
|
||||
await PingCommand(that).ExecuteNonQueryAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using FreeSql.Internal.ObjectPool;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Data.Odbc;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.Odbc.PostgreSQL
|
||||
@@ -144,7 +143,7 @@ namespace FreeSql.Odbc.PostgreSQL
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public Task OnGetAsync(Object<DbConnection> obj)
|
||||
async public Task OnGetAsync(Object<DbConnection> obj, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
if (_pool.IsAvailable)
|
||||
@@ -155,12 +154,12 @@ namespace FreeSql.Odbc.PostgreSQL
|
||||
throw new Exception(CoreErrorStrings.S_ConnectionStringError_Check(this.Name));
|
||||
}
|
||||
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false)
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync(false, cancellationToken)) == false)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
await obj.Value.OpenAsync();
|
||||
await obj.Value.OpenAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -221,11 +220,11 @@ namespace FreeSql.Odbc.PostgreSQL
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false)
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
await PingCommand(that).ExecuteNonQueryAsync();
|
||||
await PingCommand(that).ExecuteNonQueryAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using FreeSql.Internal.ObjectPool;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Data.Odbc;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.Odbc.SqlServer
|
||||
@@ -144,7 +144,7 @@ namespace FreeSql.Odbc.SqlServer
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public Task OnGetAsync(Object<DbConnection> obj)
|
||||
async public Task OnGetAsync(Object<DbConnection> obj, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
if (_pool.IsAvailable)
|
||||
@@ -156,12 +156,12 @@ namespace FreeSql.Odbc.SqlServer
|
||||
throw new Exception(CoreErrorStrings.S_ConnectionStringError_Check(this.Name));
|
||||
}
|
||||
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false)
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync(false, cancellationToken)) == false)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
await obj.Value.OpenAsync();
|
||||
await obj.Value.OpenAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -222,11 +222,11 @@ namespace FreeSql.Odbc.SqlServer
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false)
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
await PingCommand(that).ExecuteNonQueryAsync();
|
||||
await PingCommand(that).ExecuteNonQueryAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -12,6 +12,7 @@ using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
|
||||
namespace FreeSql.Oracle
|
||||
{
|
||||
@@ -164,7 +165,7 @@ namespace FreeSql.Oracle
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public Task OnGetAsync(Object<DbConnection> obj)
|
||||
async public Task OnGetAsync(Object<DbConnection> obj, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
if (_pool.IsAvailable)
|
||||
@@ -175,12 +176,12 @@ namespace FreeSql.Oracle
|
||||
throw new Exception(CoreErrorStrings.S_ConnectionStringError_Check(this.Name));
|
||||
}
|
||||
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false)
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync(false, cancellationToken)) == false)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
await obj.Value.OpenAsync();
|
||||
await obj.Value.OpenAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -241,11 +242,11 @@ namespace FreeSql.Oracle
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false)
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
await PingCommand(that).ExecuteNonQueryAsync();
|
||||
await PingCommand(that).ExecuteNonQueryAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using Npgsql;
|
||||
using FreeSql.Internal.ObjectPool;
|
||||
using FreeSql.Internal.ObjectPool;
|
||||
using Npgsql;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.PostgreSQL
|
||||
@@ -145,7 +144,7 @@ namespace FreeSql.PostgreSQL
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public Task OnGetAsync(Object<DbConnection> obj)
|
||||
async public Task OnGetAsync(Object<DbConnection> obj, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
if (_pool.IsAvailable)
|
||||
@@ -156,12 +155,12 @@ namespace FreeSql.PostgreSQL
|
||||
throw new Exception(CoreErrorStrings.S_ConnectionStringError_Check(this.Name));
|
||||
}
|
||||
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false)
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync(false, cancellationToken)) == false)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
await obj.Value.OpenAsync();
|
||||
await obj.Value.OpenAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -222,11 +221,11 @@ namespace FreeSql.PostgreSQL
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false)
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
await PingCommand(that).ExecuteNonQueryAsync();
|
||||
await PingCommand(that).ExecuteNonQueryAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using Npgsql;
|
||||
using FreeSql.Internal.ObjectPool;
|
||||
using FreeSql.Internal.ObjectPool;
|
||||
using Npgsql;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.QuestDb
|
||||
@@ -145,7 +144,7 @@ namespace FreeSql.QuestDb
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public Task OnGetAsync(Object<DbConnection> obj)
|
||||
async public Task OnGetAsync(Object<DbConnection> obj, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
if (_pool.IsAvailable)
|
||||
@@ -156,12 +155,12 @@ namespace FreeSql.QuestDb
|
||||
throw new Exception(CoreErrorStrings.S_ConnectionStringError_Check(this.Name));
|
||||
}
|
||||
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false)
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync(false, cancellationToken)) == false)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
await obj.Value.OpenAsync();
|
||||
await obj.Value.OpenAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -222,11 +221,11 @@ namespace FreeSql.QuestDb
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false)
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
await PingCommand(that).ExecuteNonQueryAsync();
|
||||
await PingCommand(that).ExecuteNonQueryAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Data.OscarClient;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.ShenTong
|
||||
@@ -143,7 +144,7 @@ namespace FreeSql.ShenTong
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public Task OnGetAsync(Object<DbConnection> obj)
|
||||
async public Task OnGetAsync(Object<DbConnection> obj, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
if (_pool.IsAvailable)
|
||||
@@ -154,12 +155,12 @@ namespace FreeSql.ShenTong
|
||||
throw new Exception(CoreErrorStrings.S_ConnectionStringError_Check(this.Name));
|
||||
}
|
||||
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false)
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync(false, cancellationToken)) == false)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
await obj.Value.OpenAsync();
|
||||
await obj.Value.OpenAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -220,11 +221,11 @@ namespace FreeSql.ShenTong
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false)
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
await PingCommand(that).ExecuteNonQueryAsync();
|
||||
await PingCommand(that).ExecuteNonQueryAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using FreeSql.Internal.ObjectPool;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
#if microsoft
|
||||
@@ -10,6 +9,7 @@ using Microsoft.Data.SqlClient;
|
||||
using System.Data.SqlClient;
|
||||
#endif
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.SqlServer
|
||||
@@ -148,7 +148,7 @@ namespace FreeSql.SqlServer
|
||||
}
|
||||
#if net40
|
||||
#else
|
||||
async public Task OnGetAsync(Object<DbConnection> obj)
|
||||
async public Task OnGetAsync(Object<DbConnection> obj, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
if (_pool.IsAvailable)
|
||||
@@ -160,11 +160,11 @@ namespace FreeSql.SqlServer
|
||||
throw new Exception(CoreErrorStrings.S_ConnectionStringError_Check(this.Name));
|
||||
}
|
||||
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false)
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync(false, cancellationToken)) == false)
|
||||
{
|
||||
try
|
||||
{
|
||||
await obj.Value.OpenAsync();
|
||||
await obj.Value.OpenAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -223,11 +223,11 @@ namespace FreeSql.SqlServer
|
||||
}
|
||||
#if net40
|
||||
#else
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false)
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
await PingCommand(that).ExecuteNonQueryAsync();
|
||||
await PingCommand(that).ExecuteNonQueryAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -11,6 +11,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
|
||||
namespace FreeSql.Sqlite
|
||||
{
|
||||
@@ -164,7 +165,7 @@ namespace FreeSql.Sqlite
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public Task OnGetAsync(Object<DbConnection> obj)
|
||||
async public Task OnGetAsync(Object<DbConnection> obj, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
if (_pool.IsAvailable)
|
||||
@@ -173,7 +174,7 @@ namespace FreeSql.Sqlite
|
||||
throw new Exception(CoreErrorStrings.S_ConnectionStringError_Check(this.Name));
|
||||
|
||||
if (obj.Value.State != ConnectionState.Open)
|
||||
await obj.Value.OpenAndAttachAsync(Attaches);
|
||||
await obj.Value.OpenAndAttachAsync(Attaches, cancellationToken);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -244,26 +245,9 @@ namespace FreeSql.Sqlite
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false)
|
||||
async public static Task OpenAndAttachAsync(this DbConnection that, string[] attach, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var cmd = PingCommand(that))
|
||||
{
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (that.State != ConnectionState.Closed) try { that.Close(); } catch { }
|
||||
if (isThrow) throw;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
async public static Task OpenAndAttachAsync(this DbConnection that, string[] attach)
|
||||
{
|
||||
await that.OpenAsync();
|
||||
await that.OpenAsync(cancellationToken);
|
||||
|
||||
if (attach?.Any() == true)
|
||||
{
|
||||
@@ -273,7 +257,7 @@ namespace FreeSql.Sqlite
|
||||
|
||||
var cmd = that.CreateCommand();
|
||||
cmd.CommandText = sb.ToString();
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
await cmd.ExecuteNonQueryAsync(cancellationToken);
|
||||
cmd.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,9 @@ using System.Collections.Concurrent;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using TDengine.Data.Client;
|
||||
using TDengine.Driver;
|
||||
using TDengine.Driver.Client;
|
||||
|
||||
namespace FreeSql.TDengine
|
||||
{
|
||||
@@ -141,7 +140,7 @@ namespace FreeSql.TDengine
|
||||
|
||||
#if net40
|
||||
#else
|
||||
public async Task OnGetAsync(Object<DbConnection> obj)
|
||||
public async Task OnGetAsync(Object<DbConnection> obj, CancellationToken cancellationToken)
|
||||
{
|
||||
if (InternalPool.IsAvailable)
|
||||
{
|
||||
@@ -154,11 +153,11 @@ namespace FreeSql.TDengine
|
||||
|
||||
if (obj.Value.State != ConnectionState.Open ||
|
||||
DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 &&
|
||||
(await obj.Value.PingAsync()) == false)
|
||||
(await obj.Value.PingAsync(false, cancellationToken)) == false)
|
||||
{
|
||||
try
|
||||
{
|
||||
await obj.Value.OpenAsync();
|
||||
await obj.Value.OpenAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -228,11 +227,11 @@ namespace FreeSql.TDengine
|
||||
|
||||
#if net40
|
||||
#else
|
||||
public static async Task<bool> PingAsync(this DbConnection that, bool isThrow = false)
|
||||
public static async Task<bool> PingAsync(this DbConnection that, bool isThrow = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
await PingCommand(that).ExecuteNonQueryAsync();
|
||||
await PingCommand(that).ExecuteNonQueryAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Collections.Concurrent;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.Xugu
|
||||
@@ -143,7 +144,7 @@ namespace FreeSql.Xugu
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public Task OnGetAsync(Object<DbConnection> obj)
|
||||
async public Task OnGetAsync(Object<DbConnection> obj, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
if (_pool.IsAvailable)
|
||||
@@ -154,12 +155,12 @@ namespace FreeSql.Xugu
|
||||
throw new Exception(CoreErrorStrings.S_ConnectionStringError_Check(this.Name));
|
||||
}
|
||||
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false)
|
||||
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync(false, cancellationToken)) == false)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
await obj.Value.OpenAsync();
|
||||
await obj.Value.OpenAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -220,11 +221,11 @@ namespace FreeSql.Xugu
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false)
|
||||
async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
await PingCommand(that).ExecuteNonQueryAsync();
|
||||
await PingCommand(that).ExecuteNonQueryAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
|
||||
Reference in New Issue
Block a user