Skip to content

Commit b659f88

Browse files
Move to Shared SmiEventSink and SmiEventSinkDefault (#1324)
1 parent d4c8ea0 commit b659f88

File tree

6 files changed

+113
-218
lines changed

6 files changed

+113
-218
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,12 @@
340340
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SmiTypedGetterSetter.cs">
341341
<Link>Microsoft\Data\SqlClient\Server\SmiTypedGetterSetter.cs</Link>
342342
</Compile>
343+
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SmiEventSink.cs">
344+
<Link>Microsoft\Data\SqlClient\Server\SmiEventSink.cs</Link>
345+
</Compile>
346+
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SmiEventSink_Default.cs">
347+
<Link>Microsoft\Data\SqlClient\Server\SmiEventSink_Default.Common.cs</Link>
348+
</Compile>
343349
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Reliability\Common\SqlRetryingEventArgs.cs">
344350
<Link>Microsoft\Data\SqlClient\Reliability\SqlRetryingEventArgs.cs</Link>
345351
</Compile>
@@ -476,8 +482,6 @@
476482
</EmbeddedResource>
477483
<Compile Include="Microsoft\Data\SqlClient\AAsyncCallContext.cs" />
478484
<Compile Include="Microsoft\Data\SqlClient\Server\MetadataUtilsSmi.cs" />
479-
<Compile Include="Microsoft\Data\SqlClient\Server\SmiEventSink.cs" />
480-
<Compile Include="Microsoft\Data\SqlClient\Server\SmiEventSink_Default.cs" />
481485
<Compile Include="Microsoft\Data\SqlClient\Server\SmiMetaDataProperty.cs" />
482486
<Compile Include="Microsoft\Data\SqlClient\Server\SmiXetterAccessMap.cs" />
483487
<Compile Include="Microsoft\Data\SqlClient\Server\ValueUtilsSmi.cs" />

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/Server/SmiEventSink.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,15 @@
237237
<Compile Include="..\..\src\Microsoft\Data\SqlClient\ColumnEncryptionKeyInfo.cs">
238238
<Link>Microsoft\Data\SqlClient\ColumnEncryptionKeyInfo.cs</Link>
239239
</Compile>
240+
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SmiEventSink.cs">
241+
<Link>Microsoft\Data\SqlClient\Server\SmiEventSink.cs</Link>
242+
</Compile>
243+
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SmiEventSink_Default.cs">
244+
<Link>Microsoft\Data\SqlClient\Server\SmiEventSink_Default.Common.cs</Link>
245+
</Compile>
246+
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SmiEventSink_Default.netfx.cs">
247+
<Link>Microsoft\Data\SqlClient\Server\SmiEventSink_Default.netfx.cs</Link>
248+
</Compile>
240249
<Compile Include="..\..\src\Microsoft\Data\SqlClient\OnChangedEventHandler.cs">
241250
<Link>Microsoft\Data\SqlClient\OnChangedEventHandler.cs</Link>
242251
</Compile>
@@ -573,8 +582,6 @@
573582
<Compile Include="Microsoft\Data\SqlClient\Server\SmiConnection.cs" />
574583
<Compile Include="Microsoft\Data\SqlClient\Server\SmiContext.cs" />
575584
<Compile Include="Microsoft\Data\SqlClient\Server\SmiContextFactory.cs" />
576-
<Compile Include="Microsoft\Data\SqlClient\Server\SmiEventSink.cs" />
577-
<Compile Include="Microsoft\Data\SqlClient\Server\SmiEventSink_Default.cs" />
578585
<Compile Include="Microsoft\Data\SqlClient\Server\SmiEventSink_DeferedProcessing.cs" />
579586
<Compile Include="Microsoft\Data\SqlClient\Server\SmiEventStream.cs" />
580587
<Compile Include="Microsoft\Data\SqlClient\Server\SmiExecuteType.cs" />

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/Server/SmiEventSink.cs renamed to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiEventSink.cs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44

55
namespace Microsoft.Data.SqlClient.Server
66
{
7-
8-
// SqlEventSink is implemented by calling code. In all methods that accept
9-
// a SqlEventSink directly the sink must be able to handle multiple callbacks
10-
// without control returning from the original call.
11-
12-
// Methods that do not accept SmiEventSync are (generally) ProcessEvent on
13-
// the SmiEventStream methods returning a SmiEventStream and methods that
14-
// are certain to never call to the server (most will, for in-proc back end).
15-
16-
// Methods are commented with their corresponding TDS token
17-
18-
// NOTE: Throwing from these methods will not usually produce the desired
19-
// effect -- the managed to native boundary will eat any exceptions,
20-
// and will cause a simple "Something bad happened" exception to be
21-
// thrown in the native to managed boundary...
7+
/// <summary>
8+
/// SqlEventSink is implemented by calling code. In all methods that accept
9+
/// a SqlEventSink directly the sink must be able to handle multiple callbacks
10+
/// without control returning from the original call.
11+
///
12+
/// Methods that do not accept SmiEventSync are (generally) ProcessEvent on
13+
/// the SmiEventStream methods returning a SmiEventStream and methods that
14+
/// are certain to never call to the server (most will, for in-proc back end).
15+
///
16+
/// Methods are commented with their corresponding TDS token
17+
///
18+
/// NOTE: Throwing from these methods will not usually produce the desired
19+
/// effect -- the managed to native boundary will eat any exceptions,
20+
/// and will cause a simple "Something bad happened" exception to be
21+
/// thrown in the native to managed boundary...
22+
/// </summary>
2223
internal abstract class SmiEventSink
2324
{
24-
25-
#region Active methods
25+
#if NETFRAMEWORK
2626

2727
// Called at end of stream whether errors or no
2828
internal abstract void BatchCompleted();
@@ -80,10 +80,9 @@ internal virtual void RowAvailable(SmiTypedGetterSetter rowData)
8080
// Called when a transaction is started (ENVCHANGE token)
8181
internal abstract void TransactionStarted(long transactionId);
8282

83-
#endregion
8483

85-
#region OBSOLETE METHODS
86-
#region OBSOLETED as of V200 but active in previous version
84+
#region OBSOLETE METHODS
85+
#region OBSOLETED as of V200 but active in previous version
8786
// Called zero or one time when output parameters are available (errors could prevent event from occuring)
8887
internal virtual void ParametersAvailable(SmiParameterMetaData[] metaData, ITypedGettersV3 paramValues)
8988
{
@@ -108,9 +107,9 @@ internal virtual void RowAvailable(ITypedGettersV3 rowData)
108107
Microsoft.Data.Common.ADP.InternalError(Microsoft.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
109108
}
110109

111-
#endregion
110+
#endregion
112111

113-
#region OBSOLETED and never shipped (without ObsoleteAttribute)
112+
#region OBSOLETED and never shipped (without ObsoleteAttribute)
114113
// Called when a new row arrives (ROW token)
115114
internal virtual void RowAvailable(ITypedGetters rowData)
116115
{
@@ -123,8 +122,9 @@ internal virtual void RowAvailable(ITypedGetters rowData)
123122
Microsoft.Data.Common.ADP.InternalError(Microsoft.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
124123
}
125124

126-
#endregion
127-
#endregion
125+
#endregion
126+
#endregion
127+
128+
#endif
128129
}
129130
}
130-
Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,98 @@
66

77
namespace Microsoft.Data.SqlClient.Server
88
{
9-
internal class SmiEventSink_Default : SmiEventSink
9+
internal partial class SmiEventSink_Default : SmiEventSink
1010
{
1111
private SqlErrorCollection _errors;
1212
private SqlErrorCollection _warnings;
1313

14+
internal virtual string ServerVersion => null;
15+
16+
internal SmiEventSink_Default()
17+
{
18+
}
1419

1520
internal bool HasMessages
1621
{
1722
get
1823
{
24+
#if NETFRAMEWORK
25+
SmiEventSink_Default parent = (SmiEventSink_Default)_parent;
26+
if (null != parent)
27+
{
28+
return parent.HasMessages;
29+
}
30+
else
31+
#endif
1932
{
2033
bool result = (null != _errors || null != _warnings);
2134
return result;
2235
}
2336
}
2437
}
2538

26-
virtual internal string ServerVersion
27-
{
28-
get
29-
{
30-
return null;
31-
}
32-
}
33-
34-
35-
protected virtual void DispatchMessages()
39+
protected virtual void DispatchMessages(
40+
#if NETFRAMEWORK
41+
bool ignoreNonFatalMessages
42+
#endif
43+
)
3644
{
3745
// virtual because we want a default implementation in the cases
3846
// where we don't have a connection to process stuff, but we want to
3947
// provide the connection the ability to fire info messages when it
4048
// hooks up.
49+
#if NETFRAMEWORK
50+
SmiEventSink_Default parent = (SmiEventSink_Default)_parent;
51+
if (null != parent)
4152
{
42-
SqlException errors = ProcessMessages(true); // ignore warnings, because there's no place to send them...
53+
parent.DispatchMessages(ignoreNonFatalMessages);
54+
}
55+
else
56+
#endif
57+
{
58+
SqlException errors = ProcessMessages(true
59+
#if NETFRAMEWORK
60+
, ignoreNonFatalMessages
61+
#endif
62+
); // ignore warnings, because there's no place to send them...
4363
if (null != errors)
4464
{
4565
throw errors;
4666
}
4767
}
68+
4869
}
4970

50-
protected SqlException ProcessMessages(bool ignoreWarnings)
71+
protected SqlException ProcessMessages(bool ignoreWarnings
72+
#if NETFRAMEWORK
73+
, bool ignoreNonFatalMessages
74+
#endif
75+
)
5176
{
5277
SqlException result = null;
5378
SqlErrorCollection temp = null; // temp variable to store that which is being thrown - so that local copies can be deleted
5479

5580
if (null != _errors)
5681
{
5782
Debug.Assert(0 != _errors.Count, "empty error collection?"); // must be something in the collection
58-
83+
#if NETFRAMEWORK
84+
if (ignoreNonFatalMessages)
85+
{
86+
temp = new SqlErrorCollection();
87+
foreach (SqlError error in _errors)
88+
{
89+
if (error.Class >= TdsEnums.FATAL_ERROR_CLASS)
90+
{
91+
temp.Add(error);
92+
}
93+
}
94+
if (temp.Count <= 0)
95+
{
96+
temp = null;
97+
}
98+
}
99+
else
100+
#endif
59101
{
60102
if (null != _warnings)
61103
{
@@ -92,20 +134,16 @@ protected SqlException ProcessMessages(bool ignoreWarnings)
92134
return result;
93135
}
94136

95-
96137
internal void ProcessMessagesAndThrow()
97138
{
139+
#if NETFRAMEWORK
140+
ProcessMessagesAndThrow(false);
141+
#else
98142
if (HasMessages)
99143
{
100144
DispatchMessages();
101145
}
102-
}
103-
104-
105-
106-
internal SmiEventSink_Default()
107-
{
146+
#endif
108147
}
109148
}
110149
}
111-

0 commit comments

Comments
 (0)