Skip to content

Commit f59d1c7

Browse files
Merging common code bases StringsHelper (#1288)
1 parent 75fb627 commit f59d1c7

File tree

17 files changed

+476
-518
lines changed

17 files changed

+476
-518
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Security.Native/Interop.GssApiException.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using Microsoft.Data;
56
using System;
67
using System.Runtime.InteropServices;
78

src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Security.Native/Interop.GssBuffer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using Microsoft.Data;
56
using System;
67
using System.Diagnostics;
78
using System.Runtime.InteropServices;

src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/SSPIAuthType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System.Net.Security;
66
using System.Runtime.InteropServices;
7+
using Microsoft.Data;
78

89
namespace System.Net
910
{

src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/SSPISecureChannelType.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System.Net.Security;
66
using System.Runtime.InteropServices;
7+
using Microsoft.Data;
78

89
namespace System.Net
910
{
@@ -129,7 +130,7 @@ public unsafe int QueryContextAttributes(SafeDeleteContext phContext, Interop.Ss
129130
}
130131
else
131132
{
132-
throw new ArgumentException(System.StringsHelper.Format(Strings.SSPIInvalidHandleType, handleType.FullName), nameof(handleType));
133+
throw new ArgumentException(StringsHelper.Format(Strings.SSPIInvalidHandleType, handleType.FullName), nameof(handleType));
133134
}
134135
}
135136
fixed (byte* bufferPtr = buffer)

src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/SSPIWrapper.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Globalization;
77
using System.Net.Security;
88
using System.Runtime.InteropServices;
9+
using Microsoft.Data;
910

1011
namespace System.Net
1112
{
@@ -101,7 +102,7 @@ public static SafeFreeCredentials AcquireDefaultCredential(SSPIInterface secModu
101102
if (errorCode != 0)
102103
{
103104
if (NetEventSource.IsEnabled)
104-
NetEventSource.Error(null, System.StringsHelper.Format(Strings.net_log_operation_failed_with_error, nameof(AcquireDefaultCredential), $"0x{errorCode:X}"));
105+
NetEventSource.Error(null, StringsHelper.Format(Strings.net_log_operation_failed_with_error, nameof(AcquireDefaultCredential), $"0x{errorCode:X}"));
105106
throw new Win32Exception(errorCode);
106107
}
107108
return outCredential;
@@ -118,7 +119,7 @@ public static SafeFreeCredentials AcquireCredentialsHandle(SSPIInterface secModu
118119
if (errorCode != 0)
119120
{
120121
if (NetEventSource.IsEnabled)
121-
NetEventSource.Error(null, System.StringsHelper.Format(Strings.net_log_operation_failed_with_error, nameof(AcquireCredentialsHandle), $"0x{errorCode:X}"));
122+
NetEventSource.Error(null, StringsHelper.Format(Strings.net_log_operation_failed_with_error, nameof(AcquireCredentialsHandle), $"0x{errorCode:X}"));
122123
throw new Win32Exception(errorCode);
123124
}
124125

@@ -143,7 +144,7 @@ public static SafeFreeCredentials AcquireCredentialsHandle(SSPIInterface secModu
143144
if (errorCode != 0)
144145
{
145146
if (NetEventSource.IsEnabled)
146-
NetEventSource.Error(null, System.StringsHelper.Format(Strings.net_log_operation_failed_with_error, nameof(AcquireCredentialsHandle), $"0x{errorCode:X}"));
147+
NetEventSource.Error(null, StringsHelper.Format(Strings.net_log_operation_failed_with_error, nameof(AcquireCredentialsHandle), $"0x{errorCode:X}"));
147148
throw new Win32Exception(errorCode);
148149
}
149150

@@ -359,11 +360,11 @@ private static unsafe int EncryptDecryptHelper(OP op, SSPIInterface secModule, S
359360
{
360361
if (errorCode == Interop.SspiCli.SEC_I_RENEGOTIATE)
361362
{
362-
NetEventSource.Error(null, System.StringsHelper.Format(Strings.event_OperationReturnedSomething, op, "SEC_I_RENEGOTIATE"));
363+
NetEventSource.Error(null, StringsHelper.Format(Strings.event_OperationReturnedSomething, op, "SEC_I_RENEGOTIATE"));
363364
}
364365
else
365366
{
366-
NetEventSource.Error(null, System.StringsHelper.Format(Strings.net_log_operation_failed_with_error, op, $"0x{0:X}"));
367+
NetEventSource.Error(null, StringsHelper.Format(Strings.net_log_operation_failed_with_error, op, $"0x{0:X}"));
367368
}
368369
}
369370

@@ -466,7 +467,7 @@ public static object QueryContextAttributes(SSPIInterface secModule, SafeDeleteC
466467
break;
467468

468469
default:
469-
throw new ArgumentException(System.StringsHelper.Format(Strings.net_invalid_enum, nameof(contextAttribute)), nameof(contextAttribute));
470+
throw new ArgumentException(StringsHelper.Format(Strings.net_invalid_enum, nameof(contextAttribute)), nameof(contextAttribute));
470471
}
471472

472473
SafeHandle sspiHandle = null;

src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/Common/AdapterUtil.cs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ internal static bool RemoveStringQuotes(string quotePrefix, string quoteSuffix,
200200

201201
internal static ArgumentOutOfRangeException NotSupportedEnumerationValue(Type type, string value, string method)
202202
{
203-
return ArgumentOutOfRange(System.StringsHelper.Format(Strings.ADP_NotSupportedEnumerationValue, type.Name, value, method), type.Name);
203+
return ArgumentOutOfRange(StringsHelper.Format(Strings.ADP_NotSupportedEnumerationValue, type.Name, value, method), type.Name);
204204
}
205205

206206
internal static InvalidOperationException DataAdapter(string error)
@@ -215,21 +215,21 @@ private static InvalidOperationException Provider(string error)
215215

216216
internal static ArgumentException InvalidMultipartName(string property, string value)
217217
{
218-
ArgumentException e = new ArgumentException(System.StringsHelper.Format(Strings.ADP_InvalidMultipartName, property, value));
218+
ArgumentException e = new ArgumentException(StringsHelper.Format(Strings.ADP_InvalidMultipartName, property, value));
219219
TraceExceptionAsReturnValue(e);
220220
return e;
221221
}
222222

223223
internal static ArgumentException InvalidMultipartNameIncorrectUsageOfQuotes(string property, string value)
224224
{
225-
ArgumentException e = new ArgumentException(System.StringsHelper.Format(Strings.ADP_InvalidMultipartNameQuoteUsage, property, value));
225+
ArgumentException e = new ArgumentException(StringsHelper.Format(Strings.ADP_InvalidMultipartNameQuoteUsage, property, value));
226226
TraceExceptionAsReturnValue(e);
227227
return e;
228228
}
229229

230230
internal static ArgumentException InvalidMultipartNameToManyParts(string property, string value, int limit)
231231
{
232-
ArgumentException e = new ArgumentException(System.StringsHelper.Format(Strings.ADP_InvalidMultipartNameToManyParts, property, value, limit));
232+
ArgumentException e = new ArgumentException(StringsHelper.Format(Strings.ADP_InvalidMultipartNameToManyParts, property, value, limit));
233233
TraceExceptionAsReturnValue(e);
234234
return e;
235235
}
@@ -286,23 +286,23 @@ internal static bool IsCatchableOrSecurityExceptionType(Exception e)
286286
// Invalid Enumeration
287287
internal static ArgumentOutOfRangeException InvalidEnumerationValue(Type type, int value)
288288
{
289-
return ArgumentOutOfRange(System.StringsHelper.Format(Strings.ADP_InvalidEnumerationValue, type.Name, value.ToString(CultureInfo.InvariantCulture)), type.Name);
289+
return ArgumentOutOfRange(StringsHelper.Format(Strings.ADP_InvalidEnumerationValue, type.Name, value.ToString(CultureInfo.InvariantCulture)), type.Name);
290290
}
291291

292292
//
293293
// DbConnectionOptions, DataAccess
294294
//
295295
internal static ArgumentException ConnectionStringSyntax(int index)
296296
{
297-
return Argument(System.StringsHelper.Format(Strings.ADP_ConnectionStringSyntax, index));
297+
return Argument(StringsHelper.Format(Strings.ADP_ConnectionStringSyntax, index));
298298
}
299299
internal static ArgumentException KeywordNotSupported(string keyword)
300300
{
301-
return Argument(System.StringsHelper.Format(Strings.ADP_KeywordNotSupported, keyword));
301+
return Argument(StringsHelper.Format(Strings.ADP_KeywordNotSupported, keyword));
302302
}
303303
internal static ArgumentException ConvertFailed(Type fromType, Type toType, Exception innerException)
304304
{
305-
return ADP.Argument(System.StringsHelper.Format(Strings.SqlConvert_ConvertFailed, fromType.FullName, toType.FullName), innerException);
305+
return ADP.Argument(StringsHelper.Format(Strings.SqlConvert_ConvertFailed, fromType.FullName, toType.FullName), innerException);
306306
}
307307

308308
//
@@ -314,7 +314,7 @@ internal static Exception InvalidConnectionOptionValue(string key)
314314
}
315315
internal static Exception InvalidConnectionOptionValue(string key, Exception inner)
316316
{
317-
return Argument(System.StringsHelper.Format(Strings.ADP_InvalidConnectionOptionValue, key), inner);
317+
return Argument(StringsHelper.Format(Strings.ADP_InvalidConnectionOptionValue, key), inner);
318318
}
319319
static internal InvalidOperationException InvalidDataDirectory()
320320
{
@@ -327,23 +327,23 @@ static internal InvalidOperationException InvalidDataDirectory()
327327
//
328328
internal static ArgumentException CollectionRemoveInvalidObject(Type itemType, ICollection collection)
329329
{
330-
return Argument(System.StringsHelper.Format(Strings.ADP_CollectionRemoveInvalidObject, itemType.Name, collection.GetType().Name));
330+
return Argument(StringsHelper.Format(Strings.ADP_CollectionRemoveInvalidObject, itemType.Name, collection.GetType().Name));
331331
}
332332
internal static ArgumentNullException CollectionNullValue(string parameter, Type collection, Type itemType)
333333
{
334-
return ArgumentNull(parameter, System.StringsHelper.Format(Strings.ADP_CollectionNullValue, collection.Name, itemType.Name));
334+
return ArgumentNull(parameter, StringsHelper.Format(Strings.ADP_CollectionNullValue, collection.Name, itemType.Name));
335335
}
336336
internal static IndexOutOfRangeException CollectionIndexInt32(int index, Type collection, int count)
337337
{
338-
return IndexOutOfRange(System.StringsHelper.Format(Strings.ADP_CollectionIndexInt32, index.ToString(CultureInfo.InvariantCulture), collection.Name, count.ToString(CultureInfo.InvariantCulture)));
338+
return IndexOutOfRange(StringsHelper.Format(Strings.ADP_CollectionIndexInt32, index.ToString(CultureInfo.InvariantCulture), collection.Name, count.ToString(CultureInfo.InvariantCulture)));
339339
}
340340
internal static IndexOutOfRangeException CollectionIndexString(Type itemType, string propertyName, string propertyValue, Type collection)
341341
{
342-
return IndexOutOfRange(System.StringsHelper.Format(Strings.ADP_CollectionIndexString, itemType.Name, propertyName, propertyValue, collection.Name));
342+
return IndexOutOfRange(StringsHelper.Format(Strings.ADP_CollectionIndexString, itemType.Name, propertyName, propertyValue, collection.Name));
343343
}
344344
internal static InvalidCastException CollectionInvalidType(Type collection, Type itemType, object invalidValue)
345345
{
346-
return InvalidCast(System.StringsHelper.Format(Strings.ADP_CollectionInvalidType, collection.Name, itemType.Name, invalidValue.GetType().Name));
346+
return InvalidCast(StringsHelper.Format(Strings.ADP_CollectionInvalidType, collection.Name, itemType.Name, invalidValue.GetType().Name));
347347
}
348348

349349
//
@@ -365,7 +365,7 @@ private static string ConnectionStateMsg(ConnectionState state)
365365
case (ConnectionState.Open | ConnectionState.Fetching):
366366
return Strings.ADP_ConnectionStateMsg_OpenFetching;
367367
default:
368-
return System.StringsHelper.Format(Strings.ADP_ConnectionStateMsg, state.ToString());
368+
return StringsHelper.Format(Strings.ADP_ConnectionStateMsg, state.ToString());
369369
}
370370
}
371371

@@ -374,7 +374,7 @@ private static string ConnectionStateMsg(ConnectionState state)
374374
//
375375
internal static Exception StreamClosed([CallerMemberName] string method = "")
376376
{
377-
return InvalidOperation(System.StringsHelper.Format(Strings.ADP_StreamClosed, method));
377+
return InvalidOperation(StringsHelper.Format(Strings.ADP_StreamClosed, method));
378378
}
379379

380380
internal static string BuildQuotedString(string quotePrefix, string quoteSuffix, string unQuotedString)
@@ -433,11 +433,11 @@ static internal string BuildMultiPartName(string[] strings)
433433
//
434434
internal static ArgumentException ParametersIsNotParent(Type parameterType, ICollection collection)
435435
{
436-
return Argument(System.StringsHelper.Format(Strings.ADP_CollectionIsNotParent, parameterType.Name, collection.GetType().Name));
436+
return Argument(StringsHelper.Format(Strings.ADP_CollectionIsNotParent, parameterType.Name, collection.GetType().Name));
437437
}
438438
internal static ArgumentException ParametersIsParent(Type parameterType, ICollection collection)
439439
{
440-
return Argument(System.StringsHelper.Format(Strings.ADP_CollectionIsNotParent, parameterType.Name, collection.GetType().Name));
440+
return Argument(StringsHelper.Format(Strings.ADP_CollectionIsNotParent, parameterType.Name, collection.GetType().Name));
441441
}
442442

443443

@@ -483,31 +483,31 @@ internal enum InternalErrorCode
483483

484484
internal static Exception InternalError(InternalErrorCode internalError)
485485
{
486-
return InvalidOperation(System.StringsHelper.Format(Strings.ADP_InternalProviderError, (int)internalError));
486+
return InvalidOperation(StringsHelper.Format(Strings.ADP_InternalProviderError, (int)internalError));
487487
}
488488

489489
//
490490
// : DbDataReader
491491
//
492492
internal static Exception DataReaderClosed([CallerMemberName] string method = "")
493493
{
494-
return InvalidOperation(System.StringsHelper.Format(Strings.ADP_DataReaderClosed, method));
494+
return InvalidOperation(StringsHelper.Format(Strings.ADP_DataReaderClosed, method));
495495
}
496496
internal static ArgumentOutOfRangeException InvalidSourceBufferIndex(int maxLen, long srcOffset, string parameterName)
497497
{
498-
return ArgumentOutOfRange(System.StringsHelper.Format(Strings.ADP_InvalidSourceBufferIndex, maxLen.ToString(CultureInfo.InvariantCulture), srcOffset.ToString(CultureInfo.InvariantCulture)), parameterName);
498+
return ArgumentOutOfRange(StringsHelper.Format(Strings.ADP_InvalidSourceBufferIndex, maxLen.ToString(CultureInfo.InvariantCulture), srcOffset.ToString(CultureInfo.InvariantCulture)), parameterName);
499499
}
500500
internal static ArgumentOutOfRangeException InvalidDestinationBufferIndex(int maxLen, int dstOffset, string parameterName)
501501
{
502-
return ArgumentOutOfRange(System.StringsHelper.Format(Strings.ADP_InvalidDestinationBufferIndex, maxLen.ToString(CultureInfo.InvariantCulture), dstOffset.ToString(CultureInfo.InvariantCulture)), parameterName);
502+
return ArgumentOutOfRange(StringsHelper.Format(Strings.ADP_InvalidDestinationBufferIndex, maxLen.ToString(CultureInfo.InvariantCulture), dstOffset.ToString(CultureInfo.InvariantCulture)), parameterName);
503503
}
504504
internal static IndexOutOfRangeException InvalidBufferSizeOrIndex(int numBytes, int bufferIndex)
505505
{
506-
return IndexOutOfRange(System.StringsHelper.Format(Strings.SQL_InvalidBufferSizeOrIndex, numBytes.ToString(CultureInfo.InvariantCulture), bufferIndex.ToString(CultureInfo.InvariantCulture)));
506+
return IndexOutOfRange(StringsHelper.Format(Strings.SQL_InvalidBufferSizeOrIndex, numBytes.ToString(CultureInfo.InvariantCulture), bufferIndex.ToString(CultureInfo.InvariantCulture)));
507507
}
508508
internal static Exception InvalidDataLength(long length)
509509
{
510-
return IndexOutOfRange(System.StringsHelper.Format(Strings.SQL_InvalidDataLength, length.ToString(CultureInfo.InvariantCulture)));
510+
return IndexOutOfRange(StringsHelper.Format(Strings.SQL_InvalidDataLength, length.ToString(CultureInfo.InvariantCulture)));
511511
}
512512

513513
internal static bool CompareInsensitiveInvariant(string strvalue, string strconst) =>

src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/Common/SQLResource.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,22 @@ internal static class SQLResource
5050

5151
internal static string InvalidOpStreamClosed(string method)
5252
{
53-
return System.StringsHelper.Format(Strings.SqlMisc_InvalidOpStreamClosed, method);
53+
return StringsHelper.Format(Strings.SqlMisc_InvalidOpStreamClosed, method);
5454
}
5555

5656
internal static string InvalidOpStreamNonWritable(string method)
5757
{
58-
return System.StringsHelper.Format(Strings.SqlMisc_InvalidOpStreamNonWritable, method);
58+
return StringsHelper.Format(Strings.SqlMisc_InvalidOpStreamNonWritable, method);
5959
}
6060

6161
internal static string InvalidOpStreamNonReadable(string method)
6262
{
63-
return System.StringsHelper.Format(Strings.SqlMisc_InvalidOpStreamNonReadable, method);
63+
return StringsHelper.Format(Strings.SqlMisc_InvalidOpStreamNonReadable, method);
6464
}
6565

6666
internal static string InvalidOpStreamNonSeekable(string method)
6767
{
68-
return System.StringsHelper.Format(Strings.SqlMisc_InvalidOpStreamNonSeekable, method);
68+
return StringsHelper.Format(Strings.SqlMisc_InvalidOpStreamNonSeekable, method);
6969
}
7070
} // SqlResource
7171
} // namespace System

src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Security/NegotiateStreamPal.Windows.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System.Globalization;
66
using System.ComponentModel;
7+
using Microsoft.Data;
78

89
namespace System.Net.Security
910
{
@@ -40,7 +41,7 @@ internal static unsafe SafeFreeCredentials AcquireCredentialsHandle(string packa
4041
if (result != Interop.SECURITY_STATUS.OK)
4142
{
4243
if (NetEventSource.IsEnabled)
43-
NetEventSource.Error(null, System.StringsHelper.Format(Strings.net_log_operation_failed_with_error, nameof(Interop.SspiCli.SspiEncodeStringsAsAuthIdentity), $"0x{(int)result:X}"));
44+
NetEventSource.Error(null, StringsHelper.Format(Strings.net_log_operation_failed_with_error, nameof(Interop.SspiCli.SspiEncodeStringsAsAuthIdentity), $"0x{(int)result:X}"));
4445
throw new Win32Exception((int)result);
4546
}
4647

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@
330330
<Compile Include="..\..\src\Resources\ResDescriptionAttribute.cs">
331331
<Link>Resources\ResDescriptionAttribute.cs</Link>
332332
</Compile>
333+
<Compile Include="..\..\src\Resources\StringsHelper.cs">
334+
<Link>Resources\StringsHelper.cs</Link>
335+
</Compile>
333336
</ItemGroup>
334337
<ItemGroup Condition="'$(TargetGroup)' == 'netstandard' OR '$(TargetGroup)' == 'netcoreapp' OR '$(IsUAPAssembly)' == 'true'">
335338
<Compile Include="Microsoft.Data.SqlClient.TypeForwards.cs" />
@@ -401,7 +404,9 @@
401404
<Compile Include="Microsoft\Data\SqlClient\SimulatorEnclaveProvider.NetCoreApp.cs" />
402405
</ItemGroup>
403406
<ItemGroup Condition="'$(OSGroup)' != 'AnyOS'">
404-
<Compile Include="Resources\StringsHelper.cs" />
407+
<Compile Include="Resources\StringsHelper.cs">
408+
<Link>Resources\StringsHelper.NetCore.cs</Link>
409+
</Compile>
405410
<Compile Include="Resources\Strings.Designer.cs">
406411
<DesignTime>True</DesignTime>
407412
<AutoGen>True</AutoGen>

0 commit comments

Comments
 (0)