Skip to content

Commit

Permalink
Move to Shared SmiEventSink and SmiEventSinkDefault (#1324)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaur-Parminder authored Oct 13, 2021
1 parent d4c8ea0 commit b659f88
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,12 @@
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SmiTypedGetterSetter.cs">
<Link>Microsoft\Data\SqlClient\Server\SmiTypedGetterSetter.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SmiEventSink.cs">
<Link>Microsoft\Data\SqlClient\Server\SmiEventSink.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SmiEventSink_Default.cs">
<Link>Microsoft\Data\SqlClient\Server\SmiEventSink_Default.Common.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Reliability\Common\SqlRetryingEventArgs.cs">
<Link>Microsoft\Data\SqlClient\Reliability\SqlRetryingEventArgs.cs</Link>
</Compile>
Expand Down Expand Up @@ -476,8 +482,6 @@
</EmbeddedResource>
<Compile Include="Microsoft\Data\SqlClient\AAsyncCallContext.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\MetadataUtilsSmi.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\SmiEventSink.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\SmiEventSink_Default.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\SmiMetaDataProperty.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\SmiXetterAccessMap.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\ValueUtilsSmi.cs" />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@
<Compile Include="..\..\src\Microsoft\Data\SqlClient\ColumnEncryptionKeyInfo.cs">
<Link>Microsoft\Data\SqlClient\ColumnEncryptionKeyInfo.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SmiEventSink.cs">
<Link>Microsoft\Data\SqlClient\Server\SmiEventSink.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SmiEventSink_Default.cs">
<Link>Microsoft\Data\SqlClient\Server\SmiEventSink_Default.Common.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SmiEventSink_Default.netfx.cs">
<Link>Microsoft\Data\SqlClient\Server\SmiEventSink_Default.netfx.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\OnChangedEventHandler.cs">
<Link>Microsoft\Data\SqlClient\OnChangedEventHandler.cs</Link>
</Compile>
Expand Down Expand Up @@ -573,8 +582,6 @@
<Compile Include="Microsoft\Data\SqlClient\Server\SmiConnection.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\SmiContext.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\SmiContextFactory.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\SmiEventSink.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\SmiEventSink_Default.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\SmiEventSink_DeferedProcessing.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\SmiEventStream.cs" />
<Compile Include="Microsoft\Data\SqlClient\Server\SmiExecuteType.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@

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...
/// <summary>
/// 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...
/// </summary>
internal abstract class SmiEventSink
{

#region Active methods
#if NETFRAMEWORK

// Called at end of stream whether errors or no
internal abstract void BatchCompleted();
Expand Down Expand Up @@ -80,10 +80,9 @@ 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
#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)
{
Expand All @@ -108,9 +107,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)
{
Expand All @@ -123,8 +122,9 @@ internal virtual void RowAvailable(ITypedGetters rowData)
Microsoft.Data.Common.ADP.InternalError(Microsoft.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
}

#endregion
#endregion
#endregion
#endregion

#endif
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,98 @@

namespace Microsoft.Data.SqlClient.Server
{
internal class SmiEventSink_Default : SmiEventSink
internal partial class SmiEventSink_Default : SmiEventSink
{
private SqlErrorCollection _errors;
private SqlErrorCollection _warnings;

internal virtual string ServerVersion => null;

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;
}
}
}

virtual internal string ServerVersion
{
get
{
return null;
}
}


protected virtual void DispatchMessages()
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)
{
SqlException errors = ProcessMessages(true); // ignore warnings, because there's no place to send them...
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)
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)
{
Expand Down Expand Up @@ -92,20 +134,16 @@ protected SqlException ProcessMessages(bool ignoreWarnings)
return result;
}


internal void ProcessMessagesAndThrow()
{
#if NETFRAMEWORK
ProcessMessagesAndThrow(false);
#else
if (HasMessages)
{
DispatchMessages();
}
}



internal SmiEventSink_Default()
{
#endif
}
}
}

Loading

0 comments on commit b659f88

Please sign in to comment.