diff --git a/Src/Asp.NetCore2/SqlSugar.TDSQLForPGODBC/Tools/UtilMethods.cs b/Src/Asp.NetCore2/SqlSugar.TDSQLForPGODBC/Tools/UtilMethods.cs
index 0cd31b0036c20b3c1022cf98be6e5c93331cc3ae..c8e6a3e0587a7142222a9505fd392e0a5a7c914a 100644
--- a/Src/Asp.NetCore2/SqlSugar.TDSQLForPGODBC/Tools/UtilMethods.cs
+++ b/Src/Asp.NetCore2/SqlSugar.TDSQLForPGODBC/Tools/UtilMethods.cs
@@ -599,6 +599,10 @@ namespace SqlSugar.TDSQLForPGODBC
OnLogExecuted = it.AopEvents?.OnLogExecuted,
OnLogExecuting = it.AopEvents?.OnLogExecuting,
DataExecuted = it.AopEvents?.DataExecuted,
+ CheckConnectionExecuted = it.AopEvents?.CheckConnectionExecuted,
+ CheckConnectionExecuting = it.AopEvents?.CheckConnectionExecuting,
+ OnGetDataReadered = it.AopEvents?.OnGetDataReadered,
+ OnGetDataReadering = it.AopEvents?.OnGetDataReadering,
},
ConfigId = it.ConfigId,
ConfigureExternalServices = it.ConfigureExternalServices == null ? null : new ConfigureExternalServices()
diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/AdoProvider/AdoProvider.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/AdoProvider/AdoProvider.cs
index b452294e4e5570cfeaa84d74bce272930757c145..94058536bf5dd455cfdc793919d6be115a961cc5 100644
--- a/Src/Asp.NetCore2/SqlSugar/Abstract/AdoProvider/AdoProvider.cs
+++ b/Src/Asp.NetCore2/SqlSugar/Abstract/AdoProvider/AdoProvider.cs
@@ -39,6 +39,8 @@ namespace SqlSugar
internal bool OldClearParameters { get; set; }
public IDataParameterCollection DataReaderParameters { get; set; }
public TimeSpan SqlExecutionTime { get { return AfterTime - BeforeTime; } }
+ public TimeSpan ConnectionExecutionTime { get { return CheckConnectionAfterTime - CheckConnectionBeforeTime; } }
+ public TimeSpan GetDataExecutionTime { get { return GetDataAfterTime - GetDataBeforeTime; } }
///
/// Add, delete and modify: the number of affected items;
///
@@ -47,6 +49,10 @@ namespace SqlSugar
public bool IsDisableMasterSlaveSeparation { get; set; }
internal DateTime BeforeTime = DateTime.MinValue;
internal DateTime AfterTime = DateTime.MinValue;
+ internal DateTime GetDataBeforeTime = DateTime.MinValue;
+ internal DateTime GetDataAfterTime = DateTime.MinValue;
+ internal DateTime CheckConnectionBeforeTime = DateTime.MinValue;
+ internal DateTime CheckConnectionAfterTime = DateTime.MinValue;
public virtual IDbBind DbBind
{
get
@@ -66,6 +72,10 @@ namespace SqlSugar
public virtual bool IsClearParameters { get; set; }
public virtual Action LogEventStarting => this.Context.CurrentConnectionConfig.AopEvents?.OnLogExecuting;
public virtual Action LogEventCompleted => this.Context.CurrentConnectionConfig.AopEvents?.OnLogExecuted;
+ public virtual Action CheckConnectionExecuting => this.Context.CurrentConnectionConfig.AopEvents?.CheckConnectionExecuting;
+ public virtual Action CheckConnectionExecuted => this.Context.CurrentConnectionConfig.AopEvents?.CheckConnectionExecuted;
+ public virtual Action OnGetDataReadering => this.Context.CurrentConnectionConfig.AopEvents?.OnGetDataReadering;
+ public virtual Action OnGetDataReadered => this.Context.CurrentConnectionConfig.AopEvents?.OnGetDataReadered;
public virtual Func> ProcessingEventStartingSQL => this.Context.CurrentConnectionConfig.AopEvents?.OnExecutingChangeSql;
protected virtual Func FormatSql { get; set; }
public virtual Action ErrorEvent => this.Context.CurrentConnectionConfig.AopEvents?.OnError;
@@ -175,6 +185,7 @@ namespace SqlSugar
}
public virtual void CheckConnection()
{
+ this.CheckConnectionBefore(this.Connection);
if (this.Connection.State != ConnectionState.Open)
{
try
@@ -190,10 +201,12 @@ namespace SqlSugar
Check.Exception(true, ErrorMessage.ConnnectionOpen, ex.Message+$"DbType=\"{this.Context.CurrentConnectionConfig.DbType}\";ConfigId=\"{this.Context.CurrentConnectionConfig.ConfigId}\"");
}
}
+ this.CheckConnectionAfter(this.Connection);
}
public virtual async Task CheckConnectionAsync()
{
+ this.CheckConnectionBefore(this.Connection);
if (this.Connection.State != ConnectionState.Open)
{
try
@@ -205,6 +218,31 @@ namespace SqlSugar
Check.Exception(true, ErrorMessage.ConnnectionOpen, ex.Message + $"DbType=\"{this.Context.CurrentConnectionConfig.DbType}\";ConfigId=\"{this.Context.CurrentConnectionConfig.ConfigId}\"");
}
}
+ this.CheckConnectionAfter(this.Connection);
+ }
+ public virtual void CheckConnectionBefore(IDbConnection Connection)
+ {
+ this.CheckConnectionBeforeTime = DateTime.Now;
+ if (this.IsEnableLogEvent)
+ {
+ Action action = CheckConnectionExecuting;
+ if (action != null)
+ {
+ action(Connection);
+ }
+ }
+ }
+ public virtual void CheckConnectionAfter(IDbConnection Connection)
+ {
+ this.CheckConnectionAfterTime = DateTime.Now;
+ if (this.IsEnableLogEvent)
+ {
+ Action action = CheckConnectionExecuted;
+ if (action != null)
+ {
+ action(Connection,this.ConnectionExecutionTime);
+ }
+ }
}
#endregion
@@ -1015,7 +1053,10 @@ namespace SqlSugar
builder.SqlQueryBuilder.sql.Append(sql);
if (parsmeterArray != null && parsmeterArray.Any())
builder.SqlQueryBuilder.Parameters.AddRange(parsmeterArray);
- using (var dataReader = this.GetDataReader(builder.SqlQueryBuilder.ToSqlString(), builder.SqlQueryBuilder.Parameters.ToArray()))
+ string sqlString = builder.SqlQueryBuilder.ToString();
+ SugarParameter[] Parameters = builder.SqlQueryBuilder.Parameters.ToArray();
+ this.GetDataBefore(sqlString, Parameters);
+ using (var dataReader = this.GetDataReader(sqlString, Parameters))
{
DbDataReader DbReader = (DbDataReader)dataReader;
List result = new List();
@@ -1076,6 +1117,7 @@ namespace SqlSugar
}
this.Context.Ado.DataReaderParameters = null;
}
+ this.GetDataAfter(sqlString, Parameters);
return Tuple.Create, List, List, List, List, List, List>(result, result2, result3, result4, result5, result6, result7);
}
}
@@ -1140,7 +1182,10 @@ namespace SqlSugar
builder.SqlQueryBuilder.sql.Append(sql);
if (parsmeterArray != null && parsmeterArray.Any())
builder.SqlQueryBuilder.Parameters.AddRange(parsmeterArray);
- using (var dataReader = await this.GetDataReaderAsync(builder.SqlQueryBuilder.ToSqlString(), builder.SqlQueryBuilder.Parameters.ToArray()))
+ string sqlString = builder.SqlQueryBuilder.ToSqlString();
+ SugarParameter[] Parameters = builder.SqlQueryBuilder.Parameters.ToArray();
+ this.GetDataBefore(sqlString, Parameters);
+ using (var dataReader = await this.GetDataReaderAsync(sqlString, Parameters))
{
DbDataReader DbReader = (DbDataReader)dataReader;
List result = new List();
@@ -1197,6 +1242,7 @@ namespace SqlSugar
}
this.Context.Ado.DataReaderParameters = null;
}
+ this.GetDataAfter(sqlString, Parameters);
return Tuple.Create, List, List, List, List, List, List>(result, result2, result3, result4, result5, result6, result7);
}
}
@@ -1551,6 +1597,44 @@ namespace SqlSugar
this.OldClearParameters = false;
}
}
+ public virtual void GetDataBefore(string sql, SugarParameter[] parameters)
+ {
+ this.GetDataBeforeTime = DateTime.Now;
+ if (this.IsEnableLogEvent)
+ {
+ Action action = OnGetDataReadering;
+ if (action != null)
+ {
+ if (parameters == null || parameters.Length == 0)
+ {
+ action(sql, new SugarParameter[] { });
+ }
+ else
+ {
+ action(sql, parameters);
+ }
+ }
+ }
+ }
+ public virtual void GetDataAfter(string sql, SugarParameter[] parameters)
+ {
+ this.GetDataAfterTime = DateTime.Now;
+ if (this.IsEnableLogEvent)
+ {
+ Action action = OnGetDataReadered;
+ if (action != null)
+ {
+ if (parameters == null || parameters.Length == 0)
+ {
+ action(sql, new SugarParameter[] { }, GetDataExecutionTime);
+ }
+ else
+ {
+ action(sql, parameters, GetDataExecutionTime);
+ }
+ }
+ }
+ }
public virtual SugarParameter[] GetParameters(object parameters, PropertyInfo[] propertyInfo = null)
{
if (parameters == null) return null;
diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/AopProvider/AopProvider.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/AopProvider/AopProvider.cs
index 01949351d992e91b6a0bd6ae23eef0e3d9900c6a..aee0d3e5489f48e4cb5ba7f09eaeac5231093832 100644
--- a/Src/Asp.NetCore2/SqlSugar/Abstract/AopProvider/AopProvider.cs
+++ b/Src/Asp.NetCore2/SqlSugar/Abstract/AopProvider/AopProvider.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Data;
using System.Linq;
using System.Text;
@@ -22,5 +23,9 @@ namespace SqlSugar
public virtual Action