From f53e56a0fe42c66de749141506a7c993fdae001d Mon Sep 17 00:00:00 2001 From: Wraith2 Date: Wed, 1 Nov 2023 22:49:15 +0000 Subject: [PATCH 1/7] partial implementation --- .../SqlClientDiagnosticListenerExtensions.cs | 362 +++++++++++++++--- 1 file changed, 304 insertions(+), 58 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnosticListenerExtensions.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnosticListenerExtensions.cs index 1d955b8c47..b78b4975a2 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnosticListenerExtensions.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnosticListenerExtensions.cs @@ -3,6 +3,8 @@ // See the LICENSE file in the project root for more information. using System; +using System.Collections; +using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.Runtime.CompilerServices; @@ -46,15 +48,15 @@ public static Guid WriteCommandBefore(this SqlDiagnosticListener @this, SqlComma @this.Write( SqlBeforeExecuteCommand, - new - { - OperationId = operationId, - Operation = operation, - ConnectionId = sqlCommand.Connection?.ClientConnectionId, - Command = sqlCommand, + new SqlClientCommandBefore( + operationId, + operation, + Stopwatch.GetTimestamp(), + sqlCommand.Connection?.ClientConnectionId, transaction?.InternalTransaction?.TransactionId, - Timestamp = Stopwatch.GetTimestamp() - }); + sqlCommand + ) + ); return operationId; } @@ -68,16 +70,16 @@ public static void WriteCommandAfter(this SqlDiagnosticListener @this, Guid oper { @this.Write( SqlAfterExecuteCommand, - new - { - OperationId = operationId, - Operation = operation, - ConnectionId = sqlCommand.Connection?.ClientConnectionId, - Command = sqlCommand, + new SqlClientCommandAfter( + operationId, + operation, + Stopwatch.GetTimestamp(), + sqlCommand.Connection?.ClientConnectionId, transaction?.InternalTransaction?.TransactionId, - Statistics = sqlCommand.Statistics?.GetDictionary(), - Timestamp = Stopwatch.GetTimestamp() - }); + sqlCommand, + sqlCommand.Statistics?.GetDictionary() + ) + ); } } @@ -108,14 +110,15 @@ public static Guid WriteConnectionOpenBefore(this SqlDiagnosticListener @this, S @this.Write( SqlBeforeOpenConnection, - new - { - OperationId = operationId, - Operation = operation, - Connection = sqlConnection, - ClientVersion = ThisAssembly.InformationalVersion, - Timestamp = Stopwatch.GetTimestamp() - }); + new SqlClientConnectionOpenBefore + ( + operationId, + operation, + Stopwatch.GetTimestamp(), + sqlConnection, + ThisAssembly.InformationalVersion + ) + ); return operationId; } @@ -129,16 +132,17 @@ public static void WriteConnectionOpenAfter(this SqlDiagnosticListener @this, Gu { @this.Write( SqlAfterOpenConnection, - new - { - OperationId = operationId, - Operation = operation, - ConnectionId = sqlConnection.ClientConnectionId, - Connection = sqlConnection, - ClientVersion = ThisAssembly.InformationalVersion, - Statistics = sqlConnection.Statistics?.GetDictionary(), - Timestamp = Stopwatch.GetTimestamp() - }); + new SqlClientConnectionOpenAfter + ( + operationId, + operation, + Stopwatch.GetTimestamp(), + sqlConnection.ClientConnectionId, + sqlConnection, + ThisAssembly.InformationalVersion, + sqlConnection.Statistics?.GetDictionary() + ) + ); } } @@ -148,16 +152,17 @@ public static void WriteConnectionOpenError(this SqlDiagnosticListener @this, Gu { @this.Write( SqlErrorOpenConnection, - new - { - OperationId = operationId, - Operation = operation, - ConnectionId = sqlConnection.ClientConnectionId, - Connection = sqlConnection, - ClientVersion = ThisAssembly.InformationalVersion, - Exception = ex, - Timestamp = Stopwatch.GetTimestamp() - }); + new SqlClientConnectionOpenError + ( + operationId, + operation, + Stopwatch.GetTimestamp(), + sqlConnection.ClientConnectionId, + sqlConnection, + ThisAssembly.InformationalVersion, + ex + ) + ); } } @@ -173,10 +178,11 @@ public static Guid WriteConnectionCloseBefore(this SqlDiagnosticListener @this, { OperationId = operationId, Operation = operation, + Timestamp = Stopwatch.GetTimestamp(), + ConnectionId = sqlConnection.ClientConnectionId, Connection = sqlConnection, - Statistics = sqlConnection.Statistics?.GetDictionary(), - Timestamp = Stopwatch.GetTimestamp() + Statistics = sqlConnection.Statistics?.GetDictionary() }); return operationId; @@ -195,10 +201,11 @@ public static void WriteConnectionCloseAfter(this SqlDiagnosticListener @this, G { OperationId = operationId, Operation = operation, + Timestamp = Stopwatch.GetTimestamp(), + ConnectionId = clientConnectionId, Connection = sqlConnection, Statistics = sqlConnection.Statistics?.GetDictionary(), - Timestamp = Stopwatch.GetTimestamp() }); } } @@ -213,11 +220,12 @@ public static void WriteConnectionCloseError(this SqlDiagnosticListener @this, G { OperationId = operationId, Operation = operation, + Timestamp = Stopwatch.GetTimestamp(), + ConnectionId = clientConnectionId, Connection = sqlConnection, Statistics = sqlConnection.Statistics?.GetDictionary(), Exception = ex, - Timestamp = Stopwatch.GetTimestamp() }); } } @@ -234,10 +242,11 @@ public static Guid WriteTransactionCommitBefore(this SqlDiagnosticListener @this { OperationId = operationId, Operation = operation, + Timestamp = Stopwatch.GetTimestamp(), + IsolationLevel = isolationLevel, Connection = connection, - transaction?.TransactionId, - Timestamp = Stopwatch.GetTimestamp() + transaction?.TransactionId }); return operationId; @@ -256,10 +265,11 @@ public static void WriteTransactionCommitAfter(this SqlDiagnosticListener @this, { OperationId = operationId, Operation = operation, + Timestamp = Stopwatch.GetTimestamp(), + IsolationLevel = isolationLevel, Connection = connection, - transaction?.TransactionId, - Timestamp = Stopwatch.GetTimestamp() + transaction?.TransactionId }); } } @@ -274,11 +284,12 @@ public static void WriteTransactionCommitError(this SqlDiagnosticListener @this, { OperationId = operationId, Operation = operation, + Timestamp = Stopwatch.GetTimestamp(), + IsolationLevel = isolationLevel, Connection = connection, transaction?.TransactionId, Exception = ex, - Timestamp = Stopwatch.GetTimestamp() }); } } @@ -295,11 +306,12 @@ public static Guid WriteTransactionRollbackBefore(this SqlDiagnosticListener @th { OperationId = operationId, Operation = operation, + Timestamp = Stopwatch.GetTimestamp(), + IsolationLevel = isolationLevel, Connection = connection, transaction?.TransactionId, TransactionName = transactionName, - Timestamp = Stopwatch.GetTimestamp() }); return operationId; @@ -318,11 +330,12 @@ public static void WriteTransactionRollbackAfter(this SqlDiagnosticListener @thi { OperationId = operationId, Operation = operation, + Timestamp = Stopwatch.GetTimestamp(), + IsolationLevel = isolationLevel, Connection = connection, transaction?.TransactionId, - TransactionName = transactionName, - Timestamp = Stopwatch.GetTimestamp() + TransactionName = transactionName }); } } @@ -337,12 +350,13 @@ public static void WriteTransactionRollbackError(this SqlDiagnosticListener @thi { OperationId = operationId, Operation = operation, + Timestamp = Stopwatch.GetTimestamp(), + IsolationLevel = isolationLevel, Connection = connection, transaction?.TransactionId, TransactionName = transactionName, Exception = ex, - Timestamp = Stopwatch.GetTimestamp() }); } } @@ -363,6 +377,238 @@ public static DiagnosticTransactionScope CreateTransactionRollbackScope(this Sql } } +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member + public abstract class SqlClientDiagnostic : IReadOnlyList> + { + protected const int CommonPropertyCount = 3; + + protected SqlClientDiagnostic(Guid operationId, string operation, long timestamp) + { + OperationId = operationId; + Operation = operation; + Timestamp = timestamp; + } + + public Guid OperationId { get; } + public string Operation { get; } + public long Timestamp { get; } + + public int Count => CommonPropertyCount + GetDerivedCount(); + + public KeyValuePair this[int index] + { + get + { + if (TryGetCommonProperty(index, out KeyValuePair commonProperty)) + { + return commonProperty; + } + else + { + return GetDerivedProperty(index - CommonPropertyCount); + } + } + } + + public IEnumerator> GetEnumerator() + { + var count = Count; + for (var i = 0; i < count; i++) + { + yield return this[i]; + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + protected bool TryGetCommonProperty(int index, out KeyValuePair property) + { + switch (index) + { + case 0: + property = new KeyValuePair(nameof(OperationId), OperationId); + return true; + case 1: + property = new KeyValuePair(nameof(Operation), Operation); + return true; + case 2: + property = new KeyValuePair(nameof(Timestamp), Timestamp); + return true; + default: + property = default; + return false; + } + } + + protected abstract int GetDerivedCount(); + + protected abstract KeyValuePair GetDerivedProperty(int index); + } + + public sealed class SqlClientCommandBefore : SqlClientDiagnostic + { + public SqlClientCommandBefore(Guid operationId, string operation, long timestamp, Guid? connectionId, long? transactionId, SqlCommand command) + : base(operationId, operation, timestamp) + { + ConnectionId = connectionId; + TransactionId = transactionId; + Command = command; + } + + public Guid? ConnectionId { get; } + public long? TransactionId { get; } + public SqlCommand Command { get; } + + protected sealed override int GetDerivedCount() => 3; + + protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), + 1 => new KeyValuePair(nameof(TransactionId), TransactionId), + 2 => new KeyValuePair(nameof(Command), Command), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + public sealed class SqlClientCommandAfter : SqlClientDiagnostic + { + public SqlClientCommandAfter(Guid operationId, string operation, long timestamp, Guid? connectionId, long? transactionId, SqlCommand command, IDictionary statistics) + : base(operationId, operation, timestamp) + { + ConnectionId = connectionId; + TransactionId = transactionId; + Command = command; + Statistics = statistics; + } + + public Guid? ConnectionId { get; } + public long? TransactionId { get; } + public SqlCommand Command { get; } + public IDictionary Statistics { get; } + + protected sealed override int GetDerivedCount() => 4; + + protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), + 1 => new KeyValuePair(nameof(TransactionId), TransactionId), + 2 => new KeyValuePair(nameof(Command), Command), + 3 => new KeyValuePair(nameof(Statistics), Statistics), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + public sealed class SqlClientCommandError : SqlClientDiagnostic + { + public SqlClientCommandError(Guid operationId, string operation, long timestamp, Guid? connectionId, long? transactionId, SqlCommand command, Exception exception) + : base(operationId, operation, timestamp) + { + ConnectionId = connectionId; + TransactionId = transactionId; + Command = command; + Exception = exception; + } + + public Guid? ConnectionId { get; } + public long? TransactionId { get; } + public SqlCommand Command { get; } + public Exception Exception { get; } + + protected sealed override int GetDerivedCount() => 4; + + protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), + 1 => new KeyValuePair(nameof(TransactionId), TransactionId), + 2 => new KeyValuePair(nameof(Command), Command), + 3 => new KeyValuePair(nameof(Exception), Exception), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + public sealed class SqlClientConnectionOpenBefore : SqlClientDiagnostic + { + public SqlClientConnectionOpenBefore(Guid operationId, string operation, long timestamp, SqlConnection connection, string clientVersion) + : base(operationId, operation, timestamp) + { + Connection = connection; + ClientVersion = clientVersion; + } + + public SqlConnection Connection { get; } + public string ClientVersion { get; } + + protected override int GetDerivedCount() => 2; + + protected override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(Connection), Connection), + 1 => new KeyValuePair(nameof(ClientVersion), ClientVersion), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + public sealed class SqlClientConnectionOpenAfter : SqlClientDiagnostic + { + public SqlClientConnectionOpenAfter(Guid operationId, string operation, long timestamp, Guid connectionId, SqlConnection connection, string clientVersion, IDictionary statistics) + : base(operationId, operation, timestamp) + { + ConnectionId = connectionId; + Connection = connection; + ClientVersion = clientVersion; + Statistics = statistics; + } + + public Guid ConnectionId { get; } + public SqlConnection Connection { get; } + public string ClientVersion { get; } + public IDictionary Statistics { get; } + + protected override int GetDerivedCount() => 4; + + protected override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), + 1 => new KeyValuePair(nameof(Connection), Connection), + 2 => new KeyValuePair(nameof(ClientVersion), ClientVersion), + 3 => new KeyValuePair(nameof(Statistics), Statistics), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + public sealed class SqlClientConnectionOpenError : SqlClientDiagnostic + { + public SqlClientConnectionOpenError(Guid operationId, string operation, long timestamp, Guid connectionId, SqlConnection connection, string clientVersion, Exception exception) + : base(operationId, operation, timestamp) + { + ConnectionId = connectionId; + Connection = connection; + ClientVersion = clientVersion; + Exception = exception; + } + + public Guid ConnectionId { get; } + public SqlConnection Connection { get; } + public string ClientVersion { get; } + public Exception Exception { get; } + + protected override int GetDerivedCount() => 4; + + protected override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), + 1 => new KeyValuePair(nameof(Connection), Connection), + 2 => new KeyValuePair(nameof(ClientVersion), ClientVersion), + 3 => new KeyValuePair(nameof(Exception), Exception), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + +#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member + internal ref struct DiagnosticScope //: IDisposable //ref structs cannot implement interfaces but the compiler will use pattern matching { private const int CommandOperation = 1; From 176f2cc158dc60f9a441f690b204197c46e59134 Mon Sep 17 00:00:00 2001 From: Wraith2 Date: Thu, 16 Nov 2023 20:25:43 +0000 Subject: [PATCH 2/7] remaining base implementation --- .../SqlClientDiagnosticListenerExtensions.cs | 450 ++++++++++++++---- 1 file changed, 351 insertions(+), 99 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnosticListenerExtensions.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnosticListenerExtensions.cs index b78b4975a2..f0b8b717d5 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnosticListenerExtensions.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnosticListenerExtensions.cs @@ -61,7 +61,9 @@ public static Guid WriteCommandBefore(this SqlDiagnosticListener @this, SqlComma return operationId; } else + { return Guid.Empty; + } } public static void WriteCommandAfter(this SqlDiagnosticListener @this, Guid operationId, SqlCommand sqlCommand, SqlTransaction transaction, [CallerMemberName] string operation = "") @@ -89,16 +91,17 @@ public static void WriteCommandError(this SqlDiagnosticListener @this, Guid oper { @this.Write( SqlErrorExecuteCommand, - new - { - OperationId = operationId, - Operation = operation, - ConnectionId = sqlCommand.Connection?.ClientConnectionId, - Command = sqlCommand, + new SqlClientCommandError + ( + operationId, + operation, + Stopwatch.GetTimestamp(), + sqlCommand.Connection?.ClientConnectionId, transaction?.InternalTransaction?.TransactionId, - Exception = ex, - Timestamp = Stopwatch.GetTimestamp() - }); + sqlCommand, + ex + ) + ); } } @@ -123,7 +126,9 @@ public static Guid WriteConnectionOpenBefore(this SqlDiagnosticListener @this, S return operationId; } else + { return Guid.Empty; + } } public static void WriteConnectionOpenAfter(this SqlDiagnosticListener @this, Guid operationId, SqlConnection sqlConnection, [CallerMemberName] string operation = "") @@ -174,16 +179,16 @@ public static Guid WriteConnectionCloseBefore(this SqlDiagnosticListener @this, @this.Write( SqlBeforeCloseConnection, - new - { - OperationId = operationId, - Operation = operation, - Timestamp = Stopwatch.GetTimestamp(), - - ConnectionId = sqlConnection.ClientConnectionId, - Connection = sqlConnection, - Statistics = sqlConnection.Statistics?.GetDictionary() - }); + new SqlClientConnectionCloseBefore + ( + operationId, + operation, + Stopwatch.GetTimestamp(), + sqlConnection.ClientConnectionId, + sqlConnection, + sqlConnection.Statistics?.GetDictionary() + ) + ); return operationId; } @@ -197,16 +202,16 @@ public static void WriteConnectionCloseAfter(this SqlDiagnosticListener @this, G { @this.Write( SqlAfterCloseConnection, - new - { - OperationId = operationId, - Operation = operation, - Timestamp = Stopwatch.GetTimestamp(), - - ConnectionId = clientConnectionId, - Connection = sqlConnection, - Statistics = sqlConnection.Statistics?.GetDictionary(), - }); + new SqlClientConnectionCloseAfter + ( + operationId, + operation, + Stopwatch.GetTimestamp(), + clientConnectionId, + sqlConnection, + sqlConnection.Statistics?.GetDictionary() + ) + ); } } @@ -216,17 +221,17 @@ public static void WriteConnectionCloseError(this SqlDiagnosticListener @this, G { @this.Write( SqlErrorCloseConnection, - new - { - OperationId = operationId, - Operation = operation, - Timestamp = Stopwatch.GetTimestamp(), - - ConnectionId = clientConnectionId, - Connection = sqlConnection, - Statistics = sqlConnection.Statistics?.GetDictionary(), - Exception = ex, - }); + new SqlClientConnectionCloseError + ( + operationId, + operation, + Stopwatch.GetTimestamp(), + clientConnectionId, + sqlConnection, + sqlConnection.Statistics?.GetDictionary(), + ex + ) + ); } } @@ -238,21 +243,23 @@ public static Guid WriteTransactionCommitBefore(this SqlDiagnosticListener @this @this.Write( SqlBeforeCommitTransaction, - new - { - OperationId = operationId, - Operation = operation, - Timestamp = Stopwatch.GetTimestamp(), - - IsolationLevel = isolationLevel, - Connection = connection, + new SqlClientTransactionCommitBefore + ( + operationId, + operation, + Stopwatch.GetTimestamp(), + isolationLevel, + connection, transaction?.TransactionId - }); + ) + ); return operationId; } else + { return Guid.Empty; + } } public static void WriteTransactionCommitAfter(this SqlDiagnosticListener @this, Guid operationId, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, [CallerMemberName] string operation = "") @@ -261,16 +268,16 @@ public static void WriteTransactionCommitAfter(this SqlDiagnosticListener @this, { @this.Write( SqlAfterCommitTransaction, - new - { - OperationId = operationId, - Operation = operation, - Timestamp = Stopwatch.GetTimestamp(), - - IsolationLevel = isolationLevel, - Connection = connection, + new SqlClientTransactionCommitAfter + ( + operationId, + operation, + Stopwatch.GetTimestamp(), + isolationLevel, + connection, transaction?.TransactionId - }); + ) + ); } } @@ -280,17 +287,17 @@ public static void WriteTransactionCommitError(this SqlDiagnosticListener @this, { @this.Write( SqlErrorCommitTransaction, - new - { - OperationId = operationId, - Operation = operation, - Timestamp = Stopwatch.GetTimestamp(), - - IsolationLevel = isolationLevel, - Connection = connection, + new SqlClientTransactionCommitError + ( + operationId, + operation, + Stopwatch.GetTimestamp(), + isolationLevel, + connection, transaction?.TransactionId, - Exception = ex, - }); + ex + ) + ); } } @@ -302,22 +309,24 @@ public static Guid WriteTransactionRollbackBefore(this SqlDiagnosticListener @th @this.Write( SqlBeforeRollbackTransaction, - new - { - OperationId = operationId, - Operation = operation, - Timestamp = Stopwatch.GetTimestamp(), - - IsolationLevel = isolationLevel, - Connection = connection, + new SqlClientTransactionRollbackBefore + ( + operationId, + operation, + Stopwatch.GetTimestamp(), + isolationLevel, + connection, transaction?.TransactionId, - TransactionName = transactionName, - }); + transactionName + ) + ); return operationId; } else + { return Guid.Empty; + } } public static void WriteTransactionRollbackAfter(this SqlDiagnosticListener @this, Guid operationId, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, string transactionName = null, [CallerMemberName] string operation = "") @@ -326,17 +335,17 @@ public static void WriteTransactionRollbackAfter(this SqlDiagnosticListener @thi { @this.Write( SqlAfterRollbackTransaction, - new - { - OperationId = operationId, - Operation = operation, - Timestamp = Stopwatch.GetTimestamp(), - - IsolationLevel = isolationLevel, - Connection = connection, + new SqlClientTransactionRollbackAfter + ( + operationId, + operation, + Stopwatch.GetTimestamp(), + isolationLevel, + connection, transaction?.TransactionId, - TransactionName = transactionName - }); + transactionName + ) + ); } } @@ -346,18 +355,18 @@ public static void WriteTransactionRollbackError(this SqlDiagnosticListener @thi { @this.Write( SqlErrorRollbackTransaction, - new - { - OperationId = operationId, - Operation = operation, - Timestamp = Stopwatch.GetTimestamp(), - - IsolationLevel = isolationLevel, - Connection = connection, + new SqlClientTransactionRollbackError + ( + operationId, + operation, + Stopwatch.GetTimestamp(), + isolationLevel, + connection, transaction?.TransactionId, - TransactionName = transactionName, - Exception = ex, - }); + transactionName, + ex + ) + ); } } @@ -607,6 +616,249 @@ public SqlClientConnectionOpenError(Guid operationId, string operation, long tim }; } + public sealed class SqlClientConnectionCloseBefore : SqlClientDiagnostic + { + public SqlClientConnectionCloseBefore(Guid operationId, string operation, long timestamp, Guid? connectionId, SqlConnection connection, IDictionary statistics) + : base(operationId, operation, timestamp) + { + ConnectionId = connectionId; + Connection = connection; + Statistics = statistics; + } + + public Guid? ConnectionId { get; } + public SqlConnection Connection { get; } + public IDictionary Statistics { get; } + + protected sealed override int GetDerivedCount() => 3; + + protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), + 1 => new KeyValuePair(nameof(Connection), Connection), + 2 => new KeyValuePair(nameof(Statistics), Statistics), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + public sealed class SqlClientConnectionCloseAfter : SqlClientDiagnostic + { + public SqlClientConnectionCloseAfter(Guid operationId, string operation, long timestamp, Guid? connectionId, SqlConnection connection, IDictionary statistics) + : base(operationId, operation, timestamp) + { + ConnectionId = connectionId; + Connection = connection; + Statistics = statistics; + } + + public Guid? ConnectionId { get; } + public SqlConnection Connection { get; } + public IDictionary Statistics { get; } + + protected sealed override int GetDerivedCount() => 3; + + protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), + 1 => new KeyValuePair(nameof(Connection), Connection), + 2 => new KeyValuePair(nameof(Statistics), Statistics), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + public sealed class SqlClientConnectionCloseError : SqlClientDiagnostic + { + public SqlClientConnectionCloseError(Guid operationId, string operation, long timestamp, Guid? connectionId, SqlConnection connection, IDictionary statistics, Exception ex) + : base(operationId, operation, timestamp) + { + ConnectionId = connectionId; + Connection = connection; + Statistics = statistics; + Exception = ex; + } + + public Guid? ConnectionId { get; } + public SqlConnection Connection { get; } + public IDictionary Statistics { get; } + public Exception Exception { get; } + + protected sealed override int GetDerivedCount() => 4; + + protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), + 1 => new KeyValuePair(nameof(Connection), Connection), + 2 => new KeyValuePair(nameof(Statistics), Statistics), + 3 => new KeyValuePair(nameof(Exception), Exception), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + public sealed class SqlClientTransactionCommitBefore : SqlClientDiagnostic + { + public SqlClientTransactionCommitBefore(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId) + : base(operationId, operation, timestamp) + { + IsolationLevel = isolationLevel; + Connection = connection; + TransactionId = transactionId; + } + + public IsolationLevel IsolationLevel { get; } + public SqlConnection Connection { get; } + public long? TransactionId { get; } + + protected sealed override int GetDerivedCount() => 3; + + protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), + 1 => new KeyValuePair(nameof(Connection), Connection), + 2 => new KeyValuePair(nameof(TransactionId), TransactionId), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + public sealed class SqlClientTransactionCommitAfter : SqlClientDiagnostic + { + public SqlClientTransactionCommitAfter(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId) + : base(operationId, operation, timestamp) + { + IsolationLevel = isolationLevel; + Connection = connection; + TransactionId = transactionId; + } + + public IsolationLevel IsolationLevel { get; } + public SqlConnection Connection { get; } + public long? TransactionId { get; } + + protected sealed override int GetDerivedCount() => 3; + + protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), + 1 => new KeyValuePair(nameof(Connection), Connection), + 2 => new KeyValuePair(nameof(TransactionId), TransactionId), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + public sealed class SqlClientTransactionCommitError : SqlClientDiagnostic + { + public SqlClientTransactionCommitError(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId, Exception ex) + : base(operationId, operation, timestamp) + { + IsolationLevel = isolationLevel; + Connection = connection; + TransactionId = transactionId; + Exception = ex; + } + + public IsolationLevel IsolationLevel { get; } + public SqlConnection Connection { get; } + public long? TransactionId { get; } + public Exception Exception { get; } + + protected sealed override int GetDerivedCount() => 4; + + protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), + 1 => new KeyValuePair(nameof(Connection), Connection), + 2 => new KeyValuePair(nameof(TransactionId), TransactionId), + 3 => new KeyValuePair(nameof(Exception), Exception), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + public sealed class SqlClientTransactionRollbackBefore : SqlClientDiagnostic + { + public SqlClientTransactionRollbackBefore(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId, string transactionName) + : base(operationId, operation, timestamp) + { + IsolationLevel = isolationLevel; + Connection = connection; + TransactionId = transactionId; + TransactionName = transactionName; + } + + public IsolationLevel IsolationLevel { get; } + public SqlConnection Connection { get; } + public long? TransactionId { get; } + public string TransactionName { get; } + + protected sealed override int GetDerivedCount() => 4; + + protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), + 1 => new KeyValuePair(nameof(Connection), Connection), + 2 => new KeyValuePair(nameof(TransactionId), TransactionId), + 3 => new KeyValuePair(nameof(TransactionName), TransactionName), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + public sealed class SqlClientTransactionRollbackAfter : SqlClientDiagnostic + { + public SqlClientTransactionRollbackAfter(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId, string transactionName) + : base(operationId, operation, timestamp) + { + IsolationLevel = isolationLevel; + Connection = connection; + TransactionId = transactionId; + TransactionName = transactionName; + } + + public IsolationLevel IsolationLevel { get; } + public SqlConnection Connection { get; } + public long? TransactionId { get; } + public string TransactionName { get; } + + protected sealed override int GetDerivedCount() => 4; + + protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), + 1 => new KeyValuePair(nameof(Connection), Connection), + 2 => new KeyValuePair(nameof(TransactionId), TransactionId), + 3 => new KeyValuePair(nameof(TransactionName), TransactionName), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + public sealed class SqlClientTransactionRollbackError : SqlClientDiagnostic + { + public SqlClientTransactionRollbackError(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId, string transactionName, Exception ex) + : base(operationId, operation, timestamp) + { + IsolationLevel = isolationLevel; + Connection = connection; + TransactionId = transactionId; + TransactionName = transactionName; + Exception = ex; + } + + public IsolationLevel IsolationLevel { get; } + public SqlConnection Connection { get; } + public long? TransactionId { get; } + public string TransactionName { get; } + public Exception Exception { get; } + + protected sealed override int GetDerivedCount() => 5; + + protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), + 1 => new KeyValuePair(nameof(Connection), Connection), + 2 => new KeyValuePair(nameof(TransactionId), TransactionId), + 3 => new KeyValuePair(nameof(TransactionName), TransactionName), + 4 => new KeyValuePair(nameof(Exception), Exception), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member internal ref struct DiagnosticScope //: IDisposable //ref structs cannot implement interfaces but the compiler will use pattern matching From 1ecf716f525b6cb89b56fe01d4c42c7f4e8c68e0 Mon Sep 17 00:00:00 2001 From: Wraith2 Date: Fri, 17 Nov 2023 02:22:22 +0000 Subject: [PATCH 3/7] add documentation and change internal references --- .../SqlClientDiagnostic.xml | 319 +++++++++++++++++ .../SqlClientDiagnosticListenerExtensions.cs | 332 +++++++++++++----- .../Microsoft/Data/SqlClient/SqlCommand.cs | 2 +- .../Microsoft/Data/SqlClient/SqlConnection.cs | 10 +- 4 files changed, 575 insertions(+), 88 deletions(-) create mode 100644 doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml new file mode 100644 index 0000000000..9f2dbb428b --- /dev/null +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml @@ -0,0 +1,319 @@ + + + + + The abstract base class for diagnostic events containing common fields shared by all diagnostic events. + + + A guid value used to correlate before, after and error events. + The name of the operation. + The timestamp of the event. + + Initializes a new instance of the class. + + + + A guid value used to correlate before, after and error events. + + + The name of the operation. + + + The timestamp of the event. + + + Provides the count of common properties for classes which derive from this class. + + + Provides derived classed with a method to attempt to fetch common properties from the this base class. Returns true if the property is found false otherwise. + + + Provides the base class with the count of additional properties added by derived classes. This is used to produce the Count value. + + + Provides the base class with the the ability to query for properties added by derived classes. This is used to provide values to the indexer. + + + + + Contains diagnostic information emitted before a command is executed. + + + The name of the event that that needs to be enabled for the event to be raised. + + + A nullable guid uniquely identifying the connection that the xommand is being executed on. + + + A nullable long uniquely identifying the transaction that the command enrolled in if it is enrolled in one. + + + The command object that is executing. + + + + + Contains diagnostic information emitted after a command is successfully executed. + + + The name of the event that that needs to be enabled for the event to be raised. + + + A nullable guid uniquely identifying the connection that the command is being executed on. + + + A nullable long uniquely identifying the transaction that the command is enrolled in if it is enrolled in one, or null. + + + The command object that is executing. + + + An IDictionary of statistic information about the event that has completed. + + + + + Contains diagnostic information emitted after a command execution fails with an exception. + + + The name of the event that that needs to be enabled for the event to be raised. + + + A nullable guid uniquely identifying the connection that the command is being executed on. + + + A nullable long uniquely identifying the transaction that the command is enrolled in if it is enrolled in one, or null. + + + The command object that is executing. + + + The exception object that caused the command execution to fail. + + + + + Contains diagnostic information emitted before a connection is opened. + + + The name of the event that that needs to be enabled for the event to be raised. + + + The connection object that is being opened. + + + The version of the SqlClient library. + + + + + Contains diagnostic information emitted after a connection has been successfully opened. + + + The name of the event that that needs to be enabled for the event to be raised. + + + The connection object that has been opened. + + + The version of the SqlClient library. + + + The unique guid assigned to the connection. + + + An IDictionary of statistic information about the event that has completed. + + + + + Contains diagnostic information emitted after a connection open fails with an exception. + + + The name of the event that that needs to be enabled for the event to be raised. + + + The connection object that has been opened. + + + The version of the SqlClient library. + + + The unique guid assigned to the connection. + + + The exception object that caused the command execution to fail. + + + + + Contains diagnostic information emitted before a connection is closed. + + + The name of the event that that needs to be enabled for the event to be raised. + + + The connection object that is being closed. + + + The unique guid assigned to the connection. + + + An IDictionary of statistic information about the connection. + + + + + Contains diagnostic information emitted after a connection has been successfully closed. + + + The name of the event that that needs to be enabled for the event to be raised. + + + The connection object that has been closed. + + + The unique guid assigned to the connection. + + + An IDictionary of statistic information about the connection. + + + + + Contains diagnostic information emitted after a connection close fails with an exception. + + + The name of the event that that needs to be enabled for the event to be raised. + + + The connection object that has been closed. + + + The unique guid assigned to the connection. + + + An IDictionary of statistic information about the connection. + + + The exception object that caused the command execution to fail. + + + + + Contains diagnostic information emitted before a transaction is opened. + + + The name of the event that that needs to be enabled for the event to be raised. + + + The connection object that the transaction belongs to. + + + The IsolationLevel of the transaction. + + + A nullable long uniquely identifying the transaction that the command is enrolled in if it is enrolled in one, or null. + + + + + Contains diagnostic information emitted after a transaction is successfully committed. + + + The name of the event that that needs to be enabled for the event to be raised. + + + The connection object that the transaction belongs to. + + + The IsolationLevel of the transaction. + + + A nullable long uniquely identifying the transaction that the command is enrolled in if it is enrolled in one, or null. + + + + + Contains diagnostic information emitted after a transaction commit fails with an exception. + + + The name of the event that that needs to be enabled for the event to be raised. + + + The connection object that the transaction belongs to. + + + The IsolationLevel of the transaction. + + + A nullable long uniquely identifying the transaction that the command is enrolled in if it is enrolled in one, or null. + + + The exception object that caused the command execution to fail. + + + + + Contains diagnostic information emitted before a transaction rollback is rolled back. + + + The name of the event that that needs to be enabled for the event to be raised. + + + The connection object that the transaction belongs to. + + + The IsolationLevel of the transaction. + + + A nullable long uniquely identifying the transaction that the command is enrolled in if it is enrolled in one, or null. + + + The name of the transaction which is being rolled back. + + + + + Contains diagnostic information emitted after a transaction is rolled back successfully. + + + The name of the event that that needs to be enabled for the event to be raised. + + + The connection object that the transaction belongs to. + + + The IsolationLevel of the transaction. + + + A nullable long uniquely identifying the transaction, or null. + + + The name of the transaction which is being rolled back. + + + + + Contains diagnostic information emitted after a transaction roll back failes with an exception. + + + The name of the event that that needs to be enabled for the event to be raised. + + + The connection object that the transaction belongs to. + + + The IsolationLevel of the transaction. + + + A nullable long uniquely identifying the transaction , or null. + + + The name of the transaction which is being rolled back. + + + The exception object that caused the command execution to fail. + + + diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnosticListenerExtensions.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnosticListenerExtensions.cs index f0b8b717d5..da0e8fe8b0 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnosticListenerExtensions.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnosticListenerExtensions.cs @@ -18,36 +18,14 @@ internal static class SqlClientDiagnosticListenerExtensions { public const string DiagnosticListenerName = "SqlClientDiagnosticListener"; - private const string SqlClientPrefix = "Microsoft.Data.SqlClient."; - - public const string SqlBeforeExecuteCommand = SqlClientPrefix + nameof(WriteCommandBefore); - public const string SqlAfterExecuteCommand = SqlClientPrefix + nameof(WriteCommandAfter); - public const string SqlErrorExecuteCommand = SqlClientPrefix + nameof(WriteCommandError); - - public const string SqlBeforeOpenConnection = SqlClientPrefix + nameof(WriteConnectionOpenBefore); - public const string SqlAfterOpenConnection = SqlClientPrefix + nameof(WriteConnectionOpenAfter); - public const string SqlErrorOpenConnection = SqlClientPrefix + nameof(WriteConnectionOpenError); - - public const string SqlBeforeCloseConnection = SqlClientPrefix + nameof(WriteConnectionCloseBefore); - public const string SqlAfterCloseConnection = SqlClientPrefix + nameof(WriteConnectionCloseAfter); - public const string SqlErrorCloseConnection = SqlClientPrefix + nameof(WriteConnectionCloseError); - - public const string SqlBeforeCommitTransaction = SqlClientPrefix + nameof(WriteTransactionCommitBefore); - public const string SqlAfterCommitTransaction = SqlClientPrefix + nameof(WriteTransactionCommitAfter); - public const string SqlErrorCommitTransaction = SqlClientPrefix + nameof(WriteTransactionCommitError); - - public const string SqlBeforeRollbackTransaction = SqlClientPrefix + nameof(WriteTransactionRollbackBefore); - public const string SqlAfterRollbackTransaction = SqlClientPrefix + nameof(WriteTransactionRollbackAfter); - public const string SqlErrorRollbackTransaction = SqlClientPrefix + nameof(WriteTransactionRollbackError); - public static Guid WriteCommandBefore(this SqlDiagnosticListener @this, SqlCommand sqlCommand, SqlTransaction transaction, [CallerMemberName] string operation = "") { - if (@this.IsEnabled(SqlBeforeExecuteCommand)) + if (@this.IsEnabled(SqlClientCommandBefore.Name)) { Guid operationId = Guid.NewGuid(); @this.Write( - SqlBeforeExecuteCommand, + SqlClientCommandBefore.Name, new SqlClientCommandBefore( operationId, operation, @@ -68,10 +46,10 @@ public static Guid WriteCommandBefore(this SqlDiagnosticListener @this, SqlComma public static void WriteCommandAfter(this SqlDiagnosticListener @this, Guid operationId, SqlCommand sqlCommand, SqlTransaction transaction, [CallerMemberName] string operation = "") { - if (@this.IsEnabled(SqlAfterExecuteCommand)) + if (@this.IsEnabled(SqlClientCommandAfter.Name)) { @this.Write( - SqlAfterExecuteCommand, + SqlClientCommandAfter.Name, new SqlClientCommandAfter( operationId, operation, @@ -87,10 +65,10 @@ public static void WriteCommandAfter(this SqlDiagnosticListener @this, Guid oper public static void WriteCommandError(this SqlDiagnosticListener @this, Guid operationId, SqlCommand sqlCommand, SqlTransaction transaction, Exception ex, [CallerMemberName] string operation = "") { - if (@this.IsEnabled(SqlErrorExecuteCommand)) + if (@this.IsEnabled(SqlClientCommandError.Name)) { @this.Write( - SqlErrorExecuteCommand, + SqlClientCommandError.Name, new SqlClientCommandError ( operationId, @@ -107,12 +85,12 @@ public static void WriteCommandError(this SqlDiagnosticListener @this, Guid oper public static Guid WriteConnectionOpenBefore(this SqlDiagnosticListener @this, SqlConnection sqlConnection, [CallerMemberName] string operation = "") { - if (@this.IsEnabled(SqlBeforeOpenConnection)) + if (@this.IsEnabled(SqlClientConnectionOpenBefore.Name)) { Guid operationId = Guid.NewGuid(); @this.Write( - SqlBeforeOpenConnection, + SqlClientConnectionOpenBefore.Name, new SqlClientConnectionOpenBefore ( operationId, @@ -133,10 +111,10 @@ public static Guid WriteConnectionOpenBefore(this SqlDiagnosticListener @this, S public static void WriteConnectionOpenAfter(this SqlDiagnosticListener @this, Guid operationId, SqlConnection sqlConnection, [CallerMemberName] string operation = "") { - if (@this.IsEnabled(SqlAfterOpenConnection)) + if (@this.IsEnabled(SqlClientConnectionOpenAfter.Name)) { @this.Write( - SqlAfterOpenConnection, + SqlClientConnectionOpenAfter.Name, new SqlClientConnectionOpenAfter ( operationId, @@ -153,10 +131,10 @@ public static void WriteConnectionOpenAfter(this SqlDiagnosticListener @this, Gu public static void WriteConnectionOpenError(this SqlDiagnosticListener @this, Guid operationId, SqlConnection sqlConnection, Exception ex, [CallerMemberName] string operation = "") { - if (@this.IsEnabled(SqlErrorOpenConnection)) + if (@this.IsEnabled(SqlClientConnectionOpenError.Name)) { @this.Write( - SqlErrorOpenConnection, + SqlClientConnectionOpenError.Name, new SqlClientConnectionOpenError ( operationId, @@ -173,12 +151,12 @@ public static void WriteConnectionOpenError(this SqlDiagnosticListener @this, Gu public static Guid WriteConnectionCloseBefore(this SqlDiagnosticListener @this, SqlConnection sqlConnection, [CallerMemberName] string operation = "") { - if (@this.IsEnabled(SqlBeforeCloseConnection)) + if (@this.IsEnabled(SqlClientConnectionCloseBefore.Name)) { Guid operationId = Guid.NewGuid(); @this.Write( - SqlBeforeCloseConnection, + SqlClientConnectionCloseBefore.Name, new SqlClientConnectionCloseBefore ( operationId, @@ -198,10 +176,10 @@ public static Guid WriteConnectionCloseBefore(this SqlDiagnosticListener @this, public static void WriteConnectionCloseAfter(this SqlDiagnosticListener @this, Guid operationId, Guid clientConnectionId, SqlConnection sqlConnection, [CallerMemberName] string operation = "") { - if (@this.IsEnabled(SqlAfterCloseConnection)) + if (@this.IsEnabled(SqlClientConnectionCloseAfter.Name)) { @this.Write( - SqlAfterCloseConnection, + SqlClientConnectionCloseAfter.Name, new SqlClientConnectionCloseAfter ( operationId, @@ -217,10 +195,10 @@ public static void WriteConnectionCloseAfter(this SqlDiagnosticListener @this, G public static void WriteConnectionCloseError(this SqlDiagnosticListener @this, Guid operationId, Guid clientConnectionId, SqlConnection sqlConnection, Exception ex, [CallerMemberName] string operation = "") { - if (@this.IsEnabled(SqlErrorCloseConnection)) + if (@this.IsEnabled(SqlClientConnectionCloseError.Name)) { @this.Write( - SqlErrorCloseConnection, + SqlClientConnectionCloseError.Name, new SqlClientConnectionCloseError ( operationId, @@ -237,12 +215,12 @@ public static void WriteConnectionCloseError(this SqlDiagnosticListener @this, G public static Guid WriteTransactionCommitBefore(this SqlDiagnosticListener @this, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, [CallerMemberName] string operation = "") { - if (@this.IsEnabled(SqlBeforeCommitTransaction)) + if (@this.IsEnabled(SqlClientTransactionCommitBefore.Name)) { Guid operationId = Guid.NewGuid(); @this.Write( - SqlBeforeCommitTransaction, + SqlClientTransactionCommitBefore.Name, new SqlClientTransactionCommitBefore ( operationId, @@ -264,10 +242,10 @@ public static Guid WriteTransactionCommitBefore(this SqlDiagnosticListener @this public static void WriteTransactionCommitAfter(this SqlDiagnosticListener @this, Guid operationId, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, [CallerMemberName] string operation = "") { - if (@this.IsEnabled(SqlAfterCommitTransaction)) + if (@this.IsEnabled(SqlClientTransactionCommitAfter.Name)) { @this.Write( - SqlAfterCommitTransaction, + SqlClientTransactionCommitAfter.Name, new SqlClientTransactionCommitAfter ( operationId, @@ -283,10 +261,10 @@ public static void WriteTransactionCommitAfter(this SqlDiagnosticListener @this, public static void WriteTransactionCommitError(this SqlDiagnosticListener @this, Guid operationId, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, Exception ex, [CallerMemberName] string operation = "") { - if (@this.IsEnabled(SqlErrorCommitTransaction)) + if (@this.IsEnabled(SqlClientTransactionCommitError.Name)) { @this.Write( - SqlErrorCommitTransaction, + SqlClientTransactionCommitError.Name, new SqlClientTransactionCommitError ( operationId, @@ -303,12 +281,12 @@ public static void WriteTransactionCommitError(this SqlDiagnosticListener @this, public static Guid WriteTransactionRollbackBefore(this SqlDiagnosticListener @this, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, string transactionName = null, [CallerMemberName] string operation = "") { - if (@this.IsEnabled(SqlBeforeRollbackTransaction)) + if (@this.IsEnabled(SqlClientTransactionRollbackBefore.Name)) { Guid operationId = Guid.NewGuid(); @this.Write( - SqlBeforeRollbackTransaction, + SqlClientTransactionRollbackBefore.Name, new SqlClientTransactionRollbackBefore ( operationId, @@ -331,10 +309,10 @@ public static Guid WriteTransactionRollbackBefore(this SqlDiagnosticListener @th public static void WriteTransactionRollbackAfter(this SqlDiagnosticListener @this, Guid operationId, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, string transactionName = null, [CallerMemberName] string operation = "") { - if (@this.IsEnabled(SqlAfterRollbackTransaction)) + if (@this.IsEnabled(SqlClientTransactionRollbackAfter.Name)) { @this.Write( - SqlAfterRollbackTransaction, + SqlClientTransactionRollbackAfter.Name, new SqlClientTransactionRollbackAfter ( operationId, @@ -351,10 +329,10 @@ public static void WriteTransactionRollbackAfter(this SqlDiagnosticListener @thi public static void WriteTransactionRollbackError(this SqlDiagnosticListener @this, Guid operationId, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, Exception ex, string transactionName = null, [CallerMemberName] string operation = "") { - if (@this.IsEnabled(SqlErrorRollbackTransaction)) + if (@this.IsEnabled(SqlClientTransactionRollbackError.Name)) { @this.Write( - SqlErrorRollbackTransaction, + SqlClientTransactionRollbackError.Name, new SqlClientTransactionRollbackError ( operationId, @@ -386,11 +364,13 @@ public static DiagnosticTransactionScope CreateTransactionRollbackScope(this Sql } } -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member + /// public abstract class SqlClientDiagnostic : IReadOnlyList> { + /// protected const int CommonPropertyCount = 3; + /// protected SqlClientDiagnostic(Guid operationId, string operation, long timestamp) { OperationId = operationId; @@ -398,12 +378,17 @@ protected SqlClientDiagnostic(Guid operationId, string operation, long timestamp Timestamp = timestamp; } + /// public Guid OperationId { get; } + /// public string Operation { get; } + /// public long Timestamp { get; } + /// > public int Count => CommonPropertyCount + GetDerivedCount(); + /// > public KeyValuePair this[int index] { get @@ -419,20 +404,20 @@ public KeyValuePair this[int index] } } + /// > public IEnumerator> GetEnumerator() { - var count = Count; - for (var i = 0; i < count; i++) + int count = Count; + for (var index = 0; index < count; index++) { - yield return this[i]; + yield return this[index]; } } - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } + /// > + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + /// protected bool TryGetCommonProperty(int index, out KeyValuePair property) { switch (index) @@ -452,14 +437,20 @@ protected bool TryGetCommonProperty(int index, out KeyValuePair } } + /// protected abstract int GetDerivedCount(); + /// protected abstract KeyValuePair GetDerivedProperty(int index); } + /// public sealed class SqlClientCommandBefore : SqlClientDiagnostic - { - public SqlClientCommandBefore(Guid operationId, string operation, long timestamp, Guid? connectionId, long? transactionId, SqlCommand command) + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteCommandBefore"; + + internal SqlClientCommandBefore(Guid operationId, string operation, long timestamp, Guid? connectionId, long? transactionId, SqlCommand command) : base(operationId, operation, timestamp) { ConnectionId = connectionId; @@ -467,12 +458,20 @@ public SqlClientCommandBefore(Guid operationId, string operation, long timestamp Command = command; } + /// public Guid? ConnectionId { get; } + + /// public long? TransactionId { get; } + + /// public SqlCommand Command { get; } + + /// > protected sealed override int GetDerivedCount() => 3; + /// > protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch { 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), @@ -482,9 +481,13 @@ public SqlClientCommandBefore(Guid operationId, string operation, long timestamp }; } + /// public sealed class SqlClientCommandAfter : SqlClientDiagnostic { - public SqlClientCommandAfter(Guid operationId, string operation, long timestamp, Guid? connectionId, long? transactionId, SqlCommand command, IDictionary statistics) + /// + public const string Name = "Microsoft.Data.SqlClient.WriteCommandAfter"; + + internal SqlClientCommandAfter(Guid operationId, string operation, long timestamp, Guid? connectionId, long? transactionId, SqlCommand command, IDictionary statistics) : base(operationId, operation, timestamp) { ConnectionId = connectionId; @@ -493,13 +496,21 @@ public SqlClientCommandAfter(Guid operationId, string operation, long timestamp, Statistics = statistics; } + /// public Guid? ConnectionId { get; } + + /// public long? TransactionId { get; } + + /// public SqlCommand Command { get; } + + /// public IDictionary Statistics { get; } + /// > protected sealed override int GetDerivedCount() => 4; - + /// > protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch { 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), @@ -510,9 +521,14 @@ public SqlClientCommandAfter(Guid operationId, string operation, long timestamp, }; } + /// public sealed class SqlClientCommandError : SqlClientDiagnostic { - public SqlClientCommandError(Guid operationId, string operation, long timestamp, Guid? connectionId, long? transactionId, SqlCommand command, Exception exception) + /// + + public const string Name = "Microsoft.Data.SqlClient.WriteCommandError"; + + internal SqlClientCommandError(Guid operationId, string operation, long timestamp, Guid? connectionId, long? transactionId, SqlCommand command, Exception exception) : base(operationId, operation, timestamp) { ConnectionId = connectionId; @@ -521,13 +537,21 @@ public SqlClientCommandError(Guid operationId, string operation, long timestamp, Exception = exception; } + /// public Guid? ConnectionId { get; } + + /// public long? TransactionId { get; } + + /// public SqlCommand Command { get; } + + /// public Exception Exception { get; } + /// > protected sealed override int GetDerivedCount() => 4; - + /// > protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch { 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), @@ -538,20 +562,28 @@ public SqlClientCommandError(Guid operationId, string operation, long timestamp, }; } + /// public sealed class SqlClientConnectionOpenBefore : SqlClientDiagnostic { - public SqlClientConnectionOpenBefore(Guid operationId, string operation, long timestamp, SqlConnection connection, string clientVersion) + /// + public const string Name = "Microsoft.Data.SqlClient.WriteConnectionOpenBefore"; + + internal SqlClientConnectionOpenBefore(Guid operationId, string operation, long timestamp, SqlConnection connection, string clientVersion) : base(operationId, operation, timestamp) { Connection = connection; ClientVersion = clientVersion; } + /// public SqlConnection Connection { get; } + + /// public string ClientVersion { get; } + /// > protected override int GetDerivedCount() => 2; - + /// > protected override KeyValuePair GetDerivedProperty(int index) => index switch { 0 => new KeyValuePair(nameof(Connection), Connection), @@ -560,9 +592,13 @@ public SqlClientConnectionOpenBefore(Guid operationId, string operation, long ti }; } + /// public sealed class SqlClientConnectionOpenAfter : SqlClientDiagnostic { - public SqlClientConnectionOpenAfter(Guid operationId, string operation, long timestamp, Guid connectionId, SqlConnection connection, string clientVersion, IDictionary statistics) + /// + public const string Name = "Microsoft.Data.SqlClient.WriteConnectionOpenAfter"; + + internal SqlClientConnectionOpenAfter(Guid operationId, string operation, long timestamp, Guid connectionId, SqlConnection connection, string clientVersion, IDictionary statistics) : base(operationId, operation, timestamp) { ConnectionId = connectionId; @@ -571,13 +607,22 @@ public SqlClientConnectionOpenAfter(Guid operationId, string operation, long tim Statistics = statistics; } + /// public Guid ConnectionId { get; } + + /// public SqlConnection Connection { get; } + + /// public string ClientVersion { get; } + + /// public IDictionary Statistics { get; } + /// > protected override int GetDerivedCount() => 4; + /// > protected override KeyValuePair GetDerivedProperty(int index) => index switch { 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), @@ -588,9 +633,14 @@ public SqlClientConnectionOpenAfter(Guid operationId, string operation, long tim }; } + /// public sealed class SqlClientConnectionOpenError : SqlClientDiagnostic { - public SqlClientConnectionOpenError(Guid operationId, string operation, long timestamp, Guid connectionId, SqlConnection connection, string clientVersion, Exception exception) + /// + + public const string Name = "Microsoft.Data.SqlClient.WriteConnectionOpenError"; + + internal SqlClientConnectionOpenError(Guid operationId, string operation, long timestamp, Guid connectionId, SqlConnection connection, string clientVersion, Exception exception) : base(operationId, operation, timestamp) { ConnectionId = connectionId; @@ -599,13 +649,21 @@ public SqlClientConnectionOpenError(Guid operationId, string operation, long tim Exception = exception; } + /// public Guid ConnectionId { get; } + + /// public SqlConnection Connection { get; } + + /// public string ClientVersion { get; } + + /// public Exception Exception { get; } + /// > protected override int GetDerivedCount() => 4; - + /// > protected override KeyValuePair GetDerivedProperty(int index) => index switch { 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), @@ -616,9 +674,13 @@ public SqlClientConnectionOpenError(Guid operationId, string operation, long tim }; } + /// public sealed class SqlClientConnectionCloseBefore : SqlClientDiagnostic { - public SqlClientConnectionCloseBefore(Guid operationId, string operation, long timestamp, Guid? connectionId, SqlConnection connection, IDictionary statistics) + /// + public const string Name = "Microsoft.Data.SqlClient.WriteConnectionCloseBefore"; + + internal SqlClientConnectionCloseBefore(Guid operationId, string operation, long timestamp, Guid? connectionId, SqlConnection connection, IDictionary statistics) : base(operationId, operation, timestamp) { ConnectionId = connectionId; @@ -626,12 +688,19 @@ public SqlClientConnectionCloseBefore(Guid operationId, string operation, long t Statistics = statistics; } + /// public Guid? ConnectionId { get; } + + /// public SqlConnection Connection { get; } + + /// public IDictionary Statistics { get; } + /// > protected sealed override int GetDerivedCount() => 3; + /// > protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch { 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), @@ -641,9 +710,13 @@ public SqlClientConnectionCloseBefore(Guid operationId, string operation, long t }; } + /// public sealed class SqlClientConnectionCloseAfter : SqlClientDiagnostic { - public SqlClientConnectionCloseAfter(Guid operationId, string operation, long timestamp, Guid? connectionId, SqlConnection connection, IDictionary statistics) + /// + public const string Name = "Microsoft.Data.SqlClient.WriteConnectionCloseAfter"; + + internal SqlClientConnectionCloseAfter(Guid operationId, string operation, long timestamp, Guid? connectionId, SqlConnection connection, IDictionary statistics) : base(operationId, operation, timestamp) { ConnectionId = connectionId; @@ -651,12 +724,19 @@ public SqlClientConnectionCloseAfter(Guid operationId, string operation, long ti Statistics = statistics; } + /// public Guid? ConnectionId { get; } + + /// public SqlConnection Connection { get; } + + /// public IDictionary Statistics { get; } + /// > protected sealed override int GetDerivedCount() => 3; + /// > protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch { 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), @@ -666,9 +746,13 @@ public SqlClientConnectionCloseAfter(Guid operationId, string operation, long ti }; } + /// public sealed class SqlClientConnectionCloseError : SqlClientDiagnostic { - public SqlClientConnectionCloseError(Guid operationId, string operation, long timestamp, Guid? connectionId, SqlConnection connection, IDictionary statistics, Exception ex) + /// + public const string Name = "Microsoft.Data.SqlClient.WriteConnectionCloseError"; + + internal SqlClientConnectionCloseError(Guid operationId, string operation, long timestamp, Guid? connectionId, SqlConnection connection, IDictionary statistics, Exception ex) : base(operationId, operation, timestamp) { ConnectionId = connectionId; @@ -677,13 +761,23 @@ public SqlClientConnectionCloseError(Guid operationId, string operation, long ti Exception = ex; } + /// public Guid? ConnectionId { get; } + + /// + public SqlConnection Connection { get; } + + /// public IDictionary Statistics { get; } + + /// public Exception Exception { get; } + /// > protected sealed override int GetDerivedCount() => 4; + /// > protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch { 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), @@ -694,9 +788,13 @@ public SqlClientConnectionCloseError(Guid operationId, string operation, long ti }; } + /// public sealed class SqlClientTransactionCommitBefore : SqlClientDiagnostic { - public SqlClientTransactionCommitBefore(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId) + /// + public const string Name = "Microsoft.Data.SqlClient.WriteTransactionCommitBefore"; + + internal SqlClientTransactionCommitBefore(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId) : base(operationId, operation, timestamp) { IsolationLevel = isolationLevel; @@ -704,12 +802,19 @@ public SqlClientTransactionCommitBefore(Guid operationId, string operation, long TransactionId = transactionId; } + /// public IsolationLevel IsolationLevel { get; } + + /// public SqlConnection Connection { get; } + + /// public long? TransactionId { get; } + /// > protected sealed override int GetDerivedCount() => 3; + /// > protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch { 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), @@ -719,9 +824,13 @@ public SqlClientTransactionCommitBefore(Guid operationId, string operation, long }; } + /// public sealed class SqlClientTransactionCommitAfter : SqlClientDiagnostic { - public SqlClientTransactionCommitAfter(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId) + /// + public const string Name = "Microsoft.Data.SqlClient.WriteTransactionCommitAfter"; + + internal SqlClientTransactionCommitAfter(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId) : base(operationId, operation, timestamp) { IsolationLevel = isolationLevel; @@ -729,12 +838,19 @@ public SqlClientTransactionCommitAfter(Guid operationId, string operation, long TransactionId = transactionId; } + /// public IsolationLevel IsolationLevel { get; } + + /// public SqlConnection Connection { get; } + + /// public long? TransactionId { get; } + /// > protected sealed override int GetDerivedCount() => 3; + /// > protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch { 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), @@ -744,9 +860,13 @@ public SqlClientTransactionCommitAfter(Guid operationId, string operation, long }; } + /// public sealed class SqlClientTransactionCommitError : SqlClientDiagnostic { - public SqlClientTransactionCommitError(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId, Exception ex) + /// + public const string Name = "Microsoft.Data.SqlClient.WriteTransactionCommitError"; + + internal SqlClientTransactionCommitError(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId, Exception ex) : base(operationId, operation, timestamp) { IsolationLevel = isolationLevel; @@ -755,13 +875,22 @@ public SqlClientTransactionCommitError(Guid operationId, string operation, long Exception = ex; } + /// public IsolationLevel IsolationLevel { get; } + + /// public SqlConnection Connection { get; } + + /// public long? TransactionId { get; } + + /// public Exception Exception { get; } + /// > protected sealed override int GetDerivedCount() => 4; + /// > protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch { 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), @@ -772,9 +901,13 @@ public SqlClientTransactionCommitError(Guid operationId, string operation, long }; } + /// public sealed class SqlClientTransactionRollbackBefore : SqlClientDiagnostic { - public SqlClientTransactionRollbackBefore(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId, string transactionName) + /// + public const string Name = "Microsoft.Data.SqlClient.WriteTransactionRollbackBefore"; + + internal SqlClientTransactionRollbackBefore(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId, string transactionName) : base(operationId, operation, timestamp) { IsolationLevel = isolationLevel; @@ -783,13 +916,22 @@ public SqlClientTransactionRollbackBefore(Guid operationId, string operation, lo TransactionName = transactionName; } + /// public IsolationLevel IsolationLevel { get; } + + /// public SqlConnection Connection { get; } + + /// public long? TransactionId { get; } + + /// public string TransactionName { get; } + /// > protected sealed override int GetDerivedCount() => 4; + /// > protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch { 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), @@ -800,9 +942,13 @@ public SqlClientTransactionRollbackBefore(Guid operationId, string operation, lo }; } + /// public sealed class SqlClientTransactionRollbackAfter : SqlClientDiagnostic { - public SqlClientTransactionRollbackAfter(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId, string transactionName) + /// + public const string Name = "Microsoft.Data.SqlClient.WriteTransactionRollbackAfter"; + + internal SqlClientTransactionRollbackAfter(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId, string transactionName) : base(operationId, operation, timestamp) { IsolationLevel = isolationLevel; @@ -811,13 +957,22 @@ public SqlClientTransactionRollbackAfter(Guid operationId, string operation, lon TransactionName = transactionName; } + /// public IsolationLevel IsolationLevel { get; } + + /// public SqlConnection Connection { get; } + + /// public long? TransactionId { get; } + + /// public string TransactionName { get; } + /// > protected sealed override int GetDerivedCount() => 4; + /// > protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch { 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), @@ -828,9 +983,13 @@ public SqlClientTransactionRollbackAfter(Guid operationId, string operation, lon }; } + /// public sealed class SqlClientTransactionRollbackError : SqlClientDiagnostic { - public SqlClientTransactionRollbackError(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId, string transactionName, Exception ex) + /// + public const string Name = "Microsoft.Data.SqlClient.WriteTransactionRollbackError"; + + internal SqlClientTransactionRollbackError(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId, string transactionName, Exception ex) : base(operationId, operation, timestamp) { IsolationLevel = isolationLevel; @@ -840,14 +999,25 @@ public SqlClientTransactionRollbackError(Guid operationId, string operation, lon Exception = ex; } + /// public IsolationLevel IsolationLevel { get; } + + /// public SqlConnection Connection { get; } + + /// public long? TransactionId { get; } + + /// public string TransactionName { get; } + + /// public Exception Exception { get; } + /// > protected sealed override int GetDerivedCount() => 5; + /// > protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch { 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), @@ -859,8 +1029,6 @@ public SqlClientTransactionRollbackError(Guid operationId, string operation, lon }; } -#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member - internal ref struct DiagnosticScope //: IDisposable //ref structs cannot implement interfaces but the compiler will use pattern matching { private const int CommandOperation = 1; diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs index 94325d3c88..7a615dacfe 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs @@ -596,7 +596,7 @@ internal SqlStatistics Statistics if (null != _activeConnection) { if (_activeConnection.StatisticsEnabled || - s_diagnosticListener.IsEnabled(SqlClientDiagnosticListenerExtensions.SqlAfterExecuteCommand)) + s_diagnosticListener.IsEnabled(SqlClientCommandAfter.Name)) { return _activeConnection.Statistics; } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs index 1d044633ec..bbf37b0bf4 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs @@ -1689,8 +1689,8 @@ private Task InternalOpenAsync(CancellationToken cancellationToken) TaskCompletionSource completion = new TaskCompletionSource(transaction); TaskCompletionSource result = new TaskCompletionSource(state: this); - if (s_diagnosticListener.IsEnabled(SqlClientDiagnosticListenerExtensions.SqlAfterOpenConnection) || - s_diagnosticListener.IsEnabled(SqlClientDiagnosticListenerExtensions.SqlErrorOpenConnection)) + if (s_diagnosticListener.IsEnabled(SqlClientConnectionOpenAfter.Name) || + s_diagnosticListener.IsEnabled(SqlClientConnectionOpenError.Name)) { result.Task.ContinueWith( continuationAction: s_openAsyncComplete, @@ -1879,8 +1879,8 @@ internal void Retry(Task retryTask) private void PrepareStatisticsForNewConnection() { if (StatisticsEnabled || - s_diagnosticListener.IsEnabled(SqlClientDiagnosticListenerExtensions.SqlAfterExecuteCommand) || - s_diagnosticListener.IsEnabled(SqlClientDiagnosticListenerExtensions.SqlAfterOpenConnection)) + s_diagnosticListener.IsEnabled(SqlClientCommandAfter.Name) || + s_diagnosticListener.IsEnabled(SqlClientConnectionOpenAfter.Name)) { if (null == _statistics) { @@ -1985,7 +1985,7 @@ private bool TryOpen(TaskCompletionSource retry, SqlConnec // The _statistics can change with StatisticsEnabled. Copying to a local variable before checking for a null value. SqlStatistics statistics = _statistics; if (StatisticsEnabled || - (s_diagnosticListener.IsEnabled(SqlClientDiagnosticListenerExtensions.SqlAfterExecuteCommand) && statistics != null)) + (s_diagnosticListener.IsEnabled(SqlClientCommandAfter.Name) && statistics != null)) { _statistics._openTimestamp = ADP.TimerCurrent(); tdsInnerConnection.Parser.Statistics = _statistics; From 7738b78a048f2430917a48e9955253c4c66333bd Mon Sep 17 00:00:00 2001 From: Wraith2 Date: Tue, 11 Jun 2024 01:48:10 +0100 Subject: [PATCH 4/7] move diagnostics classes to dedicated namespace and file --- .../src/Microsoft.Data.SqlClient.csproj | 1 + .../Data/SqlClient/SqlClientDiagnostic.cs | 676 ++++++++++++++++++ .../SqlClientDiagnosticListenerExtensions.cs | 666 +---------------- .../Microsoft/Data/SqlClient/SqlCommand.cs | 1 + .../Microsoft/Data/SqlClient/SqlConnection.cs | 1 + 5 files changed, 680 insertions(+), 665 deletions(-) create mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnostic.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index 7cf0b1e619..46a77d5373 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -647,6 +647,7 @@ + diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnostic.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnostic.cs new file mode 100644 index 0000000000..1664776d82 --- /dev/null +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnostic.cs @@ -0,0 +1,676 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Data; + +namespace Microsoft.Data.SqlClient.Diagnostics +{ + /// + public abstract class SqlClientDiagnostic : IReadOnlyList> + { + /// + protected const int CommonPropertyCount = 3; + + /// + protected SqlClientDiagnostic(Guid operationId, string operation, long timestamp) + { + OperationId = operationId; + Operation = operation; + Timestamp = timestamp; + } + + /// + public Guid OperationId { get; } + /// + public string Operation { get; } + /// + public long Timestamp { get; } + + /// > + public int Count => CommonPropertyCount + GetDerivedCount(); + + /// > + public KeyValuePair this[int index] + { + get + { + if (TryGetCommonProperty(index, out KeyValuePair commonProperty)) + { + return commonProperty; + } + else + { + return GetDerivedProperty(index - CommonPropertyCount); + } + } + } + + /// > + public IEnumerator> GetEnumerator() + { + int count = Count; + for (var index = 0; index < count; index++) + { + yield return this[index]; + } + } + + /// > + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + /// + protected bool TryGetCommonProperty(int index, out KeyValuePair property) + { + switch (index) + { + case 0: + property = new KeyValuePair(nameof(OperationId), OperationId); + return true; + case 1: + property = new KeyValuePair(nameof(Operation), Operation); + return true; + case 2: + property = new KeyValuePair(nameof(Timestamp), Timestamp); + return true; + default: + property = default; + return false; + } + } + + /// + protected abstract int GetDerivedCount(); + + /// + protected abstract KeyValuePair GetDerivedProperty(int index); + } + + /// + public sealed class SqlClientCommandBefore : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteCommandBefore"; + + internal SqlClientCommandBefore(Guid operationId, string operation, long timestamp, Guid? connectionId, long? transactionId, SqlCommand command) + : base(operationId, operation, timestamp) + { + ConnectionId = connectionId; + TransactionId = transactionId; + Command = command; + } + + /// + public Guid? ConnectionId { get; } + + /// + public long? TransactionId { get; } + + /// + public SqlCommand Command { get; } + + + /// > + protected sealed override int GetDerivedCount() => 3; + + /// > + protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), + 1 => new KeyValuePair(nameof(TransactionId), TransactionId), + 2 => new KeyValuePair(nameof(Command), Command), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// + public sealed class SqlClientCommandAfter : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteCommandAfter"; + + internal SqlClientCommandAfter(Guid operationId, string operation, long timestamp, Guid? connectionId, long? transactionId, SqlCommand command, IDictionary statistics) + : base(operationId, operation, timestamp) + { + ConnectionId = connectionId; + TransactionId = transactionId; + Command = command; + Statistics = statistics; + } + + /// + public Guid? ConnectionId { get; } + + /// + public long? TransactionId { get; } + + /// + public SqlCommand Command { get; } + + /// + public IDictionary Statistics { get; } + + /// > + protected sealed override int GetDerivedCount() => 4; + /// > + protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), + 1 => new KeyValuePair(nameof(TransactionId), TransactionId), + 2 => new KeyValuePair(nameof(Command), Command), + 3 => new KeyValuePair(nameof(Statistics), Statistics), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// + public sealed class SqlClientCommandError : SqlClientDiagnostic + { + /// + + public const string Name = "Microsoft.Data.SqlClient.WriteCommandError"; + + internal SqlClientCommandError(Guid operationId, string operation, long timestamp, Guid? connectionId, long? transactionId, SqlCommand command, Exception exception) + : base(operationId, operation, timestamp) + { + ConnectionId = connectionId; + TransactionId = transactionId; + Command = command; + Exception = exception; + } + + /// + public Guid? ConnectionId { get; } + + /// + public long? TransactionId { get; } + + /// + public SqlCommand Command { get; } + + /// + public Exception Exception { get; } + + /// > + protected sealed override int GetDerivedCount() => 4; + /// > + protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), + 1 => new KeyValuePair(nameof(TransactionId), TransactionId), + 2 => new KeyValuePair(nameof(Command), Command), + 3 => new KeyValuePair(nameof(Exception), Exception), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// + public sealed class SqlClientConnectionOpenBefore : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteConnectionOpenBefore"; + + internal SqlClientConnectionOpenBefore(Guid operationId, string operation, long timestamp, SqlConnection connection, string clientVersion) + : base(operationId, operation, timestamp) + { + Connection = connection; + ClientVersion = clientVersion; + } + + /// + public SqlConnection Connection { get; } + + /// + public string ClientVersion { get; } + + /// > + protected override int GetDerivedCount() => 2; + /// > + protected override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(Connection), Connection), + 1 => new KeyValuePair(nameof(ClientVersion), ClientVersion), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// + public sealed class SqlClientConnectionOpenAfter : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteConnectionOpenAfter"; + + internal SqlClientConnectionOpenAfter(Guid operationId, string operation, long timestamp, Guid connectionId, SqlConnection connection, string clientVersion, IDictionary statistics) + : base(operationId, operation, timestamp) + { + ConnectionId = connectionId; + Connection = connection; + ClientVersion = clientVersion; + Statistics = statistics; + } + + /// + public Guid ConnectionId { get; } + + /// + public SqlConnection Connection { get; } + + /// + public string ClientVersion { get; } + + /// + public IDictionary Statistics { get; } + + /// > + protected override int GetDerivedCount() => 4; + + /// > + protected override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), + 1 => new KeyValuePair(nameof(Connection), Connection), + 2 => new KeyValuePair(nameof(ClientVersion), ClientVersion), + 3 => new KeyValuePair(nameof(Statistics), Statistics), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// + public sealed class SqlClientConnectionOpenError : SqlClientDiagnostic + { + /// + + public const string Name = "Microsoft.Data.SqlClient.WriteConnectionOpenError"; + + internal SqlClientConnectionOpenError(Guid operationId, string operation, long timestamp, Guid connectionId, SqlConnection connection, string clientVersion, Exception exception) + : base(operationId, operation, timestamp) + { + ConnectionId = connectionId; + Connection = connection; + ClientVersion = clientVersion; + Exception = exception; + } + + /// + public Guid ConnectionId { get; } + + /// + public SqlConnection Connection { get; } + + /// + public string ClientVersion { get; } + + /// + public Exception Exception { get; } + + /// > + protected override int GetDerivedCount() => 4; + /// > + protected override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), + 1 => new KeyValuePair(nameof(Connection), Connection), + 2 => new KeyValuePair(nameof(ClientVersion), ClientVersion), + 3 => new KeyValuePair(nameof(Exception), Exception), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// + public sealed class SqlClientConnectionCloseBefore : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteConnectionCloseBefore"; + + internal SqlClientConnectionCloseBefore(Guid operationId, string operation, long timestamp, Guid? connectionId, SqlConnection connection, IDictionary statistics) + : base(operationId, operation, timestamp) + { + ConnectionId = connectionId; + Connection = connection; + Statistics = statistics; + } + + /// + public Guid? ConnectionId { get; } + + /// + public SqlConnection Connection { get; } + + /// + public IDictionary Statistics { get; } + + /// > + protected sealed override int GetDerivedCount() => 3; + + /// > + protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), + 1 => new KeyValuePair(nameof(Connection), Connection), + 2 => new KeyValuePair(nameof(Statistics), Statistics), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// + public sealed class SqlClientConnectionCloseAfter : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteConnectionCloseAfter"; + + internal SqlClientConnectionCloseAfter(Guid operationId, string operation, long timestamp, Guid? connectionId, SqlConnection connection, IDictionary statistics) + : base(operationId, operation, timestamp) + { + ConnectionId = connectionId; + Connection = connection; + Statistics = statistics; + } + + /// + public Guid? ConnectionId { get; } + + /// + public SqlConnection Connection { get; } + + /// + public IDictionary Statistics { get; } + + /// > + protected sealed override int GetDerivedCount() => 3; + + /// > + protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), + 1 => new KeyValuePair(nameof(Connection), Connection), + 2 => new KeyValuePair(nameof(Statistics), Statistics), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// + public sealed class SqlClientConnectionCloseError : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteConnectionCloseError"; + + internal SqlClientConnectionCloseError(Guid operationId, string operation, long timestamp, Guid? connectionId, SqlConnection connection, IDictionary statistics, Exception ex) + : base(operationId, operation, timestamp) + { + ConnectionId = connectionId; + Connection = connection; + Statistics = statistics; + Exception = ex; + } + + /// + public Guid? ConnectionId { get; } + + /// + + public SqlConnection Connection { get; } + + /// + public IDictionary Statistics { get; } + + /// + public Exception Exception { get; } + + /// > + protected sealed override int GetDerivedCount() => 4; + + /// > + protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), + 1 => new KeyValuePair(nameof(Connection), Connection), + 2 => new KeyValuePair(nameof(Statistics), Statistics), + 3 => new KeyValuePair(nameof(Exception), Exception), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// + public sealed class SqlClientTransactionCommitBefore : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteTransactionCommitBefore"; + + internal SqlClientTransactionCommitBefore(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId) + : base(operationId, operation, timestamp) + { + IsolationLevel = isolationLevel; + Connection = connection; + TransactionId = transactionId; + } + + /// + public IsolationLevel IsolationLevel { get; } + + /// + public SqlConnection Connection { get; } + + /// + public long? TransactionId { get; } + + /// > + protected sealed override int GetDerivedCount() => 3; + + /// > + protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), + 1 => new KeyValuePair(nameof(Connection), Connection), + 2 => new KeyValuePair(nameof(TransactionId), TransactionId), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// + public sealed class SqlClientTransactionCommitAfter : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteTransactionCommitAfter"; + + internal SqlClientTransactionCommitAfter(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId) + : base(operationId, operation, timestamp) + { + IsolationLevel = isolationLevel; + Connection = connection; + TransactionId = transactionId; + } + + /// + public IsolationLevel IsolationLevel { get; } + + /// + public SqlConnection Connection { get; } + + /// + public long? TransactionId { get; } + + /// > + protected sealed override int GetDerivedCount() => 3; + + /// > + protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), + 1 => new KeyValuePair(nameof(Connection), Connection), + 2 => new KeyValuePair(nameof(TransactionId), TransactionId), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// + public sealed class SqlClientTransactionCommitError : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteTransactionCommitError"; + + internal SqlClientTransactionCommitError(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId, Exception ex) + : base(operationId, operation, timestamp) + { + IsolationLevel = isolationLevel; + Connection = connection; + TransactionId = transactionId; + Exception = ex; + } + + /// + public IsolationLevel IsolationLevel { get; } + + /// + public SqlConnection Connection { get; } + + /// + public long? TransactionId { get; } + + /// + public Exception Exception { get; } + + /// > + protected sealed override int GetDerivedCount() => 4; + + /// > + protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), + 1 => new KeyValuePair(nameof(Connection), Connection), + 2 => new KeyValuePair(nameof(TransactionId), TransactionId), + 3 => new KeyValuePair(nameof(Exception), Exception), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// + public sealed class SqlClientTransactionRollbackBefore : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteTransactionRollbackBefore"; + + internal SqlClientTransactionRollbackBefore(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId, string transactionName) + : base(operationId, operation, timestamp) + { + IsolationLevel = isolationLevel; + Connection = connection; + TransactionId = transactionId; + TransactionName = transactionName; + } + + /// + public IsolationLevel IsolationLevel { get; } + + /// + public SqlConnection Connection { get; } + + /// + public long? TransactionId { get; } + + /// + public string TransactionName { get; } + + /// > + protected sealed override int GetDerivedCount() => 4; + + /// > + protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), + 1 => new KeyValuePair(nameof(Connection), Connection), + 2 => new KeyValuePair(nameof(TransactionId), TransactionId), + 3 => new KeyValuePair(nameof(TransactionName), TransactionName), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// + public sealed class SqlClientTransactionRollbackAfter : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteTransactionRollbackAfter"; + + internal SqlClientTransactionRollbackAfter(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId, string transactionName) + : base(operationId, operation, timestamp) + { + IsolationLevel = isolationLevel; + Connection = connection; + TransactionId = transactionId; + TransactionName = transactionName; + } + + /// + public IsolationLevel IsolationLevel { get; } + + /// + public SqlConnection Connection { get; } + + /// + public long? TransactionId { get; } + + /// + public string TransactionName { get; } + + /// > + protected sealed override int GetDerivedCount() => 4; + + /// > + protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), + 1 => new KeyValuePair(nameof(Connection), Connection), + 2 => new KeyValuePair(nameof(TransactionId), TransactionId), + 3 => new KeyValuePair(nameof(TransactionName), TransactionName), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// + public sealed class SqlClientTransactionRollbackError : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteTransactionRollbackError"; + + internal SqlClientTransactionRollbackError(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId, string transactionName, Exception ex) + : base(operationId, operation, timestamp) + { + IsolationLevel = isolationLevel; + Connection = connection; + TransactionId = transactionId; + TransactionName = transactionName; + Exception = ex; + } + + /// + public IsolationLevel IsolationLevel { get; } + + /// + public SqlConnection Connection { get; } + + /// + public long? TransactionId { get; } + + /// + public string TransactionName { get; } + + /// + public Exception Exception { get; } + + /// > + protected sealed override int GetDerivedCount() => 5; + + /// > + protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + { + 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), + 1 => new KeyValuePair(nameof(Connection), Connection), + 2 => new KeyValuePair(nameof(TransactionId), TransactionId), + 3 => new KeyValuePair(nameof(TransactionName), TransactionName), + 4 => new KeyValuePair(nameof(Exception), Exception), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } +} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnosticListenerExtensions.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnosticListenerExtensions.cs index da0e8fe8b0..9f63cbaba8 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnosticListenerExtensions.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnosticListenerExtensions.cs @@ -8,6 +8,7 @@ using System.Data; using System.Diagnostics; using System.Runtime.CompilerServices; +using Microsoft.Data.SqlClient.Diagnostics; namespace Microsoft.Data.SqlClient { @@ -364,671 +365,6 @@ public static DiagnosticTransactionScope CreateTransactionRollbackScope(this Sql } } - /// - public abstract class SqlClientDiagnostic : IReadOnlyList> - { - /// - protected const int CommonPropertyCount = 3; - - /// - protected SqlClientDiagnostic(Guid operationId, string operation, long timestamp) - { - OperationId = operationId; - Operation = operation; - Timestamp = timestamp; - } - - /// - public Guid OperationId { get; } - /// - public string Operation { get; } - /// - public long Timestamp { get; } - - /// > - public int Count => CommonPropertyCount + GetDerivedCount(); - - /// > - public KeyValuePair this[int index] - { - get - { - if (TryGetCommonProperty(index, out KeyValuePair commonProperty)) - { - return commonProperty; - } - else - { - return GetDerivedProperty(index - CommonPropertyCount); - } - } - } - - /// > - public IEnumerator> GetEnumerator() - { - int count = Count; - for (var index = 0; index < count; index++) - { - yield return this[index]; - } - } - - /// > - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - - /// - protected bool TryGetCommonProperty(int index, out KeyValuePair property) - { - switch (index) - { - case 0: - property = new KeyValuePair(nameof(OperationId), OperationId); - return true; - case 1: - property = new KeyValuePair(nameof(Operation), Operation); - return true; - case 2: - property = new KeyValuePair(nameof(Timestamp), Timestamp); - return true; - default: - property = default; - return false; - } - } - - /// - protected abstract int GetDerivedCount(); - - /// - protected abstract KeyValuePair GetDerivedProperty(int index); - } - - /// - public sealed class SqlClientCommandBefore : SqlClientDiagnostic - { - /// - public const string Name = "Microsoft.Data.SqlClient.WriteCommandBefore"; - - internal SqlClientCommandBefore(Guid operationId, string operation, long timestamp, Guid? connectionId, long? transactionId, SqlCommand command) - : base(operationId, operation, timestamp) - { - ConnectionId = connectionId; - TransactionId = transactionId; - Command = command; - } - - /// - public Guid? ConnectionId { get; } - - /// - public long? TransactionId { get; } - - /// - public SqlCommand Command { get; } - - - /// > - protected sealed override int GetDerivedCount() => 3; - - /// > - protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch - { - 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), - 1 => new KeyValuePair(nameof(TransactionId), TransactionId), - 2 => new KeyValuePair(nameof(Command), Command), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; - } - - /// - public sealed class SqlClientCommandAfter : SqlClientDiagnostic - { - /// - public const string Name = "Microsoft.Data.SqlClient.WriteCommandAfter"; - - internal SqlClientCommandAfter(Guid operationId, string operation, long timestamp, Guid? connectionId, long? transactionId, SqlCommand command, IDictionary statistics) - : base(operationId, operation, timestamp) - { - ConnectionId = connectionId; - TransactionId = transactionId; - Command = command; - Statistics = statistics; - } - - /// - public Guid? ConnectionId { get; } - - /// - public long? TransactionId { get; } - - /// - public SqlCommand Command { get; } - - /// - public IDictionary Statistics { get; } - - /// > - protected sealed override int GetDerivedCount() => 4; - /// > - protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch - { - 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), - 1 => new KeyValuePair(nameof(TransactionId), TransactionId), - 2 => new KeyValuePair(nameof(Command), Command), - 3 => new KeyValuePair(nameof(Statistics), Statistics), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; - } - - /// - public sealed class SqlClientCommandError : SqlClientDiagnostic - { - /// - - public const string Name = "Microsoft.Data.SqlClient.WriteCommandError"; - - internal SqlClientCommandError(Guid operationId, string operation, long timestamp, Guid? connectionId, long? transactionId, SqlCommand command, Exception exception) - : base(operationId, operation, timestamp) - { - ConnectionId = connectionId; - TransactionId = transactionId; - Command = command; - Exception = exception; - } - - /// - public Guid? ConnectionId { get; } - - /// - public long? TransactionId { get; } - - /// - public SqlCommand Command { get; } - - /// - public Exception Exception { get; } - - /// > - protected sealed override int GetDerivedCount() => 4; - /// > - protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch - { - 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), - 1 => new KeyValuePair(nameof(TransactionId), TransactionId), - 2 => new KeyValuePair(nameof(Command), Command), - 3 => new KeyValuePair(nameof(Exception), Exception), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; - } - - /// - public sealed class SqlClientConnectionOpenBefore : SqlClientDiagnostic - { - /// - public const string Name = "Microsoft.Data.SqlClient.WriteConnectionOpenBefore"; - - internal SqlClientConnectionOpenBefore(Guid operationId, string operation, long timestamp, SqlConnection connection, string clientVersion) - : base(operationId, operation, timestamp) - { - Connection = connection; - ClientVersion = clientVersion; - } - - /// - public SqlConnection Connection { get; } - - /// - public string ClientVersion { get; } - - /// > - protected override int GetDerivedCount() => 2; - /// > - protected override KeyValuePair GetDerivedProperty(int index) => index switch - { - 0 => new KeyValuePair(nameof(Connection), Connection), - 1 => new KeyValuePair(nameof(ClientVersion), ClientVersion), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; - } - - /// - public sealed class SqlClientConnectionOpenAfter : SqlClientDiagnostic - { - /// - public const string Name = "Microsoft.Data.SqlClient.WriteConnectionOpenAfter"; - - internal SqlClientConnectionOpenAfter(Guid operationId, string operation, long timestamp, Guid connectionId, SqlConnection connection, string clientVersion, IDictionary statistics) - : base(operationId, operation, timestamp) - { - ConnectionId = connectionId; - Connection = connection; - ClientVersion = clientVersion; - Statistics = statistics; - } - - /// - public Guid ConnectionId { get; } - - /// - public SqlConnection Connection { get; } - - /// - public string ClientVersion { get; } - - /// - public IDictionary Statistics { get; } - - /// > - protected override int GetDerivedCount() => 4; - - /// > - protected override KeyValuePair GetDerivedProperty(int index) => index switch - { - 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), - 1 => new KeyValuePair(nameof(Connection), Connection), - 2 => new KeyValuePair(nameof(ClientVersion), ClientVersion), - 3 => new KeyValuePair(nameof(Statistics), Statistics), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; - } - - /// - public sealed class SqlClientConnectionOpenError : SqlClientDiagnostic - { - /// - - public const string Name = "Microsoft.Data.SqlClient.WriteConnectionOpenError"; - - internal SqlClientConnectionOpenError(Guid operationId, string operation, long timestamp, Guid connectionId, SqlConnection connection, string clientVersion, Exception exception) - : base(operationId, operation, timestamp) - { - ConnectionId = connectionId; - Connection = connection; - ClientVersion = clientVersion; - Exception = exception; - } - - /// - public Guid ConnectionId { get; } - - /// - public SqlConnection Connection { get; } - - /// - public string ClientVersion { get; } - - /// - public Exception Exception { get; } - - /// > - protected override int GetDerivedCount() => 4; - /// > - protected override KeyValuePair GetDerivedProperty(int index) => index switch - { - 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), - 1 => new KeyValuePair(nameof(Connection), Connection), - 2 => new KeyValuePair(nameof(ClientVersion), ClientVersion), - 3 => new KeyValuePair(nameof(Exception), Exception), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; - } - - /// - public sealed class SqlClientConnectionCloseBefore : SqlClientDiagnostic - { - /// - public const string Name = "Microsoft.Data.SqlClient.WriteConnectionCloseBefore"; - - internal SqlClientConnectionCloseBefore(Guid operationId, string operation, long timestamp, Guid? connectionId, SqlConnection connection, IDictionary statistics) - : base(operationId, operation, timestamp) - { - ConnectionId = connectionId; - Connection = connection; - Statistics = statistics; - } - - /// - public Guid? ConnectionId { get; } - - /// - public SqlConnection Connection { get; } - - /// - public IDictionary Statistics { get; } - - /// > - protected sealed override int GetDerivedCount() => 3; - - /// > - protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch - { - 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), - 1 => new KeyValuePair(nameof(Connection), Connection), - 2 => new KeyValuePair(nameof(Statistics), Statistics), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; - } - - /// - public sealed class SqlClientConnectionCloseAfter : SqlClientDiagnostic - { - /// - public const string Name = "Microsoft.Data.SqlClient.WriteConnectionCloseAfter"; - - internal SqlClientConnectionCloseAfter(Guid operationId, string operation, long timestamp, Guid? connectionId, SqlConnection connection, IDictionary statistics) - : base(operationId, operation, timestamp) - { - ConnectionId = connectionId; - Connection = connection; - Statistics = statistics; - } - - /// - public Guid? ConnectionId { get; } - - /// - public SqlConnection Connection { get; } - - /// - public IDictionary Statistics { get; } - - /// > - protected sealed override int GetDerivedCount() => 3; - - /// > - protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch - { - 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), - 1 => new KeyValuePair(nameof(Connection), Connection), - 2 => new KeyValuePair(nameof(Statistics), Statistics), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; - } - - /// - public sealed class SqlClientConnectionCloseError : SqlClientDiagnostic - { - /// - public const string Name = "Microsoft.Data.SqlClient.WriteConnectionCloseError"; - - internal SqlClientConnectionCloseError(Guid operationId, string operation, long timestamp, Guid? connectionId, SqlConnection connection, IDictionary statistics, Exception ex) - : base(operationId, operation, timestamp) - { - ConnectionId = connectionId; - Connection = connection; - Statistics = statistics; - Exception = ex; - } - - /// - public Guid? ConnectionId { get; } - - /// - - public SqlConnection Connection { get; } - - /// - public IDictionary Statistics { get; } - - /// - public Exception Exception { get; } - - /// > - protected sealed override int GetDerivedCount() => 4; - - /// > - protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch - { - 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), - 1 => new KeyValuePair(nameof(Connection), Connection), - 2 => new KeyValuePair(nameof(Statistics), Statistics), - 3 => new KeyValuePair(nameof(Exception), Exception), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; - } - - /// - public sealed class SqlClientTransactionCommitBefore : SqlClientDiagnostic - { - /// - public const string Name = "Microsoft.Data.SqlClient.WriteTransactionCommitBefore"; - - internal SqlClientTransactionCommitBefore(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId) - : base(operationId, operation, timestamp) - { - IsolationLevel = isolationLevel; - Connection = connection; - TransactionId = transactionId; - } - - /// - public IsolationLevel IsolationLevel { get; } - - /// - public SqlConnection Connection { get; } - - /// - public long? TransactionId { get; } - - /// > - protected sealed override int GetDerivedCount() => 3; - - /// > - protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch - { - 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), - 1 => new KeyValuePair(nameof(Connection), Connection), - 2 => new KeyValuePair(nameof(TransactionId), TransactionId), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; - } - - /// - public sealed class SqlClientTransactionCommitAfter : SqlClientDiagnostic - { - /// - public const string Name = "Microsoft.Data.SqlClient.WriteTransactionCommitAfter"; - - internal SqlClientTransactionCommitAfter(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId) - : base(operationId, operation, timestamp) - { - IsolationLevel = isolationLevel; - Connection = connection; - TransactionId = transactionId; - } - - /// - public IsolationLevel IsolationLevel { get; } - - /// - public SqlConnection Connection { get; } - - /// - public long? TransactionId { get; } - - /// > - protected sealed override int GetDerivedCount() => 3; - - /// > - protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch - { - 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), - 1 => new KeyValuePair(nameof(Connection), Connection), - 2 => new KeyValuePair(nameof(TransactionId), TransactionId), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; - } - - /// - public sealed class SqlClientTransactionCommitError : SqlClientDiagnostic - { - /// - public const string Name = "Microsoft.Data.SqlClient.WriteTransactionCommitError"; - - internal SqlClientTransactionCommitError(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId, Exception ex) - : base(operationId, operation, timestamp) - { - IsolationLevel = isolationLevel; - Connection = connection; - TransactionId = transactionId; - Exception = ex; - } - - /// - public IsolationLevel IsolationLevel { get; } - - /// - public SqlConnection Connection { get; } - - /// - public long? TransactionId { get; } - - /// - public Exception Exception { get; } - - /// > - protected sealed override int GetDerivedCount() => 4; - - /// > - protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch - { - 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), - 1 => new KeyValuePair(nameof(Connection), Connection), - 2 => new KeyValuePair(nameof(TransactionId), TransactionId), - 3 => new KeyValuePair(nameof(Exception), Exception), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; - } - - /// - public sealed class SqlClientTransactionRollbackBefore : SqlClientDiagnostic - { - /// - public const string Name = "Microsoft.Data.SqlClient.WriteTransactionRollbackBefore"; - - internal SqlClientTransactionRollbackBefore(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId, string transactionName) - : base(operationId, operation, timestamp) - { - IsolationLevel = isolationLevel; - Connection = connection; - TransactionId = transactionId; - TransactionName = transactionName; - } - - /// - public IsolationLevel IsolationLevel { get; } - - /// - public SqlConnection Connection { get; } - - /// - public long? TransactionId { get; } - - /// - public string TransactionName { get; } - - /// > - protected sealed override int GetDerivedCount() => 4; - - /// > - protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch - { - 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), - 1 => new KeyValuePair(nameof(Connection), Connection), - 2 => new KeyValuePair(nameof(TransactionId), TransactionId), - 3 => new KeyValuePair(nameof(TransactionName), TransactionName), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; - } - - /// - public sealed class SqlClientTransactionRollbackAfter : SqlClientDiagnostic - { - /// - public const string Name = "Microsoft.Data.SqlClient.WriteTransactionRollbackAfter"; - - internal SqlClientTransactionRollbackAfter(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId, string transactionName) - : base(operationId, operation, timestamp) - { - IsolationLevel = isolationLevel; - Connection = connection; - TransactionId = transactionId; - TransactionName = transactionName; - } - - /// - public IsolationLevel IsolationLevel { get; } - - /// - public SqlConnection Connection { get; } - - /// - public long? TransactionId { get; } - - /// - public string TransactionName { get; } - - /// > - protected sealed override int GetDerivedCount() => 4; - - /// > - protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch - { - 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), - 1 => new KeyValuePair(nameof(Connection), Connection), - 2 => new KeyValuePair(nameof(TransactionId), TransactionId), - 3 => new KeyValuePair(nameof(TransactionName), TransactionName), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; - } - - /// - public sealed class SqlClientTransactionRollbackError : SqlClientDiagnostic - { - /// - public const string Name = "Microsoft.Data.SqlClient.WriteTransactionRollbackError"; - - internal SqlClientTransactionRollbackError(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId, string transactionName, Exception ex) - : base(operationId, operation, timestamp) - { - IsolationLevel = isolationLevel; - Connection = connection; - TransactionId = transactionId; - TransactionName = transactionName; - Exception = ex; - } - - /// - public IsolationLevel IsolationLevel { get; } - - /// - public SqlConnection Connection { get; } - - /// - public long? TransactionId { get; } - - /// - public string TransactionName { get; } - - /// - public Exception Exception { get; } - - /// > - protected sealed override int GetDerivedCount() => 5; - - /// > - protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch - { - 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), - 1 => new KeyValuePair(nameof(Connection), Connection), - 2 => new KeyValuePair(nameof(TransactionId), TransactionId), - 3 => new KeyValuePair(nameof(TransactionName), TransactionName), - 4 => new KeyValuePair(nameof(Exception), Exception), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; - } - internal ref struct DiagnosticScope //: IDisposable //ref structs cannot implement interfaces but the compiler will use pattern matching { private const int CommandOperation = 1; diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs index 7a615dacfe..9b484fc96f 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs @@ -19,6 +19,7 @@ using System.Xml; using Microsoft.Data.Common; using Microsoft.Data.Sql; +using Microsoft.Data.SqlClient.Diagnostics; using Microsoft.Data.SqlClient.Server; // NOTE: The current Microsoft.VSDesigner editor attributes are implemented for System.Data.SqlClient, and are not publicly available. diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs index bbf37b0bf4..697315abc9 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs @@ -19,6 +19,7 @@ using System.Threading.Tasks; using Microsoft.Data.Common; using Microsoft.Data.ProviderBase; +using Microsoft.Data.SqlClient.Diagnostics; using Microsoft.SqlServer.Server; namespace Microsoft.Data.SqlClient From ef4bec4411fa5fd1aa9597e5ccb94ae8f245e8a1 Mon Sep 17 00:00:00 2001 From: Wraith2 Date: Fri, 17 Nov 2023 20:36:20 +0000 Subject: [PATCH 5/7] update ref assembly --- .../netcore/ref/Microsoft.Data.SqlClient.cs | 312 ++++++++++++++++++ 1 file changed, 312 insertions(+) diff --git a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs index 72203bb433..5dfbf8af3f 100644 --- a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs +++ b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs @@ -5,6 +5,8 @@ // NOTE: The current Microsoft.VSDesigner editor attributes are implemented for System.Data.SqlClient, and are not publicly available. // New attributes that are designed to work with Microsoft.Data.SqlClient and are publicly documented should be included in future. +using System; + [assembly: System.CLSCompliant(true)] namespace Microsoft.Data { @@ -1908,6 +1910,316 @@ public sealed class SqlConfigurableRetryFactory public static SqlRetryLogicBaseProvider CreateNoneRetryProvider() { throw null; } } } +namespace Microsoft.Data.SqlClient.Diagnostics +{ + /// + public abstract class SqlClientDiagnostic : System.Collections.Generic.IReadOnlyList> + { + internal SqlClientDiagnostic() { } + /// + protected const int CommonPropertyCount = 3; + /// + protected SqlClientDiagnostic(System.Guid operationId, string operation, long timestamp) { } + /// + public System.Guid OperationId => throw null; + /// + public string Operation => throw null; + /// + public long Timestamp => throw null; + /// > + public int Count => CommonPropertyCount + GetDerivedCount(); + /// > + public System.Collections.Generic.KeyValuePair this[int index] => throw null; + /// > + public System.Collections.Generic.IEnumerator> GetEnumerator() => throw null; + /// > + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator(); + /// + protected bool TryGetCommonProperty(int index, out System.Collections.Generic.KeyValuePair property) => throw null; + /// + protected abstract int GetDerivedCount(); + /// + protected abstract System.Collections.Generic.KeyValuePair GetDerivedProperty(int index); + } + + /// + public sealed class SqlClientCommandBefore : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteCommandBefore"; + /// + public System.Guid? ConnectionId => throw null; + /// + public long? TransactionId => throw null; + /// + public SqlCommand Command => throw null; + /// > + protected sealed override int GetDerivedCount() => 3; + /// > + protected sealed override System.Collections.Generic.KeyValuePair GetDerivedProperty(int index) => throw null; + } + + /// + public sealed class SqlClientCommandAfter : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteCommandAfter"; + /// + public System.Guid? ConnectionId => throw null; + /// + public long? TransactionId => throw null; + /// + public SqlCommand Command => throw null; + /// + public System.Collections.IDictionary Statistics => throw null; + /// > + protected sealed override int GetDerivedCount() => 4; + /// > + protected sealed override System.Collections.Generic.KeyValuePair GetDerivedProperty(int index) => throw null; + } + + /// + public sealed class SqlClientCommandError : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteCommandError"; + /// + public System.Guid? ConnectionId => throw null; + /// + public long? TransactionId => throw null; + /// + public SqlCommand Command => throw null; + /// + public System.Exception Exception { get; } + /// > + protected sealed override int GetDerivedCount() => 4; + /// > + protected sealed override System.Collections.Generic.KeyValuePair GetDerivedProperty(int index) => throw null; + } + + /// + public sealed class SqlClientConnectionOpenBefore : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteConnectionOpenBefore"; + /// + public SqlConnection Connection => throw null; + /// + public string ClientVersion => throw null; + /// > + protected override int GetDerivedCount() => 2; + /// > + protected sealed override System.Collections.Generic.KeyValuePair GetDerivedProperty(int index) => throw null; + } + + /// + public sealed class SqlClientConnectionOpenAfter : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteConnectionOpenAfter"; + /// + public System.Guid ConnectionId => throw null; + /// + public SqlConnection Connection => throw null; + /// + public string ClientVersion => throw null; + /// + public System.Collections.IDictionary Statistics => throw null; + /// > + protected override int GetDerivedCount() => 4; + /// > + protected sealed override System.Collections.Generic.KeyValuePair GetDerivedProperty(int index) => throw null; + } + + /// + public sealed class SqlClientConnectionOpenError : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteConnectionOpenError"; + /// + public System.Guid ConnectionId => throw null; + /// + public SqlConnection Connection => throw null; + /// + public string ClientVersion => throw null; + /// + public System.Exception Exception => throw null; + /// > + protected override int GetDerivedCount() => 4; + /// > + protected sealed override System.Collections.Generic.KeyValuePair GetDerivedProperty(int index) => throw null; + } + + /// + public sealed class SqlClientConnectionCloseBefore : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteConnectionCloseBefore"; + /// + public System.Guid? ConnectionId => throw null; + /// + public SqlConnection Connection => throw null; + /// + public System.Collections.IDictionary Statistics => throw null; + /// > + protected sealed override int GetDerivedCount() => 3; + /// > + protected sealed override System.Collections.Generic.KeyValuePair GetDerivedProperty(int index) => throw null; + } + + /// + public sealed class SqlClientConnectionCloseAfter : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteConnectionCloseAfter"; + + /// + public System.Guid? ConnectionId => throw null; + + /// + public SqlConnection Connection => throw null; + + /// + public System.Collections.IDictionary Statistics => throw null; + + /// > + protected sealed override int GetDerivedCount() => 3; + + /// > + protected sealed override System.Collections.Generic.KeyValuePair GetDerivedProperty(int index) => throw null; + } + + /// + public sealed class SqlClientConnectionCloseError : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteConnectionCloseError"; + /// + public System.Guid? ConnectionId => throw null; + /// + public SqlConnection Connection => throw null; + /// + public System.Collections.IDictionary Statistics => throw null; + /// + public System.Exception Exception => throw null; + /// > + protected sealed override int GetDerivedCount() => 4; + /// > + protected sealed override System.Collections.Generic.KeyValuePair GetDerivedProperty(int index) => throw null; + } + + /// + public sealed class SqlClientTransactionCommitBefore : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteTransactionCommitBefore"; + /// + public System.Data.IsolationLevel IsolationLevel => throw null; + /// + public SqlConnection Connection => throw null; + /// + public long? TransactionId => throw null; + /// > + protected sealed override int GetDerivedCount() => 3; + /// > + protected sealed override System.Collections.Generic.KeyValuePair GetDerivedProperty(int index) => throw null; + } + + /// + public sealed class SqlClientTransactionCommitAfter : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteTransactionCommitAfter"; + /// + public System.Data.IsolationLevel IsolationLevel => throw null; + /// + public SqlConnection Connection => throw null; + /// + public long? TransactionId => throw null; + /// > + protected sealed override int GetDerivedCount() => 3; + /// > + protected sealed override System.Collections.Generic.KeyValuePair GetDerivedProperty(int index) => throw null; + } + + /// + public sealed class SqlClientTransactionCommitError : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteTransactionCommitError"; + /// + public System.Data.IsolationLevel IsolationLevel => throw null; + /// + public SqlConnection Connection => throw null; + /// + public long? TransactionId => throw null; + /// + public System.Exception Exception => throw null; + /// > + protected sealed override int GetDerivedCount() => 4; + /// > + protected sealed override System.Collections.Generic.KeyValuePair GetDerivedProperty(int index) => throw null; + } + + /// + public sealed class SqlClientTransactionRollbackBefore : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteTransactionRollbackBefore"; + /// + public System.Data.IsolationLevel IsolationLevel => throw null; + /// + public SqlConnection Connection => throw null; + /// + public long? TransactionId => throw null; + /// + public string TransactionName => throw null; + /// > + protected sealed override int GetDerivedCount() => 4; + /// > + protected sealed override System.Collections.Generic.KeyValuePair GetDerivedProperty(int index) => throw null; + } + + /// + public sealed class SqlClientTransactionRollbackAfter : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteTransactionRollbackAfter"; + /// + public System.Data.IsolationLevel IsolationLevel => throw null; + /// + public SqlConnection Connection => throw null; + /// + public long? TransactionId => throw null; + /// + public string TransactionName => throw null; + /// > + protected sealed override int GetDerivedCount() => 4; + /// > + protected sealed override System.Collections.Generic.KeyValuePair GetDerivedProperty(int index) => throw null; + } + + /// + public sealed class SqlClientTransactionRollbackError : SqlClientDiagnostic + { + /// + public const string Name = "Microsoft.Data.SqlClient.WriteTransactionRollbackError"; + /// + public System.Data.IsolationLevel IsolationLevel => throw null; + /// + public SqlConnection Connection => throw null; + /// + public long? TransactionId => throw null; + /// + public string TransactionName => throw null; + /// + public System.Exception Exception => throw null; + /// > + protected sealed override int GetDerivedCount() => 5; + /// > + protected sealed override System.Collections.Generic.KeyValuePair GetDerivedProperty(int index) => throw null; + } +} namespace Microsoft.Data.SqlClient.Server { /// From 6b7392dd87ddf60c2051383feef5c0ff9c0dba6e Mon Sep 17 00:00:00 2001 From: Wraith2 Date: Tue, 23 Jan 2024 21:54:15 +0000 Subject: [PATCH 6/7] remove base class because otel and appinsights do not check base classes --- .../SqlClientDiagnostic.xml | 23 - src/Microsoft.Data.SqlClient.sln | 1 + .../Data/SqlClient/SqlClientDiagnostic.cs | 805 ++++++++++++------ 3 files changed, 549 insertions(+), 280 deletions(-) diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml index 9f2dbb428b..94014b0b7d 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml @@ -1,17 +1,6 @@ - - The abstract base class for diagnostic events containing common fields shared by all diagnostic events. - - - A guid value used to correlate before, after and error events. - The name of the operation. - The timestamp of the event. - - Initializes a new instance of the class. - - A guid value used to correlate before, after and error events. @@ -21,18 +10,6 @@ The timestamp of the event. - - Provides the count of common properties for classes which derive from this class. - - - Provides derived classed with a method to attempt to fetch common properties from the this base class. Returns true if the property is found false otherwise. - - - Provides the base class with the count of additional properties added by derived classes. This is used to produce the Count value. - - - Provides the base class with the the ability to query for properties added by derived classes. This is used to provide values to the indexer. - diff --git a/src/Microsoft.Data.SqlClient.sln b/src/Microsoft.Data.SqlClient.sln index 04668c8f81..9ab18e4989 100644 --- a/src/Microsoft.Data.SqlClient.sln +++ b/src/Microsoft.Data.SqlClient.sln @@ -100,6 +100,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Microsoft.Data.SqlClient", ..\doc\snippets\Microsoft.Data.SqlClient\SqlBulkCopyColumnMapping.xml = ..\doc\snippets\Microsoft.Data.SqlClient\SqlBulkCopyColumnMapping.xml ..\doc\snippets\Microsoft.Data.SqlClient\SqlBulkCopyColumnMappingCollection.xml = ..\doc\snippets\Microsoft.Data.SqlClient\SqlBulkCopyColumnMappingCollection.xml ..\doc\snippets\Microsoft.Data.SqlClient\SqlBulkCopyOptions.xml = ..\doc\snippets\Microsoft.Data.SqlClient\SqlBulkCopyOptions.xml + ..\doc\snippets\Microsoft.Data.SqlClient\SqlClientDiagnostic.xml = ..\doc\snippets\Microsoft.Data.SqlClient\SqlClientDiagnostic.xml ..\doc\snippets\Microsoft.Data.SqlClient\SqlClientFactory.xml = ..\doc\snippets\Microsoft.Data.SqlClient\SqlClientFactory.xml ..\doc\snippets\Microsoft.Data.SqlClient\SqlClientLogger.xml = ..\doc\snippets\Microsoft.Data.SqlClient\SqlClientLogger.xml ..\doc\snippets\Microsoft.Data.SqlClient\SqlClientMetaDataCollectionNames.xml = ..\doc\snippets\Microsoft.Data.SqlClient\SqlClientMetaDataCollectionNames.xml diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnostic.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnostic.cs index 1664776d82..a42b8a3f0f 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnostic.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnostic.cs @@ -9,18 +9,20 @@ namespace Microsoft.Data.SqlClient.Diagnostics { - /// - public abstract class SqlClientDiagnostic : IReadOnlyList> + /// + public sealed class SqlClientCommandBefore : IReadOnlyList> { - /// - protected const int CommonPropertyCount = 3; + /// + public const string Name = "Microsoft.Data.SqlClient.WriteCommandBefore"; - /// - protected SqlClientDiagnostic(Guid operationId, string operation, long timestamp) + internal SqlClientCommandBefore(Guid operationId, string operation, long timestamp, Guid? connectionId, long? transactionId, SqlCommand command) { OperationId = operationId; Operation = operation; Timestamp = timestamp; + ConnectionId = connectionId; + TransactionId = transactionId; + Command = command; } /// @@ -29,390 +31,512 @@ protected SqlClientDiagnostic(Guid operationId, string operation, long timestamp public string Operation { get; } /// public long Timestamp { get; } + /// + public Guid? ConnectionId { get; } + /// + public long? TransactionId { get; } + /// + public SqlCommand Command { get; } /// > - public int Count => CommonPropertyCount + GetDerivedCount(); + public int Count => 3 + 3; /// > public KeyValuePair this[int index] { - get + get => index switch { - if (TryGetCommonProperty(index, out KeyValuePair commonProperty)) - { - return commonProperty; - } - else - { - return GetDerivedProperty(index - CommonPropertyCount); - } - } + 0 => new KeyValuePair(nameof(OperationId), OperationId), + 1 => new KeyValuePair(nameof(Operation), Operation), + 2 => new KeyValuePair(nameof(Timestamp), Timestamp), + 3 => new KeyValuePair(nameof(ConnectionId), ConnectionId), + 4 => new KeyValuePair(nameof(TransactionId), TransactionId), + 5 => new KeyValuePair(nameof(Command), Command), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; } + /// > + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + /// > public IEnumerator> GetEnumerator() { int count = Count; - for (var index = 0; index < count; index++) + for (int index = 0; index < count; index++) { yield return this[index]; } } - - /// > - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - - /// - protected bool TryGetCommonProperty(int index, out KeyValuePair property) - { - switch (index) - { - case 0: - property = new KeyValuePair(nameof(OperationId), OperationId); - return true; - case 1: - property = new KeyValuePair(nameof(Operation), Operation); - return true; - case 2: - property = new KeyValuePair(nameof(Timestamp), Timestamp); - return true; - default: - property = default; - return false; - } - } - - /// - protected abstract int GetDerivedCount(); - - /// - protected abstract KeyValuePair GetDerivedProperty(int index); - } - - /// - public sealed class SqlClientCommandBefore : SqlClientDiagnostic - { - /// - public const string Name = "Microsoft.Data.SqlClient.WriteCommandBefore"; - - internal SqlClientCommandBefore(Guid operationId, string operation, long timestamp, Guid? connectionId, long? transactionId, SqlCommand command) - : base(operationId, operation, timestamp) - { - ConnectionId = connectionId; - TransactionId = transactionId; - Command = command; - } - - /// - public Guid? ConnectionId { get; } - - /// - public long? TransactionId { get; } - - /// - public SqlCommand Command { get; } - - - /// > - protected sealed override int GetDerivedCount() => 3; - - /// > - protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch - { - 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), - 1 => new KeyValuePair(nameof(TransactionId), TransactionId), - 2 => new KeyValuePair(nameof(Command), Command), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; } /// - public sealed class SqlClientCommandAfter : SqlClientDiagnostic + public sealed class SqlClientCommandAfter : IReadOnlyList> { /// public const string Name = "Microsoft.Data.SqlClient.WriteCommandAfter"; internal SqlClientCommandAfter(Guid operationId, string operation, long timestamp, Guid? connectionId, long? transactionId, SqlCommand command, IDictionary statistics) - : base(operationId, operation, timestamp) { + OperationId = operationId; + Operation = operation; + Timestamp = timestamp; ConnectionId = connectionId; TransactionId = transactionId; Command = command; Statistics = statistics; } + /// + public Guid OperationId { get; } + /// + public string Operation { get; } + /// + public long Timestamp { get; } /// public Guid? ConnectionId { get; } - /// public long? TransactionId { get; } - /// public SqlCommand Command { get; } - /// public IDictionary Statistics { get; } /// > - protected sealed override int GetDerivedCount() => 4; + public int Count => 3 + 4; /// > - protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + public KeyValuePair this[int index] { - 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), - 1 => new KeyValuePair(nameof(TransactionId), TransactionId), - 2 => new KeyValuePair(nameof(Command), Command), - 3 => new KeyValuePair(nameof(Statistics), Statistics), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; + get => index switch + { + 0 => new KeyValuePair(nameof(OperationId), OperationId), + 1 => new KeyValuePair(nameof(Operation), Operation), + 2 => new KeyValuePair(nameof(Timestamp), Timestamp), + 3 => new KeyValuePair(nameof(ConnectionId), ConnectionId), + 4 => new KeyValuePair(nameof(TransactionId), TransactionId), + 5 => new KeyValuePair(nameof(Command), Command), + 6 => new KeyValuePair(nameof(Statistics), Statistics), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// > + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + /// > + public IEnumerator> GetEnumerator() + { + int count = Count; + for (int index = 0; index < count; index++) + { + yield return this[index]; + } + } } /// - public sealed class SqlClientCommandError : SqlClientDiagnostic + public sealed class SqlClientCommandError : IReadOnlyList> { /// public const string Name = "Microsoft.Data.SqlClient.WriteCommandError"; internal SqlClientCommandError(Guid operationId, string operation, long timestamp, Guid? connectionId, long? transactionId, SqlCommand command, Exception exception) - : base(operationId, operation, timestamp) { + OperationId = operationId; + Operation = operation; + Timestamp = timestamp; ConnectionId = connectionId; TransactionId = transactionId; Command = command; Exception = exception; } - + /// + public Guid OperationId { get; } + /// + public string Operation { get; } + /// + public long Timestamp { get; } /// public Guid? ConnectionId { get; } - /// public long? TransactionId { get; } - /// public SqlCommand Command { get; } - /// public Exception Exception { get; } /// > - protected sealed override int GetDerivedCount() => 4; + public int Count => 3 + 4; /// > - protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + public KeyValuePair this[int index] { - 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), - 1 => new KeyValuePair(nameof(TransactionId), TransactionId), - 2 => new KeyValuePair(nameof(Command), Command), - 3 => new KeyValuePair(nameof(Exception), Exception), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; + get => index switch + { + 0 => new KeyValuePair(nameof(OperationId), OperationId), + 1 => new KeyValuePair(nameof(Operation), Operation), + 2 => new KeyValuePair(nameof(Timestamp), Timestamp), + 3 => new KeyValuePair(nameof(ConnectionId), ConnectionId), + 4 => new KeyValuePair(nameof(TransactionId), TransactionId), + 5 => new KeyValuePair(nameof(Command), Command), + 6 => new KeyValuePair(nameof(Exception), Exception), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// > + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + /// > + public IEnumerator> GetEnumerator() + { + int count = Count; + for (int index = 0; index < count; index++) + { + yield return this[index]; + } + } } /// - public sealed class SqlClientConnectionOpenBefore : SqlClientDiagnostic + public sealed class SqlClientConnectionOpenBefore : IReadOnlyList> { /// public const string Name = "Microsoft.Data.SqlClient.WriteConnectionOpenBefore"; internal SqlClientConnectionOpenBefore(Guid operationId, string operation, long timestamp, SqlConnection connection, string clientVersion) - : base(operationId, operation, timestamp) { + OperationId = operationId; + Operation = operation; + Timestamp = timestamp; Connection = connection; ClientVersion = clientVersion; } + /// + public Guid OperationId { get; } + /// + public string Operation { get; } + /// + public long Timestamp { get; } /// public SqlConnection Connection { get; } - /// public string ClientVersion { get; } /// > - protected override int GetDerivedCount() => 2; + public int Count => 3 + 2; + + /// > + public KeyValuePair this[int index] + { + get => index switch + { + 0 => new KeyValuePair(nameof(OperationId), OperationId), + 1 => new KeyValuePair(nameof(Operation), Operation), + 2 => new KeyValuePair(nameof(Timestamp), Timestamp), + 3 => new KeyValuePair(nameof(Connection), Connection), + 4 => new KeyValuePair(nameof(ClientVersion), ClientVersion), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// > + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + /// > - protected override KeyValuePair GetDerivedProperty(int index) => index switch + public IEnumerator> GetEnumerator() { - 0 => new KeyValuePair(nameof(Connection), Connection), - 1 => new KeyValuePair(nameof(ClientVersion), ClientVersion), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; + int count = Count; + for (int index = 0; index < count; index++) + { + yield return this[index]; + } + } } /// - public sealed class SqlClientConnectionOpenAfter : SqlClientDiagnostic + public sealed class SqlClientConnectionOpenAfter : IReadOnlyList> { /// public const string Name = "Microsoft.Data.SqlClient.WriteConnectionOpenAfter"; internal SqlClientConnectionOpenAfter(Guid operationId, string operation, long timestamp, Guid connectionId, SqlConnection connection, string clientVersion, IDictionary statistics) - : base(operationId, operation, timestamp) { + OperationId = operationId; + Operation = operation; + Timestamp = timestamp; ConnectionId = connectionId; Connection = connection; ClientVersion = clientVersion; Statistics = statistics; } + /// + public Guid OperationId { get; } + /// + public string Operation { get; } + /// + public long Timestamp { get; } /// public Guid ConnectionId { get; } - /// public SqlConnection Connection { get; } - /// public string ClientVersion { get; } - /// public IDictionary Statistics { get; } /// > - protected override int GetDerivedCount() => 4; + public int Count => 3 + 4; /// > - protected override KeyValuePair GetDerivedProperty(int index) => index switch + public KeyValuePair this[int index] { - 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), - 1 => new KeyValuePair(nameof(Connection), Connection), - 2 => new KeyValuePair(nameof(ClientVersion), ClientVersion), - 3 => new KeyValuePair(nameof(Statistics), Statistics), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; + get => index switch + { + 0 => new KeyValuePair(nameof(OperationId), OperationId), + 1 => new KeyValuePair(nameof(Operation), Operation), + 2 => new KeyValuePair(nameof(Timestamp), Timestamp), + 3 => new KeyValuePair(nameof(ConnectionId), ConnectionId), + 4 => new KeyValuePair(nameof(Connection), Connection), + 5 => new KeyValuePair(nameof(ClientVersion), ClientVersion), + 6 => new KeyValuePair(nameof(Statistics), Statistics), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// > + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + /// > + public IEnumerator> GetEnumerator() + { + int count = Count; + for (int index = 0; index < count; index++) + { + yield return this[index]; + } + } } /// - public sealed class SqlClientConnectionOpenError : SqlClientDiagnostic + public sealed class SqlClientConnectionOpenError : IReadOnlyList> { /// public const string Name = "Microsoft.Data.SqlClient.WriteConnectionOpenError"; internal SqlClientConnectionOpenError(Guid operationId, string operation, long timestamp, Guid connectionId, SqlConnection connection, string clientVersion, Exception exception) - : base(operationId, operation, timestamp) { + OperationId = operationId; + Operation = operation; + Timestamp = timestamp; ConnectionId = connectionId; Connection = connection; ClientVersion = clientVersion; Exception = exception; } + /// + public Guid OperationId { get; } + /// + public string Operation { get; } + /// + public long Timestamp { get; } + /// public Guid ConnectionId { get; } - /// public SqlConnection Connection { get; } - /// public string ClientVersion { get; } - /// public Exception Exception { get; } /// > - protected override int GetDerivedCount() => 4; + public int Count => 3 + 4; + /// > - protected override KeyValuePair GetDerivedProperty(int index) => index switch + public KeyValuePair this[int index] { - 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), - 1 => new KeyValuePair(nameof(Connection), Connection), - 2 => new KeyValuePair(nameof(ClientVersion), ClientVersion), - 3 => new KeyValuePair(nameof(Exception), Exception), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; + get => index switch + { + 0 => new KeyValuePair(nameof(OperationId), OperationId), + 1 => new KeyValuePair(nameof(Operation), Operation), + 2 => new KeyValuePair(nameof(Timestamp), Timestamp), + 3 => new KeyValuePair(nameof(ConnectionId), ConnectionId), + 4 => new KeyValuePair(nameof(Connection), Connection), + 5 => new KeyValuePair(nameof(ClientVersion), ClientVersion), + 6 => new KeyValuePair(nameof(Exception), Exception), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// > + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + /// > + public IEnumerator> GetEnumerator() + { + int count = Count; + for (int index = 0; index < count; index++) + { + yield return this[index]; + } + } } /// - public sealed class SqlClientConnectionCloseBefore : SqlClientDiagnostic + public sealed class SqlClientConnectionCloseBefore : IReadOnlyList> { /// public const string Name = "Microsoft.Data.SqlClient.WriteConnectionCloseBefore"; internal SqlClientConnectionCloseBefore(Guid operationId, string operation, long timestamp, Guid? connectionId, SqlConnection connection, IDictionary statistics) - : base(operationId, operation, timestamp) { + OperationId = operationId; + Operation = operation; + Timestamp = timestamp; ConnectionId = connectionId; Connection = connection; Statistics = statistics; } + /// + public Guid OperationId { get; } + /// + public string Operation { get; } + /// + public long Timestamp { get; } /// public Guid? ConnectionId { get; } - /// public SqlConnection Connection { get; } - /// public IDictionary Statistics { get; } /// > - protected sealed override int GetDerivedCount() => 3; + public int Count => 3 + 3; /// > - protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + public KeyValuePair this[int index] { - 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), - 1 => new KeyValuePair(nameof(Connection), Connection), - 2 => new KeyValuePair(nameof(Statistics), Statistics), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; + get => index switch + { + 0 => new KeyValuePair(nameof(OperationId), OperationId), + 1 => new KeyValuePair(nameof(Operation), Operation), + 2 => new KeyValuePair(nameof(Timestamp), Timestamp), + 3 => new KeyValuePair(nameof(ConnectionId), ConnectionId), + 4 => new KeyValuePair(nameof(Connection), Connection), + 5 => new KeyValuePair(nameof(Statistics), Statistics), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// > + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + /// > + public IEnumerator> GetEnumerator() + { + int count = Count; + for (int index = 0; index < count; index++) + { + yield return this[index]; + } + } } /// - public sealed class SqlClientConnectionCloseAfter : SqlClientDiagnostic + public sealed class SqlClientConnectionCloseAfter : IReadOnlyList> { /// public const string Name = "Microsoft.Data.SqlClient.WriteConnectionCloseAfter"; internal SqlClientConnectionCloseAfter(Guid operationId, string operation, long timestamp, Guid? connectionId, SqlConnection connection, IDictionary statistics) - : base(operationId, operation, timestamp) { + OperationId = operationId; + Operation = operation; + Timestamp = timestamp; ConnectionId = connectionId; Connection = connection; Statistics = statistics; } + /// + public Guid OperationId { get; } + /// + public string Operation { get; } + /// + public long Timestamp { get; } /// public Guid? ConnectionId { get; } - /// public SqlConnection Connection { get; } - /// public IDictionary Statistics { get; } /// > - protected sealed override int GetDerivedCount() => 3; + public int Count => 3 + 3; + + /// > + public KeyValuePair this[int index] + { + get => index switch + { + 0 => new KeyValuePair(nameof(OperationId), OperationId), + 1 => new KeyValuePair(nameof(Operation), Operation), + 2 => new KeyValuePair(nameof(Timestamp), Timestamp), + 3 => new KeyValuePair(nameof(ConnectionId), ConnectionId), + 4 => new KeyValuePair(nameof(Connection), Connection), + 5 => new KeyValuePair(nameof(Statistics), Statistics), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// > + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); /// > - protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + public IEnumerator> GetEnumerator() { - 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), - 1 => new KeyValuePair(nameof(Connection), Connection), - 2 => new KeyValuePair(nameof(Statistics), Statistics), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; + int count = Count; + for (int index = 0; index < count; index++) + { + yield return this[index]; + } + } } /// - public sealed class SqlClientConnectionCloseError : SqlClientDiagnostic + public sealed class SqlClientConnectionCloseError : IReadOnlyList> { /// public const string Name = "Microsoft.Data.SqlClient.WriteConnectionCloseError"; internal SqlClientConnectionCloseError(Guid operationId, string operation, long timestamp, Guid? connectionId, SqlConnection connection, IDictionary statistics, Exception ex) - : base(operationId, operation, timestamp) { + OperationId = operationId; + Operation = operation; + Timestamp = timestamp; ConnectionId = connectionId; Connection = connection; Statistics = statistics; Exception = ex; } + /// + public Guid OperationId { get; } + /// + public string Operation { get; } + /// + public long Timestamp { get; } + /// public Guid? ConnectionId { get; } - /// - public SqlConnection Connection { get; } - /// public IDictionary Statistics { get; } @@ -420,223 +544,368 @@ internal SqlClientConnectionCloseError(Guid operationId, string operation, long public Exception Exception { get; } /// > - protected sealed override int GetDerivedCount() => 4; + public int Count => 3 + 4; /// > - protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + public KeyValuePair this[int index] { - 0 => new KeyValuePair(nameof(ConnectionId), ConnectionId), - 1 => new KeyValuePair(nameof(Connection), Connection), - 2 => new KeyValuePair(nameof(Statistics), Statistics), - 3 => new KeyValuePair(nameof(Exception), Exception), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; + get => index switch + { + 0 => new KeyValuePair(nameof(OperationId), OperationId), + 1 => new KeyValuePair(nameof(Operation), Operation), + 2 => new KeyValuePair(nameof(Timestamp), Timestamp), + 3 => new KeyValuePair(nameof(ConnectionId), ConnectionId), + 4 => new KeyValuePair(nameof(Connection), Connection), + 5 => new KeyValuePair(nameof(Statistics), Statistics), + 6 => new KeyValuePair(nameof(Exception), Exception), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// > + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + /// > + public IEnumerator> GetEnumerator() + { + int count = Count; + for (int index = 0; index < count; index++) + { + yield return this[index]; + } + } } /// - public sealed class SqlClientTransactionCommitBefore : SqlClientDiagnostic + public sealed class SqlClientTransactionCommitBefore : IReadOnlyList> { /// public const string Name = "Microsoft.Data.SqlClient.WriteTransactionCommitBefore"; internal SqlClientTransactionCommitBefore(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId) - : base(operationId, operation, timestamp) { + OperationId = operationId; + Operation = operation; + Timestamp = timestamp; IsolationLevel = isolationLevel; Connection = connection; TransactionId = transactionId; } + /// + public Guid OperationId { get; } + /// + public string Operation { get; } + /// + public long Timestamp { get; } /// public IsolationLevel IsolationLevel { get; } - /// public SqlConnection Connection { get; } - /// public long? TransactionId { get; } /// > - protected sealed override int GetDerivedCount() => 3; + public int Count => 3 + 3; /// > - protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + public KeyValuePair this[int index] { - 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), - 1 => new KeyValuePair(nameof(Connection), Connection), - 2 => new KeyValuePair(nameof(TransactionId), TransactionId), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; + get => index switch + { + 0 => new KeyValuePair(nameof(OperationId), OperationId), + 1 => new KeyValuePair(nameof(Operation), Operation), + 2 => new KeyValuePair(nameof(Timestamp), Timestamp), + 3 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), + 4 => new KeyValuePair(nameof(Connection), Connection), + 5 => new KeyValuePair(nameof(TransactionId), TransactionId), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// > + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + /// > + public IEnumerator> GetEnumerator() + { + int count = Count; + for (int index = 0; index < count; index++) + { + yield return this[index]; + } + } } /// - public sealed class SqlClientTransactionCommitAfter : SqlClientDiagnostic + public sealed class SqlClientTransactionCommitAfter : IReadOnlyList> { /// public const string Name = "Microsoft.Data.SqlClient.WriteTransactionCommitAfter"; internal SqlClientTransactionCommitAfter(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId) - : base(operationId, operation, timestamp) { + OperationId = operationId; + Operation = operation; + Timestamp = timestamp; IsolationLevel = isolationLevel; Connection = connection; TransactionId = transactionId; } + /// + public Guid OperationId { get; } + /// + public string Operation { get; } + /// + public long Timestamp { get; } + /// public IsolationLevel IsolationLevel { get; } - /// public SqlConnection Connection { get; } - /// public long? TransactionId { get; } + /// > + public int Count => 3 + 3; /// > - protected sealed override int GetDerivedCount() => 3; + public KeyValuePair this[int index] + { + get => index switch + { + 0 => new KeyValuePair(nameof(OperationId), OperationId), + 1 => new KeyValuePair(nameof(Operation), Operation), + 2 => new KeyValuePair(nameof(Timestamp), Timestamp), + 3 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), + 4 => new KeyValuePair(nameof(Connection), Connection), + 5 => new KeyValuePair(nameof(TransactionId), TransactionId), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// > + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); /// > - protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + public IEnumerator> GetEnumerator() { - 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), - 1 => new KeyValuePair(nameof(Connection), Connection), - 2 => new KeyValuePair(nameof(TransactionId), TransactionId), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; + int count = Count; + for (int index = 0; index < count; index++) + { + yield return this[index]; + } + } } /// - public sealed class SqlClientTransactionCommitError : SqlClientDiagnostic + public sealed class SqlClientTransactionCommitError : IReadOnlyList> { /// public const string Name = "Microsoft.Data.SqlClient.WriteTransactionCommitError"; internal SqlClientTransactionCommitError(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId, Exception ex) - : base(operationId, operation, timestamp) { + OperationId = operationId; + Operation = operation; + Timestamp = timestamp; IsolationLevel = isolationLevel; Connection = connection; TransactionId = transactionId; Exception = ex; } + /// + public Guid OperationId { get; } + /// + public string Operation { get; } + /// + public long Timestamp { get; } + /// public IsolationLevel IsolationLevel { get; } - /// public SqlConnection Connection { get; } - /// public long? TransactionId { get; } - /// public Exception Exception { get; } /// > - protected sealed override int GetDerivedCount() => 4; + public int Count => 3 + 4; + + /// > + public KeyValuePair this[int index] + { + get => index switch + { + 0 => new KeyValuePair(nameof(OperationId), OperationId), + 1 => new KeyValuePair(nameof(Operation), Operation), + 2 => new KeyValuePair(nameof(Timestamp), Timestamp), + 3 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), + 4 => new KeyValuePair(nameof(Connection), Connection), + 5 => new KeyValuePair(nameof(TransactionId), TransactionId), + 6 => new KeyValuePair(nameof(Exception), Exception), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// > + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); /// > - protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + public IEnumerator> GetEnumerator() { - 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), - 1 => new KeyValuePair(nameof(Connection), Connection), - 2 => new KeyValuePair(nameof(TransactionId), TransactionId), - 3 => new KeyValuePair(nameof(Exception), Exception), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; + int count = Count; + for (int index = 0; index < count; index++) + { + yield return this[index]; + } + } } /// - public sealed class SqlClientTransactionRollbackBefore : SqlClientDiagnostic + public sealed class SqlClientTransactionRollbackBefore : IReadOnlyList> { /// public const string Name = "Microsoft.Data.SqlClient.WriteTransactionRollbackBefore"; internal SqlClientTransactionRollbackBefore(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId, string transactionName) - : base(operationId, operation, timestamp) { + OperationId = operationId; + Operation = operation; + Timestamp = timestamp; IsolationLevel = isolationLevel; Connection = connection; TransactionId = transactionId; TransactionName = transactionName; } + /// + public Guid OperationId { get; } + /// + public string Operation { get; } + /// + public long Timestamp { get; } + /// public IsolationLevel IsolationLevel { get; } - /// public SqlConnection Connection { get; } - /// public long? TransactionId { get; } - /// public string TransactionName { get; } /// > - protected sealed override int GetDerivedCount() => 4; + public int Count => 3 + 4; /// > - protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + public KeyValuePair this[int index] { - 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), - 1 => new KeyValuePair(nameof(Connection), Connection), - 2 => new KeyValuePair(nameof(TransactionId), TransactionId), - 3 => new KeyValuePair(nameof(TransactionName), TransactionName), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; + get => index switch + { + 0 => new KeyValuePair(nameof(OperationId), OperationId), + 1 => new KeyValuePair(nameof(Operation), Operation), + 2 => new KeyValuePair(nameof(Timestamp), Timestamp), + 3 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), + 4 => new KeyValuePair(nameof(Connection), Connection), + 5 => new KeyValuePair(nameof(TransactionId), TransactionId), + 6 => new KeyValuePair(nameof(TransactionName), TransactionName), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// > + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + /// > + public IEnumerator> GetEnumerator() + { + int count = Count; + for (int index = 0; index < count; index++) + { + yield return this[index]; + } + } } /// - public sealed class SqlClientTransactionRollbackAfter : SqlClientDiagnostic + public sealed class SqlClientTransactionRollbackAfter : IReadOnlyList> { /// public const string Name = "Microsoft.Data.SqlClient.WriteTransactionRollbackAfter"; internal SqlClientTransactionRollbackAfter(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId, string transactionName) - : base(operationId, operation, timestamp) { + OperationId = operationId; + Operation = operation; + Timestamp = timestamp; IsolationLevel = isolationLevel; Connection = connection; TransactionId = transactionId; TransactionName = transactionName; } + /// + public Guid OperationId { get; } + /// + public string Operation { get; } + /// + public long Timestamp { get; } /// public IsolationLevel IsolationLevel { get; } - /// public SqlConnection Connection { get; } - /// public long? TransactionId { get; } - /// public string TransactionName { get; } /// > - protected sealed override int GetDerivedCount() => 4; + public int Count => 3 + 4; /// > - protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + public KeyValuePair this[int index] { - 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), - 1 => new KeyValuePair(nameof(Connection), Connection), - 2 => new KeyValuePair(nameof(TransactionId), TransactionId), - 3 => new KeyValuePair(nameof(TransactionName), TransactionName), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; + get => index switch + { + 0 => new KeyValuePair(nameof(OperationId), OperationId), + 1 => new KeyValuePair(nameof(Operation), Operation), + 2 => new KeyValuePair(nameof(Timestamp), Timestamp), + 3 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), + 4 => new KeyValuePair(nameof(Connection), Connection), + 5 => new KeyValuePair(nameof(TransactionId), TransactionId), + 6 => new KeyValuePair(nameof(TransactionName), TransactionName), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// > + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + /// > + public IEnumerator> GetEnumerator() + { + int count = Count; + for (int index = 0; index < count; index++) + { + yield return this[index]; + } + } } /// - public sealed class SqlClientTransactionRollbackError : SqlClientDiagnostic + public sealed class SqlClientTransactionRollbackError : IReadOnlyList> { /// public const string Name = "Microsoft.Data.SqlClient.WriteTransactionRollbackError"; internal SqlClientTransactionRollbackError(Guid operationId, string operation, long timestamp, IsolationLevel isolationLevel, SqlConnection connection, long? transactionId, string transactionName, Exception ex) - : base(operationId, operation, timestamp) { + OperationId = operationId; + Operation = operation; + Timestamp = timestamp; IsolationLevel = isolationLevel; Connection = connection; TransactionId = transactionId; @@ -644,33 +913,55 @@ internal SqlClientTransactionRollbackError(Guid operationId, string operation, l Exception = ex; } + + /// + public Guid OperationId { get; } + /// + public string Operation { get; } + /// + public long Timestamp { get; } /// public IsolationLevel IsolationLevel { get; } - /// public SqlConnection Connection { get; } - /// public long? TransactionId { get; } - /// public string TransactionName { get; } - /// public Exception Exception { get; } /// > - protected sealed override int GetDerivedCount() => 5; + public int Count => 3 + 5; /// > - protected sealed override KeyValuePair GetDerivedProperty(int index) => index switch + public KeyValuePair this[int index] { - 0 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), - 1 => new KeyValuePair(nameof(Connection), Connection), - 2 => new KeyValuePair(nameof(TransactionId), TransactionId), - 3 => new KeyValuePair(nameof(TransactionName), TransactionName), - 4 => new KeyValuePair(nameof(Exception), Exception), - _ => throw new IndexOutOfRangeException(nameof(index)), - }; + get => index switch + { + 0 => new KeyValuePair(nameof(OperationId), OperationId), + 1 => new KeyValuePair(nameof(Operation), Operation), + 2 => new KeyValuePair(nameof(Timestamp), Timestamp), + 3 => new KeyValuePair(nameof(IsolationLevel), IsolationLevel), + 4 => new KeyValuePair(nameof(Connection), Connection), + 5 => new KeyValuePair(nameof(TransactionId), TransactionId), + 6 => new KeyValuePair(nameof(TransactionName), TransactionName), + 7 => new KeyValuePair(nameof(Exception), Exception), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; + } + + /// > + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + /// > + public IEnumerator> GetEnumerator() + { + int count = Count; + for (int index = 0; index < count; index++) + { + yield return this[index]; + } + } } } From 8f7f3d562ee69f4c30a1bcdfdfd040f5067bc3ab Mon Sep 17 00:00:00 2001 From: Wraith2 Date: Tue, 11 Jun 2024 01:39:12 +0100 Subject: [PATCH 7/7] review feedback and removal of inheritdoc --- .../SqlClientDiagnostic.xml | 46 ++++--- .../Data/SqlClient/SqlClientDiagnostic.cs | 123 +++++++++--------- 2 files changed, 94 insertions(+), 75 deletions(-) diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml index 94014b0b7d..3711bbb7f7 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml @@ -10,13 +10,29 @@ The timestamp of the event. + + + Gets the element at the specified index in the read-only list. + + The zero-based index of the element to get. + The element at the specified index in the read-only list. + + + + Gets the number of elements in the collection. + The number of elements in the collection. + + + Returns an enumerator that iterates through the collection. + An enumerator that can be used to iterate through the collection. + Contains diagnostic information emitted before a command is executed. - The name of the event that that needs to be enabled for the event to be raised. + The name of the event that needs to be enabled for the event to be raised. A nullable guid uniquely identifying the connection that the xommand is being executed on. @@ -33,7 +49,7 @@ Contains diagnostic information emitted after a command is successfully executed. - The name of the event that that needs to be enabled for the event to be raised. + The name of the event that needs to be enabled for the event to be raised. A nullable guid uniquely identifying the connection that the command is being executed on. @@ -53,7 +69,7 @@ Contains diagnostic information emitted after a command execution fails with an exception. - The name of the event that that needs to be enabled for the event to be raised. + The name of the event that needs to be enabled for the event to be raised. A nullable guid uniquely identifying the connection that the command is being executed on. @@ -73,7 +89,7 @@ Contains diagnostic information emitted before a connection is opened. - The name of the event that that needs to be enabled for the event to be raised. + The name of the event that needs to be enabled for the event to be raised. The connection object that is being opened. @@ -87,7 +103,7 @@ Contains diagnostic information emitted after a connection has been successfully opened. - The name of the event that that needs to be enabled for the event to be raised. + The name of the event that needs to be enabled for the event to be raised. The connection object that has been opened. @@ -107,7 +123,7 @@ Contains diagnostic information emitted after a connection open fails with an exception. - The name of the event that that needs to be enabled for the event to be raised. + The name of the event that needs to be enabled for the event to be raised. The connection object that has been opened. @@ -127,7 +143,7 @@ Contains diagnostic information emitted before a connection is closed. - The name of the event that that needs to be enabled for the event to be raised. + The name of the event that needs to be enabled for the event to be raised. The connection object that is being closed. @@ -144,7 +160,7 @@ Contains diagnostic information emitted after a connection has been successfully closed. - The name of the event that that needs to be enabled for the event to be raised. + The name of the event that needs to be enabled for the event to be raised. The connection object that has been closed. @@ -161,7 +177,7 @@ Contains diagnostic information emitted after a connection close fails with an exception. - The name of the event that that needs to be enabled for the event to be raised. + The name of the event that needs to be enabled for the event to be raised. The connection object that has been closed. @@ -181,7 +197,7 @@ Contains diagnostic information emitted before a transaction is opened. - The name of the event that that needs to be enabled for the event to be raised. + The name of the event that needs to be enabled for the event to be raised. The connection object that the transaction belongs to. @@ -198,7 +214,7 @@ Contains diagnostic information emitted after a transaction is successfully committed. - The name of the event that that needs to be enabled for the event to be raised. + The name of the event that needs to be enabled for the event to be raised. The connection object that the transaction belongs to. @@ -215,7 +231,7 @@ Contains diagnostic information emitted after a transaction commit fails with an exception. - The name of the event that that needs to be enabled for the event to be raised. + The name of the event that needs to be enabled for the event to be raised. The connection object that the transaction belongs to. @@ -235,7 +251,7 @@ Contains diagnostic information emitted before a transaction rollback is rolled back. - The name of the event that that needs to be enabled for the event to be raised. + The name of the event that needs to be enabled for the event to be raised. The connection object that the transaction belongs to. @@ -255,7 +271,7 @@ Contains diagnostic information emitted after a transaction is rolled back successfully. - The name of the event that that needs to be enabled for the event to be raised. + The name of the event that needs to be enabled for the event to be raised. The connection object that the transaction belongs to. @@ -275,7 +291,7 @@ Contains diagnostic information emitted after a transaction roll back failes with an exception. - The name of the event that that needs to be enabled for the event to be raised. + The name of the event that needs to be enabled for the event to be raised. The connection object that the transaction belongs to. diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnostic.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnostic.cs index a42b8a3f0f..51a2f8f0ba 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnostic.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientDiagnostic.cs @@ -38,10 +38,10 @@ internal SqlClientCommandBefore(Guid operationId, string operation, long timesta /// public SqlCommand Command { get; } - /// > + /// public int Count => 3 + 3; - /// > + /// public KeyValuePair this[int index] { get => index switch @@ -56,10 +56,10 @@ public KeyValuePair this[int index] }; } - /// > + /// IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - /// > + /// public IEnumerator> GetEnumerator() { int count = Count; @@ -102,9 +102,10 @@ internal SqlClientCommandAfter(Guid operationId, string operation, long timestam /// public IDictionary Statistics { get; } - /// > + /// public int Count => 3 + 4; - /// > + + /// public KeyValuePair this[int index] { get => index switch @@ -120,10 +121,10 @@ public KeyValuePair this[int index] }; } - /// > + /// IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - /// > + /// public IEnumerator> GetEnumerator() { int count = Count; @@ -166,9 +167,10 @@ internal SqlClientCommandError(Guid operationId, string operation, long timestam /// public Exception Exception { get; } - /// > + /// public int Count => 3 + 4; - /// > + + /// public KeyValuePair this[int index] { get => index switch @@ -184,10 +186,10 @@ public KeyValuePair this[int index] }; } - /// > + /// IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - /// > + /// public IEnumerator> GetEnumerator() { int count = Count; @@ -224,10 +226,10 @@ internal SqlClientConnectionOpenBefore(Guid operationId, string operation, long /// public string ClientVersion { get; } - /// > + /// public int Count => 3 + 2; - /// > + /// public KeyValuePair this[int index] { get => index switch @@ -241,10 +243,10 @@ public KeyValuePair this[int index] }; } - /// > + /// IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - /// > + /// public IEnumerator> GetEnumerator() { int count = Count; @@ -287,10 +289,10 @@ internal SqlClientConnectionOpenAfter(Guid operationId, string operation, long t /// public IDictionary Statistics { get; } - /// > + /// public int Count => 3 + 4; - /// > + /// public KeyValuePair this[int index] { get => index switch @@ -306,10 +308,10 @@ public KeyValuePair this[int index] }; } - /// > + /// IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - /// > + /// public IEnumerator> GetEnumerator() { int count = Count; @@ -354,10 +356,10 @@ internal SqlClientConnectionOpenError(Guid operationId, string operation, long t /// public Exception Exception { get; } - /// > + /// public int Count => 3 + 4; - /// > + /// public KeyValuePair this[int index] { get => index switch @@ -373,10 +375,10 @@ public KeyValuePair this[int index] }; } - /// > + /// IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - /// > + /// public IEnumerator> GetEnumerator() { int count = Count; @@ -416,10 +418,10 @@ internal SqlClientConnectionCloseBefore(Guid operationId, string operation, long /// public IDictionary Statistics { get; } - /// > + /// public int Count => 3 + 3; - /// > + /// public KeyValuePair this[int index] { get => index switch @@ -434,10 +436,10 @@ public KeyValuePair this[int index] }; } - /// > + /// IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - /// > + /// public IEnumerator> GetEnumerator() { int count = Count; @@ -477,10 +479,10 @@ internal SqlClientConnectionCloseAfter(Guid operationId, string operation, long /// public IDictionary Statistics { get; } - /// > + /// public int Count => 3 + 3; - /// > + /// public KeyValuePair this[int index] { get => index switch @@ -495,10 +497,10 @@ public KeyValuePair this[int index] }; } - /// > + /// IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - /// > + /// public IEnumerator> GetEnumerator() { int count = Count; @@ -543,10 +545,10 @@ internal SqlClientConnectionCloseError(Guid operationId, string operation, long /// public Exception Exception { get; } - /// > + /// public int Count => 3 + 4; - /// > + /// public KeyValuePair this[int index] { get => index switch @@ -562,10 +564,10 @@ public KeyValuePair this[int index] }; } - /// > + /// IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - /// > + /// public IEnumerator> GetEnumerator() { int count = Count; @@ -605,10 +607,10 @@ internal SqlClientTransactionCommitBefore(Guid operationId, string operation, lo /// public long? TransactionId { get; } - /// > + /// public int Count => 3 + 3; - /// > + /// public KeyValuePair this[int index] { get => index switch @@ -623,10 +625,10 @@ public KeyValuePair this[int index] }; } - /// > + /// IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - /// > + /// public IEnumerator> GetEnumerator() { int count = Count; @@ -666,10 +668,11 @@ internal SqlClientTransactionCommitAfter(Guid operationId, string operation, lon public SqlConnection Connection { get; } /// public long? TransactionId { get; } - /// > + + /// public int Count => 3 + 3; - /// > + /// public KeyValuePair this[int index] { get => index switch @@ -684,10 +687,10 @@ public KeyValuePair this[int index] }; } - /// > + /// IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - /// > + /// public IEnumerator> GetEnumerator() { int count = Count; @@ -731,10 +734,10 @@ internal SqlClientTransactionCommitError(Guid operationId, string operation, lon /// public Exception Exception { get; } - /// > + /// public int Count => 3 + 4; - /// > + /// public KeyValuePair this[int index] { get => index switch @@ -750,10 +753,10 @@ public KeyValuePair this[int index] }; } - /// > + /// IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - /// > + /// public IEnumerator> GetEnumerator() { int count = Count; @@ -797,10 +800,10 @@ internal SqlClientTransactionRollbackBefore(Guid operationId, string operation, /// public string TransactionName { get; } - /// > + /// public int Count => 3 + 4; - /// > + /// public KeyValuePair this[int index] { get => index switch @@ -816,10 +819,10 @@ public KeyValuePair this[int index] }; } - /// > + /// IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - /// > + /// public IEnumerator> GetEnumerator() { int count = Count; @@ -862,10 +865,10 @@ internal SqlClientTransactionRollbackAfter(Guid operationId, string operation, l /// public string TransactionName { get; } - /// > + /// public int Count => 3 + 4; - /// > + /// public KeyValuePair this[int index] { get => index switch @@ -881,10 +884,10 @@ public KeyValuePair this[int index] }; } - /// > + /// IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - /// > + /// public IEnumerator> GetEnumerator() { int count = Count; @@ -931,10 +934,10 @@ internal SqlClientTransactionRollbackError(Guid operationId, string operation, l /// public Exception Exception { get; } - /// > + /// public int Count => 3 + 5; - /// > + /// public KeyValuePair this[int index] { get => index switch @@ -951,10 +954,10 @@ public KeyValuePair this[int index] }; } - /// > + /// IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - /// > + /// public IEnumerator> GetEnumerator() { int count = Count;