From 1cba36890c83df498da87532a8f2f82d5ec6cae2 Mon Sep 17 00:00:00 2001 From: Kaur-Parminder Date: Wed, 6 Oct 2021 16:56:11 -0700 Subject: [PATCH 1/4] Move to Shared SmiEventSink and smiEventsinkDefault Move SmiEventSink to shared folder using if defs (The NetCore file was empty) and SmiEventsinkDefault has 6 overlapping methods. Created partial classes to divide the code. --- .../src/Microsoft.Data.SqlClient.csproj | 11 ++++++-- .../Data/SqlClient/Server/SmiEventSink.cs | 25 ----------------- .../netfx/src/Microsoft.Data.SqlClient.csproj | 11 ++++++-- .../Data/SqlClient/Server/SmiEventSink.cs | 20 +++++++------- .../Server/SmiEventSink_Default.Common.cs | 27 +++++++++++++++++++ .../Server/SmiEventSink_Default.netcore.cs} | 26 +++--------------- .../Server/SmiEventSink_Default.netfx.cs} | 19 +------------ 7 files changed, 60 insertions(+), 79 deletions(-) delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/Server/SmiEventSink.cs rename src/Microsoft.Data.SqlClient/{netfx => }/src/Microsoft/Data/SqlClient/Server/SmiEventSink.cs (95%) create mode 100644 src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.Common.cs rename src/Microsoft.Data.SqlClient/{netcore/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.cs => src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.netcore.cs} (84%) rename src/Microsoft.Data.SqlClient/{netfx/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.cs => src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.netfx.cs} (97%) 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 5729b6fa40..b45215985c 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -295,6 +295,15 @@ Microsoft\Data\SqlClient\Server\SmiRecordBuffer.cs + + Microsoft\Data\SqlClient\Server\SmiEventSink.cs + + + Microsoft\Data\SqlClient\Server\SmiEventSink_Default.Common.cs + + + Microsoft\Data\SqlClient\Server\SmiEventSink_Default.netcore.cs + Microsoft\Data\SqlClient\Reliability\SqlRetryingEventArgs.cs @@ -428,8 +437,6 @@ - - diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/Server/SmiEventSink.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/Server/SmiEventSink.cs deleted file mode 100644 index 04ae3bedc5..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/Server/SmiEventSink.cs +++ /dev/null @@ -1,25 +0,0 @@ -// 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. - -namespace Microsoft.Data.SqlClient.Server -{ - // SqlEventSink is implemented by calling code. In all methods that accept - // a SqlEventSink directly the sink must be able to handle multiple callbacks - // without control returning from the original call. - - // Methods that do not accept SmiEventSync are (generally) ProcessEvent on - // the SmiEventStream methods returning a SmiEventStream and methods that - // are certain to never call to the server (most will, for in-proc back end). - - // Methods are commented with their corresponding TDS token - - // NOTE: Throwing from these methods will not usually produce the desired - // effect -- the managed to native boundary will eat any exceptions, - // and will cause a simple "Something bad happened" exception to be - // thrown in the native to managed boundary... - internal abstract class SmiEventSink - { - } -} - diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj index 1b8756600a..dc2e34a0dc 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj @@ -219,6 +219,15 @@ Microsoft\Data\SqlClient\ColumnEncryptionKeyInfo.cs + + Microsoft\Data\SqlClient\Server\SmiEventSink.cs + + + Microsoft\Data\SqlClient\Server\SmiEventSink_Default.Common.cs + + + Microsoft\Data\SqlClient\Server\SmiEventSink_Default.netfx.cs + Microsoft\Data\SqlClient\OnChangedEventHandler.cs @@ -537,8 +546,6 @@ - - diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/Server/SmiEventSink.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink.cs similarity index 95% rename from src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/Server/SmiEventSink.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink.cs index 1c672da82c..535ec722c3 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/Server/SmiEventSink.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink.cs @@ -21,8 +21,8 @@ namespace Microsoft.Data.SqlClient.Server // thrown in the native to managed boundary... internal abstract class SmiEventSink { - - #region Active methods +#if NETFRAMEWORK +#region Active methods // Called at end of stream whether errors or no internal abstract void BatchCompleted(); @@ -80,10 +80,10 @@ internal virtual void RowAvailable(SmiTypedGetterSetter rowData) // Called when a transaction is started (ENVCHANGE token) internal abstract void TransactionStarted(long transactionId); - #endregion +#endregion - #region OBSOLETE METHODS - #region OBSOLETED as of V200 but active in previous version +#region OBSOLETE METHODS +#region OBSOLETED as of V200 but active in previous version // Called zero or one time when output parameters are available (errors could prevent event from occuring) internal virtual void ParametersAvailable(SmiParameterMetaData[] metaData, ITypedGettersV3 paramValues) { @@ -108,9 +108,9 @@ internal virtual void RowAvailable(ITypedGettersV3 rowData) Microsoft.Data.Common.ADP.InternalError(Microsoft.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod); } - #endregion +#endregion - #region OBSOLETED and never shipped (without ObsoleteAttribute) +#region OBSOLETED and never shipped (without ObsoleteAttribute) // Called when a new row arrives (ROW token) internal virtual void RowAvailable(ITypedGetters rowData) { @@ -123,8 +123,10 @@ internal virtual void RowAvailable(ITypedGetters rowData) Microsoft.Data.Common.ADP.InternalError(Microsoft.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod); } - #endregion - #endregion +#endregion +#endregion + +#endif } } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.Common.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.Common.cs new file mode 100644 index 0000000000..488e4de56a --- /dev/null +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.Common.cs @@ -0,0 +1,27 @@ +// 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.Diagnostics; + +namespace Microsoft.Data.SqlClient.Server +{ + internal partial class SmiEventSink_Default : SmiEventSink + { + private SqlErrorCollection _errors; + private SqlErrorCollection _warnings; + + virtual internal string ServerVersion + { + get + { + return null; + } + } + + internal SmiEventSink_Default() + { + } + } +} + diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.netcore.cs similarity index 84% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.netcore.cs index 9b94b49c13..70d77e8bfa 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.netcore.cs @@ -6,32 +6,17 @@ namespace Microsoft.Data.SqlClient.Server { - internal class SmiEventSink_Default : SmiEventSink + internal partial class SmiEventSink_Default : SmiEventSink { - private SqlErrorCollection _errors; - private SqlErrorCollection _warnings; - - internal bool HasMessages { get { - { - bool result = (null != _errors || null != _warnings); - return result; - } + bool result = (null != _errors || null != _warnings); + return result; } } - virtual internal string ServerVersion - { - get - { - return null; - } - } - - protected virtual void DispatchMessages() { // virtual because we want a default implementation in the cases @@ -101,11 +86,6 @@ internal void ProcessMessagesAndThrow() } } - - - internal SmiEventSink_Default() - { - } } } diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.netfx.cs similarity index 97% rename from src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.netfx.cs index 663d042127..a6c2dec622 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.netfx.cs @@ -6,14 +6,10 @@ namespace Microsoft.Data.SqlClient.Server { - internal class SmiEventSink_Default : SmiEventSink + internal partial class SmiEventSink_Default : SmiEventSink { private SmiEventSink _parent; // next level up, which we'll defer to if we don't need to handle the event. - - private SqlErrorCollection _errors; - private SqlErrorCollection _warnings; - private SqlErrorCollection Errors { get @@ -44,14 +40,6 @@ internal bool HasMessages } } - virtual internal string ServerVersion - { - get - { - return null; - } - } - internal SmiEventSink Parent { get @@ -206,11 +194,6 @@ internal enum UnexpectedEventType TransactionStarted, } - - internal SmiEventSink_Default() - { - } - internal SmiEventSink_Default(SmiEventSink parent) { _parent = parent; From e86d213019e5f8b0d50ad1111559c29e8738d52d Mon Sep 17 00:00:00 2001 From: Parminder Kaur <88398605+Kaur-Parminder@users.noreply.github.com> Date: Fri, 8 Oct 2021 11:43:03 -0700 Subject: [PATCH 2/4] Apply suggestions from code review Co-authored-by: DavoudEshtehari <61173489+DavoudEshtehari@users.noreply.github.com> --- .../Microsoft/Data/SqlClient/Server/SmiEventSink.cs | 3 --- .../SqlClient/Server/SmiEventSink_Default.Common.cs | 11 +---------- .../SqlClient/Server/SmiEventSink_Default.netcore.cs | 2 -- .../SqlClient/Server/SmiEventSink_Default.netfx.cs | 1 - 4 files changed, 1 insertion(+), 16 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink.cs index 535ec722c3..56ceaa2fd7 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink.cs @@ -22,7 +22,6 @@ namespace Microsoft.Data.SqlClient.Server internal abstract class SmiEventSink { #if NETFRAMEWORK -#region Active methods // Called at end of stream whether errors or no internal abstract void BatchCompleted(); @@ -80,7 +79,6 @@ internal virtual void RowAvailable(SmiTypedGetterSetter rowData) // Called when a transaction is started (ENVCHANGE token) internal abstract void TransactionStarted(long transactionId); -#endregion #region OBSOLETE METHODS #region OBSOLETED as of V200 but active in previous version @@ -129,4 +127,3 @@ internal virtual void RowAvailable(ITypedGetters rowData) #endif } } - diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.Common.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.Common.cs index 488e4de56a..726cdb832d 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.Common.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.Common.cs @@ -2,8 +2,6 @@ // 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.Diagnostics; - namespace Microsoft.Data.SqlClient.Server { internal partial class SmiEventSink_Default : SmiEventSink @@ -11,17 +9,10 @@ internal partial class SmiEventSink_Default : SmiEventSink private SqlErrorCollection _errors; private SqlErrorCollection _warnings; - virtual internal string ServerVersion - { - get - { - return null; - } - } + internal virtual string ServerVersion => null; internal SmiEventSink_Default() { } } } - diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.netcore.cs index 70d77e8bfa..3b96f540d3 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.netcore.cs @@ -85,7 +85,5 @@ internal void ProcessMessagesAndThrow() DispatchMessages(); } } - } } - diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.netfx.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.netfx.cs index a6c2dec622..f2af9ce59a 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.netfx.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.netfx.cs @@ -8,7 +8,6 @@ namespace Microsoft.Data.SqlClient.Server { internal partial class SmiEventSink_Default : SmiEventSink { - private SmiEventSink _parent; // next level up, which we'll defer to if we don't need to handle the event. private SqlErrorCollection Errors { From d0c89cb1022f42825ef9efb2f02255191ba54c52 Mon Sep 17 00:00:00 2001 From: Kaur-Parminder Date: Fri, 8 Oct 2021 16:52:11 -0700 Subject: [PATCH 3/4] Addressing review comments Merged netcore and common and updated csproj files + xml comments --- .../src/Microsoft.Data.SqlClient.csproj | 3 - .../Data/SqlClient/Server/SmiEventSink.cs | 31 ++-- .../Server/SmiEventSink_Default.Common.cs | 131 +++++++++++++++++ .../Server/SmiEventSink_Default.netcore.cs | 89 ------------ .../Server/SmiEventSink_Default.netfx.cs | 135 ++---------------- 5 files changed, 159 insertions(+), 230 deletions(-) delete mode 100644 src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.netcore.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 b45215985c..7cd69d4e96 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -301,9 +301,6 @@ Microsoft\Data\SqlClient\Server\SmiEventSink_Default.Common.cs - - Microsoft\Data\SqlClient\Server\SmiEventSink_Default.netcore.cs - Microsoft\Data\SqlClient\Reliability\SqlRetryingEventArgs.cs diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink.cs index 56ceaa2fd7..a7de4b1947 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink.cs @@ -4,21 +4,22 @@ namespace Microsoft.Data.SqlClient.Server { - - // SqlEventSink is implemented by calling code. In all methods that accept - // a SqlEventSink directly the sink must be able to handle multiple callbacks - // without control returning from the original call. - - // Methods that do not accept SmiEventSync are (generally) ProcessEvent on - // the SmiEventStream methods returning a SmiEventStream and methods that - // are certain to never call to the server (most will, for in-proc back end). - - // Methods are commented with their corresponding TDS token - - // NOTE: Throwing from these methods will not usually produce the desired - // effect -- the managed to native boundary will eat any exceptions, - // and will cause a simple "Something bad happened" exception to be - // thrown in the native to managed boundary... + /// + /// SqlEventSink is implemented by calling code. In all methods that accept + /// a SqlEventSink directly the sink must be able to handle multiple callbacks + /// without control returning from the original call. + /// + /// Methods that do not accept SmiEventSync are (generally) ProcessEvent on + /// the SmiEventStream methods returning a SmiEventStream and methods that + /// are certain to never call to the server (most will, for in-proc back end). + /// + /// Methods are commented with their corresponding TDS token + /// + /// NOTE: Throwing from these methods will not usually produce the desired + /// effect -- the managed to native boundary will eat any exceptions, + /// and will cause a simple "Something bad happened" exception to be + /// thrown in the native to managed boundary... + /// internal abstract class SmiEventSink { #if NETFRAMEWORK diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.Common.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.Common.cs index 726cdb832d..39f87beaae 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.Common.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.Common.cs @@ -2,6 +2,8 @@ // 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.Diagnostics; + namespace Microsoft.Data.SqlClient.Server { internal partial class SmiEventSink_Default : SmiEventSink @@ -14,5 +16,134 @@ internal partial class SmiEventSink_Default : SmiEventSink internal SmiEventSink_Default() { } + + internal bool HasMessages + { + get + { +#if NETFRAMEWORK + SmiEventSink_Default parent = (SmiEventSink_Default)_parent; + if (null != parent) + { + return parent.HasMessages; + } + else +#endif + { + bool result = (null != _errors || null != _warnings); + return result; + } + } + } + + protected virtual void DispatchMessages( +#if NETFRAMEWORK + bool ignoreNonFatalMessages +#endif + ) + { + // virtual because we want a default implementation in the cases + // where we don't have a connection to process stuff, but we want to + // provide the connection the ability to fire info messages when it + // hooks up. +#if NETFRAMEWORK + SmiEventSink_Default parent = (SmiEventSink_Default)_parent; + if (null != parent) + { + parent.DispatchMessages(ignoreNonFatalMessages); + } + else +#endif + { + SqlException errors = ProcessMessages(true +#if NETFRAMEWORK + , ignoreNonFatalMessages +#endif + ); // ignore warnings, because there's no place to send them... + if (null != errors) + { + throw errors; + } + } + + } + + protected SqlException ProcessMessages(bool ignoreWarnings +#if NETFRAMEWORK + , bool ignoreNonFatalMessages +#endif + ) + { + SqlException result = null; + SqlErrorCollection temp = null; // temp variable to store that which is being thrown - so that local copies can be deleted + + if (null != _errors) + { + Debug.Assert(0 != _errors.Count, "empty error collection?"); // must be something in the collection +#if NETFRAMEWORK + if (ignoreNonFatalMessages) + { + temp = new SqlErrorCollection(); + foreach (SqlError error in _errors) + { + if (error.Class >= TdsEnums.FATAL_ERROR_CLASS) + { + temp.Add(error); + } + } + if (temp.Count <= 0) + { + temp = null; + } + } + else +#endif + { + if (null != _warnings) + { + // When we throw an exception we place all the warnings that + // occurred at the end of the collection - after all the errors. + // That way the user can see all the errors AND warnings that + // occurred for the exception. + foreach (SqlError warning in _warnings) + { + _errors.Add(warning); + } + } + temp = _errors; + } + + _errors = null; + _warnings = null; + } + else + { + Debug.Assert(null == _warnings || 0 != _warnings.Count, "empty warning collection?");// must be something in the collection + + if (!ignoreWarnings) + { + temp = _warnings; + } + _warnings = null; + } + + if (null != temp) + { + result = SqlException.CreateException(temp, ServerVersion); + } + return result; + } + + internal void ProcessMessagesAndThrow() + { +#if NETFRAMEWORK + ProcessMessagesAndThrow(false); +#else + if (HasMessages) + { + DispatchMessages(); + } +#endif + } } } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.netcore.cs deleted file mode 100644 index 3b96f540d3..0000000000 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.netcore.cs +++ /dev/null @@ -1,89 +0,0 @@ -// 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.Diagnostics; - -namespace Microsoft.Data.SqlClient.Server -{ - internal partial class SmiEventSink_Default : SmiEventSink - { - internal bool HasMessages - { - get - { - bool result = (null != _errors || null != _warnings); - return result; - } - } - - protected virtual void DispatchMessages() - { - // virtual because we want a default implementation in the cases - // where we don't have a connection to process stuff, but we want to - // provide the connection the ability to fire info messages when it - // hooks up. - { - SqlException errors = ProcessMessages(true); // ignore warnings, because there's no place to send them... - if (null != errors) - { - throw errors; - } - } - } - - protected SqlException ProcessMessages(bool ignoreWarnings) - { - SqlException result = null; - SqlErrorCollection temp = null; // temp variable to store that which is being thrown - so that local copies can be deleted - - if (null != _errors) - { - Debug.Assert(0 != _errors.Count, "empty error collection?"); // must be something in the collection - - { - if (null != _warnings) - { - // When we throw an exception we place all the warnings that - // occurred at the end of the collection - after all the errors. - // That way the user can see all the errors AND warnings that - // occurred for the exception. - foreach (SqlError warning in _warnings) - { - _errors.Add(warning); - } - } - temp = _errors; - } - - _errors = null; - _warnings = null; - } - else - { - Debug.Assert(null == _warnings || 0 != _warnings.Count, "empty warning collection?");// must be something in the collection - - if (!ignoreWarnings) - { - temp = _warnings; - } - _warnings = null; - } - - if (null != temp) - { - result = SqlException.CreateException(temp, ServerVersion); - } - return result; - } - - - internal void ProcessMessagesAndThrow() - { - if (HasMessages) - { - DispatchMessages(); - } - } - } -} diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.netfx.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.netfx.cs index f2af9ce59a..75d61f09ff 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.netfx.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.netfx.cs @@ -22,33 +22,10 @@ private SqlErrorCollection Errors } } - internal bool HasMessages - { - get - { - SmiEventSink_Default parent = (SmiEventSink_Default)_parent; - if (null != parent) - { - return parent.HasMessages; - } - else - { - bool result = (null != _errors || null != _warnings); - return result; - } - } - } - internal SmiEventSink Parent { - get - { - return _parent; - } - set - { - _parent = value; - } + get => _parent; + set => _parent = value; } private SqlErrorCollection Warnings @@ -64,86 +41,12 @@ private SqlErrorCollection Warnings } } - protected virtual void DispatchMessages(bool ignoreNonFatalMessages) - { - // virtual because we want a default implementation in the cases - // where we don't have a connection to process stuff, but we want to - // provide the connection the ability to fire info messages when it - // hooks up. - SmiEventSink_Default parent = (SmiEventSink_Default)_parent; - if (null != parent) - { - parent.DispatchMessages(ignoreNonFatalMessages); - } - else - { - SqlException errors = ProcessMessages(true, ignoreNonFatalMessages); // ignore warnings, because there's no place to send them... - if (null != errors) - { - throw errors; - } - } - } - - protected SqlException ProcessMessages(bool ignoreWarnings, bool ignoreNonFatalMessages) + internal void ProcessMessagesAndThrow(bool ignoreNonFatalMessages) { - SqlException result = null; - SqlErrorCollection temp = null; // temp variable to store that which is being thrown - so that local copies can be deleted - - if (null != _errors) - { - Debug.Assert(0 != _errors.Count, "empty error collection?"); // must be something in the collection - - if (ignoreNonFatalMessages) - { - temp = new SqlErrorCollection(); - foreach (SqlError error in _errors) - { - if (error.Class >= TdsEnums.FATAL_ERROR_CLASS) - { - temp.Add(error); - } - } - if (temp.Count <= 0) - { - temp = null; - } - } - else - { - if (null != _warnings) - { - // When we throw an exception we place all the warnings that - // occurred at the end of the collection - after all the errors. - // That way the user can see all the errors AND warnings that - // occurred for the exception. - foreach (SqlError warning in _warnings) - { - _errors.Add(warning); - } - } - temp = _errors; - } - - _errors = null; - _warnings = null; - } - else - { - Debug.Assert(null == _warnings || 0 != _warnings.Count, "empty warning collection?");// must be something in the collection - - if (!ignoreWarnings) - { - temp = _warnings; - } - _warnings = null; - } - - if (null != temp) + if (HasMessages) { - result = SqlException.CreateException(temp, ServerVersion); + DispatchMessages(ignoreNonFatalMessages); } - return result; } internal void CleanMessages() @@ -160,19 +63,6 @@ internal void CleanMessages() } } - internal void ProcessMessagesAndThrow() - { - ProcessMessagesAndThrow(false); - } - - internal void ProcessMessagesAndThrow(bool ignoreNonFatalMessages) - { - if (HasMessages) - { - DispatchMessages(ignoreNonFatalMessages); - } - } - internal enum UnexpectedEventType { BatchCompleted, @@ -198,15 +88,14 @@ internal SmiEventSink_Default(SmiEventSink parent) _parent = parent; } - - // NOTE: See the note in SmiEventSink about throwing from these methods; - // We're throwing here because we don't want to miss something, but - // you'll need to turn on Bid tracing to figure out what it is that - // was thrown, because they will be eaten by the server and replaced - // with a different exception. - - + // + //NOTE: See the note in SmiEventSink about throwing from these methods; + // We're throwing here because we don't want to miss something, but + //you'll need to turn on Bid tracing to figure out what it is that + //was thrown, because they will be eaten by the server and replaced + //with a different exception. // Called at end of stream + // internal override void BatchCompleted() { if (null == _parent) From 49ae67c206ebea9ebb6d44b07b09cb99a9fec843 Mon Sep 17 00:00:00 2001 From: Kaur-Parminder Date: Fri, 8 Oct 2021 17:03:01 -0700 Subject: [PATCH 4/4] addressing review comments Renamed file from common.cs to .cs only --- .../netcore/src/Microsoft.Data.SqlClient.csproj | 2 +- .../netfx/src/Microsoft.Data.SqlClient.csproj | 2 +- .../{SmiEventSink_Default.Common.cs => SmiEventSink_Default.cs} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/{SmiEventSink_Default.Common.cs => SmiEventSink_Default.cs} (100%) 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 7cd69d4e96..fdd8fdb50e 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -298,7 +298,7 @@ Microsoft\Data\SqlClient\Server\SmiEventSink.cs - + Microsoft\Data\SqlClient\Server\SmiEventSink_Default.Common.cs diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj index dc2e34a0dc..666bb60793 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj @@ -222,7 +222,7 @@ Microsoft\Data\SqlClient\Server\SmiEventSink.cs - + Microsoft\Data\SqlClient\Server\SmiEventSink_Default.Common.cs diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.Common.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.Common.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink_Default.cs